Revert "archive: Use memfd instead"

* It sucks, seems simplify the conditions, but more syscalls are
  made(read/seek/write), more context switch, futhermore AImageDecoder itself does support
  read raw buffer, and we are not intend to support multi-process decoding

This reverts commit f4826ea727.
This commit is contained in:
tarsin committed 2022-08-07 19:14:25 +08:00
1 parent f4826ea727
commit a0fe6f0d7d
6 files changed
+63 -25

No files matched your search

@@ -21,6 +21,10 @@ package com.hippo;
import android.content.Context;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.system.Os;
import android.system.OsConstants;
import java.io.FileDescriptor;
public class UriArchiveAccessor {
ParcelFileDescriptor pfd;
@@ -39,7 +43,7 @@ public class UriArchiveAccessor {
private native int openArchive(int fd, long size);
public native int extractToMemfd(int index);
public native long extracttoOutputStream(int index);
public native boolean needPassword();
@@ -49,7 +49,7 @@ public class ArchiveGalleryProvider extends GalleryProvider2 {
private final UriArchiveAccessor archiveAccessor;
private final Stack<Integer> requests = new Stack<>();
private final AtomicInteger extractingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
private final LinkedHashMap<Integer, Integer> streams = new LinkedHashMap<>();
private final LinkedHashMap<Integer, Long> streams = new LinkedHashMap<>();
private final AtomicInteger decodingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
private Thread archiveThread;
private Thread decodeThread;
@@ -255,10 +255,10 @@ public class ArchiveGalleryProvider extends GalleryProvider2 {
}
}
int fd = archiveAccessor.extractToMemfd(index);
long addr = archiveAccessor.extracttoOutputStream(index);
synchronized (streams) {
streams.put(index, fd);
streams.put(index, addr);
streams.notify();
}
}
@@ -270,7 +270,7 @@ public class ArchiveGalleryProvider extends GalleryProvider2 {
public void run() {
while (!Thread.currentThread().isInterrupted()) {
int index;
int fd;
Long addr;
synchronized (streams) {
if (streams.isEmpty()) {
try {
@@ -282,16 +282,16 @@ public class ArchiveGalleryProvider extends GalleryProvider2 {
continue;
}
Iterator<Map.Entry<Integer, Integer>> iterator = streams.entrySet().iterator();
Map.Entry<Integer, Integer> entry = iterator.next();
Iterator<Map.Entry<Integer, Long>> iterator = streams.entrySet().iterator();
Map.Entry<Integer, Long> entry = iterator.next();
iterator.remove();
index = entry.getKey();
fd = entry.getValue();
addr = entry.getValue();
decodingIndex.lazySet(index);
}
try {
Image image = Image.decode(fd, false);
Image image = Image.decodeAddr(addr, true);
if (image != null) {
notifyPageSucceed(index, image);
} else {
@@ -71,6 +71,14 @@ public final class Image {
return newFromAddr(nativeDecodeFdInt(fd));
}
/**
* Decode image from {@code InputStream}
*/
@Nullable
public static Image decodeAddr(Long addr, boolean partially) {
return newFromAddr(nativeDecodeAddr(addr));
}
/**
* Create a plain image from Bitmap
*/
@@ -91,6 +99,8 @@ public final class Image {
private static native long nativeDecodeFdInt(int fd);
private static native long nativeDecodeAddr(long addr);
private static native long nativeCreate(Bitmap bitmap);
private static native void nativeRender(long nativePtr,