LOAndroid3: Simplify begin/endDrawing calls, remove JSON metadata
Change-Id: Ie8aadd20095eeea05110032ac026a6027771aab8
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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 void initialize() {
|
||||
mApplication = LibreOfficeMainActivity.mAppContext;
|
||||
mTileProvider = new LOKitTileProvider(mApplication.getLayerController());
|
||||
}
|
||||
|
||||
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 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) {
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -195,6 +195,7 @@ public abstract class Layer {
|
||||
* update is complete.
|
||||
*/
|
||||
protected boolean performUpdates(RenderContext context) {
|
||||
|
||||
if (mNewOrigin != null) {
|
||||
mOrigin = mNewOrigin;
|
||||
mNewOrigin = null;
|
||||
|
@@ -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";
|
||||
|
Reference in New Issue
Block a user