1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview;
7 import android.graphics.Bitmap;
8 import android.graphics.Canvas;
10 import org.chromium.base.CalledByNative;
11 import org.chromium.base.JNINamespace;
14 * Provides auxiliary methods related to Picture objects and native SkPictures.
16 @JNINamespace("android_webview")
17 public class JavaBrowserViewRendererHelper {
18 private static final String LOGTAG = "JavaBrowserViewRendererHelper";
21 * Provides a Bitmap object with a given width and height used for auxiliary rasterization.
22 * |canvas| is optional and if supplied indicates the Canvas that this Bitmap will be
23 * drawn into. Note the Canvas will not be modified in any way.
26 private static Bitmap createBitmap(int width, int height, Canvas canvas) {
28 // When drawing into a Canvas, there is a maximum size imposed
29 // on Bitmaps that can be drawn. Respect that limit.
30 width = Math.min(width, canvas.getMaximumBitmapWidth());
31 height = Math.min(height, canvas.getMaximumBitmapHeight());
35 bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
36 } catch (OutOfMemoryError e) {
37 android.util.Log.w(LOGTAG, "Error allocating bitmap");
43 * Draws a provided bitmap into a canvas.
44 * Used for convenience from the native side and other static helper methods.
47 private static void drawBitmapIntoCanvas(Bitmap bitmap, Canvas canvas, int x, int y) {
48 canvas.drawBitmap(bitmap, x, y, null);
51 // Should never be instantiated.
52 private JavaBrowserViewRendererHelper() {