diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-09 12:35:11 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-09 12:35:11 +0000 |
commit | ee44bd0c40e393afe5deccf34c6abda1dd459193 (patch) | |
tree | 0de806f5771046f121f9a6f2688b74b0db882126 /android_webview/java | |
parent | 06fee5bd02ba9d8b6ed9c8d5c19b6260df468f7d (diff) | |
download | chromium_src-ee44bd0c40e393afe5deccf34c6abda1dd459193.zip chromium_src-ee44bd0c40e393afe5deccf34c6abda1dd459193.tar.gz chromium_src-ee44bd0c40e393afe5deccf34c6abda1dd459193.tar.bz2 |
Android WebView: Make a custom Picture subclass
This allows the capturePicture path to work fully even when using
mismatched skia version to the system. AwCreatePictureFunction is now
obsolete and can be removed in a followup.
BUG=b/9814370
Review URL: https://chromiumcodereview.appspot.com/22035002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216667 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/java')
-rw-r--r-- | android_webview/java/src/org/chromium/android_webview/AwContents.java | 8 | ||||
-rw-r--r-- | android_webview/java/src/org/chromium/android_webview/AwPicture.java | 95 |
2 files changed, 99 insertions, 4 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index eb0128e..46989c0 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -717,9 +717,9 @@ public class AwContents { } public Picture capturePicture() { - return nativeCapturePicture(mNativeAwContents, - mScrollOffsetManager.computeHorizontalScrollRange(), - mScrollOffsetManager.computeVerticalScrollRange()); + return new AwPicture(nativeCapturePicture(mNativeAwContents, + mScrollOffsetManager.computeHorizontalScrollRange(), + mScrollOffsetManager.computeVerticalScrollRange())); } /** @@ -1814,7 +1814,7 @@ public class AwContents { private native void nativeSetBackgroundColor(int nativeAwContents, int color); private native int nativeGetAwDrawGLViewContext(int nativeAwContents); - private native Picture nativeCapturePicture(int nativeAwContents, int width, int height); + private native int nativeCapturePicture(int nativeAwContents, int width, int height); private native void nativeEnableOnNewPicture(int nativeAwContents, boolean enabled); private native void nativeInvokeGeolocationCallback( 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 0000000..30ec57b --- /dev/null +++ b/android_webview/java/src/org/chromium/android_webview/AwPicture.java @@ -0,0 +1,95 @@ +// 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; + + // 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. + */ + AwPicture(int nativeAwPicture) { + mNativeAwPicture = nativeAwPicture; + mCleanupReference = new CleanupReference(this, new DestroyRunnable(nativeAwPicture)); + } + + @Override + public Canvas beginRecording(int width, int height) { + unsupportedOperation(); + return null; + } + + @Override + public void endRecording() { + // Intentional no-op. The native picture ended recording prior to java c'tor call. + } + + @Override + public int getWidth() { + return nativeGetWidth(mNativeAwPicture); + } + + @Override + public int getHeight() { + return nativeGetHeight(mNativeAwPicture); + } + + // Effectively a local variable of draw(), but held as a member to avoid GC churn. + private Rect mClipBoundsTemporary = new Rect(); + + @Override + public void draw(Canvas canvas) { + canvas.getClipBounds(mClipBoundsTemporary); + nativeDraw(mNativeAwPicture, canvas, + mClipBoundsTemporary.left, mClipBoundsTemporary.top, + mClipBoundsTemporary.right, mClipBoundsTemporary.bottom); + } + + @Override + public void writeToStream(OutputStream stream) { + unsupportedOperation(); + } + + private void unsupportedOperation() { + throw new IllegalStateException("Unsupported in AwPicture"); + } + + 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); +} + |