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.Canvas;
8 import android.graphics.Picture;
9 import android.graphics.Rect;
11 import org.chromium.base.JNINamespace;
12 import org.chromium.content.common.CleanupReference;
14 import java.io.OutputStream;
16 // A simple wrapper around a SkPicture, that allows final rendering to be performed using the
17 // chromium skia library.
18 @JNINamespace("android_webview")
19 class AwPicture extends Picture {
21 private long mNativeAwPicture;
23 // There is no explicit destroy method on Picture base-class, so cleanup is always
24 // handled via the CleanupReference.
25 private static final class DestroyRunnable implements Runnable {
26 private long mNativeAwPicture;
27 private DestroyRunnable(long nativeAwPicture) {
28 mNativeAwPicture = nativeAwPicture;
32 nativeDestroy(mNativeAwPicture);
36 private CleanupReference mCleanupReference;
39 * @param nativeAwPicture is an instance of the AwPicture native class. Ownership is
40 * taken by this java instance.
42 AwPicture(long nativeAwPicture) {
43 mNativeAwPicture = nativeAwPicture;
44 mCleanupReference = new CleanupReference(this, new DestroyRunnable(nativeAwPicture));
48 public Canvas beginRecording(int width, int height) {
49 unsupportedOperation();
54 public void endRecording() {
55 // Intentional no-op. The native picture ended recording prior to java c'tor call.
59 public int getWidth() {
60 return nativeGetWidth(mNativeAwPicture);
64 public int getHeight() {
65 return nativeGetHeight(mNativeAwPicture);
68 // Effectively a local variable of draw(), but held as a member to avoid GC churn.
69 private Rect mClipBoundsTemporary = new Rect();
72 public void draw(Canvas canvas) {
73 canvas.getClipBounds(mClipBoundsTemporary);
74 nativeDraw(mNativeAwPicture, canvas,
75 mClipBoundsTemporary.left, mClipBoundsTemporary.top,
76 mClipBoundsTemporary.right, mClipBoundsTemporary.bottom);
80 @SuppressWarnings("deprecation")
81 public void writeToStream(OutputStream stream) {
82 unsupportedOperation();
85 private void unsupportedOperation() {
86 throw new IllegalStateException("Unsupported in AwPicture");
89 private static native void nativeDestroy(long nativeAwPicture);
90 private native int nativeGetWidth(long nativeAwPicture);
91 private native int nativeGetHeight(long nativeAwPicture);
92 private native void nativeDraw(long nativeAwPicture, Canvas canvas,
93 int left, int top, int right, int bottom);