diff --git a/mobile/android/base/Makefile.in b/mobile/android/base/Makefile.in index 44445ebe0fd4..87dc508f3f56 100644 --- a/mobile/android/base/Makefile.in +++ b/mobile/android/base/Makefile.in @@ -101,7 +101,6 @@ FENNEC_JAVA_FILES = \ gfx/CairoGLInfo.java \ gfx/CairoImage.java \ gfx/CairoUtils.java \ - gfx/CheckerboardImage.java \ gfx/FloatSize.java \ gfx/GeckoSoftwareLayerClient.java \ gfx/InputConnectionHandler.java \ @@ -511,6 +510,7 @@ MOZ_ANDROID_DRAWABLES += \ mobile/android/base/resources/drawable/tabs_tray_close_button.xml \ mobile/android/base/resources/drawable/tabs_tray_list_divider.xml \ mobile/android/base/resources/drawable/tabs_tray_list_selector.xml \ + mobile/android/base/resources/drawable/checkerboard.png \ mobile/android/base/resources/drawable/shadow.png \ $(NULL) diff --git a/mobile/android/base/gfx/CheckerboardImage.java b/mobile/android/base/gfx/CheckerboardImage.java deleted file mode 100644 index 101c9146d7d9..000000000000 --- a/mobile/android/base/gfx/CheckerboardImage.java +++ /dev/null @@ -1,150 +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) 2012 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Patrick Walton - * - * 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 org.mozilla.gecko.GeckoAppShell; -import android.graphics.Color; -import java.nio.ByteBuffer; -import java.nio.ShortBuffer; -import java.util.Arrays; - -/** A Cairo image that displays a tinted checkerboard. */ -public class CheckerboardImage extends CairoImage { - // The width and height of the checkerboard tile. - private static final int SIZE = 16; - // The pixel format of the checkerboard tile. - private static final int FORMAT = CairoImage.FORMAT_RGB16_565; - // The color to mix in to tint the background color. - private static final int TINT_COLOR = Color.GRAY; - // The amount to mix in. - private static final float TINT_OPACITY = 0.4f; - - private ByteBuffer mBuffer; - private int mMainColor; - - /** Creates a new checkerboard image. */ - public CheckerboardImage() { - int bpp = CairoUtils.bitsPerPixelForCairoFormat(FORMAT); - mBuffer = GeckoAppShell.allocateDirectBuffer(SIZE * SIZE * bpp / 8); - setColor(Color.WHITE); - } - - /** Returns the current color of the checkerboard. */ - public int getColor() { - return mMainColor; - } - - /** Sets the color of the checkerboard image and regenerates it. */ - public void setColor(int color) { - if (mMainColor == color) { - return; - } - - mMainColor = color; - int tintColor = tint(mMainColor); - short mainColor16 = convertTo16Bit(mMainColor), tintColor16 = convertTo16Bit(tintColor); - - short[] mainPattern = new short[SIZE / 2], tintPattern = new short[SIZE / 2]; - Arrays.fill(mainPattern, mainColor16); - Arrays.fill(tintPattern, tintColor16); - - // The checkerboard pattern looks like this: - // - // +---+---+ - // | N | T | N = normal - // +---+---+ T = tinted - // | T | N | - // +---+---+ - - mBuffer.rewind(); - ShortBuffer shortBuffer = mBuffer.asShortBuffer(); - for (int i = 0; i < SIZE / 2; i++) { - shortBuffer.put(mainPattern); - shortBuffer.put(tintPattern); - } - for (int i = SIZE / 2; i < SIZE; i++) { - shortBuffer.put(tintPattern); - shortBuffer.put(mainPattern); - } - } - - // Tints the given color appropriately and returns the tinted color. - private int tint(int color) { - float negTintOpacity = 1.0f - TINT_OPACITY; - float r = Color.red(color) * negTintOpacity + Color.red(TINT_COLOR) * TINT_OPACITY; - float g = Color.green(color) * negTintOpacity + Color.green(TINT_COLOR) * TINT_OPACITY; - float b = Color.blue(color) * negTintOpacity + Color.blue(TINT_COLOR) * TINT_OPACITY; - return Color.rgb(Math.round(r), Math.round(g), Math.round(b)); - } - - // Converts a 32-bit ARGB color to 16-bit R5G6B5, truncating values and discarding the alpha - // channel. - 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)); - } - - @Override - protected void finalize() throws Throwable { - try { - if (mBuffer != null) { - GeckoAppShell.freeDirectBuffer(mBuffer); - } - } finally { - super.finalize(); - } - } - - @Override - public ByteBuffer getBuffer() { - return mBuffer; - } - - @Override - public IntSize getSize() { - return new IntSize(SIZE, SIZE); - } - - @Override - public int getFormat() { - return FORMAT; - } -} - diff --git a/mobile/android/base/gfx/GeckoSoftwareLayerClient.java b/mobile/android/base/gfx/GeckoSoftwareLayerClient.java index abcc7321a34b..eb82d649c5ce 100644 --- a/mobile/android/base/gfx/GeckoSoftwareLayerClient.java +++ b/mobile/android/base/gfx/GeckoSoftwareLayerClient.java @@ -54,7 +54,6 @@ import org.mozilla.gecko.GeckoEventListener; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; @@ -64,8 +63,6 @@ import android.util.Log; import org.json.JSONException; import org.json.JSONObject; import java.nio.ByteBuffer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * Transfers a software-rendered Gecko to an ImageLayer so that it can be rendered by our @@ -105,8 +102,6 @@ public class GeckoSoftwareLayerClient extends LayerClient implements GeckoEventL // inside a transaction, so no synchronization is needed. private boolean mUpdateViewportOnEndDraw; - private static Pattern sColorPattern; - public GeckoSoftwareLayerClient(Context context) { mContext = context; @@ -232,9 +227,6 @@ public class GeckoSoftwareLayerClient extends LayerClient implements GeckoEventL mTileLayer.setOrigin(PointUtils.round(displayportOrigin)); mTileLayer.setResolution(mGeckoViewport.getZoomFactor()); - int backgroundColor = parseColorFromGecko(viewportObject.getString("backgroundColor")); - controller.setCheckerboardColor(backgroundColor); - if (onlyUpdatePageSize) { // Don't adjust page size when zooming unless zoom levels are // approximately equal. @@ -462,23 +454,5 @@ public class GeckoSoftwareLayerClient extends LayerClient implements GeckoEventL mUpdateViewportOnEndDraw = true; } } - - // Parses a color from an RGB triple of the form "rgb([0-9]+, [0-9]+, [0-9]+)". If the color - // cannot be parsed, returns white. - private static int parseColorFromGecko(String string) { - if (sColorPattern == null) { - sColorPattern = Pattern.compile("rgb\\((\\d+),\\s*(\\d+),\\s*(\\d+)\\)"); - } - - Matcher matcher = sColorPattern.matcher(string); - if (!matcher.matches()) { - return Color.WHITE; - } - - int r = Integer.parseInt(matcher.group(1)); - int g = Integer.parseInt(matcher.group(2)); - int b = Integer.parseInt(matcher.group(3)); - return Color.rgb(r, g, b); - } } diff --git a/mobile/android/base/gfx/LayerController.java b/mobile/android/base/gfx/LayerController.java index cc6d9d002214..ad6f5270f83c 100644 --- a/mobile/android/base/gfx/LayerController.java +++ b/mobile/android/base/gfx/LayerController.java @@ -81,11 +81,8 @@ public class LayerController { * updates our visible rect appropriately. */ - private OnTouchListener mOnTouchListener; /* The touch listener. */ - private LayerClient mLayerClient; /* The layer client. */ - - /* The new color for the checkerboard. */ - private int mCheckerboardColor; + private OnTouchListener mOnTouchListener; /* The touch listener. */ + private LayerClient mLayerClient; /* The layer client. */ private boolean mForceRedraw; @@ -147,6 +144,7 @@ public class LayerController { } public Bitmap getBackgroundPattern() { return getDrawable("background"); } + public Bitmap getCheckerboardPattern() { return getDrawable("checkerboard"); } public Bitmap getShadowPattern() { return getDrawable("shadow"); } public GestureDetector.OnGestureListener getGestureListener() { return mPanZoomController; } @@ -353,16 +351,5 @@ public class LayerController { return mOnTouchListener.onTouch(mView, event); return false; } - - /** Retrieves the color that the checkerboard should be. */ - public int getCheckerboardColor() { - return mCheckerboardColor; - } - - /** Sets a new color for the checkerboard. */ - public void setCheckerboardColor(int newColor) { - mCheckerboardColor = newColor; - mView.requestRender(); - } } diff --git a/mobile/android/base/gfx/LayerRenderer.java b/mobile/android/base/gfx/LayerRenderer.java index cd620a31c83c..fe9cdb92b0ec 100644 --- a/mobile/android/base/gfx/LayerRenderer.java +++ b/mobile/android/base/gfx/LayerRenderer.java @@ -80,7 +80,6 @@ public class LayerRenderer implements GLSurfaceView.Renderer { private final LayerView mView; private final SingleTileLayer mBackgroundLayer; - private final CheckerboardImage mCheckerboardImage; private final SingleTileLayer mCheckerboardLayer; private final NinePatchTileLayer mShadowLayer; private final TextLayer mFrameRateLayer; @@ -103,8 +102,8 @@ public class LayerRenderer implements GLSurfaceView.Renderer { CairoImage backgroundImage = new BufferedCairoImage(controller.getBackgroundPattern()); mBackgroundLayer = new SingleTileLayer(true, backgroundImage); - mCheckerboardImage = new CheckerboardImage(); - mCheckerboardLayer = new SingleTileLayer(true, mCheckerboardImage); + CairoImage checkerboardImage = new BufferedCairoImage(controller.getCheckerboardPattern()); + mCheckerboardLayer = new SingleTileLayer(true, checkerboardImage); CairoImage shadowImage = new BufferedCairoImage(controller.getShadowPattern()); mShadowLayer = new NinePatchTileLayer(shadowImage); @@ -172,7 +171,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer { if (rootLayer != null) updated &= rootLayer.update(gl, pageContext); updated &= mBackgroundLayer.update(gl, screenContext); updated &= mShadowLayer.update(gl, pageContext); - updateCheckerboardLayer(gl, screenContext); + updated &= mCheckerboardLayer.update(gl, screenContext); updated &= mFrameRateLayer.update(gl, screenContext); updated &= mVertScrollLayer.update(gl, pageContext); updated &= mHorizScrollLayer.update(gl, pageContext); @@ -335,23 +334,6 @@ public class LayerRenderer implements GLSurfaceView.Renderer { }).start(); } - private void updateCheckerboardLayer(GL10 gl, RenderContext renderContext) { - int newCheckerboardColor = mView.getController().getCheckerboardColor(); - if (newCheckerboardColor == mCheckerboardImage.getColor()) { - return; - } - - mCheckerboardLayer.beginTransaction(); - try { - mCheckerboardImage.setColor(newCheckerboardColor); - mCheckerboardLayer.invalidate(); - } finally { - mCheckerboardLayer.endTransaction(); - } - - mCheckerboardLayer.update(gl, renderContext); - } - class FadeRunnable implements Runnable { private boolean mStarted; private long mRunAt; diff --git a/mobile/android/base/resources/drawable/checkerboard.png b/mobile/android/base/resources/drawable/checkerboard.png new file mode 100644 index 000000000000..57cfbe80fdcf Binary files /dev/null and b/mobile/android/base/resources/drawable/checkerboard.png differ diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 7b6b76ad54b0..e915df9052c6 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -802,18 +802,7 @@ var BrowserApp = { }, getDrawMetadata: function getDrawMetadata() { - let viewport = this.selectedTab.viewport; - - // Sample the background color of the page and pass it along. (This is used to draw the - // checkerboard.) - let browser = this.selectedBrowser; - if (browser) { - let { contentDocument, contentWindow } = browser; - let computedStyle = contentWindow.getComputedStyle(contentDocument.body); - viewport.backgroundColor = computedStyle.backgroundColor; - } - - return JSON.stringify(viewport); + return JSON.stringify(this.selectedTab.viewport); }, observe: function(aSubject, aTopic, aData) {