Chromium Code Reviews| Index: content/browser/android/content_view_core_impl.cc |
| diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc |
| index fefc89104c42d7c69e081309dab3400f1d204a01..851d272c5e0a86da4f4762d1c3726e49f64880c1 100644 |
| --- a/content/browser/android/content_view_core_impl.cc |
| +++ b/content/browser/android/content_view_core_impl.cc |
| @@ -7,7 +7,6 @@ |
| #include "base/android/jni_android.h" |
| #include "base/android/jni_array.h" |
| #include "base/android/jni_string.h" |
| -#include "base/android/scoped_java_ref.h" |
| #include "base/command_line.h" |
| #include "base/json/json_writer.h" |
| #include "base/logging.h" |
| @@ -24,6 +23,7 @@ |
| #include "content/browser/frame_host/navigation_entry_impl.h" |
| #include "content/browser/media/android/browser_media_player_manager.h" |
| #include "content/browser/renderer_host/compositor_impl_android.h" |
| +#include "content/browser/renderer_host/dip_util.h" |
| #include "content/browser/renderer_host/input/web_input_event_builders_android.h" |
| #include "content/browser/renderer_host/java/java_bound_object.h" |
| #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h" |
| @@ -457,6 +457,17 @@ void ContentViewCoreImpl::OnTabCrashed() { |
| Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); |
| } |
| +void ContentViewCoreImpl::OnBitmapReady(bool result, const SkBitmap& bitmap) { |
| + JNIEnv* env = AttachCurrentThread(); |
| + ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| + if (obj.is_null()) |
| + return; |
| + java_bitmap_.reset(NULL); |
| + Java_ContentViewCore_onBitmapReady(env, obj.obj(), |
| + result, |
| + jbitmap_.Release()); |
| +} |
| + |
| // All positions and sizes are in CSS pixels. |
| // Note that viewport_width/height is a best effort based. |
| // ContentViewCore has the actual information about the physical viewport size. |
| @@ -570,6 +581,29 @@ void ContentViewCoreImpl::ShowSelectPopupMenu( |
| multiple, selected_array.obj()); |
| } |
| +void ContentViewCoreImpl::ProxyBitmapAllocator(SkBitmap*& bitmap, |
| + const gfx::Size& computed_size, |
| + SkBitmap::Config bitmap_config) |
| +{ |
| + const gfx::Display& display = |
| + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| + float device_scale_factor = display.device_scale_factor(); |
| + gfx::Size dst_size_in_pixel = |
| + ConvertRectToPixel(device_scale_factor, gfx::Rect(computed_size)).size(); |
| + |
| + base::android::ScopedJavaLocalRef<jobject> new_bitmap = |
| + gfx::CreateJavaBitmap(dst_size_in_pixel.width(), |
| + dst_size_in_pixel.height(), |
| + (bitmap_config == SkBitmap::kRGB_565_Config)); |
| + jbitmap_.Reset(AttachCurrentThread(), new_bitmap.obj()); |
| + java_bitmap_.reset(new gfx::JavaBitmap(jbitmap_.obj())); |
| + |
| + bitmap = new SkBitmap(); |
| + bitmap->setConfig(bitmap_config, dst_size_in_pixel.width() , |
| + dst_size_in_pixel.height()); |
| + bitmap->setPixels(java_bitmap_->pixels()); |
| +} |
| + |
| void ContentViewCoreImpl::ConfirmTouchEvent(InputEventAckState ack_result) { |
| touch_disposition_gesture_filter_.OnTouchEventAck(ack_result); |
| } |
| @@ -698,14 +732,18 @@ void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) { |
| void ContentViewCoreImpl::GetScaledContentBitmap( |
| float scale, |
| - const base::Callback<void(bool, const SkBitmap&)>& result_callback) { |
| + const base::Callback<void(bool, const SkBitmap&)>& result_callback, |
| + SkBitmap::Config bitmap_config, |
| + const gfx::Rect& bounding_rect, |
| + const BitmapAllocator bitmap_allocator) { |
| RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| if (!view) { |
| result_callback.Run(false, SkBitmap()); |
| return; |
| } |
| - view->GetScaledContentBitmap(scale, result_callback); |
| + view->GetScaledContentBitmap(scale, result_callback, |
| + bitmap_config, bounding_rect, bitmap_allocator); |
| } |
| void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { |
| @@ -1469,6 +1507,35 @@ jboolean ContentViewCoreImpl::PopulateBitmapFromCompositor(JNIEnv* env, |
| return view->PopulateBitmapWithContents(jbitmap); |
| } |
| +void ContentViewCoreImpl::PopulateBitmapFromCompositorAsync( |
| + JNIEnv* env, |
| + jobject obj, |
| + jint x, |
| + jint y, |
| + jint width, |
| + jint height, |
| + jfloat scale, |
| + jobject jbitmap_config) { |
| + RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| + if (!view) |
| + return; |
| + |
| + base::Callback<void(bool, const SkBitmap&)> callback = |
| + base::Bind(&ContentViewCoreImpl::OnBitmapReady, |
| + base::Unretained(this)); |
| + |
| + BitmapAllocator bitmap_allocator = |
| + base::Bind(&ContentViewCoreImpl::ProxyBitmapAllocator, |
| + base::Unretained(this)); |
| + |
| + //SkBitmap::Config bitmap_config = gfx::ConvertToSkiaConfig(jbitmap_config); |
|
vivekg
2014/02/26 01:44:46
This would be enabled once https://codereview.chro
|
| + SkBitmap::Config bitmap_config = SkBitmap::kARGB_8888_Config; |
| + |
| + GetScaledContentBitmap(scale, callback, bitmap_config, |
| + gfx::Rect(x, y, width, height), |
| + bitmap_allocator); |
| +} |
| + |
| void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { |
| RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| if (view) |