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

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


 android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java                 |   12 ++-
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java          |    9 +-
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java             |   17 ++++
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java       |   37 ++++++----
 android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java        |    4 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java            |    2 
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ComposedTileLayer.java |    9 +-
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/RectUtils.java         |    8 ++
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TileLayer.java         |    4 +
 9 files changed, 82 insertions(+), 20 deletions(-)

New commits:
commit 9a006fc32963cf67f7ab3e1f7cf9cff6a956b8c8
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Jan 9 19:55:30 2015 +0900

    android: bypass Bitmap creation and copying when creating tiles
    
    Copying tile buffer just because we can is not really a good idea
    when just using the buffer in CairoImage works perfectly well. This
    should speed things up a bit but probably won't be noticable.
    
    Change-Id: I8d191d3e3870b20b15db56841ed72da22546aefc

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index a70b0bc..d8e11bc 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -189,7 +189,6 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
     @Override
     public CairoImage createTile(float x, float y, IntSize tileSize, float zoom) {
         ByteBuffer buffer = ByteBuffer.allocateDirect(tileSize.width * tileSize.height * 4);
-        Bitmap bitmap = Bitmap.createBitmap(tileSize.width, tileSize.height, Bitmap.Config.ARGB_8888);
 
         if (mDocument != null) {
             float twipX = pixelToTwip(x, mDPI) / zoom;
@@ -207,9 +206,7 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
             Log.e(LOGTAG, "Document is null!!");
         }
 
-        bitmap.copyPixelsFromBuffer(buffer);
-
-        CairoImage image = new BufferedCairoImage(bitmap);
+        CairoImage image = new BufferedCairoImage(buffer, tileSize.width, tileSize.height, CairoImage.FORMAT_ARGB32);
 
         return image;
     }
commit 43cc45f034879baaa14e50c2057cfb05d3e53e1d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Jan 9 19:45:15 2015 +0900

    android: support to rerender tile buffer directly
    
    Add new event TILE_RERENDER to the LOEvent and handle rerender
    so that the tile's image buffer is rerendered and the tile
    invalidated (instead of creating a new tile and deleting the old
    one).
    
    Change-Id: Id0fec307cb82c44a8584425dc7f877f39955844b

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
index 77ad269..5b13da4 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
@@ -2,9 +2,9 @@ package org.libreoffice;
 
 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;
     public static final int TILE_SIZE = 2;
     public static final int CHANGE_PART = 3;
