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

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java

Issue 15795002: Cache auxiliary bitmap across draw frames (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.android_webview; 5 package org.chromium.android_webview;
6 6
7 import android.graphics.Bitmap; 7 import android.graphics.Bitmap;
8 import android.graphics.Canvas; 8 import android.graphics.Canvas;
9 import android.graphics.Color; 9 import android.graphics.Color;
10 import android.graphics.Picture; 10 import android.graphics.Picture;
11 11
12 import org.chromium.base.CalledByNative; 12 import org.chromium.base.CalledByNative;
13 import org.chromium.base.JNINamespace; 13 import org.chromium.base.JNINamespace;
14 14
15 import java.lang.ref.SoftReference;
16
15 /** 17 /**
16 * Provides auxiliary methods related to Picture objects and native SkPictures. 18 * Provides auxiliary methods related to Picture objects and native SkPictures.
17 */ 19 */
18 @JNINamespace("android_webview") 20 @JNINamespace("android_webview")
19 public class JavaBrowserViewRendererHelper { 21 public class JavaBrowserViewRendererHelper {
20 22
23 private static SoftReference<Bitmap> sCachedBitmap;
24
21 /** 25 /**
22 * Provides a Bitmap object with a given width and height used for auxiliary rasterization. 26 * Provides a Bitmap object with a given width and height used for auxiliary rasterization.
23 */ 27 */
24 @CalledByNative 28 @CalledByNative
25 private static Bitmap createBitmap(int width, int height) { 29 private static Bitmap createBitmap(int width, int height, boolean cacheResul t) {
26 return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 30 if (cacheResult && sCachedBitmap != null) {
31 Bitmap result = sCachedBitmap.get();
32 if (result != null && result.getWidth() == width && result.getHeight () == height) {
33 return result;
34 }
35 }
36 Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_88 88);
37 if (cacheResult) sCachedBitmap = new SoftReference<Bitmap>(result);
kaanb 2013/05/23 16:56:11 nit: it would be more readable if you break this s
joth 2013/05/23 20:23:14 Done.
38 return result;
27 } 39 }
28 40
29 /** 41 /**
30 * Draws a provided bitmap into a canvas. 42 * Draws a provided bitmap into a canvas.
31 * Used for convenience from the native side and other static helper methods . 43 * Used for convenience from the native side and other static helper methods .
32 */ 44 */
33 @CalledByNative 45 @CalledByNative
34 private static void drawBitmapIntoCanvas(Bitmap bitmap, Canvas canvas) { 46 private static void drawBitmapIntoCanvas(Bitmap bitmap, Canvas canvas) {
35 canvas.drawBitmap(bitmap, 0, 0, null); 47 canvas.drawBitmap(bitmap, 0, 0, null);
36 } 48 }
(...skipping 10 matching lines...) Expand all
47 drawBitmapIntoCanvas(bitmap, recordingCanvas); 59 drawBitmapIntoCanvas(bitmap, recordingCanvas);
48 picture.endRecording(); 60 picture.endRecording();
49 } 61 }
50 return picture; 62 return picture;
51 } 63 }
52 64
53 // Should never be instantiated. 65 // Should never be instantiated.
54 private JavaBrowserViewRendererHelper() { 66 private JavaBrowserViewRendererHelper() {
55 } 67 }
56 } 68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698