diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2012-09-18 14:26:17 +0100 |
---|---|---|
committer | Paul Gardiner <paulg.artifex@glidos.net> | 2012-09-19 15:06:18 +0100 |
commit | 9e609e1dcf6a1dac9195a4cfecac2a573ba42433 (patch) | |
tree | c9b6bc1339390474ebf20adca7e0111be4cf848e /android/src/com | |
parent | 7428d9e85791260bf9d481b49e90c4321339453a (diff) | |
download | mupdf-9e609e1dcf6a1dac9195a4cfecac2a573ba42433.tar.xz |
Android: make bitmap creation part of the synchronised drawPage method
If the user rapidly changes page, many drawPage calls can be queued for
many page views, each holding a reference to a bitmap. This change ensures
that bitmap creation will be delayed until the bitmaps of other views will
be gc'able, thus fixing bug 693230: "Mupdf/android provokes out of memory
when continuously rendering pages in pdf with large images".
Diffstat (limited to 'android/src/com')
-rw-r--r-- | android/src/com/artifex/mupdf/MuPDFCore.java | 7 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/MuPDFPageAdapter.java | 1 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/MuPDFPageView.java | 4 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/PageView.java | 57 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/ReaderView.java | 1 |
5 files changed, 33 insertions, 37 deletions
diff --git a/android/src/com/artifex/mupdf/MuPDFCore.java b/android/src/com/artifex/mupdf/MuPDFCore.java index a4b80fef..b52a3682 100644 --- a/android/src/com/artifex/mupdf/MuPDFCore.java +++ b/android/src/com/artifex/mupdf/MuPDFCore.java @@ -1,5 +1,6 @@ package com.artifex.mupdf; import android.graphics.Bitmap; +import android.graphics.Bitmap.Config; import android.graphics.PointF; import android.graphics.RectF; @@ -79,12 +80,14 @@ public class MuPDFCore destroying(); } - public synchronized void drawPage(int page, Bitmap bitmap, + public synchronized Bitmap drawPage(int page, int pageW, int pageH, int patchX, int patchY, int patchW, int patchH) { gotoPage(page); - drawPage(bitmap, pageW, pageH, patchX, patchY, patchW, patchH); + Bitmap bm = Bitmap.createBitmap(patchW, patchH, Config.ARGB_8888); + drawPage(bm, pageW, pageH, patchX, patchY, patchW, patchH); + return bm; } public synchronized int hitLinkPage(int page, float x, float y) { diff --git a/android/src/com/artifex/mupdf/MuPDFPageAdapter.java b/android/src/com/artifex/mupdf/MuPDFPageAdapter.java index e015ceb4..8189f81f 100644 --- a/android/src/com/artifex/mupdf/MuPDFPageAdapter.java +++ b/android/src/com/artifex/mupdf/MuPDFPageAdapter.java @@ -3,7 +3,6 @@ package com.artifex.mupdf; import android.content.Context; import android.graphics.Point; import android.graphics.PointF; -import android.os.AsyncTask; import android.util.SparseArray; import android.view.View; import android.view.ViewGroup; diff --git a/android/src/com/artifex/mupdf/MuPDFPageView.java b/android/src/com/artifex/mupdf/MuPDFPageView.java index 4678fc9c..6294bc55 100644 --- a/android/src/com/artifex/mupdf/MuPDFPageView.java +++ b/android/src/com/artifex/mupdf/MuPDFPageView.java @@ -25,9 +25,9 @@ public class MuPDFPageView extends PageView { } @Override - protected void drawPage(Bitmap bm, int sizeX, int sizeY, + protected Bitmap drawPage(int sizeX, int sizeY, int patchX, int patchY, int patchWidth, int patchHeight) { - mCore.drawPage(mPageNumber, bm, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight); + return mCore.drawPage(mPageNumber, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight); } @Override diff --git a/android/src/com/artifex/mupdf/PageView.java b/android/src/com/artifex/mupdf/PageView.java index 7a0fcfa9..32ff7e74 100644 --- a/android/src/com/artifex/mupdf/PageView.java +++ b/android/src/com/artifex/mupdf/PageView.java @@ -8,8 +8,6 @@ import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; -import android.os.AsyncTask; -import android.os.Build; import android.os.Handler; import android.view.View; import android.view.ViewGroup; @@ -21,8 +19,8 @@ class PatchInfo { public Point patchViewSize; public Rect patchArea; - public PatchInfo(Bitmap aBm, Point aPatchViewSize, Rect aPatchArea) { - bm = aBm; + public PatchInfo(Point aPatchViewSize, Rect aPatchArea) { + bm = null; patchViewSize = aPatchViewSize; patchArea = aPatchArea; } @@ -53,8 +51,8 @@ public abstract class PageView extends ViewGroup { protected float mSourceScale; private ImageView mEntire; // Image rendered at minimum zoom - private Bitmap mEntireBm; - private SafeAsyncTask<Void,Void,LinkInfo[]> mDrawEntire; + private SafeAsyncTask<Void,Void,LinkInfo[]> mGetLinkInfo; + private SafeAsyncTask<Void,Void,Bitmap> mDrawEntire; private Point mPatchViewSize; // View size on the basis of which the patch was created private Rect mPatchArea; @@ -64,7 +62,6 @@ public abstract class PageView extends ViewGroup { private LinkInfo mLinks[]; private View mSearchView; private boolean mIsBlank; - private boolean mUsingHardwareAcceleration; private boolean mHighlightLinks; private ProgressBar mBusyIndicator; @@ -75,10 +72,9 @@ public abstract class PageView extends ViewGroup { mContext = c; mParentSize = parentSize; setBackgroundColor(BACKGROUND_COLOR); - mUsingHardwareAcceleration = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; } - protected abstract void drawPage(Bitmap bm, 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 LinkInfo[] getLinkInfo(); public void releaseResources() { @@ -165,26 +161,28 @@ public abstract class PageView extends ViewGroup { Point newSize = new Point((int)(size.x*mSourceScale), (int)(size.y*mSourceScale)); mSize = newSize; - if (mUsingHardwareAcceleration) { - // When hardware accelerated, updates to the bitmap seem to be - // ignored, so we recreate it. There may be another way around this - // that we are yet to find. - mEntire.setImageBitmap(null); - mEntireBm = null; - } + mEntire.setImageBitmap(null); - if (mEntireBm == null || mEntireBm.getWidth() != newSize.x - || mEntireBm.getHeight() != newSize.y) { - mEntireBm = Bitmap.createBitmap(mSize.x, mSize.y, Bitmap.Config.ARGB_8888); - } - - // Render the page in the background - mDrawEntire = new SafeAsyncTask<Void,Void,LinkInfo[]>() { + // Get the link info in the background + mGetLinkInfo = new SafeAsyncTask<Void,Void,LinkInfo[]>() { protected LinkInfo[] doInBackground(Void... v) { - drawPage(mEntireBm, mSize.x, mSize.y, 0, 0, mSize.x, mSize.y); return getLinkInfo(); } + protected void onPostExecute(LinkInfo[] v) { + mLinks = v; + invalidate(); + } + }; + + mGetLinkInfo.safeExecute(); + + // Render the page in the background + mDrawEntire = new SafeAsyncTask<Void,Void,Bitmap>() { + protected Bitmap doInBackground(Void... v) { + return drawPage(mSize.x, mSize.y, 0, 0, mSize.x, mSize.y); + } + protected void onPreExecute() { mEntire.setImageBitmap(null); @@ -203,11 +201,10 @@ public abstract class PageView extends ViewGroup { } } - protected void onPostExecute(LinkInfo[] v) { + protected void onPostExecute(Bitmap bm) { removeView(mBusyIndicator); mBusyIndicator = null; - mEntire.setImageBitmap(mEntireBm); - mLinks = v; + mEntire.setImageBitmap(bm); invalidate(); } }; @@ -352,11 +349,9 @@ public abstract class PageView extends ViewGroup { mSearchView.bringToFront(); } - Bitmap bm = Bitmap.createBitmap(patchArea.width(), patchArea.height(), Bitmap.Config.ARGB_8888); - mDrawPatch = new SafeAsyncTask<PatchInfo,Void,PatchInfo>() { protected PatchInfo doInBackground(PatchInfo... v) { - drawPage(v[0].bm, v[0].patchViewSize.x, v[0].patchViewSize.y, + 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()); return v[0]; @@ -374,7 +369,7 @@ public abstract class PageView extends ViewGroup { } }; - mDrawPatch.safeExecute(new PatchInfo(bm, patchViewSize, patchArea)); + mDrawPatch.safeExecute(new PatchInfo(patchViewSize, patchArea)); } } diff --git a/android/src/com/artifex/mupdf/ReaderView.java b/android/src/com/artifex/mupdf/ReaderView.java index fc031471..de68ca39 100644 --- a/android/src/com/artifex/mupdf/ReaderView.java +++ b/android/src/com/artifex/mupdf/ReaderView.java @@ -28,7 +28,6 @@ public class ReaderView extends AdapterView<Adapter> private static final int FLING_MARGIN = 100; private static final int GAP = 20; - private static final int SCROLL_SPEED = 2; private static final float MIN_SCALE = 1.0f; private static final float MAX_SCALE = 5.0f; |