[Libreoffice-commits] core.git: 14 commits - android/experimental
Tomaž Vajngerl
tomaz.vajngerl at collabora.com
Thu Jul 10 02:15:39 PDT 2014
android/experimental/LOAndroid3/src/java/org/libreoffice/DirectBufferAllocator.java | 33 +++
android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java | 9
android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java | 94 ---------
android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java | 73 +++++--
android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java | 89 +-------
android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java | 11 -
android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java | 65 +-----
android/experimental/LOAndroid3/src/java/org/libreoffice/TileIterator.java | 6
android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java | 4
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java | 90 +++-----
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoGLInfo.java | 51 -----
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoImage.java | 40 ---
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoUtils.java | 74 +------
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java | 13 -
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/FlexibleGLSurfaceView.java | 24 --
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/FloatSize.java | 67 +-----
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java | 44 ----
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java | 40 +--
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java | 22 --
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerRenderer.java | 25 --
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java | 16 -
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScrollbarLayer.java | 9
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextLayer.java | 20 -
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextureGenerator.java | 102 +++++-----
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextureReaper.java | 63 +-----
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TileLayer.java | 10
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomController.java | 44 ----
android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/SubdocumentScrollHelper.java | 56 -----
28 files changed, 350 insertions(+), 844 deletions(-)
New commits:
commit e5e7e706f8b71e0a60f376b88df78b8d440c6d93
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Tue Jul 8 21:35:30 2014 +0200
LOAndroid3: upgrade to latest CairoGLInfo, CairoUtils, FloatSize
Change-Id: I93c0761b1e76848ee8b07c5bcc524c95c036d322
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoGLInfo.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoGLInfo.java
index bd4eedc..078aa41 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoGLInfo.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoGLInfo.java
@@ -1,47 +1,13 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Android code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2009-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Patrick Walton <pcwalton at mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+ * 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 javax.microedition.khronos.opengles.GL10;
-/**
- * Information needed to render Cairo bitmaps using OpenGL ES.
- */
+/** Information needed to render Cairo bitmaps using OpenGL ES. */
public class CairoGLInfo {
public final int internalFormat;
public final int format;
@@ -50,16 +16,13 @@ public class CairoGLInfo {
public CairoGLInfo(int cairoFormat) {
switch (cairoFormat) {
case CairoImage.FORMAT_ARGB32:
- internalFormat = format = GL10.GL_RGBA;
- type = GL10.GL_UNSIGNED_BYTE;
+ internalFormat = format = GL10.GL_RGBA; type = GL10.GL_UNSIGNED_BYTE;
break;
case CairoImage.FORMAT_RGB24:
- internalFormat = format = GL10.GL_RGB;
- type = GL10.GL_UNSIGNED_BYTE;
+ internalFormat = format = GL10.GL_RGB; type = GL10.GL_UNSIGNED_BYTE;
break;
case CairoImage.FORMAT_RGB16_565:
- internalFormat = format = GL10.GL_RGB;
- type = GL10.GL_UNSIGNED_SHORT_5_6_5;
+ internalFormat = format = GL10.GL_RGB; type = GL10.GL_UNSIGNED_SHORT_5_6_5;
break;
case CairoImage.FORMAT_A8:
case CairoImage.FORMAT_A1:
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoUtils.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoUtils.java
index 00bd896..e0db6530 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoUtils.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoUtils.java
@@ -1,45 +1,11 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Android code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2009-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Patrick Walton <pcwalton at mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+ * 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 org.mozilla.gecko.gfx.CairoImage;
import android.graphics.Bitmap;
-import javax.microedition.khronos.opengles.GL10;
/**
* Utility methods useful when displaying Cairo bitmaps using OpenGL ES.
@@ -49,13 +15,13 @@ public class CairoUtils {
public static int bitsPerPixelForCairoFormat(int cairoFormat) {
switch (cairoFormat) {
- case CairoImage.FORMAT_A1: return 1;
- case CairoImage.FORMAT_A8: return 8;
- case CairoImage.FORMAT_RGB16_565: return 16;
- case CairoImage.FORMAT_RGB24: return 24;
- case CairoImage.FORMAT_ARGB32: return 32;
- default:
- throw new RuntimeException("Unknown Cairo format");
+ case CairoImage.FORMAT_A1: return 1;
+ case CairoImage.FORMAT_A8: return 8;
+ case CairoImage.FORMAT_RGB16_565: return 16;
+ case CairoImage.FORMAT_RGB24: return 24;
+ case CairoImage.FORMAT_ARGB32: return 32;
+ default:
+ throw new RuntimeException("Unknown Cairo format");
}
}
@@ -64,21 +30,21 @@ public class CairoUtils {
return CairoImage.FORMAT_ARGB32; /* Droid Pro fix. */
switch (config) {
- case ALPHA_8: return CairoImage.FORMAT_A8;
- case ARGB_4444: throw new RuntimeException("ARGB_444 unsupported");
- case ARGB_8888: return CairoImage.FORMAT_ARGB32;
- case RGB_565: return CairoImage.FORMAT_RGB16_565;
- default: throw new RuntimeException("Unknown Skia bitmap config");
+ case ALPHA_8: return CairoImage.FORMAT_A8;
+ case ARGB_4444: throw new RuntimeException("ARGB_444 unsupported");
+ case ARGB_8888: return CairoImage.FORMAT_ARGB32;
+ case RGB_565: return CairoImage.FORMAT_RGB16_565;
+ default: throw new RuntimeException("Unknown Skia bitmap config");
}
}
public static Bitmap.Config cairoFormatTobitmapConfig(int format) {
switch (format) {
- case CairoImage.FORMAT_A8: return Bitmap.Config.ALPHA_8;
- case CairoImage.FORMAT_ARGB32: return Bitmap.Config.ARGB_8888;
- case CairoImage.FORMAT_RGB16_565: return Bitmap.Config.RGB_565;
- default:
- throw new RuntimeException("Unknown CairoImage format");
+ case CairoImage.FORMAT_A8: return Bitmap.Config.ALPHA_8;
+ case CairoImage.FORMAT_ARGB32: return Bitmap.Config.ARGB_8888;
+ case CairoImage.FORMAT_RGB16_565: return Bitmap.Config.RGB_565;
+ default:
+ throw new RuntimeException("Unknown CairoImage format");
}
}
}
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/FloatSize.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/FloatSize.java
index 5fb73ec..dd9c1b3 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/FloatSize.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/FloatSize.java
@@ -1,78 +1,33 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Android code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2009-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Patrick Walton <pcwalton at mozilla.com>
- * Chris Lord <chrislord.net at gmail.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+ * 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 org.mozilla.gecko.util.FloatUtils;
+
import org.json.JSONException;
import org.json.JSONObject;
-import org.mozilla.gecko.util.FloatUtils;
public class FloatSize {
public final float width, height;
- public FloatSize(FloatSize size) {
- width = size.width;
- height = size.height;
- }
-
- public FloatSize(IntSize size) {
- width = size.width;
- height = size.height;
- }
-
- public FloatSize(float aWidth, float aHeight) {
- width = aWidth;
- height = aHeight;
- }
+ public FloatSize(FloatSize size) { width = size.width; height = size.height; }
+ public FloatSize(IntSize size) { width = size.width; height = size.height; }
+ public FloatSize(float aWidth, float aHeight) { width = aWidth; height = aHeight; }
public FloatSize(JSONObject json) {
try {
- width = (float) json.getDouble("width");
- height = (float) json.getDouble("height");
+ width = (float)json.getDouble("width");
+ height = (float)json.getDouble("height");
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
@Override
- public String toString() {
- return "(" + width + "," + height + ")";
- }
+ public String toString() { return "(" + width + "," + height + ")"; }
public boolean isPositive() {
return (width > 0 && height > 0);
commit 5957f5d02d5b20651e65e8518846082db7f7103c
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Tue Jul 8 21:31:56 2014 +0200
LOAndroid3: Allocate buffer of correct size in "BufferedCairoImage"
Change-Id: I7d70a90508d5a77234c670d6938c295321c08296
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
index ce836fe..de431d7 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
@@ -76,7 +76,7 @@ public class BufferedCairoImage extends CairoImage {
mFormat = CairoUtils.bitmapConfigToCairoFormat(bitmap.getConfig());
mSize = new IntSize(bitmap.getWidth(), bitmap.getHeight());
- int bpp = CairoUtils.bitsPerPixelForCairoFormat(mFormat);
+ int bpp = CairoUtils.bitsPerPixelForCairoFormat(mFormat) / 8;
mBuffer = DirectBufferAllocator.allocate(mSize.getArea() * bpp);
bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
}
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 31c1b6d..ccb50ad 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
@@ -81,6 +81,7 @@ public abstract class TileLayer extends Layer {
if (mTextureIDs != null) {
TextureReaper.get().add(mTextureIDs);
}
+ mImage.destroy();
}
/**
commit 25ad527972ce3fcb86b6b5b03789e1b7b5568a45
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Tue Jul 8 16:57:57 2014 +0200
LOAndroid3: tile loading and invalidation
Change-Id: I6e0157efc52d8cd0eabf650e14559697139d8e7e
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index 63bc72b..4744cf4 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -1,31 +1,23 @@
package org.libreoffice;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
import android.graphics.Rect;
-import android.util.JsonWriter;
+import android.graphics.RectF;
import android.util.Log;
import org.mozilla.gecko.gfx.FloatSize;
import org.mozilla.gecko.gfx.SubTile;
import org.mozilla.gecko.gfx.ViewportMetrics;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.nio.ByteBuffer;
-import java.util.Random;
+import java.util.ArrayList;
import java.util.concurrent.ConcurrentLinkedQueue;
public class LOKitThread extends Thread {
private static final String LOGTAG = LOKitThread.class.getSimpleName();
private static final int TILE_SIZE = 256;
+ public ConcurrentLinkedQueue<LOEvent> mEvents = new ConcurrentLinkedQueue<LOEvent>();
private LibreOfficeMainActivity mApplication;
private TileProvider mTileProvider;
-
- public ConcurrentLinkedQueue<LOEvent> gEvents = new ConcurrentLinkedQueue<LOEvent>();
private ViewportMetrics mViewportMetrics;
LOKitThread() {
@@ -38,14 +30,53 @@ public class LOKitThread extends Thread {
mViewportMetrics = new ViewportMetrics();
mViewportMetrics.setPageSize(new FloatSize(pageWidth, pageHeight));
+ RectF viewport = mApplication.getLayerController().getViewportMetrics().getClampedViewport();
+ float zoomFactor = mApplication.getLayerController().getViewportMetrics().getZoomFactor();
+
boolean shouldContinue = mApplication.getLayerClient().beginDrawing(mViewportMetrics);
if (!shouldContinue) {
return false;
}
- for (SubTile tile : mTileProvider.getTileIterator()) {
- mApplication.getLayerClient().addTile(tile);
+ int minX = ((int) viewport.left / TILE_SIZE) * TILE_SIZE;
+ int minY = ((int) viewport.top / TILE_SIZE) * TILE_SIZE;
+ int maxX = (((int) viewport.right / TILE_SIZE) + 1) * TILE_SIZE;
+ int maxY = (((int) viewport.bottom / TILE_SIZE) + 1) * TILE_SIZE;
+
+ Rect rect = new Rect(
+ Math.round(minX / zoomFactor),
+ Math.round(minY / zoomFactor),
+ Math.round(maxX / zoomFactor),
+ Math.round(maxY / zoomFactor));
+
+ ArrayList<SubTile> removeTiles = new ArrayList<SubTile>();
+ for (SubTile tile : mApplication.getLayerClient().getTiles()) {
+ if (!rect.intersects(tile.x, tile.y, tile.x + TILE_SIZE, tile.y + TILE_SIZE)) {
+ removeTiles.add(tile);
+ }
+ }
+ mApplication.getLayerClient().getTiles().removeAll(removeTiles);
+
+ for (int y = minY; y <= maxY; y+=TILE_SIZE) {
+ for (int x = minX; x <= maxX; x+=TILE_SIZE) {
+ if (x > pageWidth) {
+ continue;
+ }
+ if (y > pageHeight) {
+ continue;
+ }
+ boolean contains = false;
+ for (SubTile tile : mApplication.getLayerClient().getTiles()) {
+ if (tile.x == x && tile.y == y) {
+ contains = true;
+ }
+ }
+ if (!contains) {
+ SubTile tile = mTileProvider.createTile(x, y);
+ mApplication.getLayerClient().addTile(tile);
+ }
+ }
}
mApplication.getLayerClient().endDrawing();
@@ -63,14 +94,10 @@ public class LOKitThread extends Thread {
try {
boolean drawn = false;
while (true) {
- if (!gEvents.isEmpty()) {
- processEvent(gEvents.poll());
- } else {
- if (!drawn) {
- drawn = draw();
- }
- Thread.sleep(100L);
+ if (!mEvents.isEmpty()) {
+ processEvent(mEvents.poll());
}
+ Thread.sleep(100L);
}
} catch (InterruptedException ex) {
}
@@ -80,6 +107,7 @@ public class LOKitThread extends Thread {
switch (event.mType) {
case LOEvent.VIEWPORT:
mViewportMetrics = event.getViewport();
+ draw();
break;
case LOEvent.DRAW:
draw();
@@ -89,5 +117,8 @@ public class LOKitThread extends Thread {
}
}
-
+ public void queueEvent(LOEvent event) {
+ Log.i(LOGTAG, "Event: " + event.getTypeString());
+ mEvents.add(event);
+ }
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 32bfe30..3459e2b 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -1,24 +1,24 @@
package org.libreoffice;
import android.graphics.Bitmap;
-import android.util.Log;
+import org.libreoffice.kit.Document;
+import org.libreoffice.kit.LibreOfficeKit;
+import org.libreoffice.kit.Office;
import org.mozilla.gecko.gfx.BufferedCairoImage;
import org.mozilla.gecko.gfx.CairoImage;
import org.mozilla.gecko.gfx.LayerController;
+import org.mozilla.gecko.gfx.SubTile;
import java.nio.ByteBuffer;
-import java.util.Iterator;
-
-import org.libreoffice.kit.LibreOfficeKit;
-import org.libreoffice.kit.Office;
-import org.libreoffice.kit.Document;
-import org.mozilla.gecko.gfx.SubTile;
public class LOKitTileProvider implements TileProvider {
private final LayerController mLayerController;
public static int TILE_SIZE = 256;
+ private final double mTileWidth;
+ private final double mTileHeight;
+
public final Office mOffice;
public final Document mDocument;
@@ -42,6 +42,9 @@ public class LOKitTileProvider implements TileProvider {
mOffice = new Office(LibreOfficeKit.getLibreOfficeKitHandle());
String input = "/assets/test1.odt";
mDocument = mOffice.documentLoad(input);
+
+ mTileWidth = pixelToTwip(TILE_SIZE, mDPI);
+ mTileHeight = pixelToTwip(TILE_SIZE, mDPI);
}
@Override
@@ -54,71 +57,17 @@ public class LOKitTileProvider implements TileProvider {
return (int) twipToPixel(mDocument.getDocumentHeight(), mDPI);
}
- public TileIterator getTileIterator() {
- return new LoKitTileIterator();
- }
-
- public class LoKitTileIterator implements TileIterator, Iterator<SubTile> {
- private final double mTileWidth;
- private final double mTileHeight;
-
- private double mPositionWidth = 0;
- private double mPositionHeight = 0;
- private int mX = 0;
- private int mY = 0;
-
- private double mPageWidth;
- private double mPageHeight;
-
- public LoKitTileIterator() {
- mTileWidth = pixelToTwip(TILE_SIZE, mDPI);
- mTileHeight = pixelToTwip(TILE_SIZE, mDPI);
-
- mPageWidth = mDocument.getDocumentWidth();
- mPageHeight = mDocument.getDocumentHeight();
- }
-
- @Override
- public boolean hasNext() {
- return mPositionHeight <= mPageHeight;
- }
-
- @Override
- public SubTile next() {
- ByteBuffer buffer = ByteBuffer.allocateDirect(TILE_SIZE * TILE_SIZE * 4);
- Bitmap bitmap = Bitmap.createBitmap(TILE_SIZE, TILE_SIZE, Bitmap.Config.ARGB_8888);
-
- mDocument.paintTile(buffer, TILE_SIZE, TILE_SIZE,
- (int) Math.round(mPositionWidth), (int) Math.round(mPositionHeight), (int) Math.round(mTileWidth + pixelToTwip(1, mDPI)), (int) Math.round(mTileHeight+ pixelToTwip(1, mDPI)));
-
- bitmap.copyPixelsFromBuffer(buffer);
-
- CairoImage image = new BufferedCairoImage(bitmap);
- SubTile tile = new SubTile(image, mX, mY);
- tile.beginTransaction();
-
- mPositionWidth += mTileWidth;
- mX += TILE_SIZE;
-
- if (mPositionWidth > mPageWidth) {
- mPositionHeight += mTileHeight;
- mY += TILE_SIZE;
-
- mPositionWidth = 0;
- mX = 0;
- }
+ public SubTile createTile(int x, int y) {
+ ByteBuffer buffer = ByteBuffer.allocateDirect(TILE_SIZE * TILE_SIZE * 4);
+ Bitmap bitmap = Bitmap.createBitmap(TILE_SIZE, TILE_SIZE, Bitmap.Config.ARGB_8888);
- return tile;
- }
+ mDocument.paintTile(buffer, TILE_SIZE, TILE_SIZE, (int) pixelToTwip(x, mDPI), (int) pixelToTwip(y, mDPI), (int)mTileWidth, (int)mTileHeight);
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
+ bitmap.copyPixelsFromBuffer(buffer);
- @Override
- public Iterator<SubTile> iterator() {
- return this;
- }
+ CairoImage image = new BufferedCairoImage(bitmap);
+ SubTile tile = new SubTile(image, x, y);
+ tile.beginTransaction();
+ return tile;
}
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
index ab535a9..9dd39e4 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
@@ -2,15 +2,11 @@ package org.libreoffice;
import android.graphics.Bitmap;
-import org.apache.http.MethodNotSupportedException;
import org.mozilla.gecko.gfx.BufferedCairoImage;
import org.mozilla.gecko.gfx.CairoImage;
import org.mozilla.gecko.gfx.LayerController;
import org.mozilla.gecko.gfx.SubTile;
-import java.util.Iterator;
-import java.util.List;
-
public class MockTileProvider implements TileProvider {
private final LayerController layerController;
private static final int TILE_SIZE = 256;
@@ -26,58 +22,23 @@ public class MockTileProvider implements TileProvider {
@Override
public int getPageHeight() {
- return 630;
- }
-
- public TileIterator getTileIterator() {
- return new MockTileIterator(layerController);
+ return 630*5;
}
- public class MockTileIterator implements TileIterator, Iterator<SubTile> {
- private final LayerController layerController;
-
- private int tileNumber = 1;
-
- private int x = 0;
- private int y = 0;
-
- public MockTileIterator(LayerController layerController) {
- this.layerController = layerController;
- }
-
- @Override
- public boolean hasNext() {
- return tileNumber <= 9;
- }
-
- @Override
- public SubTile next() {
- String imageName = "d" + tileNumber;
- tileNumber++;
- Bitmap bitmap = layerController.getDrawable(imageName);
-
- CairoImage image = new BufferedCairoImage(bitmap);
- SubTile tile = new SubTile(image, x, y);
- tile.beginTransaction();
-
- x += TILE_SIZE;
-
- if (x > getPageWidth()) {
- x = 0;
- y += TILE_SIZE;
- }
+ @Override
+ public SubTile createTile(int x, int y) {
+ int tiles = (getPageWidth() / TILE_SIZE) + 1;
+ int tileNumber = (y / TILE_SIZE) * tiles + (x / TILE_SIZE);
+ tileNumber %= 9;
+ tileNumber += 1; // 0 to 1 based numbering
- return tile;
- }
+ String imageName = "d" + tileNumber;
+ Bitmap bitmap = layerController.getDrawable(imageName);
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
+ CairoImage image = new BufferedCairoImage(bitmap);
+ SubTile tile = new SubTile(image, x, y);
+ tile.beginTransaction();
- @Override
- public Iterator<SubTile> iterator() {
- return this;
- }
+ return tile;
}
}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIterator.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIterator.java
deleted file mode 100644
index b091561..0000000
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileIterator.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package org.libreoffice;
-
-import org.mozilla.gecko.gfx.SubTile;
-
-public interface TileIterator extends Iterable<SubTile> {
-}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
index dbaa040..296bf03 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
@@ -1,9 +1,11 @@
package org.libreoffice;
+import org.mozilla.gecko.gfx.SubTile;
+
public interface TileProvider {
int getPageWidth();
int getPageHeight();
- TileIterator getTileIterator();
+ SubTile createTile(int x, int y);
}
commit 019cf5e8f900f6ff35183e37d9a139aea2d54c85
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Tue Jul 8 16:49:56 2014 +0200
LOAndroid3: Expose LOKitThread in MainActivity
Change-Id: I7919e2469e1db87af6d2e0fbb3a476f4ca86d4d7
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 0f12208..1d267d9 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -7,14 +7,11 @@ import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.MotionEvent;
-import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import org.mozilla.gecko.gfx.GeckoSoftwareLayerClient;
import org.mozilla.gecko.gfx.LayerController;
-import org.mozilla.gecko.gfx.LayerView;
public class LibreOfficeMainActivity extends Activity {
@@ -61,7 +58,6 @@ public class LibreOfficeMainActivity extends Activity {
mAppContext = this;
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate");
@@ -82,15 +78,16 @@ public class LibreOfficeMainActivity extends Activity {
mGeckoLayout.addView(mLayerController.getView(), 0);
}
- mLayerController.notifyLayerClientOfGeometryChange();
-
sLOKitThread = new LOKitThread();
sLOKitThread.start();
-
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up");
}
+ public LOKitThread getLOKitThread() {
+ return sLOKitThread;
+ }
+
public static GeckoSoftwareLayerClient getLayerClient() {
return mLayerClient;
}
commit dd1fbacd25e7f871fd415d4139ecde97f65dacfa
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Tue Jul 8 16:48:46 2014 +0200
LOAndroid3: use CopyOnWriteArrayList in MultiTileLayer
Change-Id: Idb7fa8234bf74c83295816cb95dcc56e50c05969
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java
index e069a96..0d20b9d 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java
@@ -44,9 +44,8 @@ import android.graphics.RectF;
import android.graphics.Region;
import android.util.Log;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
/**
* Encapsulates the logic needed to draw a layer made of multiple tiles.
@@ -61,7 +60,7 @@ public class MultiTileLayer extends Layer {
public MultiTileLayer(IntSize tileSize) {
super();
mTileSize = tileSize;
- mTiles = Collections.synchronizedList(new ArrayList<SubTile>());
+ mTiles = new CopyOnWriteArrayList<SubTile>();
mSize = new IntSize(0,0);
}
commit 40499e3db9ab890af13e6e8b47da68191fa11157
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Tue Jul 8 16:45:47 2014 +0200
LOAndroid3: clean-up imports TileLayer, GeckoSoftwareLayerClient
Change-Id: I420d2b28a3d3904989ea9c52e8a4326a0c8d7c3c
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java
index 8efe82d..43cf88d 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java
@@ -74,8 +74,9 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
@Override
protected boolean setupLayer() {
Log.i(LOGTAG, "Creating MultiTileLayer");
- if(mTileLayer == null)
+ if(mTileLayer == null) {
mTileLayer = new MultiTileLayer(TILE_SIZE);
+ }
mLayerController.setRoot(mTileLayer);
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 64ec94d..31c1b6d 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
@@ -38,16 +38,12 @@
package org.mozilla.gecko.gfx;
-import android.graphics.Point;
import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.Region;
import android.opengl.GLES20;
import android.util.Log;
+
import java.nio.Buffer;
import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
/**
* Base class for tile layers, which encapsulate the logic needed to draw textured tiles in OpenGL
@@ -82,8 +78,9 @@ public abstract class TileLayer extends Layer {
@Override
protected void finalize() throws Throwable {
- if (mTextureIDs != null)
+ if (mTextureIDs != null) {
TextureReaper.get().add(mTextureIDs);
+ }
}
/**
commit d646e43cc088c70c2d8c2decaf1590ede0f3e898
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Tue Jul 8 16:43:31 2014 +0200
LOAndroid3: CairoImage, BufferedCairoImage update to latest code
Change-Id: If6b7e63a89c13015d4a96fae1862c9ccf6b04237
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
index 7a98be3..ce836fe 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
@@ -1,90 +1,51 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Android code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2009-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Patrick Walton <pcwalton at mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+ * 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.graphics.Bitmap;
+import android.util.Log;
import org.libreoffice.DirectBufferAllocator;
import java.nio.ByteBuffer;
-//import org.mozilla.gecko.GeckoAppShell;
-
/**
* A Cairo image that simply saves a buffer of pixel data.
*/
public class BufferedCairoImage extends CairoImage {
+ private static String LOGTAG = "GeckoBufferedCairoImage";
private ByteBuffer mBuffer;
private IntSize mSize;
private int mFormat;
- private boolean mNeedToFreeBuffer = false;
/**
* Creates a buffered Cairo image from a byte buffer.
*/
public BufferedCairoImage(ByteBuffer inBuffer, int inWidth, int inHeight, int inFormat) {
- mBuffer = inBuffer;
- mSize = new IntSize(inWidth, inHeight);
- mFormat = inFormat;
+ setBuffer(inBuffer, inWidth, inHeight, inFormat);
}
/**
* Creates a buffered Cairo image from an Android bitmap.
*/
public BufferedCairoImage(Bitmap bitmap) {
- mFormat = CairoUtils.bitmapConfigToCairoFormat(bitmap.getConfig());
- mSize = new IntSize(bitmap.getWidth(), bitmap.getHeight());
- mNeedToFreeBuffer = true;
- // XXX Why is this * 4? Shouldn't it depend on mFormat?
- mBuffer = DirectBufferAllocator.allocate(mSize.getArea() * 4);
+ setBitmap(bitmap);
+ }
- bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
+ private synchronized void freeBuffer() {
+ mBuffer = DirectBufferAllocator.free(mBuffer);
}
- protected void finalize() throws Throwable {
+ @Override
+ public void destroy() {
try {
- if (mNeedToFreeBuffer && mBuffer != null) {
- DirectBufferAllocator.free(mBuffer);
- }
- mNeedToFreeBuffer = false;
- mBuffer = null;
- } finally {
- super.finalize();
+ freeBuffer();
+ } catch (Exception ex) {
+ Log.e(LOGTAG, "error clearing buffer: ", ex);
}
}
@@ -102,5 +63,21 @@ public class BufferedCairoImage extends CairoImage {
public int getFormat() {
return mFormat;
}
-}
+
+ public void setBuffer(ByteBuffer buffer, int width, int height, int format) {
+ freeBuffer();
+ mBuffer = buffer;
+ mSize = new IntSize(width, height);
+ mFormat = format;
+ }
+
+ public void setBitmap(Bitmap bitmap) {
+ mFormat = CairoUtils.bitmapConfigToCairoFormat(bitmap.getConfig());
+ mSize = new IntSize(bitmap.getWidth(), bitmap.getHeight());
+
+ int bpp = CairoUtils.bitsPerPixelForCairoFormat(mFormat);
+ mBuffer = DirectBufferAllocator.allocate(mSize.getArea() * bpp);
+ bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
+ }
+}
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoImage.java
index 06c389d..5a18a4b 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoImage.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CairoImage.java
@@ -1,39 +1,7 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Android code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2009-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Patrick Walton <pcwalton at mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+ * 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;
@@ -45,6 +13,8 @@ import java.nio.ByteBuffer;
public abstract class CairoImage {
public abstract ByteBuffer getBuffer();
+ public abstract void destroy();
+
public abstract IntSize getSize();
public abstract int getFormat();
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java
index 05a4d57a..7af94fa 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java
@@ -160,6 +160,11 @@ public class CheckerboardImage extends CairoImage {
}
@Override
+ public void destroy() {
+
+ }
+
+ @Override
public IntSize getSize() {
return new IntSize(SIZE, SIZE);
}
commit d4ab22323a34c286b411044a598f5041e189d159
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Mon Jul 7 21:15:41 2014 +0200
LOAndroid3: remove GeckoEventListener dependency & bufferSize
Change-Id: I2e7bf8eb463fa9d9480f247732bde0af2055bd76
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 66ac7e9..3ed1104 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
@@ -40,30 +40,27 @@ package org.mozilla.gecko.gfx;
import android.content.Context;
import android.graphics.PointF;
-import android.graphics.Rect;
import android.os.SystemClock;
import android.util.DisplayMetrics;
import android.util.Log;
-import org.json.JSONObject;
import org.libreoffice.LOEvent;
import org.libreoffice.LOKitShell;
import org.libreoffice.LibreOfficeMainActivity;
-import org.mozilla.gecko.GeckoEventListener;
import org.mozilla.gecko.util.FloatUtils;
-import java.util.regex.Pattern;
-
-public abstract class GeckoLayerClient implements GeckoEventListener {
+public abstract class GeckoLayerClient {
private static final String LOGTAG = "GeckoLayerClient";
private static final long MIN_VIEWPORT_CHANGE_DELAY = 25L;
- private static Pattern sColorPattern;
protected IntSize mScreenSize;
protected Layer mTileLayer;
+
/* The viewport that Gecko is currently displaying. */
protected ViewportMetrics mGeckoViewport;
+
/* The viewport that Gecko will display when drawing is finished */
protected ViewportMetrics mNewGeckoViewport;
+
protected LayerController mLayerController;
private long mLastViewportChangeTime;
private boolean mPendingViewportAdjust;
@@ -84,8 +81,6 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
protected abstract void updateLayerAfterDraw();
- protected abstract IntSize getBufferSize();
-
protected abstract IntSize getTileSize();
/**
@@ -171,12 +166,11 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
}
mScreenSize = new IntSize(metrics.widthPixels, metrics.heightPixels);
- IntSize bufferSize = getBufferSize();
IntSize tileSize = getTileSize();
Log.e(LOGTAG, "### Screen-size changed to " + mScreenSize);
- LOEvent event = LOEvent.sizeChanged(bufferSize.width, bufferSize.height,
+ LOEvent event = LOEvent.sizeChanged(
metrics.widthPixels, metrics.heightPixels,
tileSize.width, tileSize.height);
LOKitShell.sendEvent(event);
@@ -217,8 +211,6 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
private void adjustViewport() {
ViewportMetrics viewportMetrics = new ViewportMetrics(mLayerController.getViewportMetrics());
- PointF viewportOffset = viewportMetrics.getOptimumViewportOffset(getBufferSize());
- viewportMetrics.setViewportOffset(viewportOffset);
viewportMetrics.setViewport(viewportMetrics.getClampedViewport());
LOKitShell.sendEvent(LOEvent.viewport(viewportMetrics));
@@ -230,21 +222,6 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
mLastViewportChangeTime = System.currentTimeMillis();
}
- public void handleMessage(String event, JSONObject message) {
- if ("Viewport:UpdateAndDraw".equals(event)) {
- Log.e(LOGTAG, "### Java side Viewport:UpdateAndDraw()!");
- mUpdateViewportOnEndDraw = true;
-
- // Redraw everything.
- IntSize bufferSize = getBufferSize();
- Rect rect = new Rect(0, 0, bufferSize.width, bufferSize.height);
- LOKitShell.sendEvent(LOEvent.draw(rect));
- } else if ("Viewport:UpdateLater".equals(event)) {
- Log.e(LOGTAG, "### Java side Viewport:UpdateLater()!");
- mUpdateViewportOnEndDraw = true;
- }
- }
-
public void geometryChanged() {
sendResizeEventIfNecessary();
render();
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java
index 66adaf2..8efe82d 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java
@@ -53,15 +53,10 @@ import java.util.List;
public class GeckoSoftwareLayerClient extends GeckoLayerClient {
private static final String LOGTAG = "GeckoSoftwareLayerClient";
- private int mFormat;
- private IntSize mViewportSize;
- private IntSize mBufferSize;
private static final IntSize TILE_SIZE = new IntSize(256, 256);
public GeckoSoftwareLayerClient(Context context) {
super(context);
- mBufferSize = new IntSize(0,0);
- mFormat = CairoImage.FORMAT_ARGB32;
}
public void setLayerController(LayerController layerController) {
@@ -98,12 +93,6 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
}
}
- @Override
- protected IntSize getBufferSize() {
- return new IntSize(
- ((mScreenSize.width + LayerController.MIN_BUFFER.width - 1) / TILE_SIZE.width + 1) * TILE_SIZE.width,
- ((mScreenSize.height + LayerController.MIN_BUFFER.height - 1) / TILE_SIZE.height + 1) * TILE_SIZE.height);
- }
@Override
protected IntSize getTileSize() {
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java
index 0ddd7aa..38de9c4 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java
@@ -68,7 +68,6 @@ public class LayerController {
* smooth, asynchronous scrolling. Depending on a device's support for NPOT
* textures, this may be rounded up to the nearest power of two.
*/
- public static final IntSize MIN_BUFFER = new IntSize(512, 1024);
private static final String LOGTAG = "GeckoLayerController";
/* If the visible rect is within the danger zone (measured in pixels from each edge of a tile),
* we start aggressively redrawing to minimize checkerboarding. */
@@ -79,10 +78,7 @@ public class LayerController {
private static final int PREVENT_DEFAULT_TIMEOUT = 200;
private Layer mRootLayer; /* The root layer. */
private LayerView mView; /* The main rendering view. */
- /*
- * The panning and zooming controller, which interprets pan and zoom gestures for us and
- * updates our visible rect appropriately.
- */
+
private Context mContext; /* The current context. */
private ViewportMetrics mViewportMetrics; /* The current viewport metrics. */
private boolean mWaitForTouchListeners;
@@ -100,7 +96,6 @@ public class LayerController {
public LayerController(Context context) {
mContext = context;
-
mForceRedraw = true;
mViewportMetrics = new ViewportMetrics();
mPanZoomController = new PanZoomController(this);
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomController.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomController.java
index 066f4ce..7d15bdb 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomController.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/PanZoomController.java
@@ -45,13 +45,10 @@ import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
-import org.json.JSONObject;
import org.libreoffice.LOKitShell;
import org.libreoffice.LibreOfficeMainActivity;
-import org.mozilla.gecko.GeckoEventListener;
import org.mozilla.gecko.gfx.FloatSize;
import org.mozilla.gecko.gfx.LayerController;
-import org.mozilla.gecko.gfx.PointUtils;
import org.mozilla.gecko.gfx.ViewportMetrics;
import org.mozilla.gecko.util.FloatUtils;
@@ -64,9 +61,7 @@ import java.util.TimerTask;
* Many ideas are from Joe Hewitt's Scrollability:
* https://github.com/joehewitt/scrollability/
*/
-public class PanZoomController
- extends GestureDetector.SimpleOnGestureListener
- implements SimpleScaleGestureDetector.SimpleScaleGestureListener, GeckoEventListener {
+public class PanZoomController extends GestureDetector.SimpleOnGestureListener implements SimpleScaleGestureDetector.SimpleScaleGestureListener {
// The distance the user has to pan before we recognize it as such (e.g. to avoid 1-pixel pans
// between the touch-down and touch-up of a click). In units of density-independent pixels.
public static final float PAN_THRESHOLD = 1 / 16f * LOKitShell.getDpi();
@@ -127,43 +122,6 @@ public class PanZoomController
mState = PanZoomState.NOTHING;
}
- public void handleMessage(String event, JSONObject message) {
- Log.i(LOGTAG, "Got message: " + event);
- try {
- if (MESSAGE_ZOOM_RECT.equals(event)) {
- float x = (float) message.getDouble("x");
- float y = (float) message.getDouble("y");
- final RectF zoomRect = new RectF(x, y,
- x + (float) message.getDouble("w"),
- y + (float) message.getDouble("h"));
- mController.post(new Runnable() {
- public void run() {
- animatedZoomTo(zoomRect);
- }
- });
- } else if (MESSAGE_ZOOM_PAGE.equals(event)) {
- FloatSize pageSize = mController.getPageSize();
-
- RectF viewableRect = mController.getViewport();
- float y = viewableRect.top;
- // attempt to keep zoom keep focused on the center of the viewport
- float newHeight = viewableRect.height() * pageSize.width / viewableRect.width();
- float dh = viewableRect.height() - newHeight; // increase in the height
- final RectF r = new RectF(0.0f,
- y + dh / 2,
- pageSize.width,
- y + dh / 2 + newHeight);
- mController.post(new Runnable() {
- public void run() {
- animatedZoomTo(r);
- }
- });
- }
- } catch (Exception e) {
- Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
- }
- }
-
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
commit 2375959cdbdce2b2ac9e908f91f26abf9ed2f95b
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Mon Jul 7 21:10:57 2014 +0200
LOAndroid3: cleanup & remove obsolete code - LOEvent / LOKitShell
Change-Id: Ia41effca9aa54076290f105a9412bee9e388007d
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
index bf4f98b..2814730 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
@@ -1,7 +1,6 @@
package org.libreoffice;
import android.graphics.Rect;
-import android.util.Log;
import org.mozilla.gecko.gfx.IntSize;
import org.mozilla.gecko.gfx.ViewportMetrics;
@@ -20,9 +19,9 @@ public class LOEvent {
ViewportMetrics viewportMetrics;
- public LOEvent(int type, int width, int height, int widthPixels, int heightPixels, int tileWidth, int tileHeight) {
+ public LOEvent(int type, int widthPixels, int heightPixels, int tileWidth, int tileHeight) {
mType = type;
- mTypeString = "Size Changed";
+ mTypeString = "Size Changed: " + widthPixels + " "+ heightPixels;
}
public LOEvent(int type, IntSize tileSize) {
@@ -45,8 +44,8 @@ public class LOEvent {
return new LOEvent(DRAW, rect);
}
- public static LOEvent sizeChanged(int width, int height, int widthPixels, int heightPixels, int tileWidth, int tileHeight) {
- return new LOEvent(SIZE_CHANGED, width, height, widthPixels, heightPixels, tileWidth, tileHeight);
+ public static LOEvent sizeChanged(int widthPixels, int heightPixels, int tileWidth, int tileHeight) {
+ return new LOEvent(SIZE_CHANGED, widthPixels, heightPixels, tileWidth, tileHeight);
}
public static LOEvent tileSize(IntSize tileSize) {
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
index e9781ff..4ceeddc 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
@@ -2,7 +2,6 @@ package org.libreoffice;
import android.util.DisplayMetrics;
-import android.util.Log;
public class LOKitShell {
private static final String LOGTAG = LOKitShell.class.getSimpleName();
@@ -21,41 +20,6 @@ public class LOKitShell {
}
}
- public static void runGecko(String apkPath, String args, String url, boolean restoreSession) {
- // run gecko -- it will spawn its own thread
- // GeckoAppShell.nativeInit();
-
- Log.i(LOGTAG, "post native init");
-
- // Tell Gecko where the target byte buffer is for rendering
- //GeckoAppShell.setSoftwareLayerClient(GeckoApp.mAppContext.getSoftwareLayerClient());
-
- Log.i(LOGTAG, "setSoftwareLayerClient called");
-
- // First argument is the .apk path
- String combinedArgs = apkPath + " -greomni " + apkPath;
- if (args != null)
- combinedArgs += " " + args;
- if (url != null)
- combinedArgs += " -remote " + url;
- if (restoreSession)
- combinedArgs += " -restoresession";
-
- DisplayMetrics metrics = new DisplayMetrics();
- LibreOfficeMainActivity.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
- combinedArgs += " -width " + metrics.widthPixels + " -height " + metrics.heightPixels;
-
- LibreOfficeMainActivity.mAppContext.runOnUiThread(new Runnable() {
- public void run() {
- geckoLoaded();
- }
- });
- }
-
- // Called on the UI thread after Gecko loads.
- private static void geckoLoaded() {
- }
-
public static void viewSizeChanged() {
}
commit 9cebdb5965114fb682598f19ad56fa8e56dc87b5
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Mon Jul 7 17:31:38 2014 +0200
LOAndroid3: MultiTileLayer - use SynchroniozedList for tiles
Change-Id: If2aa13eb3f772925f561b02eaf09f88620eabeef
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java
index e13bda8..e069a96 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java
@@ -45,6 +45,7 @@ import android.graphics.Region;
import android.util.Log;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
@@ -53,14 +54,14 @@ import java.util.List;
public class MultiTileLayer extends Layer {
private static final String LOGTAG = "GeckoMultiTileLayer";
- private final ArrayList<SubTile> mTiles;
+ private final List<SubTile> mTiles;
private IntSize mTileSize;
private IntSize mSize;
public MultiTileLayer(IntSize tileSize) {
super();
mTileSize = tileSize;
- mTiles = new ArrayList<SubTile>();
+ mTiles = Collections.synchronizedList(new ArrayList<SubTile>());
mSize = new IntSize(0,0);
}
commit 842d8fb5118fa1ac46102cfaac6a1aafc33cbd46
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Mon Jul 7 17:30:30 2014 +0200
LOAndroid3: Add and use DirectBufferAllocator
Change-Id: I20a1de3a18deab6b978192d1d8a54278addbb083
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/DirectBufferAllocator.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/DirectBufferAllocator.java
new file mode 100644
index 0000000..902d94a
--- /dev/null
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/DirectBufferAllocator.java
@@ -0,0 +1,33 @@
+package org.libreoffice;
+
+import java.nio.ByteBuffer;
+
+public class DirectBufferAllocator {
+ public static ByteBuffer allocate(int size) {
+ if (size <= 0) {
+ throw new IllegalArgumentException("Invalid size " + size);
+ }
+
+ ByteBuffer directBuffer = ByteBuffer.allocateDirect(size);
+ //ByteBuffer directBuffer = nativeAllocateDirectBuffer(size);
+ if (directBuffer == null) {
+ throw new OutOfMemoryError("allocateDirectBuffer() returned null");
+ } else if (!directBuffer.isDirect()) {
+ throw new AssertionError("allocateDirectBuffer() did not return a direct buffer");
+ }
+
+ return directBuffer;
+ }
+
+ public static ByteBuffer free(ByteBuffer buffer) {
+ if (buffer == null) {
+ return null;
+ }
+
+ if (!buffer.isDirect()) {
+ throw new IllegalArgumentException("buffer must be direct");
+ }
+ //nativeFreeDirectBuffer(buffer);
+ return buffer;
+ }
+}
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
index e4f6b08..e9781ff 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java
@@ -3,15 +3,6 @@ package org.libreoffice;
import android.util.DisplayMetrics;
import android.util.Log;
-import android.view.MotionEvent;
-import android.view.View;
-
-import org.mozilla.gecko.gfx.GeckoSoftwareLayerClient;
-import org.mozilla.gecko.gfx.IntSize;
-import org.mozilla.gecko.gfx.LayerController;
-import org.mozilla.gecko.gfx.LayerView;
-
-import java.nio.ByteBuffer;
public class LOKitShell {
private static final String LOGTAG = LOKitShell.class.getSimpleName();
@@ -21,39 +12,13 @@ public class LOKitShell {
return (int) metrics.density * 160;
}
- public static ByteBuffer allocateDirectBuffer(int size) {
- if (size <= 0) {
- throw new IllegalArgumentException("Invalid size " + size);
- }
-
- ByteBuffer directBuffer = ByteBuffer.allocateDirect(size);
- //ByteBuffer directBuffer = nativeAllocateDirectBuffer(size);
- if (directBuffer == null) {
- throw new OutOfMemoryError("allocateDirectBuffer() returned null");
- } else if (!directBuffer.isDirect()) {
- throw new AssertionError("allocateDirectBuffer() did not return a direct buffer");
- }
-
- return directBuffer;
- }
-
- public static void freeDirectBuffer(ByteBuffer buffer) {
- if (buffer == null) {
- return;
- }
-
- if (!buffer.isDirect()) {
- throw new IllegalArgumentException("buffer must be direct");
- }
- //nativeFreeDirectBuffer(buffer);
- return ;
- }
-
public static void bindWidgetTexture() {
}
public static void sendEvent(LOEvent event) {
- Log.i(LOGTAG, "Event: " + event.getTypeString());
+ if (LibreOfficeMainActivity.mAppContext != null && LibreOfficeMainActivity.mAppContext.getLOKitThread() != null) {
+ LibreOfficeMainActivity.mAppContext.getLOKitThread().queueEvent(event);
+ }
}
public static void runGecko(String apkPath, String args, String url, boolean restoreSession) {
@@ -85,27 +50,10 @@ public class LOKitShell {
geckoLoaded();
}
});
-
- //LOKitShell.nativeRun(combinedArgs);
}
// Called on the UI thread after Gecko loads.
private static void geckoLoaded() {
- /*final LayerController layerController = LibreOfficeMainActivity.mAppContext.getLayerController();
- LayerView v = layerController.getView();
- mInputConnection = GeckoInputConnection.create(v);
- v.setInputConnectionHandler(mInputConnection);
-
- layerController.setOnTouchListener(new View.OnTouchListener() {
- public boolean onTouch(View view, MotionEvent event) {
- if (event == null)
- return true;
- GeckoAppShell.sendEventToGecko(new GeckoEvent(event));
- return true;
- }
- });
-
- layerController.notifyLayerClientOfGeometryChange();*/
}
public static void viewSizeChanged() {
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
index 2ffe113..7a98be3 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java
@@ -39,7 +39,7 @@ package org.mozilla.gecko.gfx;
import android.graphics.Bitmap;
-import org.libreoffice.LOKitShell;
+import org.libreoffice.DirectBufferAllocator;
import java.nio.ByteBuffer;
@@ -71,15 +71,16 @@ public class BufferedCairoImage extends CairoImage {
mSize = new IntSize(bitmap.getWidth(), bitmap.getHeight());
mNeedToFreeBuffer = true;
// XXX Why is this * 4? Shouldn't it depend on mFormat?
- mBuffer = LOKitShell.allocateDirectBuffer(mSize.getArea() * 4);
+ mBuffer = DirectBufferAllocator.allocate(mSize.getArea() * 4);
bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
}
protected void finalize() throws Throwable {
try {
- if (mNeedToFreeBuffer && mBuffer != null)
- LOKitShell.freeDirectBuffer(mBuffer);
+ if (mNeedToFreeBuffer && mBuffer != null) {
+ DirectBufferAllocator.free(mBuffer);
+ }
mNeedToFreeBuffer = false;
mBuffer = null;
} finally {
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java
index 392d7e8..05a4d57a 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java
@@ -37,8 +37,10 @@
package org.mozilla.gecko.gfx;
-import org.libreoffice.LOKitShell;
import android.graphics.Color;
+
+import org.libreoffice.DirectBufferAllocator;
+
import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
import java.util.Arrays;
@@ -61,7 +63,7 @@ public class CheckerboardImage extends CairoImage {
/** Creates a new checkerboard image. */
public CheckerboardImage() {
int bpp = CairoUtils.bitsPerPixelForCairoFormat(FORMAT);
- mBuffer = LOKitShell.allocateDirectBuffer(SIZE * SIZE * bpp / 8);
+ mBuffer = DirectBufferAllocator.allocate(SIZE * SIZE * bpp / 8);
update(true, Color.WHITE);
}
@@ -145,7 +147,7 @@ public class CheckerboardImage extends CairoImage {
protected void finalize() throws Throwable {
try {
if (mBuffer != null) {
- LOKitShell.freeDirectBuffer(mBuffer);
+ DirectBufferAllocator.free(mBuffer);
}
} finally {
super.finalize();
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 5fd130f..66ac7e9 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
@@ -64,6 +64,7 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
protected ViewportMetrics mGeckoViewport;
/* The viewport that Gecko will display when drawing is finished */
protected ViewportMetrics mNewGeckoViewport;
+ protected LayerController mLayerController;
private long mLastViewportChangeTime;
private boolean mPendingViewportAdjust;
private boolean mViewportSizeChanged;
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerRenderer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerRenderer.java
index 095a6f4..8fb391a 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerRenderer.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerRenderer.java
@@ -39,21 +39,9 @@
package org.mozilla.gecko.gfx;
-import org.libreoffice.LOKitShell;
-import org.mozilla.gecko.gfx.BufferedCairoImage;
-import org.mozilla.gecko.gfx.IntSize;
-import org.mozilla.gecko.gfx.Layer.RenderContext;
-import org.mozilla.gecko.gfx.LayerController;
-import org.mozilla.gecko.gfx.NinePatchTileLayer;
-import org.mozilla.gecko.gfx.SingleTileLayer;
-import org.mozilla.gecko.gfx.TextureReaper;
-import org.mozilla.gecko.gfx.TextureGenerator;
-import org.mozilla.gecko.gfx.TextLayer;
-import org.mozilla.gecko.gfx.TileLayer;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Point;
-import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
@@ -61,17 +49,20 @@ import android.graphics.RegionIterator;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.os.SystemClock;
-import android.util.DisplayMetrics;
import android.util.Log;
-import android.view.WindowManager;
-import javax.microedition.khronos.egl.EGLConfig;
-import javax.microedition.khronos.opengles.GL10;
+
+import org.libreoffice.DirectBufferAllocator;
+import org.mozilla.gecko.gfx.Layer.RenderContext;
+
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
/**
* The layer renderer implements the rendering logic for a layer view.
*/
@@ -186,7 +177,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
// Initialize the FloatBuffer that will be used to store all vertices and texture
// coordinates in draw() commands.
- ByteBuffer byteBuffer = LOKitShell.allocateDirectBuffer(COORD_BUFFER_SIZE * 4);
+ ByteBuffer byteBuffer = DirectBufferAllocator.allocate(COORD_BUFFER_SIZE * 4);
byteBuffer.order(ByteOrder.nativeOrder());
mCoordBuffer = byteBuffer.asFloatBuffer();
}
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScrollbarLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScrollbarLayer.java
index 68b7265..9c33d40 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScrollbarLayer.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScrollbarLayer.java
@@ -47,7 +47,7 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.opengl.GLES20;
-import org.libreoffice.LOKitShell;
+import org.libreoffice.DirectBufferAllocator;
import org.mozilla.gecko.util.FloatUtils;
import java.nio.ByteBuffer;
@@ -128,7 +128,7 @@ public class ScrollbarLayer extends TileLayer {
// just create an empty image for now, it will get drawn
// on demand anyway
int imageSize = IntSize.nextPowerOfTwo(BAR_SIZE);
- ByteBuffer buffer = LOKitShell.allocateDirectBuffer(imageSize * imageSize * 4);
+ ByteBuffer buffer = DirectBufferAllocator.allocate(imageSize * imageSize * 4);
CairoImage image = new BufferedCairoImage(buffer, imageSize, imageSize,
CairoImage.FORMAT_ARGB32);
return new ScrollbarLayer(image, vertical, buffer);
@@ -136,8 +136,9 @@ public class ScrollbarLayer extends TileLayer {
protected void finalize() throws Throwable {
try {
- if (!mFinalized && mBuffer != null)
- LOKitShell.freeDirectBuffer(mBuffer);
+ if (!mFinalized && mBuffer != null) {
+ DirectBufferAllocator.free(mBuffer);
+ }
mFinalized = true;
} finally {
super.finalize();
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextLayer.java
index f2cc640..e3bd2f2 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextLayer.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextLayer.java
@@ -38,19 +38,15 @@
package org.mozilla.gecko.gfx;
//import org.mozilla.gecko.GeckoAppShell;
-import org.libreoffice.LOKitShell;
-import org.mozilla.gecko.gfx.BufferedCairoImage;
-import org.mozilla.gecko.gfx.CairoImage;
-import org.mozilla.gecko.gfx.IntSize;
-import org.mozilla.gecko.gfx.SingleTileLayer;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
-import android.util.Log;
+
+import org.libreoffice.DirectBufferAllocator;
+
import java.nio.ByteBuffer;
-import java.nio.IntBuffer;
/**
* Draws text on a layer. This is used for the frame rate meter.
@@ -73,8 +69,9 @@ public class TextLayer extends SingleTileLayer {
protected void finalize() throws Throwable {
try {
- if (!mFinalized && mBuffer != null)
- /*GeckoAppShell*/ LOKitShell.freeDirectBuffer(mBuffer);
+ if (!mFinalized && mBuffer != null) {
+ DirectBufferAllocator.free(mBuffer);
+ }
mFinalized = true;
} finally {
super.finalize();
@@ -82,9 +79,8 @@ public class TextLayer extends SingleTileLayer {
}
public static TextLayer create(IntSize size, String text) {
- ByteBuffer buffer = /*GeckoAppShell*/LOKitShell.allocateDirectBuffer(size.width * size.height * 4);
- BufferedCairoImage image = new BufferedCairoImage(buffer, size.width, size.height,
- CairoImage.FORMAT_ARGB32);
+ ByteBuffer buffer = DirectBufferAllocator.allocate(size.width * size.height * 4);
+ BufferedCairoImage image = new BufferedCairoImage(buffer, size.width, size.height, CairoImage.FORMAT_ARGB32);
return new TextLayer(buffer, image, size, text);
}
commit e7b401d9fb86da9b6d18709a21886cb91e7a0ce5
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Mon Jul 7 17:16:09 2014 +0200
LOAndorid3: Clean unused code, add getTiles() to MultiTileLayer
Change-Id: I1a539d10de2ad8bf7410a59adafcb18cc2639068
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/FlexibleGLSurfaceView.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/FlexibleGLSurfaceView.java
index dc20077..0f47524 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/FlexibleGLSurfaceView.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/FlexibleGLSurfaceView.java
@@ -46,8 +46,6 @@ import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
-import org.libreoffice.LibreOfficeMainActivity;
-
public class FlexibleGLSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private static final String LOGTAG = "GeckoFlexibleGLSurfaceView";
@@ -151,8 +149,7 @@ public class FlexibleGLSurfaceView extends SurfaceView implements SurfaceHolder.
return mController;
}
- public synchronized void surfaceChanged(SurfaceHolder holder, int format, int width,
- int height) {
+ public synchronized void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
mController.sizeChanged(width, height);
if (mGLThread != null) {
mGLThread.surfaceChanged(width, height);
@@ -181,25 +178,6 @@ public class FlexibleGLSurfaceView extends SurfaceView implements SurfaceHolder.
}
}
- // Called from the compositor thread
- public static GLController registerCxxCompositor() {
- try {
- Log.e(LOGTAG, "### registerCxxCompositor point A");
- System.out.println("register layer comp");
- Log.e(LOGTAG, "### registerCxxCompositor point B");
- FlexibleGLSurfaceView flexView = (FlexibleGLSurfaceView) /*GeckoApp*/LibreOfficeMainActivity.mAppContext.getLayerController().getView();
- Log.e(LOGTAG, "### registerCxxCompositor point C: " + flexView);
- try {
- flexView.destroyGLThread().join();
- } catch (InterruptedException e) {}
- Log.e(LOGTAG, "### registerCxxCompositor point D: " + flexView.getGLController());
- return flexView.getGLController();
- } catch (Exception e) {
- Log.e(LOGTAG, "### Exception! " + e);
- return null;
- }
- }
-
public interface Listener {
void renderRequested();
void compositionPauseRequested();
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 d7fe6b3..5fd130f 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
@@ -39,16 +39,12 @@
package org.mozilla.gecko.gfx;
import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.Rect;
-import android.graphics.RectF;
import android.os.SystemClock;
import android.util.DisplayMetrics;
import android.util.Log;
-import org.json.JSONException;
import org.json.JSONObject;
import org.libreoffice.LOEvent;
import org.libreoffice.LOKitShell;
@@ -56,7 +52,6 @@ import org.libreoffice.LibreOfficeMainActivity;
import org.mozilla.gecko.GeckoEventListener;
import org.mozilla.gecko.util.FloatUtils;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class GeckoLayerClient implements GeckoEventListener {
@@ -72,7 +67,6 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
private long mLastViewportChangeTime;
private boolean mPendingViewportAdjust;
private boolean mViewportSizeChanged;
-
// mUpdateViewportOnEndDraw is used to indicate that we received a
// viewport update notification while drawing. therefore, when the
// draw finishes, we need to update the entire viewport rather than
@@ -81,8 +75,6 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
private boolean mUpdateViewportOnEndDraw;
private String mLastCheckerboardColor;
- protected LayerController mLayerController;
-
public GeckoLayerClient(Context context) {
mScreenSize = new IntSize(0, 0);
}
@@ -110,7 +102,7 @@ public abstract class GeckoLayerClient implements GeckoEventListener {
}
public boolean beginDrawing(ViewportMetrics viewportMetrics) {
- if (setupLayer()) {
+ if (setupLayer()) {
Log.e(LOGTAG, "### Cancelling due to layer setup");
return false;
}
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java
index e09e727..66adaf2 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java
@@ -38,24 +38,11 @@
package org.mozilla.gecko.gfx;
-import org.libreoffice.LOKitShell;
-import org.mozilla.gecko.gfx.CairoImage;
-import org.mozilla.gecko.gfx.IntSize;
-import org.mozilla.gecko.gfx.GeckoLayerClient;
-import org.mozilla.gecko.gfx.LayerController;
-import org.mozilla.gecko.gfx.LayerRenderer;
-import org.mozilla.gecko.gfx.MultiTileLayer;
-import org.mozilla.gecko.gfx.PointUtils;
-import org.mozilla.gecko.gfx.WidgetTileLayer;
-//import org.mozilla.gecko.GeckoAppShell;
import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.graphics.RectF;
import android.util.Log;
-import java.nio.ByteBuffer;
+
+import java.util.List;
+
/**
* Transfers a software-rendered Gecko to an ImageLayer so that it can be rendered by our
@@ -128,5 +115,12 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
((MultiTileLayer)mTileLayer).addTile(tile);
}
}
+
+ public List<SubTile> getTiles() {
+ if (mTileLayer instanceof MultiTileLayer) {
+ return ((MultiTileLayer)mTileLayer).getTiles();
+ }
+ return null;
+ }
}
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java
index e237052..0ddd7aa 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerController.java
@@ -276,15 +276,6 @@ public class LayerController {
return BitmapFactory.decodeResource(mContext.getResources(), resourceID, options);
}
- public Bitmap getDrawable16(String name) {
- Resources resources = mContext.getResources();
- int resourceID = resources.getIdentifier(name, "drawable", mContext.getPackageName());
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inScaled = false;
- options.inPreferredConfig = Bitmap.Config.RGB_565;
- return BitmapFactory.decodeResource(mContext.getResources(), resourceID, options);
- }
-
/**
* Scrolls the viewport by the given offset. You must hold the monitor while calling this.
*/
@@ -293,9 +284,7 @@ public class LayerController {
origin.offset(point.x, point.y);
mViewportMetrics.setOrigin(origin);
Log.d(LOGTAG, "scrollBy: " + mViewportMetrics);
-
notifyLayerClientOfGeometryChange();
- //GeckoApp.mAppContext.repositionPluginViews(false);
mView.requestRender();
}
@@ -310,7 +299,6 @@ public class LayerController {
// We assume the zoom level will only be modified by the
// PanZoomController, so no need to notify it of this change.
notifyLayerClientOfGeometryChange();
- //GeckoApp.mAppContext.repositionPluginViews(false);
mView.requestRender();
}
@@ -327,8 +315,9 @@ public class LayerController {
* the geometry changed.
*/
public void notifyLayerClientOfGeometryChange() {
- if (mLayerClient != null)
+ if (mLayerClient != null) {
mLayerClient.geometryChanged();
+ }
}
/**
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java
index 65f4e79..e13bda8 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/MultiTileLayer.java
@@ -38,18 +38,14 @@
package org.mozilla.gecko.gfx;
-import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.util.Log;
-import org.libreoffice.LOKitShell;
-
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.List;
/**
* Encapsulates the logic needed to draw a layer made of multiple tiles.
@@ -242,5 +238,9 @@ public class MultiTileLayer extends Layer {
public void addTile(SubTile tile) {
mTiles.add(tile);
}
+
+ public List<SubTile> getTiles() {
+ return mTiles;
+ }
}
commit 7b55df0b2c04f1a58922585415bc2e32c5d68e08
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Mon Jul 7 17:09:01 2014 +0200
LOAndoid3: clean-up SubdocumentScrollHelper
Change-Id: Ie02b0a08c8bdcb93929fb742729a0169ee6a0666
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/SubdocumentScrollHelper.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/SubdocumentScrollHelper.java
index f24a5b7..30b4b30 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/SubdocumentScrollHelper.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/ui/SubdocumentScrollHelper.java
@@ -40,19 +40,9 @@ package org.mozilla.gecko.ui;
import android.graphics.PointF;
import android.os.Handler;
-import android.util.Log;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.mozilla.gecko.GeckoEventListener;
-
-class SubdocumentScrollHelper implements GeckoEventListener {
- private static final String LOGTAG = "GeckoSubdocumentScrollHelper";
-
- private static String MESSAGE_PANNING_OVERRIDE = "Panning:Override";
- private static String MESSAGE_CANCEL_OVERRIDE = "Panning:CancelOverride";
- private static String MESSAGE_SCROLL = "Gesture:Scroll";
- private static String MESSAGE_SCROLL_ACK = "Gesture:ScrollAck";
+class SubdocumentScrollHelper {
+ private static final String LOGTAG = SubdocumentScrollHelper.class.getSimpleName();
private final PanZoomController mPanZoomController;
private final Handler mUiHandler;
@@ -64,12 +54,7 @@ class SubdocumentScrollHelper implements GeckoEventListener {
SubdocumentScrollHelper(PanZoomController controller) {
mPanZoomController = controller;
- // mUiHandler will be bound to the UI thread since that's where this constructor runs
mUiHandler = new Handler();
-
- //GeckoAppShell.registerGeckoEventListener(MESSAGE_PANNING_OVERRIDE, this);
- //GeckoAppShell.registerGeckoEventListener(MESSAGE_CANCEL_OVERRIDE, this);
- //GeckoAppShell.registerGeckoEventListener(MESSAGE_SCROLL_ACK, this);
}
boolean scrollBy(PointF displacement) {
@@ -85,15 +70,6 @@ class SubdocumentScrollHelper implements GeckoEventListener {
mOverrideScrollAck = false;
mOverrideScrollPending = false;
- JSONObject json = new JSONObject();
- try {
- json.put("x", displacement.x);
- json.put("y", displacement.y);
- } catch (JSONException e) {
- Log.e(LOGTAG, "Error forming subwindow scroll message: ", e);
- }
- //GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent(MESSAGE_SCROLL, json.toString()));
-
return true;
}
@@ -109,32 +85,4 @@ class SubdocumentScrollHelper implements GeckoEventListener {
return mScrollSucceeded;
}
- // GeckoEventListener implementation
-
- public void handleMessage(final String event, final JSONObject message) {
- // this comes in on the gecko thread; hand off the handling to the UI thread
- mUiHandler.post(new Runnable() {
- public void run() {
- Log.i(LOGTAG, "Got message: " + event);
- try {
- if (MESSAGE_PANNING_OVERRIDE.equals(event)) {
- mOverridePanning = true;
- mOverrideScrollAck = true;
- mOverrideScrollPending = false;
- mScrollSucceeded = true;
- } else if (MESSAGE_CANCEL_OVERRIDE.equals(event)) {
- mOverridePanning = false;
- } else if (MESSAGE_SCROLL_ACK.equals(event)) {
- mOverrideScrollAck = true;
- mScrollSucceeded = message.getBoolean("scrolled");
- if (mOverridePanning && mOverrideScrollPending) {
- scrollBy(mPanZoomController.getDisplacement());
- }
- }
- } catch (Exception e) {
- Log.e(LOGTAG, "Exception handling message", e);
- }
- }
- });
- }
}
commit 2c7c21b3f498fa15361ce9218aba1baa38643d8d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Mon Jul 7 17:00:53 2014 +0200
LOAndroid3: upgrade TextureGenerator/Reaper to the latest version
Change-Id: Ic84d3f0901f071a22af411d914a51a2ba92dbf9f
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextureGenerator.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextureGenerator.java
index 4392c55..1527261 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextureGenerator.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextureGenerator.java
@@ -1,52 +1,30 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Android code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2009-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * James Willcox <jwillcox at mozilla.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+ * 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.opengl.GLES10;
-import java.util.Stack;
+import android.opengl.GLES20;
+import android.util.Log;
+
+import java.util.concurrent.ArrayBlockingQueue;
+
+import javax.microedition.khronos.egl.EGL10;
+import javax.microedition.khronos.egl.EGLContext;
public class TextureGenerator {
- private static final int MIN_TEXTURES = 5;
+ private static final String LOGTAG = "TextureGenerator";
+ private static final int POOL_SIZE = 5;
private static TextureGenerator sSharedInstance;
- private Stack<Integer> mTextureIds;
- private TextureGenerator() { mTextureIds = new Stack<Integer>(); }
+ private ArrayBlockingQueue<Integer> mTextureIds;
+ private EGLContext mContext;
+
+ private TextureGenerator() {
+ mTextureIds = new ArrayBlockingQueue<Integer>(POOL_SIZE);
+ }
public static TextureGenerator get() {
if (sSharedInstance == null)
@@ -55,19 +33,45 @@ public class TextureGenerator {
}
public synchronized int take() {
- if (mTextureIds.empty())
+ try {
+ // Will block until one becomes available
+ return (int) mTextureIds.take();
+ } catch (InterruptedException e) {
return 0;
-
- return (int)mTextureIds.pop();
+ }
}
public synchronized void fill() {
- int[] textures = new int[1];
- while (mTextureIds.size() < MIN_TEXTURES) {
- GLES10.glGenTextures(1, textures, 0);
- mTextureIds.push(textures[0]);
+ EGL10 egl = (EGL10) EGLContext.getEGL();
+ EGLContext context = egl.eglGetCurrentContext();
+
+ if (mContext != null && mContext != context) {
+ mTextureIds.clear();
}
- }
-}
+ mContext = context;
+ int numNeeded = mTextureIds.remainingCapacity();
+ if (numNeeded == 0)
+ return;
+
+ // Clear existing GL errors
+ int error;
+ while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
+ Log.w(LOGTAG, String.format("Clearing GL error: %#x", error));
+ }
+
+ int[] textures = new int[numNeeded];
+ GLES20.glGenTextures(numNeeded, textures, 0);
+
+ error = GLES20.glGetError();
+ if (error != GLES20.GL_NO_ERROR) {
+ Log.e(LOGTAG, String.format("Failed to generate textures: %#x", error), new Exception());
+ return;
+ }
+
+ for (int i = 0; i < numNeeded; i++) {
+ mTextureIds.offer(textures[i]);
+ }
+ }
+}
diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextureReaper.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextureReaper.java
index e18139c..3063e5b 100644
--- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextureReaper.java
+++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextureReaper.java
@@ -1,52 +1,24 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla Android code.
- *
- * The Initial Developer of the Original Code is Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2009-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Patrick Walton <pcwalton at mozilla.com>
- * Arkady Blyakher <rkadyb at mit.edu>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+ * 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.opengl.GLES20;
+
import java.util.ArrayList;
-/** Manages a list of dead tiles, so we don't leak resources. */
+/**
+ * Manages a list of dead tiles, so we don't leak resources.
+ */
public class TextureReaper {
private static TextureReaper sSharedInstance;
private ArrayList<Integer> mDeadTextureIDs;
- private TextureReaper() { mDeadTextureIDs = new ArrayList<Integer>(); }
+ private TextureReaper() {
+ mDeadTextureIDs = new ArrayList<Integer>();
+ }
public static TextureReaper get() {
if (sSharedInstance == null)
@@ -64,13 +36,18 @@ public class TextureReaper {
}
public void reap() {
- int[] deadTextureIDs = new int[mDeadTextureIDs.size()];
- for (int i = 0; i < deadTextureIDs.length; i++)
+ int numTextures = mDeadTextureIDs.size();
+ // Adreno 200 will generate INVALID_VALUE if len == 0 is passed to glDeleteTextures,
+ // even though it's not supposed to.
+ if (numTextures == 0)
+ return;
+
+ int[] deadTextureIDs = new int[numTextures];
+ for (int i = 0; i < numTextures; i++) {
deadTextureIDs[i] = mDeadTextureIDs.get(i);
+ }
mDeadTextureIDs.clear();
GLES20.glDeleteTextures(deadTextureIDs.length, deadTextureIDs, 0);
}
-}
-
-
+}
\ No newline at end of file
More information about the Libreoffice-commits
mailing list