[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 8 commits - android/experimental

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Wed Feb 18 02:01:12 PST 2015


 android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java                 |    9 
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java              |    8 
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java             |   66 +++--
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ComposedTileLayer.java |  117 +++++-----
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java  |    6 
 5 files changed, 114 insertions(+), 92 deletions(-)

New commits:
commit 1e9cffb2ad524f9fa142056d97c17c48d28cd93f
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Feb 18 15:42:05 2015 +0900

    android: restructure reevaluateTiles
    
    Change-Id: I1c0657e512e6d3bf7a4742a356f201c993aef658

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 683955e..e11c91c 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
@@ -153,15 +153,18 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba
             return;
         }
 
+        long currentReevaluationNanoTime = System.nanoTime();
+        if ((currentReevaluationNanoTime - reevaluationNanoTime) < 25 * 1000000) {
+            return;
+        }
+
+        reevaluationNanoTime = currentReevaluationNanoTime;
+
         currentViewport = newViewPort;
         currentZoom = newZoom;
         currentPageRect = viewportMetrics.getPageRect();
 
-        long currentReevaluationNanoTime = System.nanoTime();
-        if ((currentReevaluationNanoTime - reevaluationNanoTime) > 25 * 1000000) {
-            reevaluationNanoTime = currentReevaluationNanoTime;
-            LOKitShell.sendTileReevaluationRequest(this);
-        }
+        LOKitShell.sendTileReevaluationRequest(this);
     }
 
     protected abstract RectF getViewPort(ImmutableViewportMetrics viewportMetrics);
