summaryrefslogtreecommitdiff
path: root/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
diff options
context:
space:
mode:
authorMatt Holgate <matt@emobix.co.uk>2014-06-20 10:21:40 +0100
committerMatt Holgate <matt@emobix.co.uk>2014-06-20 10:21:40 +0100
commitd7ece4132d6219ee10ba9ed85a9f2a052a6bb92c (patch)
tree47b751a13321ad9d7fe4fa8261b41ff29587a353 /platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
parent7ba8c60c5af8ff745336c50c7504bec4f9b22a76 (diff)
downloadmupdf-d7ece4132d6219ee10ba9ed85a9f2a052a6bb92c.tar.xz
Improvement which should hopefully help with bug #693607 - MupdfActivity crash when rotating the device.
When cancelling a render async task, we now wait for it to actually finish before continuing. The benefit of this is that we should be able to guarantee that its Bitmap becomes eligible for GC before we continue to create any new bitmaps. This should hopefully help with the OOM errors seen when rotating the device and trying to create the new bitmaps. To prevent the UI thread from being blocked for too long while we're waiting for the async task to finish, we use a fz_cookie and set the 'abort' flag to request the render be stopped as soon as possible.
Diffstat (limited to 'platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java')
-rw-r--r--platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java43
1 files changed, 37 insertions, 6 deletions
diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
index ecdeccc7..ec35ef7c 100644
--- a/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
+++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
@@ -33,12 +33,14 @@ public class MuPDFCore
private native void drawPage(Bitmap bitmap,
int pageW, int pageH,
int patchX, int patchY,
- int patchW, int patchH);
+ int patchW, int patchH,
+ long cookiePtr);
private native void updatePageInternal(Bitmap bitmap,
int page,
int pageW, int pageH,
int patchX, int patchY,
- int patchW, int patchH);
+ int patchW, int patchH,
+ long cookiePtr);
private native RectF[] searchPage(String text);
private native TextChar[][][][] text();
private native byte[] textAsHtml();
@@ -69,9 +71,36 @@ public class MuPDFCore
private native void destroying();
private native boolean hasChangesInternal();
private native void saveInternal();
+ private native long createCookie();
+ private native void destroyCookie(long cookie);
+ private native void abortCookie(long cookie);
public native boolean javascriptSupported();
+ public class Cookie
+ {
+ private final long cookiePtr;
+
+ public Cookie()
+ {
+ cookiePtr = createCookie();
+ if (cookiePtr == 0)
+ throw new OutOfMemoryError();
+ }
+
+ public void abort()
+ {
+ abortCookie(cookiePtr);
+ }
+
+ public void destroy()
+ {
+ // We could do this in finalize, but there's no guarantee that
+ // a finalize will occur before the muPDF context occurs.
+ destroyCookie(cookiePtr);
+ }
+ }
+
public MuPDFCore(Context context, String filename) throws Exception
{
globals = openFile(filename);
@@ -152,16 +181,18 @@ public class MuPDFCore
public synchronized void drawPage(Bitmap bm, int page,
int pageW, int pageH,
int patchX, int patchY,
- int patchW, int patchH) {
+ int patchW, int patchH,
+ MuPDFCore.Cookie cookie) {
gotoPage(page);
- drawPage(bm, pageW, pageH, patchX, patchY, patchW, patchH);
+ drawPage(bm, pageW, pageH, patchX, patchY, patchW, patchH, cookie.cookiePtr);
}
public synchronized void updatePage(Bitmap bm, int page,
int pageW, int pageH,
int patchX, int patchY,
- int patchW, int patchH) {
- updatePageInternal(bm, page, pageW, pageH, patchX, patchY, patchW, patchH);
+ int patchW, int patchH,
+ MuPDFCore.Cookie cookie) {
+ updatePageInternal(bm, page, pageW, pageH, patchX, patchY, patchW, patchH, cookie.cookiePtr);
}
public synchronized PassClickResult passClickEvent(int page, float x, float y) {