summaryrefslogtreecommitdiff
path: root/android/src/com/artifex/mupdfdemo
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-01-22 10:31:12 +0000
committerRobin Watts <robin.watts@artifex.com>2013-01-22 10:37:43 +0000
commitb9b12fb56e0337fd068ad5bf810914ffdc5a7e7a (patch)
tree395bc35db15e1397c2fef9c8701f3872e28ca201 /android/src/com/artifex/mupdfdemo
parent5822ff1619fda7f0cc0b10f77d351eb459e3c67c (diff)
downloadmupdf-b9b12fb56e0337fd068ad5bf810914ffdc5a7e7a.tar.xz
More work on android bitmap recycling.
After much discussion and investigation, Paul and I have realised that we do in fact (in the current scheme at least) need to hold the existing bitmap in memory while drawing the next one (as the existing bitmap is still in an ImageView and being used for any foreground render requests). As such remove a 'setBm(null)' in drawPage. Also, in the onPostExecute for the patch redraw, we cannot recycle the bitmap in a bitmap holder due to it still potentially being in use. We therefore add a 'drop' method to the BitmapHolder class that sets the reference to null without recycling. This is not ideal, but is better than recycling too early and causing crashes.
Diffstat (limited to 'android/src/com/artifex/mupdfdemo')
-rw-r--r--android/src/com/artifex/mupdfdemo/BitmapHolder.java4
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFCore.java4
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFPageView.java4
-rw-r--r--android/src/com/artifex/mupdfdemo/PageView.java18
4 files changed, 16 insertions, 14 deletions
diff --git a/android/src/com/artifex/mupdfdemo/BitmapHolder.java b/android/src/com/artifex/mupdfdemo/BitmapHolder.java
index f563e897..5816e7bb 100644
--- a/android/src/com/artifex/mupdfdemo/BitmapHolder.java
+++ b/android/src/com/artifex/mupdfdemo/BitmapHolder.java
@@ -15,6 +15,10 @@ public class BitmapHolder {
bm = abm;
}
+ public synchronized void drop() {
+ bm = null;
+ }
+
public synchronized Bitmap getBm() {
return bm;
}
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFCore.java b/android/src/com/artifex/mupdfdemo/MuPDFCore.java
index 1e5c0686..cf35be8d 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFCore.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFCore.java
@@ -119,13 +119,11 @@ public class MuPDFCore
globals = 0;
}
- public synchronized Bitmap drawPage(BitmapHolder h, int page,
+ public synchronized Bitmap drawPage(int page,
int pageW, int pageH,
int patchX, int patchY,
int patchW, int patchH) {
gotoPage(page);
- // Clear the reference out before creating the new bitmap
- h.setBm(null);
Bitmap bm = Bitmap.createBitmap(patchW, patchH, Config.ARGB_8888);
drawPage(bm, pageW, pageH, patchX, patchY, patchW, patchH);
return bm;
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
index c975cc70..64877198 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
@@ -201,9 +201,9 @@ public class MuPDFPageView extends PageView {
}
@Override
- protected Bitmap drawPage(BitmapHolder h, int sizeX, int sizeY,
+ protected Bitmap drawPage(int sizeX, int sizeY,
int patchX, int patchY, int patchWidth, int patchHeight) {
- return mCore.drawPage(h, mPageNumber, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight);
+ return mCore.drawPage(mPageNumber, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight);
}
@Override
diff --git a/android/src/com/artifex/mupdfdemo/PageView.java b/android/src/com/artifex/mupdfdemo/PageView.java
index 064ce3f8..8e784b24 100644
--- a/android/src/com/artifex/mupdfdemo/PageView.java
+++ b/android/src/com/artifex/mupdfdemo/PageView.java
@@ -140,7 +140,7 @@ public abstract class PageView extends ViewGroup {
mPatchBmh = new BitmapHolder();
}
- protected abstract Bitmap drawPage(BitmapHolder h, int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight);
+ protected abstract Bitmap drawPage(int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight);
protected abstract Bitmap updatePage(BitmapHolder h, int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight);
protected abstract LinkInfo[] getLinkInfo();
protected abstract TextWord[][] getText();
@@ -255,7 +255,7 @@ public abstract class PageView extends ViewGroup {
// Render the page in the background
mDrawEntire = new AsyncTask<Void,Void,Bitmap>() {
protected Bitmap doInBackground(Void... v) {
- return drawPage(mEntireBmh, mSize.x, mSize.y, 0, 0, mSize.x, mSize.y);
+ return drawPage(mSize.x, mSize.y, 0, 0, mSize.x, mSize.y);
}
protected void onPreExecute() {
@@ -529,7 +529,7 @@ public abstract class PageView extends ViewGroup {
// previously invoked task, and possibly for a different
// area, so we cannot risk the bitmap generated by this task
// being passed to it
- mPatchBmh.setBm(null);
+ mPatchBmh.drop();
mPatchBmh = new BitmapHolder();
}
@@ -544,13 +544,13 @@ public abstract class PageView extends ViewGroup {
mDrawPatch = new AsyncTask<PatchInfo,Void,PatchInfo>() {
protected PatchInfo doInBackground(PatchInfo... v) {
if (v[0].completeRedraw) {
- v[0].bm = drawPage(v[0].bmh, v[0].patchViewSize.x, v[0].patchViewSize.y,
- v[0].patchArea.left, v[0].patchArea.top,
- v[0].patchArea.width(), v[0].patchArea.height());
+ v[0].bm = drawPage(v[0].patchViewSize.x, v[0].patchViewSize.y,
+ v[0].patchArea.left, v[0].patchArea.top,
+ v[0].patchArea.width(), v[0].patchArea.height());
} else {
- v[0].bm = updatePage(v[0].bmh, v[0].patchViewSize.x, v[0].patchViewSize.y,
- v[0].patchArea.left, v[0].patchArea.top,
- v[0].patchArea.width(), v[0].patchArea.height());
+ v[0].bm = updatePage(v[0].bmh, v[0].patchViewSize.x, v[0].patchViewSize.y,
+ v[0].patchArea.left, v[0].patchArea.top,
+ v[0].patchArea.width(), v[0].patchArea.height());
}
return v[0];