commit c2bee7c937ea6f8f30ca9fc77e3c0f7451d0953c
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Feb 18 15:14:57 2015 +0900

    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

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
index 04afd80..bc786f5 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 fab30b2..a829579 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 7743047..e06107d 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 62eae49..683955e 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)) {
commit c8f80bb049372235f0da722fadb54829026cad7b
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Feb 17 19:15:52 2015 +0900

    android: no need endDrawing to be synchronized
    
    Change-Id: I50bee82140e444d918ca759816edf6992a47644b

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 98f3221..40fb8bb 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
@@ -231,10 +231,8 @@ public class GeckoLayerClient implements PanZoomTarget {
     }
 
     public void endDrawing() {
-        synchronized (this) {
-            mLowResLayer.endTransaction();
-            mRootLayer.endTransaction();
-        }
+        mLowResLayer.endTransaction();
+        mRootLayer.endTransaction();
     }
 
     public void geometryChanged() {
commit 6ba15da026beb75e4c5473ba9966a1ea90ebeb13
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Feb 17 19:14:12 2015 +0900

    android: cleanup ComposedTileLayer
    
    Change-Id: I976384ac5515295a56bc1339791ab63a62dc4bea

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 9299656..62eae49 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
@@ -24,18 +24,50 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba
     protected final List<SubTile> tiles = new ArrayList<SubTile>();
 
     protected final IntSize tileSize;
-    protected RectF currentViewport = new RectF();
-    protected float currentZoom;
-
     private final ReadWriteLock tilesReadWriteLock = new ReentrantReadWriteLock();
     private final Lock tilesReadLock = tilesReadWriteLock.readLock();
     private final Lock tilesWriteLock = tilesReadWriteLock.writeLock();
 
+    protected RectF currentViewport = new RectF();
+    protected float currentZoom;
+
     public ComposedTileLayer(Context context) {
         context.registerComponentCallbacks(this);
         this.tileSize = new IntSize(256, 256);
     }
 
+    protected static RectF roundToTileSize(RectF input, IntSize tileSize) {
+        float minX = ((int) (input.left / tileSize.width)) * tileSize.width;
+        float minY = ((int) (input.top / tileSize.height)) * tileSize.height;
+        float maxX = ((int) (input.right / tileSize.width) + 1) * tileSize.width;
+        float maxY = ((int) (input.bottom / tileSize.height) + 1) * tileSize.height;
+        return new RectF(minX, minY, maxX, maxY);
+    }
+
+    protected static RectF inflate(RectF rect, IntSize inflateSize) {
+        RectF newRect = new RectF(rect);
+        newRect.left -= inflateSize.width;
+        newRect.left = newRect.left < 0.0f ? 0.0f : newRect.left;
+
+        newRect.top -= inflateSize.height;
+        newRect.top = newRect.top < 0.0f ? 0.0f : newRect.top;
+
+        newRect.right += inflateSize.width;
+        newRect.bottom += inflateSize.height;
+
+        return newRect;
+    }
+
+    protected static RectF normalizeRect(RectF rect, float sourceFactor, float targetFactor) {
+        RectF normalizedRect = new RectF(
+                (rect.left / sourceFactor) * targetFactor,
+                (rect.top / sourceFactor) * targetFactor,
+                (rect.right / sourceFactor) * targetFactor,
+                (rect.bottom / sourceFactor) * targetFactor);
+
+        return normalizedRect;
+    }
+
     public void invalidate() {
         tilesReadLock.lock();
         for (SubTile tile : tiles) {
@@ -110,38 +142,6 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba
         tilesReadLock.unlock();
     }
 
-    protected RectF roundToTileSize(RectF input, IntSize tileSize) {
-        float minX = ((int) (input.left / tileSize.width)) * tileSize.width;
-        float minY = ((int) (input.top / tileSize.height)) * tileSize.height;
-        float maxX = ((int) (input.right / tileSize.width) + 1) * tileSize.width;
-        float maxY = ((int) (input.bottom / tileSize.height) + 1) * tileSize.height;
-        return new RectF(minX, minY, maxX, maxY);
-    }
-
-    protected RectF inflate(RectF rect, IntSize inflateSize) {
-        RectF newRect = new RectF(rect);
-        newRect.left -= inflateSize.width;
-        newRect.left = newRect.left < 0.0f ? 0.0f : newRect.left;
-
-        newRect.top -= inflateSize.height;
-        newRect.top = newRect.top < 0.0f ? 0.0f : newRect.top;
-
-        newRect.right += inflateSize.width;
-        newRect.bottom += inflateSize.height;
-
-        return newRect;
-    }
-
-    protected RectF normalizeRect(RectF rect, float sourceFactor, float targetFactor) {
-        RectF normalizedRect = new RectF(
-                (rect.left / sourceFactor) * targetFactor,
-                (rect.top / sourceFactor) * targetFactor,
-                (rect.right / sourceFactor) * targetFactor,
-                (rect.bottom / sourceFactor) * targetFactor);
-
-        return normalizedRect;
-    }
-
     public void reevaluateTiles(ImmutableViewportMetrics viewportMetrics, DisplayPortMetrics mDisplayPort) {
         RectF newViewPort = getViewPort(viewportMetrics);
         float newZoom = getZoom(viewportMetrics);
@@ -276,7 +276,4 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba
             Log.i(LOGTAG, "Trimming memory - TRIM_MEMORY_RUNNING_LOW");
         }
     }
-
-    public void cleanupInvalidTile(TileIdentifier tileId) {
-    }
 }
commit 056766b52d964414d4d9a6801c90183f3420e707
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Feb 17 19:11:57 2015 +0900

    android: force a screen render on redraw in LOKitThread
    
    Change-Id: I0e0a072cbe31c85f5f2f9459ad724edcd8d5986a

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index 3265fa7..7743047 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -94,6 +94,7 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation
         zoomAndRepositionTheDocument();
 
         mLayerClient.forceRedraw();
+        mLayerClient.forceRender();
     }
 
     private void zoomAndRepositionTheDocument() {
commit 5a0fd1b3780b4361eb92345df90a654489e5086d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Feb 17 19:10:39 2015 +0900

    android: use Iterator for removing of tiles
    
    Change-Id: Ie4de7682d4f5b7e677e23fa8aae3548040bffdc7

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 ae7f98a..9299656 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
@@ -12,6 +12,7 @@ import org.libreoffice.TileIdentifier;
 import org.mozilla.gecko.util.FloatUtils;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
@@ -197,15 +198,15 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba
     }
 
     private void clearMarkedTiles() {
-        List<SubTile> tilesToRemove = new ArrayList<SubTile>();
         tilesWriteLock.lock();
-        for (SubTile tile : tiles) {
+        Iterator<SubTile> iterator = tiles.iterator();
+        while (iterator.hasNext()) {
+            SubTile tile = iterator.next();
             if (tile.markedForRemoval) {
                 tile.destroy();
-                tilesToRemove.add(tile);
+                iterator.remove();
             }
         }
-        tiles.removeAll(tilesToRemove);
         tilesWriteLock.unlock();
     }
 
commit ece1131650d1f84e278ed37b44c89380825964ee
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Feb 17 19:07:39 2015 +0900

    android: create SubTile right away to reduce tile change events
    
    Change-Id: Idbc18a721c482fccd80d9c7da00f5f5dca1a864c

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
index c51b445..04afd80 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
@@ -7,6 +7,7 @@ import android.view.MotionEvent;
 
 import org.mozilla.gecko.gfx.ComposedTileLayer;
 import org.mozilla.gecko.gfx.IntSize;
+import org.mozilla.gecko.gfx.SubTile;
 
 public class LOEvent implements Comparable<LOEvent> {
     public static final int SIZE_CHANGED = 1;
@@ -28,7 +29,7 @@ public class LOEvent implements Comparable<LOEvent> {
     public String mTypeString;
     public int mPartIndex;
     public String mFilename;
-    public TileIdentifier mTileId;
+    public SubTile mTile;
     public ComposedTileLayer mComposedTileLayer;
     public String mTouchType;
     public MotionEvent mMotionEvent;
@@ -46,11 +47,11 @@ public class LOEvent implements Comparable<LOEvent> {
         mTypeString = "Size Changed: " + widthPixels + " " + heightPixels;
     }
 
-    public LOEvent(int type, ComposedTileLayer composedTileLayer, TileIdentifier tileId) {
+    public LOEvent(int type, ComposedTileLayer composedTileLayer, SubTile tile) {
         mType = type;
         mTypeString = "Tile Request";
         mComposedTileLayer = composedTileLayer;
-        mTileId = tileId;
+        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 fd54bbf..fab30b2 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
@@ -11,6 +11,7 @@ import android.view.MotionEvent;
 
 import org.mozilla.gecko.gfx.ComposedTileLayer;
 import org.mozilla.gecko.gfx.LayerView;
+import org.mozilla.gecko.gfx.SubTile;
 
 
 public class LOKitShell {
@@ -122,9 +123,8 @@ public class LOKitShell {
         LOKitShell.sendEvent(new LOEvent(LOEvent.REDRAW));
     }
 
-    public static void sendTileRequestEvent(ComposedTileLayer composedTileLayer, TileIdentifier tileID, boolean forceRedraw, int priority) {
-        LOEvent event = new LOEvent(LOEvent.TILE_REQUEST, composedTileLayer, tileID);
-        event.mPriority = priority;
+    public static void sendTileRequestEvent(ComposedTileLayer composedTileLayer, SubTile tile, boolean forceRedraw, int priority) {
+        LOEvent event = new LOEvent(LOEvent.TILE_REQUEST, composedTileLayer, tile);
         LOKitShell.sendEvent(event);
     }
 
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index d5b0781..3265fa7 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -44,23 +44,20 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation
         }
     }
 
-    private void tileRequest(ComposedTileLayer composedTileLayer, TileIdentifier tileId) {
+    private void tileRequest(ComposedTileLayer composedTileLayer, SubTile tile) {
         if (mTileProvider == null) {
             return;
         }
 
-        if (composedTileLayer.isStillValid(tileId)) {
+        if (composedTileLayer.isStillValid(tile.id)) {
+            TileIdentifier tileId = tile.id;
             CairoImage image = mTileProvider.createTile(tileId.x, tileId.y, tileId.size, tileId.zoom);
             if (image != null) {
                 mLayerClient.beginDrawing();
-                SubTile tile = new SubTile(tileId);
                 tile.setImage(image);
-                composedTileLayer.addTile(tile);
                 mLayerClient.endDrawing();
                 mLayerClient.forceRender();
             }
-        } else {
-            composedTileLayer.cleanupInvalidTile(tileId);
         }
     }
 
@@ -174,7 +171,7 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation
                 changePart(event.mPartIndex);
                 break;
             case LOEvent.TILE_REQUEST:
-                tileRequest(event.mComposedTileLayer, event.mTileId);
+                tileRequest(event.mComposedTileLayer, event.mTile);
                 break;
             case LOEvent.TILE_INVALIDATION:
                 tileInvalidation(event.mInvalidationRect);
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 1dee5de..ae7f98a 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
@@ -27,7 +27,7 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba
     protected float currentZoom;
 
     private final ReadWriteLock tilesReadWriteLock = new ReentrantReadWriteLock();
-    private final Lock tilesReadLock  = tilesReadWriteLock.readLock();
+    private final Lock tilesReadLock = tilesReadWriteLock.readLock();
     private final Lock tilesWriteLock = tilesReadWriteLock.writeLock();
 
     public ComposedTileLayer(Context context) {
@@ -177,6 +177,7 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba
     }
 
     private void addNewTiles(RectF pageRect) {
+        beginTransaction();
         for (float y = currentViewport.top; y < currentViewport.bottom; y += tileSize.height) {
             if (y > pageRect.height()) {
                 continue;
@@ -187,10 +188,12 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba
                 }
                 if (!containsTilesMatching(x, y, currentZoom)) {
                     TileIdentifier tileId = new TileIdentifier((int) x, (int) y, currentZoom, tileSize);
-                    LOKitShell.sendTileRequestEvent(this, tileId, true, getTilePriority());
+                    SubTile tile = createNewTile(tileId);
+                    LOKitShell.sendTileRequestEvent(this, tile, true, getTilePriority());
                 }
             }
         }
+        endTransaction();
     }
 
     private void clearMarkedTiles() {
@@ -228,11 +231,13 @@ public abstract class ComposedTileLayer extends Layer implements ComponentCallba
         currentViewport = new RectF();
     }
 
-    public void addTile(SubTile tile) {
+    private SubTile createNewTile(TileIdentifier tileId) {
+        SubTile tile = new SubTile(tileId);
         tile.beginTransaction();
         tilesWriteLock.lock();
         tiles.add(tile);
         tilesWriteLock.unlock();
+        return tile;
     }
 
     public boolean isStillValid(TileIdentifier tileId) {
commit 6b39ff7627130638075374bd6fb3e836ad8e292e
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Feb 17 18:54:18 2015 +0900

    android: change back to LinkedBlockingQueue
    
    PriorityBlockingQueue doesn't preserve order within equal elements.
    This means elements with same priority will be returned in
    arbitrary order, which we don't want to have - for example we want
    tiles to render in the same order they were added to the queue.
    Also there is no measurable or felt benefit that priority bring so
    lets just drop PriorityBlockingQueue for LinkedBlockingQueue.
    
    Change-Id: I6ffe0bf896f0e18e8b5ffc75a4001d8f40515a56

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index b76a684..d5b0781 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -15,12 +15,13 @@ import org.mozilla.gecko.gfx.SubTile;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.concurrent.PriorityBlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
 
 public class LOKitThread extends Thread implements TileProvider.TileInvalidationCallback {
     private static final String LOGTAG = LOKitThread.class.getSimpleName();
 
-    private PriorityBlockingQueue<LOEvent> mEventQueue = new PriorityBlockingQueue<LOEvent>();
+    private LinkedBlockingQueue<LOEvent> mEventQueue = new LinkedBlockingQueue<LOEvent>();
+
     private LibreOfficeMainActivity mApplication;
     private TileProvider mTileProvider;
     private ImmutableViewportMetrics mViewportMetrics;
@@ -30,9 +31,23 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation
         TileProviderFactory.initialize();
     }
 
+    @Override
+    public void run() {
+        while (true) {
+            LOEvent event;
+            try {
+                event = mEventQueue.take();
+                processEvent(event);
+            } catch (InterruptedException exception) {
+                throw new RuntimeException(exception);
+            }
+        }
+    }
+
     private void tileRequest(ComposedTileLayer composedTileLayer, TileIdentifier tileId) {
-        if (mTileProvider == null)
+        if (mTileProvider == null) {
             return;
+        }
 
         if (composedTileLayer.isStillValid(tileId)) {
             CairoImage image = mTileProvider.createTile(tileId.x, tileId.y, tileId.size, tileId.zoom);
@@ -143,16 +158,6 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation
         }
     }
 
-    @Override
-    public void run() {
-        try {
-            while (true) {
-                processEvent(mEventQueue.take());
-            }
-        } catch (InterruptedException ex) {
-        }
-    }
-
     private void processEvent(LOEvent event) {
         switch (event.mType) {
             case LOEvent.LOAD:


More information about the Libreoffice-commits mailing list