Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 } |
| OLD | NEW |