Bug 740146 - Remove unused screenshot code. r=blassey

This commit is contained in:
Geoff Brown 2012-04-01 15:17:32 -04:00
parent a0a15d0e56
commit 487c80efc5
4 changed files with 8 additions and 210 deletions

View File

@ -47,7 +47,6 @@ import org.mozilla.gecko.gfx.IntSize;
import org.mozilla.gecko.gfx.Layer; import org.mozilla.gecko.gfx.Layer;
import org.mozilla.gecko.gfx.LayerController; import org.mozilla.gecko.gfx.LayerController;
import org.mozilla.gecko.gfx.LayerView; import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.gfx.PlaceholderLayerClient;
import org.mozilla.gecko.gfx.RectUtils; import org.mozilla.gecko.gfx.RectUtils;
import org.mozilla.gecko.gfx.SurfaceTextureLayer; import org.mozilla.gecko.gfx.SurfaceTextureLayer;
import org.mozilla.gecko.gfx.ViewportMetrics; import org.mozilla.gecko.gfx.ViewportMetrics;
@ -112,10 +111,7 @@ abstract public class GeckoApp
public static final String ACTION_LOAD = "org.mozilla.gecko.LOAD"; public static final String ACTION_LOAD = "org.mozilla.gecko.LOAD";
public static final String ACTION_UPDATE = "org.mozilla.gecko.UPDATE"; public static final String ACTION_UPDATE = "org.mozilla.gecko.UPDATE";
public static final String ACTION_INIT_PW = "org.mozilla.gecko.INIT_PW"; public static final String ACTION_INIT_PW = "org.mozilla.gecko.INIT_PW";
public static final String SAVED_STATE_URI = "uri";
public static final String SAVED_STATE_TITLE = "title"; public static final String SAVED_STATE_TITLE = "title";
public static final String SAVED_STATE_VIEWPORT = "viewport";
public static final String SAVED_STATE_SCREEN = "screen";
public static final String SAVED_STATE_SESSION = "session"; public static final String SAVED_STATE_SESSION = "session";
StartupMode mStartupMode = null; StartupMode mStartupMode = null;
@ -142,15 +138,11 @@ abstract public class GeckoApp
public Favicons mFavicons; public Favicons mFavicons;
private static LayerController mLayerController; private static LayerController mLayerController;
private static PlaceholderLayerClient mPlaceholderLayerClient;
private static GeckoLayerClient mLayerClient; private static GeckoLayerClient mLayerClient;
private AboutHomeContent mAboutHomeContent; private AboutHomeContent mAboutHomeContent;
private static AbsoluteLayout mPluginContainer; private static AbsoluteLayout mPluginContainer;
public String mLastTitle; public String mLastTitle;
public String mLastSnapshotUri;
public String mLastViewport;
public byte[] mLastScreen;
private int mOwnActivityDepth = 0; private int mOwnActivityDepth = 0;
private boolean mRestoreSession = false; private boolean mRestoreSession = false;
private boolean mInitialized = false; private boolean mInitialized = false;
@ -546,54 +538,11 @@ abstract public class GeckoApp
if (outState == null) if (outState == null)
outState = new Bundle(); outState = new Bundle();
new SessionSnapshotRunnable(null).run();
outState.putString(SAVED_STATE_TITLE, mLastTitle); outState.putString(SAVED_STATE_TITLE, mLastTitle);
outState.putString(SAVED_STATE_VIEWPORT, mLastViewport);
outState.putByteArray(SAVED_STATE_SCREEN, mLastScreen);
outState.putBoolean(SAVED_STATE_SESSION, true); outState.putBoolean(SAVED_STATE_SESSION, true);
} }
public class SessionSnapshotRunnable implements Runnable { void getAndProcessThumbnailForTab(final Tab tab) {
Tab mThumbnailTab;
SessionSnapshotRunnable(Tab thumbnailTab) {
mThumbnailTab = thumbnailTab;
}
public void run() {
if (mLayerClient == null)
return;
synchronized (mLayerClient) {
if (!Tabs.getInstance().isSelectedTab(mThumbnailTab))
return;
HistoryEntry lastHistoryEntry = mThumbnailTab.getLastHistoryEntry();
if (lastHistoryEntry == null)
return;
ViewportMetrics viewportMetrics = mLayerClient.getGeckoViewportMetrics();
// If we don't have viewport metrics, the screenshot won't be right so bail
if (viewportMetrics == null)
return;
String viewportJSON = viewportMetrics.toJSON();
// If the title, uri and viewport haven't changed, the old screenshot is probably valid
// Ordering of .equals() below is important since mLast* variables may be null
if (viewportJSON.equals(mLastViewport) &&
lastHistoryEntry.mTitle.equals(mLastTitle) &&
lastHistoryEntry.mUri.equals(mLastSnapshotUri))
return;
mLastViewport = viewportJSON;
mLastTitle = lastHistoryEntry.mTitle;
mLastSnapshotUri = lastHistoryEntry.mUri;
getAndProcessThumbnailForTab(mThumbnailTab, true);
}
}
}
void getAndProcessThumbnailForTab(final Tab tab, boolean forceBigSceenshot) {
boolean isSelectedTab = Tabs.getInstance().isSelectedTab(tab); boolean isSelectedTab = Tabs.getInstance().isSelectedTab(tab);
final Bitmap bitmap = isSelectedTab ? mLayerClient.getBitmap() : null; final Bitmap bitmap = isSelectedTab ? mLayerClient.getBitmap() : null;
@ -609,12 +558,10 @@ abstract public class GeckoApp
return; return;
} }
mLastScreen = null; int sw = tab.getMinScreenshotWidth();
View view = mLayerController.getView(); int sh = tab.getMinScreenshotHeight();
int sw = forceBigSceenshot ? view.getWidth() : tab.getMinScreenshotWidth(); int dw = tab.getThumbnailWidth();
int sh = forceBigSceenshot ? view.getHeight(): tab.getMinScreenshotHeight(); int dh = tab.getThumbnailHeight();
int dw = forceBigSceenshot ? sw : tab.getThumbnailWidth();
int dh = forceBigSceenshot ? sh : tab.getThumbnailHeight();
GeckoAppShell.sendEventToGecko(GeckoEvent.createScreenshotEvent(tab.getId(), sw, sh, dw, dh)); GeckoAppShell.sendEventToGecko(GeckoEvent.createScreenshotEvent(tab.getId(), sw, sh, dw, dh));
} }
} }
@ -626,7 +573,6 @@ abstract public class GeckoApp
bitmap.compress(Bitmap.CompressFormat.PNG, 0, bos); bitmap.compress(Bitmap.CompressFormat.PNG, 0, bos);
compressed = bos.toByteArray(); compressed = bos.toByteArray();
} }
mLastScreen = compressed;
} }
if ("about:home".equals(thumbnailTab.getURL())) { if ("about:home".equals(thumbnailTab.getURL())) {
@ -1254,11 +1200,6 @@ abstract public class GeckoApp
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.STOP); Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.STOP);
} }
}); });
if (Tabs.getInstance().isSelectedTab(tab)) {
Runnable r = new SessionSnapshotRunnable(tab);
GeckoAppShell.getHandler().postDelayed(r, 500);
}
} }
void handleShowToast(final String message, final String duration) { void handleShowToast(final String message, final String duration) {
@ -1619,8 +1560,6 @@ abstract public class GeckoApp
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate"); Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate");
if (savedInstanceState != null) { if (savedInstanceState != null) {
mLastTitle = savedInstanceState.getString(SAVED_STATE_TITLE); mLastTitle = savedInstanceState.getString(SAVED_STATE_TITLE);
mLastViewport = savedInstanceState.getString(SAVED_STATE_VIEWPORT);
mLastScreen = savedInstanceState.getByteArray(SAVED_STATE_SCREEN);
mRestoreSession = savedInstanceState.getBoolean(SAVED_STATE_SESSION); mRestoreSession = savedInstanceState.getBoolean(SAVED_STATE_SESSION);
} }
@ -1663,8 +1602,6 @@ abstract public class GeckoApp
if (m.find()) { if (m.find()) {
mProfile = GeckoProfile.get(this, m.group(1)); mProfile = GeckoProfile.get(this, m.group(1));
mLastTitle = null; mLastTitle = null;
mLastViewport = null;
mLastScreen = null;
} }
} }
@ -1748,11 +1685,8 @@ abstract public class GeckoApp
mLayerController = new LayerController(this); mLayerController = new LayerController(this);
View v = mLayerController.getView(); View v = mLayerController.getView();
mPlaceholderLayerClient = new PlaceholderLayerClient(mLayerController, mLastViewport); // Instead of flickering the checkerboard, show a white screen until Gecko paints
if (!mPlaceholderLayerClient.loadScreenshot()) { v.setBackgroundColor(Color.WHITE);
// Instead of flickering the checkerboard, show a white screen until Gecko paints
v.setBackgroundColor(Color.WHITE);
}
mGeckoLayout.addView(v, 0); mGeckoLayout.addView(v, 0);
} }
@ -2041,9 +1975,6 @@ abstract public class GeckoApp
{ {
Log.i(LOGTAG, "pause"); Log.i(LOGTAG, "pause");
Runnable r = new SessionSnapshotRunnable(null);
GeckoAppShell.getHandler().post(r);
GeckoAppShell.sendEventToGecko(GeckoEvent.createPauseEvent(mOwnActivityDepth)); GeckoAppShell.sendEventToGecko(GeckoEvent.createPauseEvent(mOwnActivityDepth));
// The user is navigating away from this activity, but nothing // The user is navigating away from this activity, but nothing
// has come to the foreground yet; for Gecko, we may want to // has come to the foreground yet; for Gecko, we may want to
@ -2823,9 +2754,6 @@ abstract public class GeckoApp
private void connectGeckoLayerClient() { private void connectGeckoLayerClient() {
if (mPlaceholderLayerClient != null)
mPlaceholderLayerClient.destroy();
LayerController layerController = getLayerController(); LayerController layerController = getLayerController();
layerController.setLayerClient(mLayerClient); layerController.setLayerClient(mLayerClient);
} }

View File

@ -135,7 +135,6 @@ FENNEC_JAVA_FILES = \
gfx/LayerView.java \ gfx/LayerView.java \
gfx/NinePatchTileLayer.java \ gfx/NinePatchTileLayer.java \
gfx/PanningPerfAPI.java \ gfx/PanningPerfAPI.java \
gfx/PlaceholderLayerClient.java \
gfx/PointUtils.java \ gfx/PointUtils.java \
gfx/RectUtils.java \ gfx/RectUtils.java \
gfx/ScrollbarLayer.java \ gfx/ScrollbarLayer.java \

View File

@ -310,7 +310,7 @@ public class Tabs implements GeckoEventListener {
final Tab tab = iterator.next(); final Tab tab = iterator.next();
GeckoAppShell.getHandler().post(new Runnable() { GeckoAppShell.getHandler().post(new Runnable() {
public void run() { public void run() {
GeckoApp.mAppContext.getAndProcessThumbnailForTab(tab, false); GeckoApp.mAppContext.getAndProcessThumbnailForTab(tab);
} }
}); });
} }

View File

@ -1,129 +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 org.mozilla.gecko.GeckoApp;
import org.mozilla.gecko.GeckoAppShell;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
/**
* A stand-in for Gecko that renders cached content of the previous page. We use this until Gecko
* is up, then we hand off control to it.
*/
public class PlaceholderLayerClient {
private static final String LOGTAG = "PlaceholderLayerClient";
private final LayerController mLayerController;
private ViewportMetrics mViewport;
private boolean mViewportUnknown;
private int mWidth, mHeight, mFormat;
private ByteBuffer mBuffer;
public PlaceholderLayerClient(LayerController controller, String lastViewport) {
mLayerController = controller;
mViewportUnknown = true;
if (lastViewport != null) {
try {
JSONObject viewportObject = new JSONObject(lastViewport);
mViewport = new ViewportMetrics(viewportObject);
mViewportUnknown = false;
} catch (JSONException e) {
Log.e(LOGTAG, "Error parsing saved viewport!");
mViewport = new ViewportMetrics();
}
} else {
mViewport = new ViewportMetrics();
}
}
public void destroy() {
if (mBuffer != null) {
GeckoAppShell.freeDirectBuffer(mBuffer);
mBuffer = null;
}
}
public boolean loadScreenshot() {
if (GeckoApp.mAppContext.mLastScreen == null)
return false;
Bitmap bitmap = BitmapFactory.decodeStream(new ByteArrayInputStream(GeckoApp.mAppContext.mLastScreen));
if (bitmap == null)
return false;
Bitmap.Config config = bitmap.getConfig();
mWidth = bitmap.getWidth();
mHeight = bitmap.getHeight();
mFormat = CairoUtils.bitmapConfigToCairoFormat(config);
int bpp = CairoUtils.bitsPerPixelForCairoFormat(mFormat) / 8;
mBuffer = GeckoAppShell.allocateDirectBuffer(mWidth * mHeight * bpp);
bitmap.copyPixelsToBuffer(mBuffer.asIntBuffer());
if (mViewportUnknown) {
mViewport.setPageSize(new FloatSize(mWidth, mHeight));
mLayerController.setPageSize(mViewport.getPageSize());
}
BufferedCairoImage image = new BufferedCairoImage(mBuffer, mWidth, mHeight, mFormat);
SingleTileLayer tileLayer = new SingleTileLayer(image);
tileLayer.beginTransaction(); // calling thread irrelevant; nobody else has a ref to tileLayer yet
try {
Point origin = PointUtils.round(mViewport.getOrigin());
tileLayer.setPosition(new Rect(origin.x, origin.y, origin.x + mWidth, origin.y + mHeight));
} finally {
tileLayer.endTransaction();
}
mLayerController.setRoot(tileLayer);
return true;
}
}