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 93a78d483f5664bf64b4ffcf8fb23f9667b728ce..5cada2a3cdba2529aad472587175efa901295f7b 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; |
@@ -379,6 +380,19 @@ public class AwContents { |
} |
} |
+ 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); |
@@ -884,6 +898,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( |
@@ -956,6 +975,22 @@ 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 = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
joth
2013/01/12 02:36:28
maybe add a comment for the obvious: we could cach
Leandro GraciĆ” Gil
2013/01/12 17:59:14
Interesting, I didn't know about soft references.
|
+ 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); |
@@ -985,6 +1020,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, |
@@ -1024,4 +1060,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); |
} |