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

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Mon Feb 23 03:55:12 PST 2015


 android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java   |  125 ++++++++++
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java            |    2 
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java     |  111 --------
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/DrawTimingQueue.java |   95 -------
 android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/PanningPerfAPI.java  |   93 -------
 5 files changed, 132 insertions(+), 294 deletions(-)

New commits:
commit 922d6d1c85ef26445576b7b4b7b3d3d52cd99254
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Feb 23 20:53:35 2015 +0900

    android: remove DrawTimingQueue and PanningPerfAPI
    
    Change-Id: I094c345524059030a157a940702ad47fad358176

diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/DrawTimingQueue.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/DrawTimingQueue.java
deleted file mode 100644
index ce868f1..0000000
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/DrawTimingQueue.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.gfx;
-
-import android.os.SystemClock;
-
-/**
- * A custom-built data structure to assist with measuring draw times.
- *
- * This class maintains a fixed-size circular buffer of DisplayPortMetrics
- * objects and associated timestamps. It provides only three operations, which
- * is all we require for our purposes of measuring draw times. Note
- * in particular that the class is designed so that even though it is
- * accessed from multiple threads, it does not require synchronization;
- * any concurrency errors that result from this are handled gracefully.
- *
- * Assuming an unrolled buffer so that mTail is greater than mHead, the data
- * stored in the buffer at entries [mHead, mTail) will never be modified, and
- * so are "safe" to read. If this reading is done on the same thread that
- * owns mHead, then reading the range [mHead, mTail) is guaranteed to be safe
- * since the range itself will not shrink.
- */
-final class DrawTimingQueue {
-    private static final String LOGTAG = "GeckoDrawTimingQueue";
-    private static final int BUFFER_SIZE = 16;
-
-    private final DisplayPortMetrics[] mMetrics;
-    private final long[] mTimestamps;
-
-    private int mHead;
-    private int mTail;
-
-    DrawTimingQueue() {
-        mMetrics = new DisplayPortMetrics[BUFFER_SIZE];
-        mTimestamps = new long[BUFFER_SIZE];
-        mHead = BUFFER_SIZE - 1;
-        mTail = 0;
-    }
-
-    /**
-     * Add a new entry to the tail of the queue. If the buffer is full,
-     * do nothing. This must only be called from the Java UI thread.
-     */
-    boolean add(DisplayPortMetrics metrics) {
-        if (mHead == mTail) {
-            return false;
-        }
-        mMetrics[mTail] = metrics;
-        mTimestamps[mTail] = SystemClock.uptimeMillis();
-        mTail = (mTail + 1) % BUFFER_SIZE;
-        return true;
-    }
-
-    /**
-     * Find the timestamp associated with the given metrics, AND remove
-     * all metrics objects from the start of the queue up to and including
-     * the one provided. Note that because of draw coalescing, the metrics
-     * object passed in here may not be the one at the head of the queue,
-     * and so we must iterate our way through the list to find it.
-     * This must only be called from the compositor thread.
-     */
-    long findTimeFor(DisplayPortMetrics metrics) {
-        // keep a copy of the tail pointer so that we ignore new items
-        // added to the queue while we are searching. this is fine because
-        // the one we are looking for will either have been added already
-        // or will not be in the queue at all.
-        int tail = mTail;
-        // walk through the "safe" range from mHead to tail; these entries
-        // will not be modified unless we change mHead.
-        int i = (mHead + 1) % BUFFER_SIZE;
-        while (i != tail) {
-            if (mMetrics[i].fuzzyEquals(metrics)) {
-                // found it, copy out the timestamp to a local var BEFORE
-                // changing mHead or add could clobber the timestamp.
-                long timestamp = mTimestamps[i];
-                mHead = i;
-                return timestamp;
-            }
-            i = (i + 1) % BUFFER_SIZE;
-        }
-        return -1;
-    }
-
-    /**
-     * Reset the buffer to empty.
-     * This must only be called from the compositor thread.
-     */
-    void reset() {
-        // we can only modify mHead on this thread.
-        mHead = (mTail + BUFFER_SIZE - 1) % BUFFER_SIZE;
-    }
-}
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/PanningPerfAPI.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/PanningPerfAPI.java
deleted file mode 100644
index f50b46a..0000000
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/PanningPerfAPI.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko.gfx;
-
-import android.os.SystemClock;
-import android.util.Log;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class PanningPerfAPI {
-    private static final String LOGTAG = "GeckoPanningPerfAPI";
-
-    // make this large enough to avoid having to resize the frame time
-    // list, as that may be expensive and impact the thing we're trying
-    // to measure.
-    private static final int EXPECTED_FRAME_COUNT = 2048;
-
-    private static boolean mRecordingFrames = false;
-    private static List<Long> mFrameTimes;
-    private static long mFrameStartTime;
-
-    private static boolean mRecordingCheckerboard = false;
-    private static List<Float> mCheckerboardAmounts;
-    private static long mCheckerboardStartTime;
-
-    public static void startFrameTimeRecording() {
-        if (mRecordingFrames) {
-            Log.e(LOGTAG, "Error: startFrameTimeRecording() called while already recording!");
-            return;
-        }
-        mRecordingFrames = true;
-        if (mFrameTimes == null) {
-            mFrameTimes = new ArrayList<Long>(EXPECTED_FRAME_COUNT);
-        } else {
-            mFrameTimes.clear();
-        }
-        mFrameStartTime = SystemClock.uptimeMillis();
-    }
-
-    public static List<Long> stopFrameTimeRecording() {
-        if (!mRecordingFrames) {
-            Log.e(LOGTAG, "Error: stopFrameTimeRecording() called when not recording!");
-            return null;
-        }
-        mRecordingFrames = false;
-        return mFrameTimes;
-    }
-
-    public static void recordFrameTime() {
-        // this will be called often, so try to make it as quick as possible
-        if (mRecordingFrames) {
-            mFrameTimes.add(SystemClock.uptimeMillis() - mFrameStartTime);
-        }
-    }
-
-    public static boolean isRecordingCheckerboard() {
-        return mRecordingCheckerboard;
-    }
-
-    public static void startCheckerboardRecording() {
-        if (mRecordingCheckerboard) {
-            Log.e(LOGTAG, "Error: startCheckerboardRecording() called while already recording!");
-            return;
-        }
-        mRecordingCheckerboard = true;
-        if (mCheckerboardAmounts == null) {
-            mCheckerboardAmounts = new ArrayList<Float>(EXPECTED_FRAME_COUNT);
-        } else {
-            mCheckerboardAmounts.clear();
-        }
-        mCheckerboardStartTime = SystemClock.uptimeMillis();
-    }
-
-    public static List<Float> stopCheckerboardRecording() {
-        if (!mRecordingCheckerboard) {
-            Log.e(LOGTAG, "Error: stopCheckerboardRecording() called when not recording!");
-            return null;
-        }
-        mRecordingCheckerboard = false;
-        return mCheckerboardAmounts;
-    }
-
-    public static void recordCheckerboard(float amount) {
-        // this will be called often, so try to make it as quick as possible
-        if (mRecordingCheckerboard) {
-            mCheckerboardAmounts.add(amount);
-        }
-    }
-}
commit a6a4cf07fd3c1d8288f5c82649ac3768910b679c
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Feb 23 20:53:03 2015 +0900

    android: extrac invalidations into InvalidationHandler
    
    Change-Id: Iccdb5e64acac603fbc623d1c325d6e922568de81

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
new file mode 100644
index 0000000..a37d3d4
--- /dev/null
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/InvalidationHandler.java
@@ -0,0 +1,125 @@
+package org.libreoffice;
+
+import android.graphics.RectF;
+import android.util.Log;
+
+import org.libreoffice.kit.Document;
+import org.mozilla.gecko.TextSelection;
+import org.mozilla.gecko.TextSelectionHandle;
+
+public class InvalidationHandler {
+    private static String LOGTAG = InvalidationHandler.class.getSimpleName();
+
+    public InvalidationHandler() {
+    }
+
+    public void processMessage(int messageID, String payload) {
+        switch (messageID) {
+            case Document.CALLBACK_INVALIDATE_TILES:
+                invalidateTiles(payload);
+                break;
+            case Document.CALLBACK_INVALIDATE_VISIBLE_CURSOR:
+                invalidateCursor(payload);
+                break;
+            case Document.CALLBACK_INVALIDATE_TEXT_SELECTION:
+                Log.i(LOGTAG, "Selection: " + payload);
+                invalidateSelection(payload);
+                break;
+            case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_START:
+                Log.i(LOGTAG, "Selection start: " + payload);
+                invalidateSelectionStart(payload);
+                break;
+            case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_END:
+                Log.i(LOGTAG, "Selection end: " + payload);
+                invalidateSelectionEnd(payload);
+                break;
+        }
+    }
+
+    private RectF convertCallbackMessageStringToRectF(String text) {
+        if (text.equals("EMPTY")) {
+            return null;
+        }
+
+        String[] coordinates = text.split(",");
+
+        if (coordinates.length != 4) {
+            return null;
+        }
+        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());
+
+        float dpi = (float) LOKitShell.getDpi();
+
+        RectF rect = new RectF(
+                LOKitTileProvider.twipToPixel(x, dpi),
+                LOKitTileProvider.twipToPixel(y, dpi),
+                LOKitTileProvider.twipToPixel(x + width, dpi),
+                LOKitTileProvider.twipToPixel(y + height, dpi)
+        );
+
+        return rect;
+    }
+
+    private void invalidateCursor(String payload) {
+        RectF rect = convertCallbackMessageStringToRectF(payload);
+        if (rect != null) {
+            RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
+            TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
+            textSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, underSelection);
+            textSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
+
+            TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
+            textCursorLayer.positionCursor(rect);
+            textCursorLayer.showCursor();
+        }
+    }
+
+    private void invalidateTiles(String payload) {
+        RectF rect = convertCallbackMessageStringToRectF(payload);
+        if (rect != null) {
+            LOKitShell.sendTileInvalidationRequest(rect);
+        }
+    }
+
+    private void invalidateSelectionStart(String payload) {
+        RectF rect = convertCallbackMessageStringToRectF(payload);
+        if (rect != null) {
+            RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
+            TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
+            textSelection.positionHandle(TextSelectionHandle.HandleType.START, underSelection);
+            textSelection.showHandle(TextSelectionHandle.HandleType.START);
+
+            textSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
+
+            TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
+            textCursorLayer.hideCursor();
+        }
+    }
+
+    private void invalidateSelectionEnd(String payload) {
+        RectF rect = convertCallbackMessageStringToRectF(payload);
+        if (rect != null) {
+            RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
+            TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
+            textSelection.positionHandle(TextSelectionHandle.HandleType.END, underSelection);
+            textSelection.showHandle(TextSelectionHandle.HandleType.END);
+
+            textSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
+
+            TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
+            textCursorLayer.hideCursor();
+        }
+    }
+
+    private void invalidateSelection(String payload) {
+        if (payload.isEmpty()) {
+            TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
+            textSelection.hideHandle(TextSelectionHandle.HandleType.START);
+            textSelection.hideHandle(TextSelectionHandle.HandleType.END);
+        }
+    }
+
+}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 1fd1388..f99cda0 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -37,6 +37,8 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
     private float mWidthTwip;
     private float mHeightTwip;
 
