diff options
8 files changed, 72 insertions, 12 deletions
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc index 8dd58b7..4ecebb7 100644 --- a/content/browser/android/content_view_core_impl.cc +++ b/content/browser/android/content_view_core_impl.cc @@ -380,15 +380,19 @@ void ContentViewCoreImpl::UpdateFrameInfo( const gfx::Vector2dF& controls_offset, const gfx::Vector2dF& content_offset, float overdraw_bottom_height) { - if (window_android_) - window_android_->set_content_offset( - gfx::ScaleVector2d(content_offset, dpi_scale_)); - JNIEnv* env = AttachCurrentThread(); ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); if (obj.is_null()) return; + if (window_android_) { + gfx::Vector2dF window_offset( + Java_ContentViewCore_getLocationInWindowX(env, obj.obj()), + Java_ContentViewCore_getLocationInWindowY(env, obj.obj())); + window_android_->set_content_offset( + gfx::ScaleVector2d(content_offset, dpi_scale_) + window_offset); + } + Java_ContentViewCore_updateFrameInfo( env, obj.obj(), scroll_offset.x(), diff --git a/content/browser/android/content_view_render_view.cc b/content/browser/android/content_view_render_view.cc index 4faa4df..05f2482 100644 --- a/content/browser/android/content_view_render_view.cc +++ b/content/browser/android/content_view_render_view.cc @@ -16,8 +16,10 @@ #include "content/public/browser/android/compositor.h" #include "content/public/browser/android/content_view_layer_renderer.h" #include "jni/ContentViewRenderView_jni.h" +#include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/size.h" +#include <android/bitmap.h> #include <android/native_window_jni.h> using base::android::ScopedJavaLocalRef; @@ -83,6 +85,15 @@ jboolean ContentViewRenderView::Composite(JNIEnv* env, jobject obj) { return buffers_swapped_during_composite_; } +jboolean ContentViewRenderView::CompositeToBitmap(JNIEnv* env, jobject obj, + jobject java_bitmap) { + gfx::JavaBitmap bitmap(java_bitmap); + if (!compositor_ || bitmap.format() != ANDROID_BITMAP_FORMAT_RGBA_8888) + return false; + return compositor_->CompositeAndReadback(bitmap.pixels(), + gfx::Rect(bitmap.size())); +} + void ContentViewRenderView::ScheduleComposite() { JNIEnv* env = base::android::AttachCurrentThread(); Java_ContentViewRenderView_requestRender(env, java_obj_.obj()); diff --git a/content/browser/android/content_view_render_view.h b/content/browser/android/content_view_render_view.h index 714f02f7..65c3874 100644 --- a/content/browser/android/content_view_render_view.h +++ b/content/browser/android/content_view_render_view.h @@ -28,6 +28,7 @@ class ContentViewRenderView : public CompositorClient { void SurfaceDestroyed(JNIEnv* env, jobject obj); void SurfaceSetSize(JNIEnv* env, jobject obj, jint width, jint height); jboolean Composite(JNIEnv* env, jobject obj); + jboolean CompositeToBitmap(JNIEnv* env, jobject obj, jobject java_bitmap); // CompositorClient --------------------------------------------------------- virtual void ScheduleComposite() OVERRIDE; diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentView.java b/content/public/android/java/src/org/chromium/content/browser/ContentView.java index 77f448c..ef00b36 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentView.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentView.java @@ -40,6 +40,7 @@ public class ContentView extends FrameLayout private float mCurrentTouchOffsetX; private float mCurrentTouchOffsetY; + private final int[] mLocationInWindow = new int[2]; /** * Creates an instance of a ContentView. @@ -417,6 +418,15 @@ public class ContentView extends FrameLayout } @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + if (changed) { + getLocationInWindow(mLocationInWindow); + mContentViewCore.onLocationInWindowChanged(mLocationInWindow[0], mLocationInWindow[1]); + } + } + + @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { return mContentViewCore.onCreateInputConnection(outAttrs); } diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java index a7da5bc..63dde98 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java @@ -388,6 +388,8 @@ public class ContentViewCore private int mOverdrawBottomHeightPix; private int mViewportSizeOffsetWidthPix; private int mViewportSizeOffsetHeightPix; + private int mLocationInWindowX; + private int mLocationInWindowY; // Cached copy of all positions and scales as reported by the renderer. private final RenderCoordinates mRenderCoordinates; @@ -1603,6 +1605,15 @@ public class ContentViewCore } /** + * Called when the ContentView's position in the activity window changed. This information is + * used for cropping screenshots. + */ + public void onLocationInWindowChanged(int x, int y) { + mLocationInWindowX = x; + mLocationInWindowY = y; + } + + /** * Called when the underlying surface the compositor draws to changes size. * This may be larger than the viewport size. */ @@ -3070,6 +3081,16 @@ public class ContentViewCore } @CalledByNative + private int getLocationInWindowX() { + return mLocationInWindowX; + } + + @CalledByNative + private int getLocationInWindowY() { + return mLocationInWindowY; + } + + @CalledByNative private static Rect createRect(int x, int y, int right, int bottom) { return new Rect(x, y, right, bottom); } diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewRenderView.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewRenderView.java index 76a6083..3c7f70b 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewRenderView.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewRenderView.java @@ -5,6 +5,8 @@ package org.chromium.content.browser; import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Canvas; import android.graphics.Color; import android.os.Build; import android.os.Handler; @@ -202,7 +204,18 @@ public class ContentViewRenderView extends FrameLayout { * @return The created SurfaceView object. */ protected SurfaceView createSurfaceView(Context context) { - return new SurfaceView(context); + return new SurfaceView(context) { + @Override + public void onDraw(Canvas canvas) { + // We only need to draw to software canvases, which are used for taking screenshots. + if (canvas.isHardwareAccelerated()) return; + Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), + Bitmap.Config.ARGB_8888); + if (nativeCompositeToBitmap(mNativeContentViewRenderView, bitmap)) { + canvas.drawBitmap(bitmap, 0, 0, null); + } + } + }; } /** @@ -286,4 +299,5 @@ public class ContentViewRenderView extends FrameLayout { private native void nativeSurfaceSetSize(int nativeContentViewRenderView, int width, int height); private native boolean nativeComposite(int nativeContentViewRenderView); + private native boolean nativeCompositeToBitmap(int nativeContentViewRenderView, Bitmap bitmap); } diff --git a/tools/telemetry/telemetry/core/backends/chrome/inspector_backend.py b/tools/telemetry/telemetry/core/backends/chrome/inspector_backend.py index ad1cb04..05b26a6 100644 --- a/tools/telemetry/telemetry/core/backends/chrome/inspector_backend.py +++ b/tools/telemetry/telemetry/core/backends/chrome/inspector_backend.py @@ -109,7 +109,8 @@ class InspectorBackend(object): 'window.chrome.gpuBenchmarking.beginWindowSnapshotPNG === undefined'): return False - return self._browser_backend.chrome_branch_number >= 1391 + return (self._browser_backend.chrome_branch_number >= 1391 or + self._browser_backend.is_content_shell) def Screenshot(self, timeout): if self._runtime.Evaluate( diff --git a/ui/android/java/src/org/chromium/ui/WindowAndroid.java b/ui/android/java/src/org/chromium/ui/WindowAndroid.java index 0707eaf..7c8141b 100644 --- a/ui/android/java/src/org/chromium/ui/WindowAndroid.java +++ b/ui/android/java/src/org/chromium/ui/WindowAndroid.java @@ -225,12 +225,10 @@ public class WindowAndroid { @CalledByNative public byte[] grabSnapshot(int windowX, int windowY, int width, int height) { try { - // Take a screenshot of the content view. This generally includes UI - // controls such as the URL bar. - View contentView = mActivity.findViewById(android.R.id.content); - if (contentView == null) return null; - Bitmap bitmap = - UiUtils.generateScaledScreenshot(contentView, 0, Bitmap.Config.ARGB_8888); + // Take a screenshot of the root activity view. This generally includes UI + // controls such as the URL bar and OS windows such as the status bar. + View rootView = mActivity.findViewById(android.R.id.content).getRootView(); + Bitmap bitmap = UiUtils.generateScaledScreenshot(rootView, 0, Bitmap.Config.ARGB_8888); if (bitmap == null) return null; // Clip the result into the requested region. |