summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorclamy@chromium.org <clamy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-27 12:55:46 +0000
committerclamy@chromium.org <clamy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-27 12:55:46 +0000
commit3fdd7b895a52a95723b63781595dd8188cf67beb (patch)
tree1a99ee13eccb4aa9b8167a30fd157cde7de159da /content
parent395f6fd0ad5c1a754c12933ae3a1556ef1b95493 (diff)
downloadchromium_src-3fdd7b895a52a95723b63781595dd8188cf67beb.zip
chromium_src-3fdd7b895a52a95723b63781595dd8188cf67beb.tar.gz
chromium_src-3fdd7b895a52a95723b63781595dd8188cf67beb.tar.bz2
Revert "Adds support for capturing a sub rect of the compositing surface."
This reverts https://codereview.chromium.org/173023005. It is an Android only change breaking downstream Android bots. TBR=clholgat@chromium.org,sievers@chromium.org,tedchoc@chromium.org BUG= Review URL: https://codereview.chromium.org/183063002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253763 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/android/content_view_core_impl.cc14
-rw-r--r--content/browser/android/content_view_core_impl.h4
-rw-r--r--content/browser/renderer_host/render_widget_host_view_android.cc40
-rw-r--r--content/browser/renderer_host/render_widget_host_view_android.h2
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/ContentView.java16
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java56
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/PageInfo.java16
-rw-r--r--content/public/browser/android/content_view_core.h2
8 files changed, 138 insertions, 12 deletions
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc
index ecc627f..357d2a9 100644
--- a/content/browser/android/content_view_core_impl.cc
+++ b/content/browser/android/content_view_core_impl.cc
@@ -699,7 +699,6 @@ void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) {
void ContentViewCoreImpl::GetScaledContentBitmap(
float scale,
jobject jbitmap_config,
- gfx::Rect src_subrect,
const base::Callback<void(bool, const SkBitmap&)>& result_callback) {
RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
if (!view) {
@@ -707,8 +706,7 @@ void ContentViewCoreImpl::GetScaledContentBitmap(
return;
}
SkBitmap::Config skbitmap_format = gfx::ConvertToSkiaConfig(jbitmap_config);
- view->GetScaledContentBitmap(scale, skbitmap_format, src_subrect,
- result_callback);
+ view->GetScaledContentBitmap(scale, skbitmap_format, result_callback);
}
void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) {
@@ -1462,6 +1460,16 @@ jboolean ContentViewCoreImpl::OnAnimate(JNIEnv* env, jobject /* obj */,
return view->Animate(base::TimeTicks::FromInternalValue(frame_time_micros));
}
+jboolean ContentViewCoreImpl::PopulateBitmapFromCompositor(JNIEnv* env,
+ jobject obj,
+ jobject jbitmap) {
+ RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
+ if (!view)
+ return false;
+
+ return view->PopulateBitmapWithContents(jbitmap);
+}
+
void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) {
RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
if (view)
diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h
index 595f418..1e63521 100644
--- a/content/browser/android/content_view_core_impl.h
+++ b/content/browser/android/content_view_core_impl.h
@@ -60,7 +60,6 @@ class ContentViewCoreImpl : public ContentViewCore,
virtual void GetScaledContentBitmap(
float scale,
jobject bitmap_config,
- gfx::Rect src_subrect,
const base::Callback<void(bool, const SkBitmap&)>& result_callback)
OVERRIDE;
virtual float GetDpiScale() const OVERRIDE;
@@ -199,6 +198,9 @@ class ContentViewCoreImpl : public ContentViewCore,
jlong interval_micros);
void OnVSync(JNIEnv* env, jobject /* obj */, jlong frame_time_micros);
jboolean OnAnimate(JNIEnv* env, jobject /* obj */, jlong frame_time_micros);
+ jboolean PopulateBitmapFromCompositor(JNIEnv* env,
+ jobject obj,
+ jobject jbitmap);
void WasResized(JNIEnv* env, jobject obj);
jboolean IsRenderWidgetHostViewReady(JNIEnv* env, jobject obj);
void ExitFullscreen(JNIEnv* env, jobject obj);
diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc
index 7f7f82f..8db7f7c 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.cc
+++ b/content/browser/renderer_host/render_widget_host_view_android.cc
@@ -254,7 +254,6 @@ void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) {
void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
float scale,
SkBitmap::Config bitmap_config,
- gfx::Rect src_subrect,
const base::Callback<void(bool, const SkBitmap&)>& result_callback) {
if (!IsSurfaceAvailableForCopy()) {
result_callback.Run(false, SkBitmap());
@@ -262,10 +261,7 @@ void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
}
gfx::Size bounds = layer_->bounds();
- if (src_subrect.IsEmpty())
- src_subrect = gfx::Rect(bounds);
- DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width());
- DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height());
+ gfx::Rect src_subrect(bounds);
const gfx::Display& display =
gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
float device_scale_factor = display.device_scale_factor();
@@ -276,6 +272,40 @@ void RenderWidgetHostViewAndroid::GetScaledContentBitmap(
src_subrect, dst_size, result_callback, bitmap_config);
}
+bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents(jobject jbitmap) {
+ if (!CompositorImpl::IsInitialized() ||
+ texture_id_in_layer_ == 0 ||
+ texture_size_in_layer_.IsEmpty())
+ return false;
+
+ gfx::JavaBitmap bitmap(jbitmap);
+
+ // TODO(dtrainor): Eventually add support for multiple formats here.
+ DCHECK(bitmap.format() == ANDROID_BITMAP_FORMAT_RGBA_8888);
+
+ GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper();
+
+ GLuint texture = helper->CopyAndScaleTexture(
+ texture_id_in_layer_,
+ texture_size_in_layer_,
+ bitmap.size(),
+ true,
+ GLHelper::SCALER_QUALITY_FAST);
+ if (texture == 0u)
+ return false;
+
+ helper->ReadbackTextureSync(texture,
+ gfx::Rect(bitmap.size()),
+ static_cast<unsigned char*> (bitmap.pixels()),
+ SkBitmap::kARGB_8888_Config);
+
+ gpu::gles2::GLES2Interface* gl =
+ ImageTransportFactoryAndroid::GetInstance()->GetContextGL();
+ gl->DeleteTextures(1, &texture);
+
+ return true;
+}
+
bool RenderWidgetHostViewAndroid::HasValidFrame() const {
if (!content_view_core_)
return false;
diff --git a/content/browser/renderer_host/render_widget_host_view_android.h b/content/browser/renderer_host/render_widget_host_view_android.h
index 8bd493f..9709180 100644
--- a/content/browser/renderer_host/render_widget_host_view_android.h
+++ b/content/browser/renderer_host/render_widget_host_view_android.h
@@ -227,8 +227,8 @@ class RenderWidgetHostViewAndroid
void GetScaledContentBitmap(
float scale,
SkBitmap::Config bitmap_config,
- gfx::Rect src_subrect,
const base::Callback<void(bool, const SkBitmap&)>& result_callback);
+ bool PopulateBitmapWithContents(jobject jbitmap);
bool HasValidFrame() const;
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 2a45f7e2..40221a3 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
@@ -6,6 +6,7 @@ package org.chromium.content.browser;
import android.content.Context;
import android.content.res.Configuration;
+import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Build;
@@ -122,6 +123,21 @@ public class ContentView extends FrameLayout
}
@Override
+ public boolean isReadyForSnapshot() {
+ return mContentViewCore.isReady();
+ }
+
+ @Override
+ public Bitmap getBitmap() {
+ return getBitmap(getWidth(), getHeight());
+ }
+
+ @Override
+ public Bitmap getBitmap(int width, int height) {
+ return mContentViewCore.getBitmap(width, height);
+ }
+
+ @Override
public int getBackgroundColor() {
return mContentViewCore.getBackgroundColor();
}
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 df8988f..43e166f 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
@@ -27,6 +27,7 @@ import android.provider.Settings;
import android.text.Editable;
import android.text.TextUtils;
import android.util.Log;
+import android.util.Pair;
import android.view.ActionMode;
import android.view.HapticFeedbackConstants;
import android.view.InputDevice;
@@ -1034,6 +1035,58 @@ public class ContentViewCore
return mRenderCoordinates.getContentWidthCss();
}
+ public Bitmap getBitmap() {
+ return getBitmap(getViewportWidthPix(), getViewportHeightPix());
+ }
+
+ public Bitmap getBitmap(int width, int height) {
+ if (width == 0 || height == 0
+ || getViewportWidthPix() == 0 || getViewportHeightPix() == 0) {
+ return null;
+ }
+
+ Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+
+ if (mNativeContentViewCore != 0 &&
+ nativePopulateBitmapFromCompositor(mNativeContentViewCore, b)) {
+ // If we successfully grabbed a bitmap, check if we have to draw the Android overlay
+ // components as well.
+ if (mContainerView.getChildCount() > 0) {
+ Canvas c = new Canvas(b);
+ c.scale(width / (float) getViewportWidthPix(),
+ height / (float) getViewportHeightPix());
+ mContainerView.draw(c);
+ }
+ return b;
+ }
+
+ return null;
+ }
+
+ /**
+ * Generates a bitmap of the content that is performance optimized based on capture time.
+ *
+ * <p>
+ * To have a consistent capture time across devices, we will scale down the captured bitmap
+ * where necessary to reduce the time to generate the bitmap.
+ *
+ * @param width The width of the content to be captured.
+ * @param height The height of the content to be captured.
+ * @return A pair of the generated bitmap, and the scale that needs to be applied to return the
+ * bitmap to it's original size (i.e. if the bitmap is scaled down 50%, this
+ * will be 2).
+ */
+ public Pair<Bitmap, Float> getScaledPerformanceOptimizedBitmap(int width, int height) {
+ float scale = 1f;
+ // On tablets, always scale down to MDPI for performance reasons.
+ if (DeviceUtils.isTablet(getContext())) {
+ scale = getContext().getResources().getDisplayMetrics().density;
+ }
+ return Pair.create(
+ getBitmap((int) (width / scale), (int) (height / scale)),
+ scale);
+ }
+
// TODO(teddchoc): Remove all these navigation controller methods from here and have the
// embedders manage it.
/**
@@ -3391,6 +3444,9 @@ public class ContentViewCore
private native boolean nativeOnAnimate(long nativeContentViewCoreImpl, long frameTimeMicros);
+ private native boolean nativePopulateBitmapFromCompositor(long nativeContentViewCoreImpl,
+ Bitmap bitmap);
+
private native void nativeWasResized(long nativeContentViewCoreImpl);
private native boolean nativeIsRenderWidgetHostViewReady(long nativeContentViewCoreImpl);
diff --git a/content/public/android/java/src/org/chromium/content/browser/PageInfo.java b/content/public/android/java/src/org/chromium/content/browser/PageInfo.java
index 2a8830c..07e4352 100644
--- a/content/public/android/java/src/org/chromium/content/browser/PageInfo.java
+++ b/content/public/android/java/src/org/chromium/content/browser/PageInfo.java
@@ -4,6 +4,7 @@
package org.chromium.content.browser;
+import android.graphics.Bitmap;
import android.view.View;
/**
@@ -18,6 +19,21 @@ public interface PageInfo {
String getTitle();
/**
+ * @return True, if the view is in a suitable state for a snapshot.
+ */
+ boolean isReadyForSnapshot();
+
+ /**
+ * @return An unscaled screenshot of the page.
+ */
+ Bitmap getBitmap();
+
+ /**
+ * @return A screenshot of the page scaled to the specified size.
+ */
+ Bitmap getBitmap(int width, int height);
+
+ /**
* @return The background color of the page.
*/
int getBackgroundColor();
diff --git a/content/public/browser/android/content_view_core.h b/content/public/browser/android/content_view_core.h
index ff1db97..0f3503e 100644
--- a/content/public/browser/android/content_view_core.h
+++ b/content/public/browser/android/content_view_core.h
@@ -11,7 +11,6 @@
#include "base/callback.h"
#include "content/common/content_export.h"
#include "content/public/browser/navigation_controller.h"
-#include "ui/gfx/rect.h"
class SkBitmap;
@@ -58,7 +57,6 @@ class CONTENT_EXPORT ContentViewCore {
virtual void GetScaledContentBitmap(
float scale,
jobject bitmap_config,
- gfx::Rect src_rect,
const base::Callback<void(bool, const SkBitmap&)>& result_callback) = 0;
virtual float GetDpiScale() const = 0;
virtual void PauseVideo() = 0;