Index: android_webview/java/src/org/chromium/android_webview/RenderHelper.java |
diff --git a/android_webview/java/src/org/chromium/android_webview/RenderHelper.java b/android_webview/java/src/org/chromium/android_webview/RenderHelper.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d4df000015a84f371f91ac0f2b8e45a8da427571 |
--- /dev/null |
+++ b/android_webview/java/src/org/chromium/android_webview/RenderHelper.java |
@@ -0,0 +1,62 @@ |
+ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.android_webview; |
+ |
+import android.graphics.Bitmap; |
+import android.graphics.Canvas; |
+import android.graphics.Color; |
+import android.graphics.Picture; |
+ |
+import org.chromium.base.CalledByNative; |
+import org.chromium.base.JNINamespace; |
+ |
+import java.lang.ref.SoftReference; |
+ |
+/** |
+ * Provides auxiliary methods related to Picture objects and native SkPictures. |
+ */ |
+@JNINamespace("android_webview") |
+public abstract class RenderHelper { |
mkosiba (inactive)
2013/01/22 02:13:34
nit1: like in my other comment - you should probab
Leandro Graciá Gil
2013/01/22 08:18:46
Done.
|
+ |
+ // Cached bitmap used for auxiliary rasterization in rendering fallback modes. |
+ private static SoftReference<Bitmap> sBitmapCache; |
+ |
+ /** |
+ * Provides a Bitmap object with a given width and height used for auxiliary rasterization. |
+ * Might reuse cached bitmaps. |
+ */ |
+ @CalledByNative |
+ private static Bitmap createBitmap(int width, int height) { |
joth
2013/01/21 22:54:24
maybe createTemporaryBitmap? to reflect fact the
Leandro Graciá Gil
2013/01/22 08:18:46
Leaving as it is since we're removing the soft ref
|
+ Bitmap bitmap = sBitmapCache != null ? sBitmapCache.get() : null; |
+ if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
+ bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
benm (inactive)
2013/01/21 20:34:49
in the case that bitmap != null, would bitmap.recy
joth
2013/01/21 22:54:24
In general this could be dangerous, as the caller
Leandro Graciá Gil
2013/01/22 08:18:46
Removing SoftReference as suggested.
|
+ bitmap.eraseColor(Color.BLACK); |
+ sBitmapCache = new SoftReference<Bitmap>(bitmap); |
+ } |
+ return bitmap; |
+ } |
+ |
+ /** |
+ * Draws a provided bitmap into a canvas. |
+ * Used for convenience from the native side and other static helper methods. |
+ */ |
+ @CalledByNative |
+ private static void drawBitmapIntoCanvas(Bitmap bitmap, Canvas canvas) { |
+ canvas.drawBitmap(bitmap, 0, 0, null); |
+ } |
+ |
+ /** |
+ * Creates a new Picture that records drawing a provided bitmap. |
+ */ |
+ @CalledByNative |
+ private static Picture recordRasterizedBitmap(Bitmap bitmap) { |
joth
2013/01/21 22:54:24
maybe clearer as createPictureFromBitmap or conver
Leandro Graciá Gil
2013/01/22 08:18:46
Using recordBitmapIntoPicture to make it consisten
|
+ Picture picture = new Picture(); |
+ Canvas recordingCanvas = picture.beginRecording(bitmap.getWidth(), bitmap.getHeight()); |
+ drawBitmapIntoCanvas(bitmap, recordingCanvas); |
+ picture.endRecording(); |
+ return picture; |
+ } |
+} |