+    private InvalidationHandler mInvalidationHandler = new InvalidationHandler();
+
     private long objectCreationTime = System.currentTimeMillis();
 
     public LOKitTileProvider(GeckoLayerClient layerClient, String input) {
@@ -133,11 +135,11 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
         }
     }
 
-    private float twipToPixel(float input, float dpi) {
+    public static float twipToPixel(float input, float dpi) {
         return input / 1440.0f * dpi;
     }
 
-    private float pixelToTwip(float input, float dpi) {
+    public static float pixelToTwip(float input, float dpi) {
         return (input / dpi) * 1440.0f;
     }
 
@@ -359,117 +361,16 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
         return mDocument.getPart();
     }
 
-    private RectF convertCallbackMessageStringToRectF(String text) {
-        if (text.equals("EMPTY")) {
-            return null;
-        }
-
-        String[] coordinates = text.split(",");
-
-        if (coordinates.length != 4) {
-            return null;
-        }
-        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(x, mDPI),
-                twipToPixel(y, mDPI),
-                twipToPixel(x + width, mDPI),
-                twipToPixel(y + height, mDPI)
-        );
-        return rect;
-    }
-
     /**
      * Process the retrieved messages from LOK
      */
     @Override
-    public void messageRetrieved(int signalNumber, String payload) {
+    public void messageRetrieved(int messageID, String payload) {
         if (!LOKitShell.isEditingEnabled()) {
             return;
         }
 
-        switch (signalNumber) {
-            case Document.CALLBACK_INVALIDATE_TILES:
-                invalidateTiles(payload);
-                break;
-            case Document.CALLBACK_INVALIDATE_VISIBLE_CURSOR:
-                invalidateCursor(payload);
-                break;
-            case Document.CALLBACK_INVALIDATE_TEXT_SELECTION:
-                Log.i(LOGTAG, "Selection: " + payload);
-                invalidateSelection(payload);
-                break;
-            case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_START:
-                Log.i(LOGTAG, "Selection start: " + payload);
-                invalidateSelectionStart(payload);
-                break;
-            case Document.CALLBACK_INVALIDATE_TEXT_SELECTION_END:
-                Log.i(LOGTAG, "Selection end: " + payload);
-                invalidateSelectionEnd(payload);
-                break;
-        }
-    }
-
-    private void invalidateCursor(String payload) {
-        RectF rect = convertCallbackMessageStringToRectF(payload);
-        if (rect != null) {
-            RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
-            TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
-            textSelection.positionHandle(TextSelectionHandle.HandleType.MIDDLE, underSelection);
-            textSelection.showHandle(TextSelectionHandle.HandleType.MIDDLE);
-
-            TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
-            textCursorLayer.positionCursor(rect);
-            textCursorLayer.showCursor();
-        }
-    }
-
-    private void invalidateTiles(String payload) {
-        RectF rect = convertCallbackMessageStringToRectF(payload);
-        if (rect != null) {
-            LOKitShell.sendTileInvalidationRequest(rect);
-        }
-    }
-
-    private void invalidateSelectionStart(String payload) {
-        RectF rect = convertCallbackMessageStringToRectF(payload);
-        if (rect != null) {
-            RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
-            TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
-            textSelection.positionHandle(TextSelectionHandle.HandleType.START, underSelection);
-            textSelection.showHandle(TextSelectionHandle.HandleType.START);
-
-            textSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
-
-            TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
-            textCursorLayer.hideCursor();
-        }
-    }
-
-    private void invalidateSelectionEnd(String payload) {
-        RectF rect = convertCallbackMessageStringToRectF(payload);
-        if (rect != null) {
-            RectF underSelection = new RectF(rect.centerX(), rect.bottom, rect.centerX(), rect.bottom);
-            TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
-            textSelection.positionHandle(TextSelectionHandle.HandleType.END, underSelection);
-            textSelection.showHandle(TextSelectionHandle.HandleType.END);
-
-            textSelection.hideHandle(TextSelectionHandle.HandleType.MIDDLE);
-
-            TextCursorLayer textCursorLayer = LibreOfficeMainActivity.mAppContext.getTextCursorLayer();
-            textCursorLayer.hideCursor();
-        }
-    }
-
-    private void invalidateSelection(String payload) {
-        if (payload.isEmpty()) {
-            TextSelection textSelection = LibreOfficeMainActivity.mAppContext.getTextSelection();
-            textSelection.hideHandle(TextSelectionHandle.HandleType.START);
-            textSelection.hideHandle(TextSelectionHandle.HandleType.END);
-        }
+        mInvalidationHandler.processMessage(messageID, payload);
     }
 }
 
commit 40f3d313f8e00362ef7a1d4efd4061a5e67b4535
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Feb 23 20:51:31 2015 +0900

    android: compilation error in LOKitShell - SIZE_CHANGED event
    
    Change-Id: I564d4db40d5cf5916de3f7a417f42f817d172019

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
index 94c47c0..e3e7a36 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
@@ -98,7 +98,7 @@ public class LOKitShell {
     }
 
     public static void sendSizeChangedEvent(int width, int height) {
-        LOKitShell.sendEvent(new LOEvent(LOEvent.SIZE_CHANGED, width, height));
+        LOKitShell.sendEvent(new LOEvent(LOEvent.SIZE_CHANGED));
     }
 
     public static void sendChangePartEvent(int part) {


More information about the Libreoffice-commits mailing list