diff options
author | fred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local> | 2016-07-14 17:09:32 -0700 |
---|---|---|
committer | fred ross-perry <fred.ross-perry@artifex.com> | 2016-07-15 10:09:03 -0700 |
commit | 599f15e3364602f5b2287a81b84037ed8c56250f (patch) | |
tree | eeefb0258bd96e13fa865e3c42c2d266968c937b /platform | |
parent | c845fe961a6846b46116a38bb0dd8a9e5bdba609 (diff) | |
download | mupdf-599f15e3364602f5b2287a81b84037ed8c56250f.tar.xz |
android example - add cacheing of page contents and annotations.
Diffstat (limited to 'platform')
-rwxr-xr-x | platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java | 87 |
1 files changed, 73 insertions, 14 deletions
diff --git a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java index bbad7cb9..52962bb5 100755 --- a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java +++ b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java @@ -15,6 +15,9 @@ import android.view.ViewGroup; import com.artifex.mupdf.fitz.android.AndroidDrawDevice; import com.artifex.mupdf.fitz.Annotation; +import com.artifex.mupdf.fitz.Cookie; +import com.artifex.mupdf.fitz.DisplayList; +import com.artifex.mupdf.fitz.DisplayListDevice; import com.artifex.mupdf.fitz.Document; import com.artifex.mupdf.fitz.Matrix; import com.artifex.mupdf.fitz.Page; @@ -45,6 +48,10 @@ public class DocPageView extends View implements Callback private final Rect mSrcRect = new Rect(); private final Rect mDstRect = new Rect(); + // cached display lists + DisplayList pageContents = null; + DisplayList annotContents = null; + // current size of this view private Point mSize; @@ -72,6 +79,16 @@ public class DocPageView extends View implements Callback { mPageNum = thePageNum; + // de-cache contents and annotations + if (pageContents != null) { + pageContents.destroy(); + pageContents = null; + } + if (annotContents != null) { + annotContents.destroy(); + annotContents = null; + } + // destroy the page before making a new one. if (mPage!=null) mPage.destroy(); @@ -210,6 +227,9 @@ public class DocPageView extends View implements Callback mRenderScale = mScale; mRenderBitmap = bitmap; + // cache this page's display and annotation lists + cachePage(); + // Render the page in the background RenderTaskParams params = new RenderTaskParams(new RenderListener() { @Override @@ -229,6 +249,53 @@ public class DocPageView extends View implements Callback new RenderTask().execute(params, null, null); } + private void cachePage() + { + Cookie cookie = new Cookie(); + + if (pageContents==null) + { + pageContents = new DisplayList(); + DisplayListDevice dispDev = new DisplayListDevice(pageContents); + try { + mPage.runPageContents(dispDev, new Matrix(1, 0, 0, 1, 0, 0), cookie); + } + catch (RuntimeException e) { + pageContents.destroy(); + dispDev.destroy(); + throw(e); + } + finally { + dispDev.destroy(); + } + } + + if (annotContents==null) + { + // run the annotation list + annotContents = new DisplayList(); + DisplayListDevice annotDev = new DisplayListDevice(annotContents); + try { + Annotation annotations[] = mPage.getAnnotations(); + if (annotations != null) + { + for (Annotation annot : annotations) + { + annot.run(annotDev, new Matrix(1, 0, 0, 1, 0, 0), cookie); + } + } + } + catch (RuntimeException e) { + annotContents.destroy(); + annotDev.destroy(); + throw(e); + } + finally { + annotDev.destroy(); + } + } + } + @Override public void onDraw(Canvas canvas) { @@ -375,20 +442,12 @@ public class DocPageView extends View implements Callback AndroidDrawDevice dev = new AndroidDrawDevice(params.bitmap, params.pageX0, params.pageY0, params.pageX1, params.pageY1, params.patchX0, params.patchY0, params.patchX1, params.patchY1); try { - // do the page - mPage.runPageContents(dev, params.ctm, null); - - // do the annotations - if (params.showAnnotations) - { - Annotation annotations[] = mPage.getAnnotations(); - if (annotations != null) - { - for (Annotation annot : annotations) - { - annot.run(dev, params.ctm, null); - } - } + Cookie cookie = new Cookie(); + if (pageContents != null) { + pageContents.run(dev, params.ctm, cookie); + } + if (annotContents != null && params.showAnnotations) { + annotContents.run(dev, params.ctm, cookie); } } catch (Exception e) |