summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2019-06-12 13:13:00 +0200
committerTor Andersson <tor.andersson@artifex.com>2019-06-12 16:08:17 +0200
commitc1b56722ba64118ed5e633f62bf7e04250661e59 (patch)
treeeff878ae84f532c81dc3f9e2d3dc0ee06732360d
parent3dba2eaee3c2dd4f81c8a18360ad84e1b6fb7f9f (diff)
Re-render page bitmap at higher resolution when zooming.1.15.0
Drawing bitmaps larger than GL supports puts the H/W acceleration in a pathological state where rendering is painfully slow. Software rendering does not have this limitation, so we need to disable H/W acceleration for the DocumentActivity. The rendering is so simple that H/W acceleration doesn't buy us much performance,
-rw-r--r--lib/src/main/AndroidManifest.xml1
-rw-r--r--lib/src/main/java/com/artifex/mupdf/mini/DocumentActivity.java18
-rw-r--r--lib/src/main/java/com/artifex/mupdf/mini/PageView.java57
3 files changed, 51 insertions, 25 deletions
diff --git a/lib/src/main/AndroidManifest.xml b/lib/src/main/AndroidManifest.xml
index 08ce245..20e9a3a 100644
--- a/lib/src/main/AndroidManifest.xml
+++ b/lib/src/main/AndroidManifest.xml
@@ -6,6 +6,7 @@
<activity android:name=".DocumentActivity"
android:label="MuPDF mini"
android:configChanges="orientation|screenSize|keyboardHidden"
+ android:hardwareAccelerated="false"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
diff --git a/lib/src/main/java/com/artifex/mupdf/mini/DocumentActivity.java b/lib/src/main/java/com/artifex/mupdf/mini/DocumentActivity.java
index 2b3f0a3..e1bf8a3 100644
--- a/lib/src/main/java/com/artifex/mupdf/mini/DocumentActivity.java
+++ b/lib/src/main/java/com/artifex/mupdf/mini/DocumentActivity.java
@@ -60,6 +60,7 @@ public class DocumentActivity extends Activity
protected float layoutW, layoutH, layoutEm;
protected float displayDPI;
protected int canvasW, canvasH;
+ protected float pageZoom;
protected View currentBar;
protected PageView pageView;
@@ -257,6 +258,7 @@ public class DocumentActivity extends Activity
}
public void onPageViewSizeChanged(int w, int h) {
+ pageZoom = 1;
canvasW = w;
canvasH = h;
layoutW = canvasW * 72 / displayDPI;
@@ -271,6 +273,13 @@ public class DocumentActivity extends Activity
}
}
+ public void onPageViewZoomChanged(float zoom) {
+ if (zoom != pageZoom) {
+ pageZoom = zoom;
+ loadPage();
+ }
+ }
+
protected void openDocument() {
worker.add(new Worker.Task() {
boolean needsPassword;
@@ -522,6 +531,7 @@ public class DocumentActivity extends Activity
protected void loadPage() {
final int pageNumber = currentPage;
+ final float zoom = pageZoom;
stopSearch = true;
worker.add(new Worker.Task() {
public Bitmap bitmap;
@@ -531,13 +541,12 @@ public class DocumentActivity extends Activity
try {
Log.i(APP, "load page " + pageNumber);
Page page = doc.loadPage(pageNumber);
- Log.i(APP, "draw page " + pageNumber);
+ Log.i(APP, "draw page " + pageNumber + " zoom=" + zoom);
Matrix ctm;
if (fitPage)
ctm = AndroidDrawDevice.fitPage(page, canvasW, canvasH);
else
ctm = AndroidDrawDevice.fitPageWidth(page, canvasW);
- bitmap = AndroidDrawDevice.drawPage(page, ctm);
links = page.getLinks();
if (links != null)
for (Link link : links)
@@ -548,13 +557,16 @@ public class DocumentActivity extends Activity
for (Quad hit : hits)
hit.transform(ctm);
}
+ if (zoom != 1)
+ ctm.scale(zoom);
+ bitmap = AndroidDrawDevice.drawPage(page, ctm);
} catch (Throwable x) {
Log.e(APP, x.getMessage());
}
}
public void run() {
if (bitmap != null)
- pageView.setBitmap(bitmap, wentBack, links, hits);
+ pageView.setBitmap(bitmap, zoom, wentBack, links, hits);
else
pageView.setError();
pageLabel.setText((currentPage+1) + " / " + pageCount);
diff --git a/lib/src/main/java/com/artifex/mupdf/mini/PageView.java b/lib/src/main/java/com/artifex/mupdf/mini/PageView.java
index d4841b8..c609d7b 100644
--- a/lib/src/main/java/com/artifex/mupdf/mini/PageView.java
+++ b/lib/src/main/java/com/artifex/mupdf/mini/PageView.java
@@ -20,7 +20,7 @@ public class PageView extends View implements
{
protected DocumentActivity actionListener;
- protected float viewScale, minScale, maxScale;
+ protected float pageScale, viewScale, minScale, maxScale;
protected Bitmap bitmap;
protected int bitmapW, bitmapH;
protected int canvasW, canvasH;
@@ -45,6 +45,7 @@ public class PageView extends View implements
detector = new GestureDetector(ctx, this);
scaleDetector = new ScaleGestureDetector(ctx, this);
+ pageScale = 1;
viewScale = 1;
minScale = 1;
maxScale = 2;
@@ -82,18 +83,21 @@ public class PageView extends View implements
invalidate();
}
- public void setBitmap(Bitmap b, boolean wentBack, Link[] ls, Quad[] hs) {
+ public void setBitmap(Bitmap b, float zoom, boolean wentBack, Link[] ls, Quad[] hs) {
if (bitmap != null)
bitmap.recycle();
error = false;
links = ls;
hits = hs;
bitmap = b;
- bitmapW = (int)(bitmap.getWidth() * viewScale);
- bitmapH = (int)(bitmap.getHeight() * viewScale);
+ bitmapW = (int)(bitmap.getWidth() * viewScale / zoom);
+ bitmapH = (int)(bitmap.getHeight() * viewScale / zoom);
scroller.forceFinished(true);
- scrollX = wentBack ? bitmapW - canvasW : 0;
- scrollY = wentBack ? bitmapH - canvasH : 0;
+ if (pageScale == zoom) {
+ scrollX = wentBack ? bitmapW - canvasW : 0;
+ scrollY = wentBack ? bitmapH - canvasH : 0;
+ }
+ pageScale = zoom;
invalidate();
}
@@ -179,7 +183,9 @@ public class PageView extends View implements
return true;
}
- public boolean onScaleBegin(ScaleGestureDetector det) { return true; }
+ public boolean onScaleBegin(ScaleGestureDetector det) {
+ return true;
+ }
public boolean onScale(ScaleGestureDetector det) {
if (bitmap != null) {
@@ -191,8 +197,8 @@ public class PageView extends View implements
viewScale *= scaleFactor;
if (viewScale < minScale) viewScale = minScale;
if (viewScale > maxScale) viewScale = maxScale;
- bitmapW = (int)(bitmap.getWidth() * viewScale);
- bitmapH = (int)(bitmap.getHeight() * viewScale);
+ bitmapW = (int)(bitmap.getWidth() * viewScale / pageScale);
+ bitmapH = (int)(bitmap.getHeight() * viewScale / pageScale);
scrollX = (int)(pageFocusX * viewScale - focusX);
scrollY = (int)(pageFocusY * viewScale - focusY);
scroller.forceFinished(true);
@@ -201,7 +207,9 @@ public class PageView extends View implements
return true;
}
- public void onScaleEnd(ScaleGestureDetector det) { }
+ public void onScaleEnd(ScaleGestureDetector det) {
+ actionListener.onPageViewZoomChanged(viewScale);
+ }
public void goBackward() {
scroller.forceFinished(true);
@@ -232,6 +240,7 @@ public class PageView extends View implements
}
public void onDraw(Canvas canvas) {
+ android.graphics.Rect dst;
int x, y;
if (bitmap == null) {
@@ -266,28 +275,32 @@ public class PageView extends View implements
y = -scrollY;
}
- canvas.translate(x, y);
- canvas.scale(viewScale, viewScale);
- canvas.drawBitmap(bitmap, 0, 0, null);
+ dst = new android.graphics.Rect(x, y, x + bitmapW, y + bitmapH);
+ canvas.drawBitmap(bitmap, null, dst, null);
if (showLinks && links != null && links.length > 0) {
for (Link link : links) {
Rect b = link.bounds;
- canvas.drawRect(b.x0, b.y0, b.x1, b.y1, linkPaint);
+ canvas.drawRect(
+ x + b.x0 * viewScale,
+ y + b.y0 * viewScale,
+ x + b.x1 * viewScale,
+ y + b.y1 * viewScale,
+ linkPaint
+ );
}
}
- if (hits != null && hits.length > 0)
- for (Quad q : hits)
- {
+ if (hits != null && hits.length > 0) {
+ for (Quad q : hits) {
Path path = new Path();
- path.moveTo(q.ul_x, q.ul_y);
- path.lineTo(q.ll_x, q.ll_y);
- path.lineTo(q.lr_x, q.lr_y);
- path.lineTo(q.ur_x, q.ur_y);
+ path.moveTo(x + q.ul_x * viewScale, y + q.ul_y * viewScale);
+ path.lineTo(x + q.ll_x * viewScale, y + q.ll_y * viewScale);
+ path.lineTo(x + q.lr_x * viewScale, y + q.lr_y * viewScale);
+ path.lineTo(x + q.ur_x * viewScale, y + q.ur_y * viewScale);
path.close();
-
canvas.drawPath(path, hitPaint);
}
+ }
}
}