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 2c08909808e6315ada2167ce6c6c036fe08dc544..ced27a82425991c74b629e232eb8c119ce6f2427 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 auxiliary rasterization in rendering fallback modes. |
| + private static SoftReference<Bitmap> sBitmapCache; |
| + |
| private static final class DestroyRunnable implements Runnable { |
| private int mNativeAwContents; |
| private DestroyRunnable(int nativeAwContents) { |
| @@ -393,7 +398,9 @@ public class AwContents { |
| public void onDraw(Canvas canvas) { |
| if (mNativeAwContents == 0) return; |
| - if (!nativeDrawSW(mNativeAwContents, canvas)) { |
| + Rect clip = canvas.getClipBounds(); |
| + if (!nativeDrawSW(mNativeAwContents, canvas, clip.left, clip.top, |
| + clip.right - clip.left, clip.bottom - clip.top)) { |
| Log.w(TAG, "Native DrawSW failed; clearing to background color."); |
| int c = mContentViewCore.getBackgroundColor(); |
| canvas.drawRGB(Color.red(c), Color.green(c), Color.blue(c)); |
| @@ -404,6 +411,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 +929,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 +1006,42 @@ public class AwContents { |
| return null; |
| } |
| + /** |
| + * Provides a Bitmap object with a given width and height used for auxiliary rasterization. |
| + * Might reuse cached bitmaps. |
| + */ |
| + @CalledByNative |
| + private static Bitmap createBitmap(int width, int height) { |
| + Bitmap bitmap = sBitmapCache != null ? sBitmapCache.get() : null; |
| + if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
| + bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| + bitmap.eraseColor(Color.BLACK); |
| + sBitmapCache = new SoftReference<Bitmap>(bitmap); |
|
joth
2013/01/22 00:05:41
looks like I read these patches out of order...
sB
Leandro Graciá Gil
2013/01/22 02:11:13
I think you're right. This caching can cause probl
|
| + } |
| + return bitmap; |
| + } |
| + |
| + /** |
| + * Draws a provided bitmap into a canvas. |
| + * Used for convenience from the native side and other static helper methods. |
| + */ |
| + @CalledByNative |
| + private static void drawBitmapIntoCanvas(Bitmap bitmap, Canvas canvas) { |
| + canvas.drawBitmap(bitmap, 0, 0, null); |
| + } |
| + |
| + /** |
| + * Creates a new Picture that records drawing a provided bitmap. |
| + */ |
| + @CalledByNative |
| + private static Picture recordRasterizedBitmap(Bitmap bitmap) { |
|
joth
2013/01/22 00:05:41
recordBitmapIntoPicture ?
Leandro Graciá Gil
2013/01/22 02:11:13
Yes, much better. Done.
|
| + Picture picture = new Picture(); |
| + Canvas recordingCanvas = picture.beginRecording(bitmap.getWidth(), bitmap.getHeight()); |
| + drawBitmapIntoCanvas(bitmap, recordingCanvas); |
| + picture.endRecording(); |
| + return picture; |
| + } |
| + |
| @CalledByNative |
| private void handleJsAlert(String url, String message, JsResultReceiver receiver) { |
| mContentsClient.handleJsAlert(url, message, receiver); |
| @@ -1024,7 +1085,8 @@ public class AwContents { |
| private native void nativeSetInterceptNavigationDelegate(int nativeAwContents, |
| InterceptNavigationDelegate navigationInterceptionDelegate); |
| - private native boolean nativeDrawSW(int nativeAwContents, Canvas canvas); |
| + private native boolean nativeDrawSW(int nativeAwContents, Canvas canvas, int clipX, int clipY, |
| + int clipW, int clipH); |
| private native void nativeSetScrollForHWFrame(int nativeAwContents, int scrollX, int scrollY); |
| private native int nativeFindAllSync(int nativeAwContents, String searchString); |
| private native void nativeFindAllAsync(int nativeAwContents, String searchString); |
| @@ -1049,4 +1111,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); |
| } |