diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-11-30 10:36:42 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-12-04 23:04:29 +0100 |
commit | a9c434a284ee9a6a2dda17d0644e6f8972f568b7 (patch) | |
tree | aada9128057fd45d43d772b14725d8ec63d0f875 /android | |
parent | b861c1cc383788792a655daf07a07853225cfeb4 (diff) |
fdo#85845 android: draw tiles immediately when they are ready
Change-Id: I924a212210703b0f6136ddefacd77d98dc89f42d
Diffstat (limited to 'android')
7 files changed, 90 insertions, 68 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java index d9f3219ee40d..ad8ed0a55abe 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java @@ -15,12 +15,14 @@ public class LOEvent { public static final int LOAD = 6; public static final int CLOSE = 7; public static final int REDRAW = 8; + public static final int TILE_REQUEST = 9; public int mType; - private ImmutableViewportMetrics mViewportMetrics; - private String mTypeString; - private int mPartIndex; - private String mFilename; + public ImmutableViewportMetrics mViewportMetrics; + public String mTypeString; + public int mPartIndex; + public String mFilename; + public TileIdentifier mTileId; public LOEvent(int type) { mType = type; @@ -31,8 +33,15 @@ public class LOEvent { mTypeString = "Size Changed: " + widthPixels + " " + heightPixels; } + public LOEvent(int type, TileIdentifier tileId) { + mType = type; + mTypeString = "Tile Request"; + mTileId = tileId; + } + public LOEvent(int type, String filename) { mType = type; + mTypeString = "Filename"; mFilename = filename; } @@ -64,16 +73,4 @@ public class LOEvent { } return mTypeString; } - - public ImmutableViewportMetrics getViewport() { - return mViewportMetrics; - } - - public int getPartIndex() { - return mPartIndex; - } - - public String getFilename() { - return mFilename; - } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java index a63b5db3d2c7..ffd440c9dfa0 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java @@ -38,4 +38,8 @@ public class LOEventFactory { public static LOEvent redraw() { return new LOEvent(LOEvent.REDRAW); } + + public static LOEvent tileRequest(TileIdentifier tileRequest) { + return new LOEvent(LOEvent.TILE_REQUEST, tileRequest); + } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java index 04b50749a1a0..c6af5e724833 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java @@ -6,7 +6,7 @@ import android.util.DisplayMetrics; import android.util.Log; import org.mozilla.gecko.gfx.GeckoLayerClient; -import org.mozilla.gecko.gfx.ImmutableViewportMetrics;; +import org.mozilla.gecko.gfx.ImmutableViewportMetrics; import java.util.concurrent.LinkedBlockingQueue; @@ -33,16 +33,17 @@ public class LOKitThread extends Thread { DisplayMetrics displayMetrics = LibreOfficeMainActivity.mAppContext.getResources().getDisplayMetrics(); mViewportMetrics = new ImmutableViewportMetrics(displayMetrics); mViewportMetrics = mViewportMetrics.setPageRect(rect, rect); - - GeckoLayerClient layerClient = mApplication.getLayerClient(); - - layerClient.beginDrawing(); - layerClient.reevaluateTiles(); - layerClient.endDrawing(mViewportMetrics); + mLayerClient.reevaluateTiles(); return true; } + private void tileRequest(TileIdentifier tileId) { + mLayerClient.beginDrawing(); + mLayerClient.addTile(tileId); + mLayerClient.endDrawing(mViewportMetrics); + } + /** Handle the geometry change + draw. */ private void redraw() { if (mLayerClient == null || mTileProvider == null) { @@ -114,13 +115,13 @@ public class LOKitThread extends Thread { Log.i(LOGTAG, "processEvent: " + event.getTypeString()); switch (event.mType) { case LOEvent.LOAD: - loadDocument(event.getFilename()); + loadDocument(event.mFilename); break; case LOEvent.CLOSE: closeDocument(); break; case LOEvent.VIEWPORT: - mViewportMetrics = event.getViewport(); + mViewportMetrics = event.mViewportMetrics; draw(); break; case LOEvent.DRAW: @@ -130,7 +131,10 @@ public class LOKitThread extends Thread { redraw(); break; case LOEvent.CHANGE_PART: - changePart(event.getPartIndex()); + changePart(event.mPartIndex); + break; + case LOEvent.TILE_REQUEST: + tileRequest(event.mTileId); break; } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIdentifier.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIdentifier.java new file mode 100644 index 000000000000..050ff1c373e5 --- /dev/null +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIdentifier.java @@ -0,0 +1,35 @@ +package org.libreoffice; + +public class TileIdentifier { + public final int x; + public final int y; + public final float zoom; + + public TileIdentifier(int x, int y, float zoom) { + this.x = x; + this.y = y; + this.zoom = zoom; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + TileIdentifier that = (TileIdentifier) o; + + if (x != that.x) return false; + if (y != that.y) return false; + if (Float.compare(that.zoom, zoom) != 0) return false; + + return true; + } + + @Override + public int hashCode() { + int result = x; + result = 31 * result + y; + result = 31 * result + (zoom != +0.0f ? Float.floatToIntBits(zoom) : 0); + return result; + } +}
\ No newline at end of file diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/DynamicTileLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/DynamicTileLayer.java index 01ab8bec9203..276ba94d113d 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/DynamicTileLayer.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/DynamicTileLayer.java @@ -5,6 +5,9 @@ import android.graphics.RectF; import android.graphics.Region; import android.util.Log; +import org.libreoffice.LOEventFactory; +import org.libreoffice.LOKitShell; +import org.libreoffice.TileIdentifier; import org.libreoffice.TileProvider; import org.mozilla.gecko.util.FloatUtils; @@ -16,6 +19,7 @@ public class DynamicTileLayer extends Layer { private static final String LOGTAG = DynamicTileLayer.class.getSimpleName(); private final List<SubTile> tiles = new CopyOnWriteArrayList<SubTile>(); + private TileProvider tileProvider; private final IntSize tileSize; private RectF currentViewport = new RectF(); @@ -33,8 +37,8 @@ public class DynamicTileLayer extends Layer { } public void invalidate() { - for (SubTile layer : tiles) { - layer.invalidate(); + for (SubTile tile : tiles) { + tile.invalidate(); } } @@ -162,10 +166,7 @@ public class DynamicTileLayer extends Layer { } } if (!contains) { - CairoImage image = tileProvider.createTile(x, y, tileSize, viewportMetrics.zoomFactor); - SubTile tile = new SubTile(image, (int) x, (int) y, viewportMetrics.zoomFactor); - tile.beginTransaction(); - tiles.add(tile); + LOKitShell.sendEvent(LOEventFactory.tileRequest(new TileIdentifier((int)x, (int)y, viewportMetrics.zoomFactor))); } } } @@ -199,4 +200,11 @@ public class DynamicTileLayer extends Layer { tiles.clear(); currentViewport = new RectF(); } + + public void addTile(TileIdentifier tileId) { + CairoImage image = tileProvider.createTile(tileId.x, tileId.y, tileSize, tileId.zoom); + SubTile tile = new SubTile(image, tileId); + tile.beginTransaction(); + tiles.add(tile); + } } diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java index 99306c5851df..7efed043e3b0 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java @@ -16,6 +16,7 @@ import android.view.GestureDetector; import org.libreoffice.LOEvent; import org.libreoffice.LOEventFactory; import org.libreoffice.LOKitShell; +import org.libreoffice.TileIdentifier; import org.libreoffice.TileProvider; import org.mozilla.gecko.ZoomConstraints; import org.mozilla.gecko.ui.PanZoomController; @@ -478,6 +479,7 @@ public class GeckoLayerClient implements PanZoomTarget, LayerView.Listener { public GestureDetector.OnDoubleTapListener getDoubleTapListener() { return mPanZoomController; } + private class AdjustRunnable implements Runnable { public void run() { mPendingViewportAdjust = false; @@ -498,4 +500,8 @@ public class GeckoLayerClient implements PanZoomTarget, LayerView.Listener { mRootLayer.clearAndReset(); } + public void addTile(TileIdentifier tileId) { + mRootLayer.addTile(tileId); + } + }
\ No newline at end of file diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/SubTile.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/SubTile.java index 7e60af1f962c..3c90501424c7 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/SubTile.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/SubTile.java @@ -5,50 +5,18 @@ package org.mozilla.gecko.gfx; +import org.libreoffice.TileIdentifier; + public class SubTile extends SingleTileLayer { public boolean markedForRemoval = false; public final TileIdentifier id; - public SubTile(CairoImage mImage, int x, int y, float zoom) { + public SubTile(CairoImage mImage, TileIdentifier id) { super(mImage); - id = new TileIdentifier(x, y, zoom); + this.id = id; } public void markForRemoval() { markedForRemoval = true; } - - public static class TileIdentifier { - public int x; - public int y; - public float zoom; - - public TileIdentifier(int x, int y, float zoom) { - this.x = x; - this.y = y; - this.zoom = zoom; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - TileIdentifier that = (TileIdentifier) o; - - if (x != that.x) return false; - if (y != that.y) return false; - if (Float.compare(that.zoom, zoom) != 0) return false; - - return true; - } - - @Override - public int hashCode() { - int result = x; - result = 31 * result + y; - result = 31 * result + (zoom != +0.0f ? Float.floatToIntBits(zoom) : 0); - return result; - } - } } |