From b9b12fb56e0337fd068ad5bf810914ffdc5a7e7a Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 22 Jan 2013 10:31:12 +0000 Subject: 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. --- android/src/com/artifex/mupdfdemo/PageView.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'android/src/com/artifex/mupdfdemo/PageView.java') 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() { 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() { 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]; -- cgit v1.2.3