summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2011-08-30 09:18:29 -0700
committerJohn Reck <jreck@google.com>2011-09-08 14:33:31 -0700
commitd7dd9b2ecb12da278c053291b684b885ee574301 (patch)
treeab37ea0497a96a104ee841b38ebc54a425bb96f1 /src
parent6f096ad33b947e95f7c5d9fd989a01398df50c95 (diff)
downloadpackages_apps_browser-d7dd9b2ecb12da278c053291b684b885ee574301.zip
packages_apps_browser-d7dd9b2ecb12da278c053291b684b885ee574301.tar.gz
packages_apps_browser-d7dd9b2ecb12da278c053291b684b885ee574301.tar.bz2
Use onDraw instead of capturePicture for thumbnails
Bug: 5220344 Change-Id: I78ebbb8ae6c574d79b99fcde8220e5d08342876c
Diffstat (limited to 'src')
-rw-r--r--src/com/android/browser/Controller.java66
1 files changed, 35 insertions, 31 deletions
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index a3887f5..4809f13 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -37,7 +37,6 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.Canvas;
-import android.graphics.Picture;
import android.net.Uri;
import android.net.http.SslError;
import android.os.AsyncTask;
@@ -146,6 +145,9 @@ public class Controller
// "no-crash-recovery" parameter in intetnt to suppress crash recovery
final static String NO_CRASH_RECOVERY = "no-crash-recovery";
+ // A bitmap that is re-used in createScreenshot as scratch space
+ private static Bitmap sThumbnailBitmap;
+
private Activity mActivity;
private UI mUi;
private TabControl mTabControl;
@@ -638,6 +640,10 @@ public class Controller
WebView.disablePlatformNotifications();
NfcHandler.unregister(mActivity);
+ if (sThumbnailBitmap != null) {
+ sThumbnailBitmap.recycle();
+ sThumbnailBitmap = null;
+ }
}
void onSaveInstanceState(Bundle outState) {
@@ -1923,45 +1929,43 @@ public class Controller
}
static Bitmap createScreenshot(WebView view, int width, int height) {
+ if (view == null || view.getContentHeight() == 0
+ || view.getContentWidth() == 0) {
+ return null;
+ }
// We render to a bitmap 2x the desired size so that we can then
// re-scale it with filtering since canvas.scale doesn't filter
// This helps reduce aliasing at the cost of being slightly blurry
final int filter_scale = 2;
- Picture thumbnail = view.capturePicture();
- if (thumbnail == null) {
- return null;
- }
- width *= filter_scale;
- height *= filter_scale;
- Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
- Canvas canvas = new Canvas(bm);
- // May need to tweak these values to determine what is the
- // best scale factor
- int thumbnailWidth = thumbnail.getWidth();
- int thumbnailHeight = thumbnail.getHeight();
- float scaleFactor = 1.0f;
- if (thumbnailWidth > 0 && thumbnailHeight > 0) {
- scaleFactor = (float) width / (float)thumbnailWidth;
- } else {
- return null;
+ int scaledWidth = width * filter_scale;
+ int scaledHeight = height * filter_scale;
+ if (sThumbnailBitmap == null || sThumbnailBitmap.getWidth() != scaledWidth
+ || sThumbnailBitmap.getHeight() != scaledHeight) {
+ if (sThumbnailBitmap != null) {
+ sThumbnailBitmap.recycle();
+ sThumbnailBitmap = null;
+ }
+ sThumbnailBitmap =
+ Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.RGB_565);
}
-
- float scaleFactorY = (float) height / (float)thumbnailHeight;
- if (scaleFactorY > scaleFactor) {
- // The picture is narrower than the requested AR
- // Center the thumnail and crop the sides
- scaleFactor = scaleFactorY;
- float wx = (thumbnailWidth * scaleFactor) - width;
- canvas.translate((int) -(wx / 2), 0);
+ Canvas canvas = new Canvas(sThumbnailBitmap);
+ int contentWidth = view.getContentWidth();
+ float overviewScale = scaledWidth / (view.getScale() * contentWidth);
+ if (view instanceof BrowserWebView) {
+ int dy = -((BrowserWebView)view).getTitleHeight();
+ canvas.translate(0, dy * overviewScale);
}
- canvas.scale(scaleFactor, scaleFactor);
+ canvas.scale(overviewScale, overviewScale);
- thumbnail.draw(canvas);
- Bitmap ret = Bitmap.createScaledBitmap(bm, width / filter_scale,
- height / filter_scale, true);
+ if (view instanceof BrowserWebView) {
+ ((BrowserWebView)view).drawContent(canvas);
+ } else {
+ view.draw(canvas);
+ }
+ Bitmap ret = Bitmap.createScaledBitmap(sThumbnailBitmap,
+ width, height, true);
canvas.setBitmap(null);
- bm.recycle();
return ret;
}