diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-07-04 19:31:54 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-07-04 19:58:17 +0200 |
commit | ff6aac4167dc72c6546ebfa43f9ede81247c1741 (patch) | |
tree | 0f2f45e039a3d9578f9d2b455f208b4c4a8d924d /android | |
parent | 81df594b4fbb147d3e4b3cb31ae27ff7f66d83b4 (diff) |
LOAndroid3: Simplify begin/endDrawing calls, remove JSON metadata
Change-Id: Ie8aadd20095eeea05110032ac026a6027771aab8
Diffstat (limited to 'android')
7 files changed, 24 insertions, 109 deletions
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java index 9d0dec73c086..e4f6b08977c8 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java @@ -18,7 +18,7 @@ public class LOKitShell { public static int getDpi() { DisplayMetrics metrics = LibreOfficeMainActivity.mAppContext.getResources().getDisplayMetrics(); - return (int) metrics.density * 200; + return (int) metrics.density * 160; } public static ByteBuffer allocateDirectBuffer(int size) { diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java index 7539d718b9b8..63bc72b34297 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java @@ -8,6 +8,7 @@ import android.graphics.Rect; import android.util.JsonWriter; import android.util.Log; +import org.mozilla.gecko.gfx.FloatSize; import org.mozilla.gecko.gfx.SubTile; import org.mozilla.gecko.gfx.ViewportMetrics; @@ -18,8 +19,10 @@ import java.util.Random; import java.util.concurrent.ConcurrentLinkedQueue; public class LOKitThread extends Thread { - private static final String LOGTAG = "GeckoThread"; + private static final String LOGTAG = LOKitThread.class.getSimpleName(); + private static final int TILE_SIZE = 256; + private LibreOfficeMainActivity mApplication; private TileProvider mTileProvider; public ConcurrentLinkedQueue<LOEvent> gEvents = new ConcurrentLinkedQueue<LOEvent>(); @@ -29,90 +32,34 @@ public class LOKitThread extends Thread { } private boolean draw() throws InterruptedException { - final LibreOfficeMainActivity application = LibreOfficeMainActivity.mAppContext; - - if (mTileProvider == null) - mTileProvider = new LOKitTileProvider(application.getLayerController()); - int pageWidth = mTileProvider.getPageWidth(); int pageHeight = mTileProvider.getPageHeight(); - String metadata = createJson(0, 0, pageWidth, pageHeight, pageWidth, pageHeight, 0, 0, 1.0); mViewportMetrics = new ViewportMetrics(); + mViewportMetrics.setPageSize(new FloatSize(pageWidth, pageHeight)); - boolean shouldContinue = application.getLayerClient().beginDrawing(pageWidth, pageHeight, TILE_SIZE, TILE_SIZE, metadata); + boolean shouldContinue = mApplication.getLayerClient().beginDrawing(mViewportMetrics); if (!shouldContinue) { return false; } - Log.i(LOGTAG, "Filling tiles.."); - for (SubTile tile : mTileProvider.getTileIterator()) { - application.getLayerClient().addTile(tile); + mApplication.getLayerClient().addTile(tile); } - Log.i(LOGTAG, "End Draw"); - - application.getLayerClient().endDrawing(0, 0, pageWidth, pageHeight); + mApplication.getLayerClient().endDrawing(); return true; } - private String createJson(ViewportMetrics viewportMetrics) { - return createJson( - (int) viewportMetrics.getOrigin().x, - (int) viewportMetrics.getOrigin().y, - (int) viewportMetrics.getSize().width, - (int) viewportMetrics.getSize().height, - (int) viewportMetrics.getPageSize().width, - (int) viewportMetrics.getPageSize().height, - (int) viewportMetrics.getViewportOffset().x, - (int) viewportMetrics.getViewportOffset().y, - viewportMetrics.getZoomFactor()); - } - - private String createJson(int x, int y, int width, int height, int pageWidth, int pageHeight, int offsetX, int offsetY, double zoom) { - try { - StringWriter stringWriter = new StringWriter(); - JsonWriter writer = new JsonWriter(stringWriter); - writer.beginObject(); - writer.name("x").value(x); - writer.name("y").value(y); - writer.name("width").value(width); - writer.name("height").value(height); - writer.name("pageWidth").value(pageWidth); - writer.name("pageHeight").value(pageHeight); - writer.name("offsetX").value(offsetX); - writer.name("offsetY").value(offsetY); - writer.name("zoom").value(zoom); - writer.name("backgroundColor").value("rgb(255,255,255)"); - writer.endObject(); - writer.close(); - return stringWriter.toString(); - } catch (IOException ex) { - } - return null; - } - - private short convertTo16Bit(int color) { - int r = Color.red(color) >> 3, g = Color.green(color) >> 2, b = Color.blue(color) >> 3; - int c = ((r << 11) | (g << 5) | b); - // Swap endianness. - return (short) ((c >> 8) | ((c & 0xff) << 8)); + private void initialize() { + mApplication = LibreOfficeMainActivity.mAppContext; + mTileProvider = new LOKitTileProvider(mApplication.getLayerController()); } - private Bitmap convert(Bitmap bitmap, Bitmap.Config config) { - Bitmap convertedBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), config); - Canvas canvas = new Canvas(convertedBitmap); - Paint paint = new Paint(); - paint.setColor(Color.BLACK); - canvas.drawBitmap(bitmap, 0, 0, paint); - return convertedBitmap; - } - - public void run() { + initialize(); try { boolean drawn = false; while (true) { diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java index e43e40165efa..32bfe302562c 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java @@ -88,8 +88,8 @@ public class LOKitTileProvider implements TileProvider { 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))); - + 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); 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 c196cf8e9feb..d7fe6b3db5a9 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 @@ -89,7 +89,7 @@ public abstract class GeckoLayerClient implements GeckoEventListener { protected abstract boolean setupLayer(); - protected abstract void updateLayerAfterDraw(Rect updatedRect); + protected abstract void updateLayerAfterDraw(); protected abstract IntSize getBufferSize(); @@ -109,38 +109,23 @@ public abstract class GeckoLayerClient implements GeckoEventListener { sendResizeEventIfNecessary(); } - public boolean beginDrawing(int width, int height, int tileWidth, int tileHeight, String metadata) { - Log.e(LOGTAG, "### beginDrawing " + width + " " + height + " " + tileWidth + " " + tileHeight); - + public boolean beginDrawing(ViewportMetrics viewportMetrics) { if (setupLayer()) { Log.e(LOGTAG, "### Cancelling due to layer setup"); return false; } - - try { - JSONObject viewportObject = new JSONObject(metadata); - mNewGeckoViewport = new ViewportMetrics(viewportObject); - Log.e(LOGTAG, "### beginDrawing new Gecko viewport " + mNewGeckoViewport); - } catch (JSONException e) { - Log.e(LOGTAG, "Aborting draw, bad viewport description: " + metadata); - return false; - } - + mNewGeckoViewport = viewportMetrics; mTileLayer.beginTransaction(); + return true; } - /* - * TODO: Would be cleaner if this took an android.graphics.Rect instead, but that would require - * a little more JNI magic. - */ - public void endDrawing(int x, int y, int width, int height) { + public void endDrawing() { synchronized (mLayerController) { try { updateViewport(!mUpdateViewportOnEndDraw); mUpdateViewportOnEndDraw = false; - Rect rect = new Rect(x, y, x + width, y + height); - updateLayerAfterDraw(rect); + updateLayerAfterDraw(); } finally { mTileLayer.endTransaction(); } 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 58e62632cd52..e09e72788125 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 @@ -105,25 +105,9 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient { } @Override - public boolean beginDrawing(int width, int height, int tileWidth, int tileHeight, String metadata) { - boolean shouldContinue = super.beginDrawing(width, height, tileWidth, tileHeight, metadata); - - if (!shouldContinue) { - return shouldContinue; - } - - // If the window size has changed, reallocate the buffer to match. - if (mBufferSize.width != width || mBufferSize.height != height) { - mBufferSize = new IntSize(width, height); - } - - return shouldContinue; - } - - @Override - protected void updateLayerAfterDraw(Rect updatedRect) { + protected void updateLayerAfterDraw() { if (mTileLayer instanceof MultiTileLayer) { - ((MultiTileLayer)mTileLayer).invalidate(updatedRect); + ((MultiTileLayer)mTileLayer).invalidate(); } } diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/Layer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/Layer.java index 40786532a303..b70c88e12768 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/Layer.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/Layer.java @@ -195,6 +195,7 @@ public abstract class Layer { * update is complete. */ protected boolean performUpdates(RenderContext context) { + if (mNewOrigin != null) { mOrigin = mNewOrigin; mNewOrigin = null; 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 56ff5ec9c01e..65f4e79e5490 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 @@ -53,8 +53,6 @@ import java.util.ArrayList; /** * Encapsulates the logic needed to draw a layer made of multiple tiles. - * <p/> - * TODO: Support repeating. */ public class MultiTileLayer extends Layer { private static final String LOGTAG = "GeckoMultiTileLayer"; |