Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1247)

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwContents.java

Issue 11823027: [Android WebView] Implement the capture picture API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed synchronous IPC problems that crashed/deadlocked tests. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/java/src/org/chromium/android_webview/AwContents.java
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 2c08909808e6315ada2167ce6c6c036fe08dc544..9de4bc7b75e2af0408f1c2d2ad7e443e3eab5dd6 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -8,6 +8,7 @@ import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
+import android.graphics.Picture;
import android.graphics.Rect;
import android.net.http.SslCertificate;
import android.os.AsyncTask;
@@ -39,6 +40,7 @@ import org.chromium.net.X509Util;
import org.chromium.ui.gfx.NativeWindow;
import java.io.File;
+import java.lang.ref.SoftReference;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.KeyStoreException;
@@ -104,6 +106,9 @@ public class AwContents {
// Must call nativeUpdateLastHitTestData first to update this before use.
private final HitTestData mPossiblyStaleHitTestData;
+ // Cached bitmap used for rasterizing Pictures.
+ private SoftReference<Bitmap> mPictureBitmapCache;
+
private static final class DestroyRunnable implements Runnable {
private int mNativeAwContents;
private DestroyRunnable(int nativeAwContents) {
@@ -404,6 +409,19 @@ public class AwContents {
mLayoutSizer.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
+ public Picture capturePicture() {
+ return nativeCapturePicture(mNativeAwContents);
+ }
+
+ /**
+ * Enable the OnNewPicture callback.
+ * @param enabled Flag to enable the callback.
+ * @param invalidationOnly Flag to call back only on invalidation without providing a picture.
+ */
+ public void enableOnNewPicture(boolean enabled, boolean invalidationOnly) {
+ nativeEnableOnNewPicture(mNativeAwContents, enabled, invalidationOnly);
+ }
+
public int findAllSync(String searchString) {
if (mNativeAwContents == 0) return 0;
return nativeFindAllSync(mNativeAwContents, searchString);
@@ -909,6 +927,11 @@ public class AwContents {
mContentsClient.onFindResultReceived(activeMatchOrdinal, numberOfMatches, isDoneCounting);
}
+ @CalledByNative
+ public void onNewPicture(Picture picture) {
+ mContentsClient.onNewPicture(picture);
+ }
+
// Called as a result of nativeUpdateLastHitTestData.
@CalledByNative
private void updateHitTestData(
@@ -981,6 +1004,28 @@ public class AwContents {
return null;
}
+ /**
+ * Rasterizes the latest available picture into a bitmap and draws it into a new Picture.
+ * This approach has performance issues and should only be used as a fallback mechanism.
+ */
+ @CalledByNative
+ private Picture rasterizeIntoPicture(int nativePicture, int width, int height) {
+ Bitmap bitmap = mPictureBitmapCache != null ? mPictureBitmapCache.get() : null;
+ if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) {
+ bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ bitmap.eraseColor(Color.BLACK);
+ mPictureBitmapCache = new SoftReference<Bitmap>(bitmap);
+ }
+
+ if (!nativeRasterizePicture(bitmap, nativePicture)) return null;
+
+ Picture picture = new Picture();
+ Canvas recordingCanvas = picture.beginRecording(width, height);
+ recordingCanvas.drawBitmap(bitmap, 0, 0, null);
+ picture.endRecording();
+ return picture;
+ }
+
@CalledByNative
private void handleJsAlert(String url, String message, JsResultReceiver receiver) {
mContentsClient.handleJsAlert(url, message, receiver);
@@ -1010,6 +1055,7 @@ public class AwContents {
private static native void nativeDestroy(int nativeAwContents);
private static native void nativeSetAwDrawSWFunctionTable(int functionTablePointer);
private static native int nativeGetAwDrawGLFunction();
+ private static native boolean nativeRasterizePicture(Bitmap bitmap, int nativePicture);
private native int nativeGetWebContents(int nativeAwContents);
private native void nativeDidInitializeContentViewCore(int nativeAwContents,
@@ -1049,4 +1095,8 @@ public class AwContents {
private native int nativeReleasePopupWebContents(int nativeAwContents);
private native void nativeSetWebContents(int nativeAwContents, int nativeNewWebContents);
private native void nativeFocusFirstNode(int nativeAwContents);
+
+ private native Picture nativeCapturePicture(int nativeAwContents);
+ private native void nativeEnableOnNewPicture(int nativeAwContents, boolean enabled,
+ boolean invalidationOnly);
}

Powered by Google App Engine
This is Rietveld 408576698