Chromium Code Reviews| 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 3d51cb74bf595552e9751b2ad554db3e24146aa4..75c34fcf8579cad15398f703365b379fd1301d45 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) { |
| @@ -402,6 +407,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); |
| @@ -907,6 +925,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( |
| @@ -979,6 +1002,30 @@ 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) { |
| + if (mPictureBitmapCache == null || mPictureBitmapCache.get() == null || |
| + mPictureBitmapCache.get().getWidth() != width || |
| + mPictureBitmapCache.get().getHeight() != height) { |
|
joth
2013/01/14 23:20:57
nit: this is technically racy, as the ref maybe GC
Leandro GraciĆ” Gil
2013/01/15 18:49:23
Two issues with your approach:
1. SoftReference<>
|
| + mPictureBitmapCache = new SoftReference<Bitmap>( |
| + Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)); |
| + mPictureBitmapCache.get().eraseColor(Color.BLACK); |
| + } |
| + |
| + Bitmap bitmap = mPictureBitmapCache.get(); |
| + 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); |
| @@ -1008,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, |
| @@ -1047,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); |
| } |