diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-02-18 15:14:57 +0900 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-02-23 10:10:25 +0100 |
commit | 9a51a1f4cc6cea442957ae5f9bda4d1cd5379685 (patch) | |
tree | ddbd1875b699e0f78ef379741032944ac617ecd5 | |
parent | f699de99bdc86408c47086d15f80408734c42ae4 (diff) |
android: do tile reevaluation in LOKitThread
Currently the tile reevaluation was done in UI thread which could
cause UI stutters as reevaluation is not a simple task. The
result was also a lot of tile rendering requests to LOKitThread.
This changes turns this around and the tile reevaluation is done
in LOKitThread instead. Now the UI thread just sends a LOEvent
when the reevaluation should be done. This should also reduce
the amount of messages that are queued in LOKitThread, however
an execution time should increase.
Change-Id: I01ce911226a71607c06da6100de323ca555db474
4 files changed, 43 insertions, 29 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java index 04afd804011f..bc786f5261b3 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java @@ -16,7 +16,7 @@ public class LOEvent implements Comparable<LOEvent> { public static final int LOAD = 4; public static final int CLOSE = 5; public static final int REDRAW = 6; - public static final int TILE_REQUEST = 7; + public static final int TILE_REEVALUATION_REQUEST = 7; public static final int THUMBNAIL = 8; public static final int TILE_INVALIDATION = 9; public static final int TOUCH = 10; @@ -29,7 +29,6 @@ public class LOEvent implements Comparable<LOEvent> { public String mTypeString; public int mPartIndex; public String mFilename; - public SubTile mTile; public ComposedTileLayer mComposedTileLayer; public String mTouchType; public MotionEvent mMotionEvent; @@ -47,11 +46,10 @@ public class LOEvent implements Comparable<LOEvent> { mTypeString = "Size Changed: " + widthPixels + " " + heightPixels; } - public LOEvent(int type, ComposedTileLayer composedTileLayer, SubTile tile) { + public LOEvent(int type, ComposedTileLayer composedTileLayer) { mType = type; - mTypeString = "Tile Request"; + mTypeString = "Tile Reevaluation"; mComposedTileLayer = composedTileLayer; - mTile = tile; } public LOEvent(int type, String filename) { diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java index fab30b2c4813..a8295796a291 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java @@ -123,9 +123,7 @@ public class LOKitShell { LOKitShell.sendEvent(new LOEvent(LOEvent.REDRAW)); } - public static void sendTileRequestEvent(ComposedTileLayer composedTileLayer, SubTile tile, boolean forceRedraw, int priority) { - LOEvent event = new LOEvent(LOEvent.TILE_REQUEST, composedTileLayer, tile); - LOKitShell.sendEvent(event); + public static void sendTileReevaluationRequest(ComposedTileLayer composedTileLayer) { + LOKitShell.sendEvent(new LOEvent(LOEvent.TILE_REEVALUATION_REQUEST, composedTileLayer)); } - } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java index 7743047fc9ba..e06107d1aecb 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java @@ -44,23 +44,36 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation } } - private void tileRequest(ComposedTileLayer composedTileLayer, SubTile tile) { + /* Viewport changed, recheck if tiles need to be added / removed */ + private void tileReevaluationRequest(ComposedTileLayer composedTileLayer) { if (mTileProvider == null) { return; } + List<SubTile> tiles = new ArrayList<SubTile>(); + + mLayerClient.beginDrawing(); + composedTileLayer.addNewTiles(tiles); + mLayerClient.endDrawing(); - if (composedTileLayer.isStillValid(tile.id)) { + for (SubTile tile : tiles) { TileIdentifier tileId = tile.id; CairoImage image = mTileProvider.createTile(tileId.x, tileId.y, tileId.size, tileId.zoom); + mLayerClient.beginDrawing(); if (image != null) { - mLayerClient.beginDrawing(); tile.setImage(image); - mLayerClient.endDrawing(); - mLayerClient.forceRender(); } + mLayerClient.endDrawing(); + mLayerClient.forceRender(); } + + mLayerClient.beginDrawing(); + composedTileLayer.markTiles(); + composedTileLayer.clearMarkedTiles(); + mLayerClient.endDrawing(); + mLayerClient.forceRender(); } + /* Invalidate tiles that intersect the input rect */ private void tileInvalidation(RectF rect) { if (mLayerClient == null || mTileProvider == null) { return; @@ -171,9 +184,6 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation case LOEvent.CHANGE_PART: changePart(event.mPartIndex); break; - case LOEvent.TILE_REQUEST: - tileRequest(event.mComposedTileLayer, event.mTile); - break; case LOEvent.TILE_INVALIDATION: tileInvalidation(event.mInvalidationRect); break; @@ -186,6 +196,9 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation case LOEvent.KEY_EVENT: keyEvent(event.mKeyEventType, event.mKeyEvent); break; + case LOEvent.TILE_REEVALUATION_REQUEST: + tileReevaluationRequest(event.mComposedTileLayer); + break; } } diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ComposedTileLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ComposedTileLayer.java index 62eae49c9469..683955ea074e 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ComposedTileLayer.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ComposedTileLayer.java @@ -29,7 +29,10 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba private final Lock tilesWriteLock = tilesReadWriteLock.writeLock(); protected RectF currentViewport = new RectF(); - protected float currentZoom; + protected float currentZoom = 1.0f; + protected RectF currentPageRect = new RectF(); + + private long reevaluationNanoTime = 0; public ComposedTileLayer(Context context) { context.registerComponentCallbacks(this); @@ -149,12 +152,16 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba if (currentViewport.equals(newViewPort) && FloatUtils.fuzzyEquals(currentZoom, newZoom)) { return; } + currentViewport = newViewPort; currentZoom = newZoom; + currentPageRect = viewportMetrics.getPageRect(); - clearMarkedTiles(); - addNewTiles(viewportMetrics.getPageRect()); - markTiles(); + long currentReevaluationNanoTime = System.nanoTime(); + if ((currentReevaluationNanoTime - reevaluationNanoTime) > 25 * 1000000) { + reevaluationNanoTime = currentReevaluationNanoTime; + LOKitShell.sendTileReevaluationRequest(this); + } } protected abstract RectF getViewPort(ImmutableViewportMetrics viewportMetrics); @@ -177,27 +184,25 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba } } - private void addNewTiles(RectF pageRect) { - beginTransaction(); + public void addNewTiles(List<SubTile> newTiles) { for (float y = currentViewport.top; y < currentViewport.bottom; y += tileSize.height) { - if (y > pageRect.height()) { + if (y > currentPageRect.height()) { continue; } for (float x = currentViewport.left; x < currentViewport.right; x += tileSize.width) { - if (x > pageRect.width()) { + if (x > currentPageRect.width()) { continue; } if (!containsTilesMatching(x, y, currentZoom)) { TileIdentifier tileId = new TileIdentifier((int) x, (int) y, currentZoom, tileSize); SubTile tile = createNewTile(tileId); - LOKitShell.sendTileRequestEvent(this, tile, true, getTilePriority()); + newTiles.add(tile); } } } - endTransaction(); } - private void clearMarkedTiles() { + public void clearMarkedTiles() { tilesWriteLock.lock(); Iterator<SubTile> iterator = tiles.iterator(); while (iterator.hasNext()) { @@ -210,7 +215,7 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba tilesWriteLock.unlock(); } - private void markTiles() { + public void markTiles() { tilesReadLock.lock(); for (SubTile tile : tiles) { if (FloatUtils.fuzzyEquals(tile.id.zoom, currentZoom)) { |