@@ -13,6 +13,7 @@ public class LOEvent implements Comparable<LOEvent> {
     public static final int REDRAW = 6;
     public static final int TILE_REQUEST = 7;
     public static final int THUMBNAIL = 8;
+    public static final int TILE_RERENDER = 9;
 
     public final int mType;
     public int mPriority = 0;
@@ -24,6 +25,7 @@ public class LOEvent implements Comparable<LOEvent> {
     public TileIdentifier mTileId;
     public ComposedTileLayer mComposedTileLayer;
     public boolean mForceRedraw;
+    public SubTile mTile;
 
     public LOEvent(int type) {
         mType = type;
@@ -64,6 +66,13 @@ public class LOEvent implements Comparable<LOEvent> {
         mTask = task;
     }
 
+    public LOEvent(int type, ComposedTileLayer composedTileLayer, SubTile tile) {
+        mType = type;
+        mTypeString = "Tile Rerender";
+        mComposedTileLayer = composedTileLayer;
+        mTile = tile;
+    }
+
     public String getTypeString() {
         if (mTypeString == null) {
             return "Event type: " + mType;
@@ -75,4 +84,5 @@ public class LOEvent implements Comparable<LOEvent> {
     public int compareTo(LOEvent another) {
         return mPriority - another.mPriority;
     }
+
 }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java
index 169c46e..b866850 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEventFactory.java
@@ -2,6 +2,7 @@ package org.libreoffice;
 
 import org.mozilla.gecko.gfx.ComposedTileLayer;
 import org.mozilla.gecko.gfx.IntSize;
+import org.mozilla.gecko.gfx.SubTile;
 
 
 public class LOEventFactory {
@@ -29,11 +30,15 @@ public class LOEventFactory {
         return new LOEvent(LOEvent.REDRAW);
     }
 
-    public static LOEvent tileRequest(ComposedTileLayer composedTileLayer, TileIdentifier tileRequest, boolean forceRedraw) {
-        return new LOEvent(LOEvent.TILE_REQUEST, composedTileLayer, tileRequest, forceRedraw);
+    public static LOEvent tileRequest(ComposedTileLayer composedTileLayer, TileIdentifier tileID, boolean forceRedraw) {
+        return new LOEvent(LOEvent.TILE_REQUEST, composedTileLayer, tileID, forceRedraw);
     }
 
     public static LOEvent thumbnail(ThumbnailCreator.ThumbnailCreationTask task) {
         return new LOEvent(LOEvent.THUMBNAIL, task);
     }
+
+    public static LOEvent tileRerender(ComposedTileLayer composedTileLayer, SubTile tile) {
+        return new LOEvent(LOEvent.TILE_RERENDER, composedTileLayer, tile);
+    }
 }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index 98b4d03..a37caa7 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -40,6 +40,18 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation
         }
     }
 
+    private void tileRerender(ComposedTileLayer composedTileLayer, SubTile tile) {
+        if (composedTileLayer.isStillValid(tile.id)) {
+            mLayerClient.beginDrawing();
+            mTileProvider.rerenderTile(tile.getImage(), tile.id.x, tile.id.y, tile.id.size, tile.id.zoom);
+            tile.invalidate();
+            Log.i(LOGTAG, "Redrawing tile " + tile.id);
+            mLayerClient.forceRedraw();
+            mLayerClient.endDrawing(mViewportMetrics);
+        }
+    }
+
+
     /** Handle the geometry change + draw. */
     private void redraw() {
         if (mLayerClient == null || mTileProvider == null) {
@@ -130,6 +142,9 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation
             case LOEvent.TILE_REQUEST:
                 tileRequest(event.mComposedTileLayer, event.mTileId, event.mForceRedraw);
                 break;
+            case LOEvent.TILE_RERENDER:
+                tileRerender(event.mComposedTileLayer, event.mTile);
+                break;
             case LOEvent.THUMBNAIL:
                 createThumbnail(event.mTask);
         }
@@ -150,6 +165,8 @@ public class LOKitThread extends Thread implements TileProvider.TileInvalidation
 
     @Override
     public void invalidate(RectF rect) {
+        Log.i(LOGTAG, "Invalidate request: " + rect);
+
         mLayerClient = mApplication.getLayerClient();
         mLayerClient.invalidateTiles(rect);
     }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index ebc6927..a70b0bc 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -215,6 +215,22 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
     }
 
     @Override
+    public void rerenderTile(CairoImage image, float x, float y, IntSize tileSize, float zoom) {
+        if (mDocument != null && image.getBuffer() != null) {
+            float twipX = pixelToTwip(x, mDPI) / zoom;
+            float twipY = pixelToTwip(y, mDPI) / zoom;
+            float twipWidth = mTileWidth / zoom;
+            float twipHeight = mTileHeight / zoom;
+
+            mDocument.paintTile(image.getBuffer(), tileSize.width, tileSize.height, (int) twipX, (int) twipY, (int) twipWidth, (int) twipHeight);
+        } else {
+            if (mDocument == null) {
+                Log.e(LOGTAG, "Document is null!!");
+            }
+        }
+    }
+
+    @Override
     public Bitmap thumbnail(int size) {
         int widthPixel = getPageWidth();
         int heightPixel = getPageHeight();
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
index 0b58f1a..16772d0 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
@@ -65,6 +65,10 @@ public class MockTileProvider implements TileProvider {
     }
 
     @Override
+    public void rerenderTile(CairoImage image, float x, float y, IntSize tileSize, float zoom) {
+    }
+
+    @Override
     public Bitmap thumbnail(int size) {
         return mLayerClient.getView().getDrawable("dummy_page");
     }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
index abe7654..c705a94 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
@@ -16,6 +16,8 @@ public interface TileProvider {
 
     CairoImage createTile(float x, float y, IntSize tileSize, float zoom);
 
+    void rerenderTile(CairoImage image, float x, float y, IntSize tileSize, float zoom);
+
     void changePart(int partIndex);
 
     int getCurrentPartNumber();
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 c5e7f9d..1a67117 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
@@ -213,12 +213,11 @@ public abstract class ComposedTileLayer extends Layer {
     }
 
     public void invalidateTiles(RectF rect) {
-        Log.i(LOGTAG, "invalidate: " + rect);
+        RectF zoomedRect = RectUtils.inverseScale(rect, currentZoom);
+
         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);
+            if (RectF.intersects(rect, tile.id.getRect())) {
+                LOKitShell.sendEvent(LOEventFactory.tileRerender(this, tile));
             }
         }
     }
commit e5e9bbdf528fb66f124f29fe9f75c592b9b737e6
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Jan 9 19:42:46 2015 +0900

    android: allow TileLayer to expose the image
    
    Change-Id: Id8968f4c71ca71d089e74314977cd406050dbd0f

diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TileLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TileLayer.java
index 9a063d0..d359502 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TileLayer.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TileLayer.java
@@ -24,6 +24,10 @@ public abstract class TileLayer extends Layer {
 
     protected final CairoImage mImage;
 
+    public CairoImage getImage() {
+        return mImage;
+    }
+
     public enum PaintMode { NORMAL, REPEAT, STRETCH };
     private PaintMode mPaintMode;
 
commit d97a847fafbbb7af2f4d6853effc81f0724c553d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Jan 9 19:39:37 2015 +0900

    android: Fix what invalidate rect numbers should mean
    
    Assumption was that the invalidate rectangle numbers from LOK
    mean (left, top, right, bottom) but they mean (width, height, x, y)
    so we need to adapt to that for now.
    
    Change-Id: Icc9c2c8aef63a8e292ff299969f2cbaf45ad0eab

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 14a6acb..ebc6927 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -287,15 +287,15 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
                     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());
+                        int width = Integer.decode(coordinates[0].trim());
+                        int height = Integer.decode(coordinates[1].trim());
+                        int x = Integer.decode(coordinates[2].trim());
+                        int y = Integer.decode(coordinates[3].trim());
                         RectF rect = new RectF(
-                                twipToPixel(left, mDPI),
-                                twipToPixel(top, mDPI),
-                                twipToPixel(right, mDPI),
-                                twipToPixel(bottom, mDPI)
+                                twipToPixel(x, mDPI),
+                                twipToPixel(y, mDPI),
+                                twipToPixel(x + width, mDPI),
+                                twipToPixel(y + height, mDPI)
                         );
                         Log.i(LOGTAG, "Invalidate R: " + rect +" - " + getPageWidth() + " " + getPageHeight());
                         tileInvalidationCallback.invalidate(rect);
commit 68c61dfb9fe3c4b72b56dbbc8a666d6d583492e4
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Fri Jan 9 19:35:52 2015 +0900

    android: Add inverseScale to RectUtils
    
    Change-Id: Id0e9a02614d3d6a23a8111622ae9ea49bef26f7d

diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/RectUtils.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/RectUtils.java
index 1608e91..09168c9 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/RectUtils.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/RectUtils.java
@@ -49,6 +49,14 @@ public final class RectUtils {
                          y + (rect.height() * scale));
     }
 
+    public static RectF inverseScale(RectF rect, float scale) {
+        float x = rect.left / scale;
+        float y = rect.top / scale;
+        return new RectF(x, y,
+                x + (rect.width() / scale),
+                y + (rect.height() / scale));
+    }
+
     /** Returns the nearest integer rect of the given rect. */
     public static Rect round(RectF rect) {
         Rect r = new Rect();


More information about the Libreoffice-commits mailing list