diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-06-29 22:12:06 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-07-01 09:12:01 +0200 |
commit | 7164161de92340809155e1ec4b218d101b7f2d9c (patch) | |
tree | c45ee9115e172e193e78bcfe2d34439fef430a7e /android | |
parent | 2820ecb7184f04f6e29b178a7d857888828d5e04 (diff) |
LODroid: remove hasDirectTexture for now
Change-Id: Iaf4ce2df890c0f61c9466a8ea1ec35731d3eed44
Diffstat (limited to 'android')
5 files changed, 40 insertions, 356 deletions
diff --git a/android/experimental/LOAndroid2/app/src/main/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid2/app/src/main/java/org/libreoffice/LOKitThread.java index 4027d61c34b4..6274e4bf6c29 100644 --- a/android/experimental/LOAndroid2/app/src/main/java/org/libreoffice/LOKitThread.java +++ b/android/experimental/LOAndroid2/app/src/main/java/org/libreoffice/LOKitThread.java @@ -39,7 +39,7 @@ public class LOKitThread extends Thread { 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) return false; diff --git a/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/BufferedCairoImage.java b/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/BufferedCairoImage.java index b6c397767619..2ffe11329f85 100644 --- a/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/BufferedCairoImage.java +++ b/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/BufferedCairoImage.java @@ -71,7 +71,7 @@ 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 = /*GeckoAppShell*/LOKitShell.allocateDirectBuffer(mSize.getArea() * 4); + mBuffer = LOKitShell.allocateDirectBuffer(mSize.getArea() * 4); bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer()); } @@ -79,7 +79,7 @@ public class BufferedCairoImage extends CairoImage { protected void finalize() throws Throwable { try { if (mNeedToFreeBuffer && mBuffer != null) - /*GeckoAppShell*/ LOKitShell.freeDirectBuffer(mBuffer); + LOKitShell.freeDirectBuffer(mBuffer); mNeedToFreeBuffer = false; mBuffer = null; } finally { diff --git a/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/GeckoGLLayerClient.java b/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/GeckoGLLayerClient.java deleted file mode 100644 index 9e4f376e7ad2..000000000000 --- a/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/GeckoGLLayerClient.java +++ /dev/null @@ -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(); - } -} - diff --git a/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/GeckoLayerClient.java b/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/GeckoLayerClient.java index 7c7579e96976..a491f070db3c 100644 --- a/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/GeckoLayerClient.java +++ b/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/GeckoLayerClient.java @@ -38,17 +38,6 @@ 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.graphics.Bitmap; import android.graphics.Color; @@ -59,13 +48,26 @@ 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; +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; +//import org.mozilla.gecko.GeckoApp; +//import org.mozilla.gecko.GeckoAppShell; +//import org.mozilla.gecko.GeckoEvent; + public abstract class GeckoLayerClient extends LayerClient implements GeckoEventListener { 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_GL = 2; + private static final String LOGTAG = "GeckoLayerClient"; private static final long MIN_VIEWPORT_CHANGE_DELAY = 25L; private static Pattern sColorPattern; @@ -79,6 +81,7 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent 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 @@ -112,7 +115,7 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent return Color.rgb(r, g, b); } - protected abstract boolean handleDirectTextureChange(boolean hasDirectTexture); + protected abstract boolean setupLayer(); protected abstract boolean shouldDrawProceed(int tileWidth, int tileHeight); @@ -140,19 +143,15 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent layerController.setViewportMetrics(mGeckoViewport); } - //GeckoAppShell.registerGeckoEventListener("Viewport:UpdateAndDraw", this); - //GeckoAppShell.registerGeckoEventListener("Viewport:UpdateLater", this); - 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 (handleDirectTextureChange(hasDirectTexture)) { - Log.e(LOGTAG, "### Cancelling draw due to direct texture change"); + if (setupLayer()) { + Log.e(LOGTAG, "### Cancelling due to layer setup"); return null; } @@ -180,7 +179,6 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent return null; } - // 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. Rect bufferRect = new Rect(0, 0, width, height); @@ -263,15 +261,14 @@ public abstract class GeckoLayerClient extends LayerClient implements GeckoEvent mTileLayer.setResolution(mGeckoViewport.getZoomFactor()); this.tileLayerUpdated(); - Log.e(LOGTAG, "### updateViewport onlyUpdatePageSize=" + onlyUpdatePageSize + - " getTileViewport " + mGeckoViewport); + Log.e(LOGTAG, "### updateViewport onlyUpdatePageSize=" + onlyUpdatePageSize + " getTileViewport " + mGeckoViewport); if (onlyUpdatePageSize) { // Don't adjust page size when zooming unless zoom levels are // approximately equal. - if (FloatUtils.fuzzyEquals(controller.getZoomFactor(), - mGeckoViewport.getZoomFactor())) + if (FloatUtils.fuzzyEquals(controller.getZoomFactor(), mGeckoViewport.getZoomFactor())) { controller.setPageSize(mGeckoViewport.getPageSize()); + } } else { controller.setViewportMetrics(mGeckoViewport); controller.abortPanZoomAnimation(); diff --git a/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java b/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java index 07b68ce090f4..ee99d16f778c 100644 --- a/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java +++ b/android/experimental/LOAndroid2/app/src/main/java/org/mozilla/gecko/gfx/GeckoSoftwareLayerClient.java @@ -74,9 +74,6 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient { 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) { super(context); @@ -110,28 +107,16 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient { 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); } @Override - protected boolean handleDirectTextureChange(boolean hasDirectTexture) { - if (mTileLayer != null && hasDirectTexture == mHasDirectTexture) + protected boolean setupLayer() { + if (mTileLayer != null) return false; - mHasDirectTexture = hasDirectTexture; - - if (mHasDirectTexture) { - Log.i(LOGTAG, "Creating WidgetTileLayer"); - mTileLayer = new WidgetTileLayer(mCairoImage); - } else { - Log.i(LOGTAG, "Creating MultiTileLayer"); - mTileLayer = new MultiTileLayer(mCairoImage, TILE_SIZE); - } + Log.i(LOGTAG, "Creating MultiTileLayer"); + mTileLayer = new MultiTileLayer(mCairoImage, TILE_SIZE); getLayerController().setRoot(mTileLayer); @@ -146,26 +131,16 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient { protected boolean shouldDrawProceed(int tileWidth, int tileHeight) { // Make sure the tile-size matches. If it doesn't, we could crash trying // 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) { - Log.e(LOGTAG, "Aborting draw, incorrect tile size of " + tileWidth + "x" + - tileHeight); - return false; - } + if (tileWidth != TILE_SIZE.width || tileHeight != TILE_SIZE.height) { + Log.e(LOGTAG, "Aborting draw, incorrect tile size of " + tileWidth + "x" + tileHeight); + return false; } - return true; } @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); + public Rect beginDrawing(int width, int height, int tileWidth, int tileHeight, String metadata) { + Rect bufferRect = super.beginDrawing(width, height, tileWidth, tileHeight, metadata); if (bufferRect == null) { return bufferRect; @@ -196,11 +171,9 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient { @Override protected void updateLayerAfterDraw(Rect updatedRect) { - if (!(mTileLayer instanceof MultiTileLayer)) { - return; + if (mTileLayer instanceof MultiTileLayer) { + ((MultiTileLayer)mTileLayer).invalidate(updatedRect); } - - ((MultiTileLayer)mTileLayer).invalidate(updatedRect); } private void copyPixelsFromMultiTileLayer(Bitmap target) { @@ -287,35 +260,14 @@ public class GeckoSoftwareLayerClient extends GeckoLayerClient { @Override protected IntSize getBufferSize() { - // Round up depending on layer implementation to remove texture wastage - if (!mHasDirectTexture) { - // Round to the next multiple of the tile size - 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))); + 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() { - // Round up depending on layer implementation to remove texture wastage - return !mHasDirectTexture ? TILE_SIZE : new IntSize(0, 0); + return TILE_SIZE; } } |