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

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Fri Jan 9 00:47:30 PST 2015


 android/Bootstrap/src/org/libreoffice/kit/Document.java                               |   13 +++
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java                 |    4 -
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java          |    4 -
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java             |   17 +++-
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java       |   40 +++++++++-
 android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java        |    4 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/TileIdentifier.java          |    5 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java            |    7 +
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ComposedTileLayer.java |   13 +++
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java  |    5 +
 10 files changed, 101 insertions(+), 11 deletions(-)

New commits:
commit ebe8a1aa721c71df2f9016cf66fa7e824a7384f4
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Jan 9 17:34:09 2015 +0900

    android: react to tile invalidation request and invalidate tiles
    
    Implement tile invalidation request in LOKitThread and pass the
    request to ComposedTileLayer where it handles the invalidation
    request by searching for the tiles that need to be invalidated
    (intersect the invlidation rectangle).
    
    Change-Id: I84e752486ff79e98cac1e74c6463b6748660cbed

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index b30e4f5..98b4d03 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -13,7 +13,7 @@ import org.mozilla.gecko.gfx.SubTile;
 
 import java.util.concurrent.PriorityBlockingQueue;
 
-public class LOKitThread extends Thread {
+public class LOKitThread extends Thread implements TileProvider.TileInvalidationCallback {
     private static final String LOGTAG = LOKitThread.class.getSimpleName();
 
     private PriorityBlockingQueue<LOEvent> mEventQueue = new PriorityBlockingQueue<LOEvent>();
@@ -89,6 +89,7 @@ public class LOKitThread extends Thread {
         boolean isReady = mTileProvider.isReady();
         if (isReady) {
             LOKitShell.showProgressSpinner();
+            mTileProvider.registerInvalidationCallback(this);
             refresh();
             LOKitShell.hideProgressSpinner();
         }
@@ -146,6 +147,12 @@ public class LOKitThread extends Thread {
     public void clearQueue() {
         mEventQueue.clear();
     }
+
+    @Override
+    public void invalidate(RectF rect) {
+        mLayerClient = mApplication.getLayerClient();
+        mLayerClient.invalidateTiles(rect);
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 cfff284..c5e7f9d 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
@@ -211,4 +211,15 @@ public abstract class ComposedTileLayer extends Layer {
     public boolean isStillValid(TileIdentifier tileId) {
         return RectF.intersects(currentViewport, tileId.getRect()) || currentViewport.contains(tileId.getRect());
     }
+
+    public void invalidateTiles(RectF rect) {
+        Log.i(LOGTAG, "invalidate: " + rect);
+        for (SubTile tile : tiles) {
+            if (RectF.intersects(rect, tile.id.getRect()) || rect.contains(tile.id.getRect())) {
+                tile.markForRemoval();
+                LOKitShell.sendEvent(LOEventFactory.tileRequest(this, tile.id, true));
+                Log.i(LOGTAG, "invalidate tile: " + tile.id);
+            }
+        }
+    }
 }
\ No newline at end of file
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 09120ec..676e73c 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
@@ -488,4 +488,9 @@ public class GeckoLayerClient implements PanZoomTarget, LayerView.Listener {
         mLowResLayer.clearAndReset();
         mRootLayer.clearAndReset();
     }
+
+    public void invalidateTiles(RectF rect) {
+        mLowResLayer.invalidateTiles(rect);
+        mRootLayer.invalidateTiles(rect);
+    }
 }
\ No newline at end of file
commit 268bc153d39b845a343d6e7b51cb1624f74d8e13
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Jan 9 17:31:23 2015 +0900

    android: Support force redraw in "tile request" event
    
    Change-Id: I554200f67a529e2b2c352e956372811f35f8238c

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
index cb71bb5..77ad269 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
@@ -23,6 +23,7 @@ public class LOEvent implements Comparable<LOEvent> {
     public String mFilename;
     public TileIdentifier mTileId;
     public ComposedTileLayer mComposedTileLayer;
+    public boolean mForceRedraw;
 
     public LOEvent(int type) {
         mType = type;
@@ -33,11 +34,12 @@ 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, TileIdentifier tileId, boolean forceRedraw) {
         mType = type;
         mTypeString = "Tile Request";
         mComposedTileLayer = composedTileLayer;
         mTileId = tileId;
+        mForceRedraw = forceRedraw;
     }
 
     public LOEvent(int type, String filename) {
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java
index 62c5a36..169c46e 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java
@@ -29,8 +29,8 @@ public class LOEventFactory {
         return new LOEvent(LOEvent.REDRAW);
     }
 
-    public static LOEvent tileRequest(ComposedTileLayer composedTileLayer, TileIdentifier tileRequest) {
-        return new LOEvent(LOEvent.TILE_REQUEST, composedTileLayer, tileRequest);
+    public static LOEvent tileRequest(ComposedTileLayer composedTileLayer, TileIdentifier tileRequest, boolean forceRedraw) {
+        return new LOEvent(LOEvent.TILE_REQUEST, composedTileLayer, tileRequest, forceRedraw);
     }
 
     public static LOEvent thumbnail(ThumbnailCreator.ThumbnailCreationTask task) {
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index 8fc75b2..b30e4f5 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -26,13 +26,17 @@ public class LOKitThread extends Thread {
         TileProviderFactory.initialize();
     }
 
-    private void tileRequest(ComposedTileLayer composedTileLayer, TileIdentifier tileId) {
+    private void tileRequest(ComposedTileLayer composedTileLayer, TileIdentifier tileId, boolean forceRedraw) {
         if (composedTileLayer.isStillValid(tileId)) {
             mLayerClient.beginDrawing();
             CairoImage image = mTileProvider.createTile(tileId.x, tileId.y, tileId.size, tileId.zoom);
             SubTile tile = new SubTile(image, tileId);
             composedTileLayer.addTile(tile);
             mLayerClient.endDrawing(mViewportMetrics);
+            if (forceRedraw) {
+                Log.i(LOGTAG, "Redrawing tile " + tileId);
+                mLayerClient.forceRedraw();
+            }
         }
     }
 
@@ -123,7 +127,7 @@ public class LOKitThread extends Thread {
                 changePart(event.mPartIndex);
                 break;
             case LOEvent.TILE_REQUEST:
-                tileRequest(event.mComposedTileLayer, event.mTileId);
+                tileRequest(event.mComposedTileLayer, event.mTileId, event.mForceRedraw);
                 break;
             case LOEvent.THUMBNAIL:
                 createThumbnail(event.mTask);
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 e6799b6..cfff284 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
@@ -165,7 +165,7 @@ public abstract class ComposedTileLayer extends Layer {
                     }
                 }
                 if (!contains) {
-                    LOEvent event = LOEventFactory.tileRequest(this, new TileIdentifier((int) x, (int) y, zoom, tileSize));
+                    LOEvent event = LOEventFactory.tileRequest(this, new TileIdentifier((int) x, (int) y, zoom, tileSize), false);
                     event.mPriority = getTilePriority();
                     LOKitShell.sendEvent(event);
                 }
commit b1c7312c02238e1fcec75db878dbf0ec59ae9c5d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Jan 9 17:25:38 2015 +0900

    android: add toString to TileIdentifier
    
    Change-Id: Id5bfa1652a8b33757d4604e0fcf89766b50c4344

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIdentifier.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIdentifier.java
index fe4071c..7c51b52 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIdentifier.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIdentifier.java
@@ -42,4 +42,9 @@ public class TileIdentifier {
         result = 31 * result + (zoom != +0.0f ? Float.floatToIntBits(zoom) : 0);
         return result;
     }
+
+    @Override
+    public String toString() {
+        return String.format("TileIdentifier (%d, %d) z=%f s=(%d, %d)", x, y, zoom, size.width, size.height);
+    }
 }
\ No newline at end of file
commit 9a2a3515eeb3f1f72873909ad86a248d71683ad9
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Jan 9 17:21:01 2015 +0900

    android: Process messages in TileProvider + invalidation interface
    
    Process the LOK messages in TileProvider and add an interface to
    register and communicate invalidation requests.
    
    Change-Id: I798dc5591dbc60ee6b055a95464cd3406ecd8b0d

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index e1aeba3..14a6acb 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -1,6 +1,7 @@
 package org.libreoffice;
 
 import android.graphics.Bitmap;
+import android.graphics.RectF;
 import android.util.Log;
 
 import org.libreoffice.kit.Document;
@@ -13,16 +14,17 @@ import org.mozilla.gecko.gfx.IntSize;
 
 import java.nio.ByteBuffer;
 
-public class LOKitTileProvider implements TileProvider {
+public class LOKitTileProvider implements TileProvider, Document.MessageCallback {
     private static final String LOGTAG = LOKitTileProvider.class.getSimpleName();
     private static int TILE_SIZE = 256;
-    private Office mOffice;
-    private Document mDocument;
     private final GeckoLayerClient mLayerClient;
     private final float mTileWidth;
     private final float mTileHeight;
     private final String mInputFile;
+    private Office mOffice;
+    private Document mDocument;
     private boolean mIsReady = false;
+    private TileInvalidationCallback tileInvalidationCallback = null;
 
     private float mDPI;
     private float mWidthTwip;
@@ -67,6 +69,7 @@ public class LOKitTileProvider implements TileProvider {
 
     public void postLoad() {
         mDocument.initializeForRendering();
+        mDocument.setMessageCallback(this);
 
         int parts = mDocument.getParts();
         Log.i(LOGTAG, "Document parts: " + parts);
@@ -254,6 +257,12 @@ public class LOKitTileProvider implements TileProvider {
     }
 
     @Override
+    public void registerInvalidationCallback(TileInvalidationCallback tileInvalidationCallback) {
+        this.tileInvalidationCallback = tileInvalidationCallback;
+    }
+
+
+    @Override
     protected void finalize() throws Throwable {
         close();
         super.finalize();
@@ -269,6 +278,31 @@ public class LOKitTileProvider implements TileProvider {
     public int getCurrentPartNumber() {
         return mDocument.getPart();
     }
+
+    @Override
+    public void messageRetrieved(int signalNumber, String payload) {
+        switch (signalNumber) {
+            case 0:
+                if (!payload.equals("EMPTY")) {
+                    String[] coordinates = payload.split(",");
+
+                    if (coordinates.length == 4) {
+                        int left = Integer.decode(coordinates[0].trim());
+                        int top = Integer.decode(coordinates[1].trim());
+                        int right = Integer.decode(coordinates[2].trim());
+                        int bottom = Integer.decode(coordinates[3].trim());
+                        RectF rect = new RectF(
+                                twipToPixel(left, mDPI),
+                                twipToPixel(top, mDPI),
+                                twipToPixel(right, mDPI),
+                                twipToPixel(bottom, mDPI)
+                        );
+                        Log.i(LOGTAG, "Invalidate R: " + rect +" - " + getPageWidth() + " " + getPageHeight());
+                        tileInvalidationCallback.invalidate(rect);
+                    }
+                }
+        }
+    }
 }
 
 // vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
index 79fef43..0b58f1a 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
@@ -79,6 +79,10 @@ public class MockTileProvider implements TileProvider {
     }
 
     @Override
+    public void registerInvalidationCallback(TileInvalidationCallback tileInvalidationCallback) {
+    }
+
+    @Override
     public void changePart(int partIndex) {
     }
 
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
index 988e53a..abe7654 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
@@ -2,6 +2,7 @@ package org.libreoffice;
 
 
 import android.graphics.Bitmap;
+import android.graphics.RectF;
 
 import org.mozilla.gecko.gfx.CairoImage;
 import org.mozilla.gecko.gfx.IntSize;
@@ -24,4 +25,10 @@ public interface TileProvider {
     void close();
 
     boolean isTextDocument();
+
+    void registerInvalidationCallback(TileProvider.TileInvalidationCallback tileInvalidationCallback);
+
+    public interface TileInvalidationCallback {
+        void invalidate(RectF rect);
+    }
 }
commit c8231163a888d26231417fd22550b43c6a66eb60
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Jan 9 17:15:42 2015 +0900

    android: interface for processing of LOK messages
    
    Added a message callback interface to Document where the provided
    implementation processes the messages from LOK (for now
    only the regions that were invalidated)
    
    Change-Id: Ic7fcb0250f87f6c4c28925bf809c4cf3f353d2bb

diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java
index 6985a7c..10d0a0c 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Document.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java
@@ -27,18 +27,25 @@ public class Document {
     public static final int DOCTYPE_OTHER = 4;
 
     private final ByteBuffer handle;
+    private MessageCallback messageCallback = null;
 
     public Document(ByteBuffer handle) {
         this.handle = handle;
         bindMessageCallback();
     }
 
+    public void setMessageCallback(MessageCallback messageCallback) {
+        this.messageCallback = messageCallback;
+    }
+
     /**
      * Callback triggered through JNI to indicate that a new singal
      * from LibreOfficeKit was retrieved.
      */
     private void messageRetrieved(int signalNumber, String payload) {
-        Log.i("Document", "Signal retrieved: " + signalNumber + " " + payload);
+        if (messageCallback != null) {
+            messageCallback.messageRetrieved(signalNumber, payload);
+        }
     }
 
     /**
@@ -78,4 +85,8 @@ public class Document {
 
     public native void initializeForRendering();
 
+    public interface MessageCallback {
+        void messageRetrieved(int signalNumber, String payload);
+    }
+
 }


More information about the Libreoffice-commits mailing list