Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1542)

Unified Diff: android_webview/java/src/org/chromium/android_webview/RenderHelper.java

Issue 12041009: [Android WebView] Migrate the rendering code to a separate set of classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698