Index: android_webview/java/src/org/chromium/android_webview/AwPicture.java |
diff --git a/android_webview/java/src/org/chromium/android_webview/AwPicture.java b/android_webview/java/src/org/chromium/android_webview/AwPicture.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2636a3184c15b598d8e8d320a31b5d3fcffcd9de |
--- /dev/null |
+++ b/android_webview/java/src/org/chromium/android_webview/AwPicture.java |
@@ -0,0 +1,116 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.android_webview; |
+ |
+import android.graphics.Canvas; |
+import android.graphics.Picture; |
+import android.graphics.Rect; |
+ |
+import org.chromium.base.CalledByNative; |
+import org.chromium.base.JNINamespace; |
+import org.chromium.content.common.CleanupReference; |
+ |
+import java.io.OutputStream; |
+ |
+// A simple wrapper around a SkPicture, that allows final rendering to be performed using the |
+// chromium skia library. |
+@JNINamespace("android_webview") |
+class AwPicture extends Picture { |
+ |
+ private int mNativeAwPicture; |
+ private boolean mCompatibilityMode; |
+ |
+ // There is no explicit destroy method on Picture base-class, so cleanup is always |
+ // handled via the CleanupReference. |
+ private static final class DestroyRunnable implements Runnable { |
+ private int mNativeAwPicture; |
+ private DestroyRunnable(int nativeAwPicture) { |
+ mNativeAwPicture = nativeAwPicture; |
+ } |
+ @Override |
+ public void run() { |
+ nativeDestroy(mNativeAwPicture); |
+ } |
+ } |
+ |
+ private CleanupReference mCleanupReference; |
+ |
+ /** |
+ * @param nativeAwPicture is an instance of the AwPicture native class. Ownership is |
+ * taken by this java instance. |
+ * @param compatibilityMode if true, unsupported methods are a no-op rather than throw. |
+ */ |
+ AwPicture(int nativeAwPicture, boolean compatibilityMode) { |
+ mNativeAwPicture = nativeAwPicture; |
+ mCompatibilityMode = compatibilityMode; |
+ mCleanupReference = new CleanupReference(this, new DestroyRunnable(nativeAwPicture)); |
+ } |
+ |
+ @Override |
+ public Canvas beginRecording(int width, int height) { |
+ checkCompat(); |
+ if (mCleanupReference != null) { |
+ mCleanupReference.cleanupNow(); |
+ mCleanupReference = null; |
+ } |
+ mNativeAwPicture = 0; |
+ return super.beginRecording(width, height); |
+ } |
+ |
+ @Override |
+ public void endRecording() { |
+ super.endRecording(); |
+ } |
+ |
+ @Override |
+ public int getWidth() { |
+ if (mNativeAwPicture != 0) { |
+ return nativeGetWidth(mNativeAwPicture); |
+ } else { |
+ return super.getWidth(); |
+ } |
+ } |
+ |
+ @Override |
+ public int getHeight() { |
+ if (mNativeAwPicture != 0) { |
+ return nativeGetHeight(mNativeAwPicture); |
+ } else { |
+ return super.getHeight(); |
+ } |
+ } |
+ |
+ Rect mClipBoundsTemporary = new Rect(); |
sgurun-gerrit only
2013/08/08 22:11:19
Is this intentional? why is it not private and def
|
+ @Override |
+ public void draw(Canvas canvas) { |
+ if (mNativeAwPicture != 0) { |
+ canvas.getClipBounds(mClipBoundsTemporary); |
+ nativeDraw(mNativeAwPicture, canvas, |
+ mClipBoundsTemporary.left, mClipBoundsTemporary.top, |
+ mClipBoundsTemporary.right, mClipBoundsTemporary.bottom); |
+ } else { |
+ super.draw(canvas); |
+ } |
+ } |
+ |
+ @Override |
+ public void writeToStream(OutputStream stream) { |
+ if (stream == null) throw new NullPointerException(); |
+ checkCompat(); |
+ } |
+ |
+ private void checkCompat() { |
+ if (!mCompatibilityMode) { |
+ throw new IllegalStateException("Unsupported in WebView Picture"); |
+ } |
joth
2013/08/03 17:38:12
else Log.e ?
Kristian Monsen
2013/08/08 21:28:59
It would potentially crash the app. It either happ
joth
2013/08/08 22:39:01
As per verbal discussion, I'll remove the mCompati
boliu
2013/08/08 23:05:10
What is that discussion? It's probably a bad idea
|
+ } |
+ |
+ private static native void nativeDestroy(int nativeAwPicture); |
+ private native int nativeGetWidth(int nativeAwPicture); |
+ private native int nativeGetHeight(int nativeAwPicture); |
+ private native void nativeDraw(int nativeAwPicture, Canvas canvas, |
+ int left, int top, int right, int bottom); |
+} |
+ |