summaryrefslogtreecommitdiffstats
path: root/android_webview
diff options
context:
space:
mode:
authorkristianm@chromium.org <kristianm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-29 01:26:19 +0000
committerkristianm@chromium.org <kristianm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-29 01:26:19 +0000
commit2f03dca3b69a9975a4bd53a6b00947bf8cb3be6e (patch)
treec9c79661a00de16ea16b9af5f9ea274a60ef5d54 /android_webview
parent1b8f8cd4545168b1b36b5ae066acc06e17963650 (diff)
downloadchromium_src-2f03dca3b69a9975a4bd53a6b00947bf8cb3be6e.zip
chromium_src-2f03dca3b69a9975a4bd53a6b00947bf8cb3be6e.tar.gz
chromium_src-2f03dca3b69a9975a4bd53a6b00947bf8cb3be6e.tar.bz2
Fix capture picture implementation
Capturing the whole content, and starting the capture from the origin. BUG=224003 NOTRY=true Review URL: https://chromiumcodereview.appspot.com/19864002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214151 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r--android_webview/browser/browser_view_renderer.h4
-rw-r--r--android_webview/browser/in_process_view_renderer.cc20
-rw-r--r--android_webview/browser/in_process_view_renderer.h4
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContents.java6
-rw-r--r--android_webview/java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java9
-rw-r--r--android_webview/native/aw_contents.cc6
-rw-r--r--android_webview/native/aw_contents.h8
7 files changed, 37 insertions, 20 deletions
diff --git a/android_webview/browser/browser_view_renderer.h b/android_webview/browser/browser_view_renderer.h
index 613b36a..0f5d53f 100644
--- a/android_webview/browser/browser_view_renderer.h
+++ b/android_webview/browser/browser_view_renderer.h
@@ -102,7 +102,9 @@ class BrowserViewRenderer {
virtual void DrawGL(AwDrawGLInfo* draw_info) = 0;
// CapturePicture API methods.
- virtual base::android::ScopedJavaLocalRef<jobject> CapturePicture() = 0;
+ virtual base::android::ScopedJavaLocalRef<jobject> CapturePicture(
+ int width,
+ int height) = 0;
virtual void EnableOnNewPicture(bool enabled) = 0;
// View update notifications.
diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc
index dbb4c24..4cb053a 100644
--- a/android_webview/browser/in_process_view_renderer.cc
+++ b/android_webview/browser/in_process_view_renderer.cc
@@ -10,6 +10,7 @@
#include "android_webview/public/browser/draw_gl.h"
#include "android_webview/public/browser/draw_sw.h"
#include "base/android/jni_android.h"
+#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/logging.h"
@@ -363,26 +364,27 @@ bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas,
}
base::android::ScopedJavaLocalRef<jobject>
-InProcessViewRenderer::CapturePicture() {
+InProcessViewRenderer::CapturePicture(int width, int height) {
if (!compositor_ || !GetAwDrawSWFunctionTable()) {
TRACE_EVENT_INSTANT0(
"android_webview", "EarlyOut_CapturePicture", TRACE_EVENT_SCOPE_THREAD);
return ScopedJavaLocalRef<jobject>();
}
- gfx::Size record_size(width_, height_);
-
// Return empty Picture objects for empty SkPictures.
JNIEnv* env = AttachCurrentThread();
- if (record_size.width() <= 0 || record_size.height() <= 0) {
- return java_helper_->RecordBitmapIntoPicture(
- env, ScopedJavaLocalRef<jobject>());
+ if (width <= 0 || height <= 0) {
+ return java_helper_->RecordBitmapIntoPicture(env,
+ ScopedJavaLocalRef<jobject>());
}
+ // Reset scroll back to the origin, will go back to the old
+ // value when scroll_reset is out of scope.
+ base::AutoReset<gfx::Vector2dF> scroll_reset(&scroll_offset_css_,
+ gfx::Vector2d());
+
skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture);
- SkCanvas* rec_canvas = picture->beginRecording(record_size.width(),
- record_size.height(),
- 0);
+ SkCanvas* rec_canvas = picture->beginRecording(width, height, 0);
if (!CompositeSW(rec_canvas))
return ScopedJavaLocalRef<jobject>();
picture->endRecording();
diff --git a/android_webview/browser/in_process_view_renderer.h b/android_webview/browser/in_process_view_renderer.h
index e4f6dd5..642c8a8 100644
--- a/android_webview/browser/in_process_view_renderer.h
+++ b/android_webview/browser/in_process_view_renderer.h
@@ -43,7 +43,9 @@ class InProcessViewRenderer : public BrowserViewRenderer,
const gfx::Rect& clip,
const gfx::Rect& visible_rect) OVERRIDE;
virtual void DrawGL(AwDrawGLInfo* draw_info) OVERRIDE;
- virtual base::android::ScopedJavaLocalRef<jobject> CapturePicture() OVERRIDE;
+ virtual base::android::ScopedJavaLocalRef<jobject> CapturePicture(
+ int width,
+ int height) OVERRIDE;
virtual void EnableOnNewPicture(bool enabled) OVERRIDE;
virtual void OnVisibilityChanged(bool visible) OVERRIDE;
virtual void OnSizeChanged(int width, int height) OVERRIDE;
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 55ebcbd..bd64336 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -671,7 +671,9 @@ public class AwContents {
}
public Picture capturePicture() {
- return nativeCapturePicture(mNativeAwContents);
+ return nativeCapturePicture(mNativeAwContents,
+ mScrollOffsetManager.computeHorizontalScrollRange(),
+ mScrollOffsetManager.computeVerticalScrollRange());
}
/**
@@ -1774,7 +1776,7 @@ public class AwContents {
private native void nativeSetBackgroundColor(int nativeAwContents, int color);
private native int nativeGetAwDrawGLViewContext(int nativeAwContents);
- private native Picture nativeCapturePicture(int nativeAwContents);
+ private native Picture 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/JavaBrowserViewRendererHelper.java b/android_webview/java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java
index cd06606..fb54279 100644
--- a/android_webview/java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java
+++ b/android_webview/java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java
@@ -8,6 +8,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Picture;
+import android.util.Log;
import android.util.LruCache;
import org.chromium.base.CalledByNative;
@@ -19,6 +20,7 @@ import org.chromium.content.common.TraceEvent;
*/
@JNINamespace("android_webview")
public class JavaBrowserViewRendererHelper {
+ private static final String LOGTAG = "JavaBrowserViewRendererHelper";
// Until the full HW path is ready, we limit to 5 AwContents on the screen at once.
private static LruCache<Integer, Bitmap> sBitmapCache = new LruCache<Integer, Bitmap>(5);
@@ -39,7 +41,12 @@ public class JavaBrowserViewRendererHelper {
}
Bitmap bitmap = sBitmapCache.get(ownerKey);
if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) {
- bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ try {
+ bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ } catch (OutOfMemoryError e) {
+ android.util.Log.w(LOGTAG, "Error allocating bitmap");
+ return null;
+ }
if (ownerKey != 0) {
if (sBitmapCache.size() > AwContents.getNativeInstanceCount()) {
sBitmapCache.evictAll();
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
index 6e773c0..9796078 100644
--- a/android_webview/native/aw_contents.cc
+++ b/android_webview/native/aw_contents.cc
@@ -747,8 +747,10 @@ void AwContents::OnWebLayoutPageScaleFactorChanged(float page_scale_factor) {
}
ScopedJavaLocalRef<jobject> AwContents::CapturePicture(JNIEnv* env,
- jobject obj) {
- return browser_view_renderer_->CapturePicture();
+ jobject obj,
+ int width,
+ int height) {
+ return browser_view_renderer_->CapturePicture(width, height);
}
void AwContents::EnableOnNewPicture(JNIEnv* env,
diff --git a/android_webview/native/aw_contents.h b/android_webview/native/aw_contents.h
index eade5aa..ee3a47f 100644
--- a/android_webview/native/aw_contents.h
+++ b/android_webview/native/aw_contents.h
@@ -116,10 +116,10 @@ class AwContents : public FindHelper::Listener,
jint visible_bottom);
jint GetAwDrawGLViewContext(JNIEnv* env, jobject obj);
base::android::ScopedJavaLocalRef<jobject> CapturePicture(JNIEnv* env,
- jobject obj);
- void EnableOnNewPicture(JNIEnv* env,
- jobject obj,
- jboolean enabled);
+ jobject obj,
+ int width,
+ int height);
+ void EnableOnNewPicture(JNIEnv* env, jobject obj, jboolean enabled);
// Geolocation API support
void ShowGeolocationPrompt(const GURL& origin, base::Callback<void(bool)>);