LODroid: remove hasDirectTexture for now

Change-Id: Iaf4ce2df890c0f61c9466a8ea1ec35731d3eed44
This commit is contained in:
Tomaž Vajngerl 2014-06-29 22:12:06 +02:00
parent 2820ecb718
commit 7164161de9
5 changed files with 40 additions and 356 deletions

View File

@ -39,7 +39,7 @@ public class LOKitThread extends Thread {
metadata = createJson(mViewportMetrics); metadata = createJson(mViewportMetrics);
} }
Rect bufferRect = application.getLayerClient().beginDrawing(originalBitmap.getWidth(), originalBitmap.getHeight(), 256, 256, metadata, false); Rect bufferRect = application.getLayerClient().beginDrawing(originalBitmap.getWidth(), originalBitmap.getHeight(), 256, 256, metadata);
if (bufferRect == null) if (bufferRect == null)
return false; return false;

View File

@ -71,7 +71,7 @@ public class BufferedCairoImage extends CairoImage {
mSize = new IntSize(bitmap.getWidth(), bitmap.getHeight()); mSize = new IntSize(bitmap.getWidth(), bitmap.getHeight());
mNeedToFreeBuffer = true; mNeedToFreeBuffer = true;
// XXX Why is this * 4? Shouldn't it depend on mFormat? // XXX Why is this * 4? Shouldn't it depend on mFormat?
mBuffer = /*GeckoAppShell*/LOKitShell.allocateDirectBuffer(mSize.getArea() * 4); mBuffer = LOKitShell.allocateDirectBuffer(mSize.getArea() * 4);
bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer()); bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
} }
@ -79,7 +79,7 @@ public class BufferedCairoImage extends CairoImage {
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
if (mNeedToFreeBuffer && mBuffer != null) if (mNeedToFreeBuffer && mBuffer != null)
/*GeckoAppShell*/ LOKitShell.freeDirectBuffer(mBuffer); LOKitShell.freeDirectBuffer(mBuffer);
mNeedToFreeBuffer = false; mNeedToFreeBuffer = false;
mBuffer = null; mBuffer = null;
} finally { } finally {

View File

@ -1,265 +0,0 @@
/* -*- 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@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 ***** */
package org.mozilla.gecko.gfx;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.Log;
import android.view.View;
import org.libreoffice.LOEvent;
import org.libreoffice.LOKitShell;
public class GeckoGLLayerClient extends GeckoLayerClient
implements FlexibleGLSurfaceView.Listener, VirtualLayer.Listener {
private static final String LOGTAG = "GeckoGLLayerClient";
private LayerRenderer mLayerRenderer;
private boolean mLayerRendererInitialized;
public GeckoGLLayerClient(Context context) {
super(context);
}
@Override
public Rect beginDrawing(int width, int height, int tileWidth, int tileHeight,
String metadata, boolean hasDirectTexture) {
Rect bufferRect = super.beginDrawing(width, height, tileWidth, tileHeight,
metadata, hasDirectTexture);
if (bufferRect == null) {
return null;
}
// Be sure to adjust the buffer size; if it's not at least as large as the viewport size,
// ViewportMetrics.getOptimumViewportOffset() gets awfully confused and severe display
// corruption results!
if (mBufferSize.width != width || mBufferSize.height != height) {
mBufferSize = new IntSize(width, height);
}
return bufferRect;
}
@Override
protected boolean handleDirectTextureChange(boolean hasDirectTexture) {
Log.e(LOGTAG, "### handleDirectTextureChange");
if (mTileLayer != null) {
return false;
}
Log.e(LOGTAG, "### Creating virtual layer");
VirtualLayer virtualLayer = new VirtualLayer();
virtualLayer.setListener(this);
virtualLayer.setSize(getBufferSize());
getLayerController().setRoot(virtualLayer);
mTileLayer = virtualLayer;
sendResizeEventIfNecessary(true);
return true;
}
@Override
public void setLayerController(LayerController layerController) {
super.setLayerController(layerController);
LayerView view = layerController.getView();
view.setListener(this);
mLayerRenderer = new LayerRenderer(view);
}
@Override
protected boolean shouldDrawProceed(int tileWidth, int tileHeight) {
Log.e(LOGTAG, "### shouldDrawProceed");
// Always draw.
return true;
}
@Override
protected void updateLayerAfterDraw(Rect updatedRect) {
Log.e(LOGTAG, "### updateLayerAfterDraw");
// Nothing to do.
}
@Override
protected IntSize getBufferSize() {
View view = (View) getLayerController().getView();
IntSize size = new IntSize(view.getWidth(), view.getHeight());
Log.e(LOGTAG, "### getBufferSize " + size);
return size;
}
@Override
protected IntSize getTileSize() {
Log.e(LOGTAG, "### getTileSize " + getBufferSize());
return getBufferSize();
}
@Override
protected void tileLayerUpdated() {
// Set the new origin and resolution instantly.
mTileLayer.performUpdates(null);
}
@Override
public Bitmap getBitmap() {
Log.e(LOGTAG, "### getBitmap");
IntSize size = getBufferSize();
try {
return Bitmap.createBitmap(size.width, size.height, Bitmap.Config.RGB_565);
} catch (OutOfMemoryError oom) {
Log.e(LOGTAG, "Unable to create bitmap", oom);
return null;
}
}
@Override
public int getType() {
Log.e(LOGTAG, "### getType");
return LAYER_CLIENT_TYPE_GL;
}
public void dimensionsChanged(Point newOrigin, float newResolution) {
Log.e(LOGTAG, "### dimensionsChanged " + newOrigin + " " + newResolution);
}
/* Informs Gecko that the screen size has changed. */
@Override
protected void sendResizeEventIfNecessary(boolean force) {
Log.e(LOGTAG, "### sendResizeEventIfNecessary " + force);
IntSize newSize = getBufferSize();
if (!force && mScreenSize != null && mScreenSize.equals(newSize)) {
return;
}
mScreenSize = newSize;
Log.e(LOGTAG, "### Screen-size changed to " + mScreenSize);
//GeckoEvent event = GeckoEvent.createSizeChangedEvent(mScreenSize.width, mScreenSize.height,
// mScreenSize.width, mScreenSize.height,
// mScreenSize.width, mScreenSize.height);
//GeckoAppShell.sendEventToGecko(event);
LOEvent event = LOEvent.sizeChanged(mScreenSize.width, mScreenSize.height,
mScreenSize.width, mScreenSize.height,
mScreenSize.width, mScreenSize.height);
LOKitShell.sendEvent(event);
}
/**
* For Gecko to use.
*/
public ViewTransform getViewTransform() {
Log.e(LOGTAG, "### getViewTransform()");
// NB: We don't begin a transaction here because this can be called in a synchronous
// manner between beginDrawing() and endDrawing(), and that will cause a deadlock.
LayerController layerController = getLayerController();
synchronized (layerController) {
ViewportMetrics viewportMetrics = layerController.getViewportMetrics();
PointF viewportOrigin = viewportMetrics.getOrigin();
Point tileOrigin = mTileLayer.getOrigin();
float scrollX = viewportOrigin.x;
float scrollY = viewportOrigin.y;
float zoomFactor = viewportMetrics.getZoomFactor();
Log.e(LOGTAG, "### Viewport metrics = " + viewportMetrics + " tile reso = " +
mTileLayer.getResolution());
return new ViewTransform(scrollX, scrollY, zoomFactor);
}
}
public void renderRequested() {
Log.e(LOGTAG, "### Render requested, scheduling composite");
LOKitShell.scheduleComposite();
}
public void compositionPauseRequested() {
Log.e(LOGTAG, "### Scheduling PauseComposition");
LOKitShell.schedulePauseComposition();
}
public void compositionResumeRequested() {
Log.e(LOGTAG, "### Scheduling ResumeComposition");
LOKitShell.scheduleResumeComposition();
}
public void surfaceChanged(int width, int height) {
compositionPauseRequested();
LayerController layerController = getLayerController();
layerController.setViewportSize(new FloatSize(width, height));
compositionResumeRequested();
renderRequested();
}
/**
* For Gecko to use.
*/
public LayerRenderer.Frame createFrame() {
// Create the shaders and textures if necessary.
if (!mLayerRendererInitialized) {
mLayerRenderer.createProgram();
mLayerRendererInitialized = true;
}
// Build the contexts and create the frame.
Layer.RenderContext pageContext = mLayerRenderer.createPageContext();
Layer.RenderContext screenContext = mLayerRenderer.createScreenContext();
return mLayerRenderer.createFrame(pageContext, screenContext);
}
/**
* For Gecko to use.
*/
public void activateProgram() {
mLayerRenderer.activateProgram();
}
/**
* For Gecko to use.
*/
public void deactivateProgram() {
mLayerRenderer.deactivateProgram();
}
}

View File

@ -38,17 +38,6 @@
package org.mozilla.gecko.gfx; package org.mozilla.gecko.gfx;
import org.libreoffice.LOEvent;
import org.libreoffice.LOKitShell;
import org.libreoffice.LibreOfficeMainActivity;
import org.mozilla.gecko.util.FloatUtils;
//import org.mozilla.gecko.GeckoApp;
//import org.mozilla.gecko.GeckoAppShell;
//import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoEventListener;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
@ -59,13 +48,26 @@ import android.os.SystemClock;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import org.json.JSONException;
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.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
//import org.mozilla.gecko.GeckoApp;
//import org.mozilla.gecko.GeckoAppShell;
//import org.mozilla.gecko.GeckoEvent;
public abstract class GeckoLayerClient extends LayerClient implements GeckoEventListener { public abstract class GeckoLayerClient extends LayerClient implements GeckoEventListener {
public static final int LAYER_CLIENT_TYPE_NONE = 0; public static final int LAYER_CLIENT_TYPE_NONE = 0;
public static final int LAYER_CLIENT_TYPE_SOFTWARE = 1; public static final int LAYER_CLIENT_TYPE_SOFTWARE = 1;
public static final int LAYER_CLIENT_TYPE_GL = 2; public static final int LAYER_CLIENT_TYPE_GL = 2;
private static final String LOGTAG = "GeckoLayerClient"; private static final String LOGTAG = "GeckoLayerClient";
private static final long MIN_VIEWPORT_CHANGE_DELAY = 25L; private static final long MIN_VIEWPORT_CHANGE_DELAY = 25L;
private static Pattern sColorPattern; private static Pattern sColorPattern;
@ -79,6 +81,7 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
private long mLastViewportChangeTime; private long mLastViewportChangeTime;
private boolean mPendingViewportAdjust; private boolean mPendingViewportAdjust;
private boolean mViewportSizeChanged; private boolean mViewportSizeChanged;
// mUpdateViewportOnEndDraw is used to indicate that we received a // mUpdateViewportOnEndDraw is used to indicate that we received a
// viewport update notification while drawing. therefore, when the // viewport update notification while drawing. therefore, when the
// draw finishes, we need to update the entire viewport rather than // draw finishes, we need to update the entire viewport rather than
@ -112,7 +115,7 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
return Color.rgb(r, g, b); return Color.rgb(r, g, b);
} }
protected abstract boolean handleDirectTextureChange(boolean hasDirectTexture); protected abstract boolean setupLayer();
protected abstract boolean shouldDrawProceed(int tileWidth, int tileHeight); protected abstract boolean shouldDrawProceed(int tileWidth, int tileHeight);
@ -140,19 +143,15 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
layerController.setViewportMetrics(mGeckoViewport); layerController.setViewportMetrics(mGeckoViewport);
} }
//GeckoAppShell.registerGeckoEventListener("Viewport:UpdateAndDraw", this);
//GeckoAppShell.registerGeckoEventListener("Viewport:UpdateLater", this);
sendResizeEventIfNecessary(); sendResizeEventIfNecessary();
} }
public Rect beginDrawing(int width, int height, int tileWidth, int tileHeight, String metadata, boolean hasDirectTexture) { public Rect beginDrawing(int width, int height, int tileWidth, int tileHeight, String metadata) {
Log.e(LOGTAG, "### beginDrawing " + width + " " + height + " " + tileWidth + " " + tileHeight + " " + hasDirectTexture); Log.e(LOGTAG, "### beginDrawing " + width + " " + height + " " + tileWidth + " " + tileHeight);
// If we've changed surface types, cancel this draw if (setupLayer()) {
if (handleDirectTextureChange(hasDirectTexture)) { Log.e(LOGTAG, "### Cancelling due to layer setup");
Log.e(LOGTAG, "### Cancelling draw due to direct texture change");
return null; return null;
} }
@ -180,7 +179,6 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
return null; return null;
} }
// Make sure we don't spend time painting areas we aren't interested in. // Make sure we don't spend time painting areas we aren't interested in.
// Only do this if the Gecko viewport isn't going to override our viewport. // Only do this if the Gecko viewport isn't going to override our viewport.
Rect bufferRect = new Rect(0, 0, width, height); Rect bufferRect = new Rect(0, 0, width, height);
@ -263,15 +261,14 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent
mTileLayer.setResolution(mGeckoViewport.getZoomFactor()); mTileLayer.setResolution(mGeckoViewport.getZoomFactor());
this.tileLayerUpdated(); this.tileLayerUpdated();
Log.e(LOGTAG, "### updateViewport onlyUpdatePageSize=" + onlyUpdatePageSize + Log.e(LOGTAG, "### updateViewport onlyUpdatePageSize=" + onlyUpdatePageSize + " getTileViewport " + mGeckoViewport);
" getTileViewport " + mGeckoViewport);
if (onlyUpdatePageSize) { if (onlyUpdatePageSize) {
// Don't adjust page size when zooming unless zoom levels are // Don't adjust page size when zooming unless zoom levels are
// approximately equal. // approximately equal.
if (FloatUtils.fuzzyEquals(controller.getZoomFactor(), if (FloatUtils.fuzzyEquals(controller.getZoomFactor(), mGeckoViewport.getZoomFactor())) {
mGeckoViewport.getZoomFactor()))
controller.setPageSize(mGeckoViewport.getPageSize()); controller.setPageSize(mGeckoViewport.getPageSize());
}
} else { } else {
controller.setViewportMetrics(mGeckoViewport); controller.setViewportMetrics(mGeckoViewport);
controller.abortPanZoomAnimation(); controller.abortPanZoomAnimation();

View File

@ -74,9 +74,6 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
private static final IntSize TILE_SIZE = new IntSize(256, 256); private static final IntSize TILE_SIZE = new IntSize(256, 256);
// Whether or not the last paint we got used direct texturing
private boolean mHasDirectTexture;
public GeckoSoftwareLayerClient(Context context) { public GeckoSoftwareLayerClient(Context context) {
super(context); super(context);
@ -110,28 +107,16 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
layerController.setViewportMetrics(mGeckoViewport); layerController.setViewportMetrics(mGeckoViewport);
} }
//GeckoAppShell.registerGeckoEventListener("Viewport:UpdateAndDraw", this);
//GeckoAppShell.registerGeckoEventListener("Viewport:UpdateLater", this);
//GeckoAppShell.registerGeckoEventListener("Checkerboard:Toggle", this);
// XXX: Review pcwalton. This signature changed on m-c, should force = false here?
sendResizeEventIfNecessary(false); sendResizeEventIfNecessary(false);
} }
@Override @Override
protected boolean handleDirectTextureChange(boolean hasDirectTexture) { protected boolean setupLayer() {
if (mTileLayer != null && hasDirectTexture == mHasDirectTexture) if (mTileLayer != null)
return false; return false;
mHasDirectTexture = hasDirectTexture;
if (mHasDirectTexture) {
Log.i(LOGTAG, "Creating WidgetTileLayer");
mTileLayer = new WidgetTileLayer(mCairoImage);
} else {
Log.i(LOGTAG, "Creating MultiTileLayer"); Log.i(LOGTAG, "Creating MultiTileLayer");
mTileLayer = new MultiTileLayer(mCairoImage, TILE_SIZE); mTileLayer = new MultiTileLayer(mCairoImage, TILE_SIZE);
}
getLayerController().setRoot(mTileLayer); getLayerController().setRoot(mTileLayer);
@ -146,26 +131,16 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
protected boolean shouldDrawProceed(int tileWidth, int tileHeight) { protected boolean shouldDrawProceed(int tileWidth, int tileHeight) {
// Make sure the tile-size matches. If it doesn't, we could crash trying // Make sure the tile-size matches. If it doesn't, we could crash trying
// to access invalid memory. // to access invalid memory.
if (mHasDirectTexture) {
if (tileWidth != 0 || tileHeight != 0) {
Log.e(LOGTAG, "Aborting draw, incorrect tile size of " + tileWidth + "x" +
tileHeight);
return false;
}
} else {
if (tileWidth != TILE_SIZE.width || tileHeight != TILE_SIZE.height) { if (tileWidth != TILE_SIZE.width || tileHeight != TILE_SIZE.height) {
Log.e(LOGTAG, "Aborting draw, incorrect tile size of " + tileWidth + "x" + Log.e(LOGTAG, "Aborting draw, incorrect tile size of " + tileWidth + "x" + tileHeight);
tileHeight);
return false; return false;
} }
}
return true; return true;
} }
@Override @Override
public Rect beginDrawing(int width, int height, int tileWidth, int tileHeight, String metadata, boolean hasDirectTexture) { public Rect beginDrawing(int width, int height, int tileWidth, int tileHeight, String metadata) {
Rect bufferRect = super.beginDrawing(width, height, tileWidth, tileHeight, metadata, hasDirectTexture); Rect bufferRect = super.beginDrawing(width, height, tileWidth, tileHeight, metadata);
if (bufferRect == null) { if (bufferRect == null) {
return bufferRect; return bufferRect;
@ -196,12 +171,10 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
@Override @Override
protected void updateLayerAfterDraw(Rect updatedRect) { protected void updateLayerAfterDraw(Rect updatedRect) {
if (!(mTileLayer instanceof MultiTileLayer)) { if (mTileLayer instanceof MultiTileLayer) {
return;
}
((MultiTileLayer)mTileLayer).invalidate(updatedRect); ((MultiTileLayer)mTileLayer).invalidate(updatedRect);
} }
}
private void copyPixelsFromMultiTileLayer(Bitmap target) { private void copyPixelsFromMultiTileLayer(Bitmap target) {
Canvas c = new Canvas(target); Canvas c = new Canvas(target);
@ -287,35 +260,14 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient {
@Override @Override
protected IntSize getBufferSize() { protected IntSize getBufferSize() {
// Round up depending on layer implementation to remove texture wastage return new IntSize(
if (!mHasDirectTexture) { ((mScreenSize.width + LayerController.MIN_BUFFER.width - 1) / TILE_SIZE.width + 1) * TILE_SIZE.width,
// Round to the next multiple of the tile size ((mScreenSize.height + LayerController.MIN_BUFFER.height - 1) / TILE_SIZE.height + 1) * TILE_SIZE.height);
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);
}
int maxSize = getLayerController().getView().getMaxTextureSize();
// XXX Integrate gralloc/tiling work to circumvent this
if (mScreenSize.width > maxSize || mScreenSize.height > maxSize) {
throw new RuntimeException("Screen size of " + mScreenSize +
" larger than maximum texture size of " + maxSize);
}
// Round to next power of two until we have NPOT texture support, respecting maximum
// texture size
return new IntSize(Math.min(maxSize, IntSize.nextPowerOfTwo(mScreenSize.width +
LayerController.MIN_BUFFER.width)),
Math.min(maxSize, IntSize.nextPowerOfTwo(mScreenSize.height +
LayerController.MIN_BUFFER.height)));
} }
@Override @Override
protected IntSize getTileSize() { protected IntSize getTileSize() {
// Round up depending on layer implementation to remove texture wastage return TILE_SIZE;
return !mHasDirectTexture ? TILE_SIZE : new IntSize(0, 0);
} }
} }