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;
10 import org.chromium.base.JNINamespace;
11 import org.chromium.content.common.CleanupReference;
13 import java.io.OutputStream;
15 // A simple wrapper around a SkPicture, that allows final rendering to be performed using the
16 // chromium skia library.
17 @JNINamespace("android_webview")
18 class AwPicture extends Picture {
20 private long mNativeAwPicture;
22 // There is no explicit destroy method on Picture base-class, so cleanup is always
23 // handled via the CleanupReference.
24 private static final class DestroyRunnable implements Runnable {
25 private long mNativeAwPicture;
26 private DestroyRunnable(long nativeAwPicture) {
27 mNativeAwPicture = nativeAwPicture;
31 nativeDestroy(mNativeAwPicture);
35 private CleanupReference mCleanupReference;
38 * @param nativeAwPicture is an instance of the AwPicture native class. Ownership is
39 * taken by this java instance.
41 AwPicture(long nativeAwPicture) {
42 mNativeAwPicture = nativeAwPicture;
43 mCleanupReference = new CleanupReference(this, new DestroyRunnable(nativeAwPicture));
47 public Canvas beginRecording(int width, int height) {
48 unsupportedOperation();
53 public void endRecording() {
54 // Intentional no-op. The native picture ended recording prior to java c'tor call.
58 public int getWidth() {
59 return nativeGetWidth(mNativeAwPicture);
63 public int getHeight() {
64 return nativeGetHeight(mNativeAwPicture);
68 public void draw(Canvas canvas) {
69 nativeDraw(mNativeAwPicture, canvas);
73 @SuppressWarnings("deprecation")
74 public void writeToStream(OutputStream stream) {
75 unsupportedOperation();
78 private void unsupportedOperation() {
79 throw new IllegalStateException("Unsupported in AwPicture");
82 private static native void nativeDestroy(long nativeAwPicture);
83 private native int nativeGetWidth(long nativeAwPicture);
84 private native int nativeGetHeight(long nativeAwPicture);
85 private native void nativeDraw(long nativeAwPicture, Canvas canvas);