summaryrefslogtreecommitdiffstats
path: root/android_webview
diff options
context:
space:
mode:
authorbenm@chromium.org <benm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-02 07:41:29 +0000
committerbenm@chromium.org <benm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-02 07:41:29 +0000
commit05f890b325e90b7fcdc112e8200d90eb8977b5c9 (patch)
tree95adc13d2af055f97159e4950e815e554dfac79c /android_webview
parent3e8eae140a0ab67dc56ce3289524d122754eef18 (diff)
downloadchromium_src-05f890b325e90b7fcdc112e8200d90eb8977b5c9.zip
chromium_src-05f890b325e90b7fcdc112e8200d90eb8977b5c9.tar.gz
chromium_src-05f890b325e90b7fcdc112e8200d90eb8977b5c9.tar.bz2
[Android WebView] Reduce jank of HW fallback
While we still have the SW draw fallback when rendering into a HW Canvas, store a bitmap per WebContents in an android.util.LruCache rather than creating a new Bitmap per frame. This drastically improves the performance of this rendering mode. Review URL: https://chromiumcodereview.appspot.com/18423002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209645 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r--android_webview/browser/browser_view_renderer.h3
-rw-r--r--android_webview/browser/in_process_view_renderer.cc5
-rw-r--r--android_webview/java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java18
-rw-r--r--android_webview/native/java_browser_view_renderer_helper.cc8
-rw-r--r--android_webview/native/java_browser_view_renderer_helper.h3
5 files changed, 27 insertions, 10 deletions
diff --git a/android_webview/browser/browser_view_renderer.h b/android_webview/browser/browser_view_renderer.h
index 5be33e9..ab0a59e 100644
--- a/android_webview/browser/browser_view_renderer.h
+++ b/android_webview/browser/browser_view_renderer.h
@@ -55,7 +55,8 @@ class BrowserViewRenderer {
JNIEnv* env,
int width,
int height,
- const base::android::JavaRef<jobject>& jcanvas) = 0;
+ const base::android::JavaRef<jobject>& jcanvas,
+ void* owner_key) = 0;
// Draws the provided Java Bitmap into the provided Java Canvas.
virtual void DrawBitmapIntoCanvas(
diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc
index 633dc51..cc7115c 100644
--- a/android_webview/browser/in_process_view_renderer.cc
+++ b/android_webview/browser/in_process_view_renderer.cc
@@ -448,7 +448,7 @@ bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas,
if (pixels == NULL) {
TRACE_EVENT0("android_webview", "RenderToAuxBitmap");
ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap(
- env, clip.width(), clip.height(), jcanvas));
+ env, clip.width(), clip.height(), jcanvas, web_contents_));
if (!jbitmap.obj()) {
TRACE_EVENT_INSTANT0("android_webview",
"EarlyOut_BitmapAllocFail",
@@ -540,7 +540,8 @@ InProcessViewRenderer::CapturePicture() {
// for |canvas| as we don't have java canvas at this point (and it would be
// software anyway).
ScopedJavaLocalRef<jobject> jbitmap(java_helper_->CreateBitmap(
- env, picture->width(), picture->height(), ScopedJavaLocalRef<jobject>()));
+ env, picture->width(), picture->height(), ScopedJavaLocalRef<jobject>(),
+ NULL));
if (!jbitmap.obj())
return ScopedJavaLocalRef<jobject>();
diff --git a/android_webview/java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java b/android_webview/java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java
index 54bb33d..4f3f9cb 100644
--- a/android_webview/java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java
+++ b/android_webview/java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java
@@ -8,6 +8,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Picture;
+import android.util.LruCache;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
@@ -19,20 +20,31 @@ import org.chromium.content.common.TraceEvent;
@JNINamespace("android_webview")
public class JavaBrowserViewRendererHelper {
+ // Until the full HW path is ready, we limit to 5 AwContents on the screen at once.
+ private static LruCache<Integer, Bitmap> sBitmapCache = new LruCache<Integer, Bitmap>(5);
+
/**
* Provides a Bitmap object with a given width and height used for auxiliary rasterization.
* |canvas| is optional and if supplied indicates the Canvas that this Bitmap will be
- * drawn into. Note the Canvas will not be modified in any way.
+ * drawn into. Note the Canvas will not be modified in any way. If |ownerKey| is non-zero
+ * the Bitmap will be cached in sBitmapCache for future use.
*/
@CalledByNative
- private static Bitmap createBitmap(int width, int height, Canvas canvas) {
+ private static Bitmap createBitmap(int width, int height, Canvas canvas, int ownerKey) {
if (canvas != null) {
// When drawing into a Canvas, there is a maximum size imposed
// on Bitmaps that can be drawn. Respect that limit.
width = Math.min(width, canvas.getMaximumBitmapWidth());
height = Math.min(height, canvas.getMaximumBitmapHeight());
}
- return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ Bitmap bitmap = sBitmapCache.get(ownerKey);
+ if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) {
+ bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ if (ownerKey != 0) {
+ sBitmapCache.put(ownerKey, bitmap);
+ }
+ }
+ return bitmap;
}
/**
diff --git a/android_webview/native/java_browser_view_renderer_helper.cc b/android_webview/native/java_browser_view_renderer_helper.cc
index 8bbed36..0426bd1 100644
--- a/android_webview/native/java_browser_view_renderer_helper.cc
+++ b/android_webview/native/java_browser_view_renderer_helper.cc
@@ -22,11 +22,13 @@ ScopedJavaLocalRef<jobject> JavaBrowserViewRendererHelper::CreateBitmap(
JNIEnv* env,
int width,
int height,
- const base::android::JavaRef<jobject>& jcanvas) {
+ const base::android::JavaRef<jobject>& jcanvas,
+ void* owner_key) {
TRACE_EVENT0("android_webview", "RendererHelper::CreateBitmap");
return width <= 0 || height <= 0 ? ScopedJavaLocalRef<jobject>() :
- Java_JavaBrowserViewRendererHelper_createBitmap(env, width, height,
- jcanvas.obj());
+ Java_JavaBrowserViewRendererHelper_createBitmap(
+ env, width, height, jcanvas.obj(),
+ reinterpret_cast<jint>(owner_key));
}
void JavaBrowserViewRendererHelper::DrawBitmapIntoCanvas(
diff --git a/android_webview/native/java_browser_view_renderer_helper.h b/android_webview/native/java_browser_view_renderer_helper.h
index 77860b3..2d1aadc 100644
--- a/android_webview/native/java_browser_view_renderer_helper.h
+++ b/android_webview/native/java_browser_view_renderer_helper.h
@@ -23,7 +23,8 @@ class JavaBrowserViewRendererHelper : public BrowserViewRenderer::JavaHelper {
JNIEnv* env,
int width,
int height,
- const base::android::JavaRef<jobject>& jcanvas) OVERRIDE;
+ const base::android::JavaRef<jobject>& jcanvas,
+ void* owner_key) OVERRIDE;
virtual void DrawBitmapIntoCanvas(
JNIEnv* env,
const base::android::JavaRef<jobject>& jbitmap,