Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 21777003: DevTools: [Android] implement RenderWidgetHostViewAndroid::CopyFromCompositingSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For landing Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_widget_host_view_android.h" 5 #include "content/browser/renderer_host/render_widget_host_view_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/worker_pool.h" 15 #include "base/threading/worker_pool.h"
16 #include "cc/layers/delegated_renderer_layer.h" 16 #include "cc/layers/delegated_renderer_layer.h"
17 #include "cc/layers/layer.h" 17 #include "cc/layers/layer.h"
18 #include "cc/layers/texture_layer.h" 18 #include "cc/layers/texture_layer.h"
19 #include "cc/output/compositor_frame.h" 19 #include "cc/output/compositor_frame.h"
20 #include "cc/output/compositor_frame_ack.h" 20 #include "cc/output/compositor_frame_ack.h"
21 #include "cc/output/copy_output_request.h"
22 #include "cc/output/copy_output_result.h"
21 #include "cc/trees/layer_tree_host.h" 23 #include "cc/trees/layer_tree_host.h"
22 #include "content/browser/accessibility/browser_accessibility_manager_android.h" 24 #include "content/browser/accessibility/browser_accessibility_manager_android.h"
23 #include "content/browser/android/content_view_core_impl.h" 25 #include "content/browser/android/content_view_core_impl.h"
24 #include "content/browser/android/in_process/synchronous_compositor_impl.h" 26 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
25 #include "content/browser/android/overscroll_glow.h" 27 #include "content/browser/android/overscroll_glow.h"
26 #include "content/browser/gpu/gpu_surface_tracker.h" 28 #include "content/browser/gpu/gpu_surface_tracker.h"
27 #include "content/browser/renderer_host/compositor_impl_android.h" 29 #include "content/browser/renderer_host/compositor_impl_android.h"
30 #include "content/browser/renderer_host/dip_util.h"
28 #include "content/browser/renderer_host/image_transport_factory_android.h" 31 #include "content/browser/renderer_host/image_transport_factory_android.h"
29 #include "content/browser/renderer_host/render_widget_host_impl.h" 32 #include "content/browser/renderer_host/render_widget_host_impl.h"
30 #include "content/browser/renderer_host/surface_texture_transport_client_android .h" 33 #include "content/browser/renderer_host/surface_texture_transport_client_android .h"
31 #include "content/browser/renderer_host/touch_smooth_scroll_gesture_android.h" 34 #include "content/browser/renderer_host/touch_smooth_scroll_gesture_android.h"
32 #include "content/common/gpu/client/gl_helper.h" 35 #include "content/common/gpu/client/gl_helper.h"
33 #include "content/common/gpu/gpu_messages.h" 36 #include "content/common/gpu/gpu_messages.h"
34 #include "content/common/input_messages.h" 37 #include "content/common/input_messages.h"
35 #include "content/common/view_messages.h" 38 #include "content/common/view_messages.h"
36 #include "content/public/common/content_switches.h" 39 #include "content/public/common/content_switches.h"
40 #include "skia/ext/image_operations.h"
37 #include "third_party/khronos/GLES2/gl2.h" 41 #include "third_party/khronos/GLES2/gl2.h"
38 #include "third_party/khronos/GLES2/gl2ext.h" 42 #include "third_party/khronos/GLES2/gl2ext.h"
39 #include "ui/gfx/android/device_display_info.h" 43 #include "ui/gfx/android/device_display_info.h"
40 #include "ui/gfx/android/java_bitmap.h" 44 #include "ui/gfx/android/java_bitmap.h"
41 #include "ui/gfx/display.h" 45 #include "ui/gfx/display.h"
42 #include "ui/gfx/screen.h" 46 #include "ui/gfx/screen.h"
43 #include "ui/gfx/size_conversions.h" 47 #include "ui/gfx/size_conversions.h"
44 48
45 namespace content { 49 namespace content {
46 50
(...skipping 28 matching lines...) Expand all
75 } 79 }
76 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 80 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
77 route_id, output_surface_id, renderer_host_id, ack); 81 route_id, output_surface_id, renderer_host_id, ack);
78 } 82 }
79 83
80 // Sends an acknowledgement to the renderer of a processed IME event. 84 // Sends an acknowledgement to the renderer of a processed IME event.
81 void SendImeEventAck(RenderWidgetHostImpl* host) { 85 void SendImeEventAck(RenderWidgetHostImpl* host) {
82 host->Send(new ViewMsg_ImeEventAck(host->GetRoutingID())); 86 host->Send(new ViewMsg_ImeEventAck(host->GetRoutingID()));
83 } 87 }
84 88
89 void CopyFromCompositingSurfaceFinished(
90 const base::Callback<void(bool, const SkBitmap&)>& callback,
91 const cc::TextureMailbox::ReleaseCallback& release_callback,
92 scoped_ptr<SkBitmap> bitmap,
93 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock,
94 bool result) {
95 bitmap_pixels_lock.reset();
96 release_callback.Run(0, false);
97 callback.Run(result, *bitmap);
98 }
99
85 } // anonymous namespace 100 } // anonymous namespace
86 101
87 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( 102 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid(
88 RenderWidgetHostImpl* widget_host, 103 RenderWidgetHostImpl* widget_host,
89 ContentViewCoreImpl* content_view_core) 104 ContentViewCoreImpl* content_view_core)
90 : host_(widget_host), 105 : host_(widget_host),
91 needs_begin_frame_(false), 106 needs_begin_frame_(false),
92 are_layers_attached_(true), 107 are_layers_attached_(true),
93 content_view_core_(NULL), 108 content_view_core_(NULL),
94 ime_adapter_android_(this), 109 ime_adapter_android_(this),
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 337 }
323 338
324 bool RenderWidgetHostViewAndroid::HasFocus() const { 339 bool RenderWidgetHostViewAndroid::HasFocus() const {
325 if (!content_view_core_) 340 if (!content_view_core_)
326 return false; // ContentViewCore not created yet. 341 return false; // ContentViewCore not created yet.
327 342
328 return content_view_core_->HasFocus(); 343 return content_view_core_->HasFocus();
329 } 344 }
330 345
331 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { 346 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const {
332 NOTIMPLEMENTED(); 347 return HasValidFrame();
333 return false;
334 } 348 }
335 349
336 void RenderWidgetHostViewAndroid::Show() { 350 void RenderWidgetHostViewAndroid::Show() {
337 if (are_layers_attached_) 351 if (are_layers_attached_)
338 return; 352 return;
339 353
340 are_layers_attached_ = true; 354 are_layers_attached_ = true;
341 AttachLayers(); 355 AttachLayers();
342 } 356 }
343 357
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 547
534 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { 548 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) {
535 RenderWidgetHostViewBase::SetBackground(background); 549 RenderWidgetHostViewBase::SetBackground(background);
536 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); 550 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background));
537 } 551 }
538 552
539 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( 553 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
540 const gfx::Rect& src_subrect, 554 const gfx::Rect& src_subrect,
541 const gfx::Size& dst_size, 555 const gfx::Size& dst_size,
542 const base::Callback<void(bool, const SkBitmap&)>& callback) { 556 const base::Callback<void(bool, const SkBitmap&)>& callback) {
543 NOTIMPLEMENTED(); 557 if (!IsSurfaceAvailableForCopy()) {
544 callback.Run(false, SkBitmap()); 558 callback.Run(false, SkBitmap());
559 return;
560 }
561
562 const gfx::Display& display =
563 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
564 float device_scale_factor = display.device_scale_factor();
565
566 DCHECK_EQ(device_scale_factor,
567 ui::GetScaleFactorScale(GetScaleFactorForView(this)));
568
569 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size);
570 gfx::Rect src_subrect_in_pixel =
571 ConvertRectToPixel(device_scale_factor, src_subrect);
572
573 scoped_ptr<cc::CopyOutputRequest> request;
574 if (src_subrect_in_pixel.size() == dst_size_in_pixel) {
575 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind(
576 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult,
577 dst_size_in_pixel,
578 callback));
579 } else {
580 request = cc::CopyOutputRequest::CreateRequest(base::Bind(
581 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult,
582 dst_size_in_pixel,
583 callback));
584 }
585 request->set_area(src_subrect_in_pixel);
586 layer_->RequestCopyOfOutput(request.Pass());
545 } 587 }
546 588
547 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( 589 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame(
548 const gfx::Rect& src_subrect, 590 const gfx::Rect& src_subrect,
549 const scoped_refptr<media::VideoFrame>& target, 591 const scoped_refptr<media::VideoFrame>& target,
550 const base::Callback<void(bool)>& callback) { 592 const base::Callback<void(bool)>& callback) {
551 NOTIMPLEMENTED(); 593 NOTIMPLEMENTED();
552 callback.Run(false); 594 callback.Run(false);
553 } 595 }
554 596
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 } 1188 }
1147 1189
1148 void RenderWidgetHostViewAndroid::OnLostResources() { 1190 void RenderWidgetHostViewAndroid::OnLostResources() {
1149 if (texture_layer_) 1191 if (texture_layer_)
1150 texture_layer_->SetIsDrawable(false); 1192 texture_layer_->SetIsDrawable(false);
1151 texture_id_in_layer_ = 0; 1193 texture_id_in_layer_ = 0;
1152 RunAckCallbacks(); 1194 RunAckCallbacks();
1153 } 1195 }
1154 1196
1155 // static 1197 // static
1198 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult(
1199 const gfx::Size& dst_size_in_pixel,
1200 const base::Callback<void(bool, const SkBitmap&)>& callback,
1201 scoped_ptr<cc::CopyOutputResult> result) {
1202 DCHECK(result->HasTexture());
1203 base::ScopedClosureRunner scoped_callback_runner(
1204 base::Bind(callback, false, SkBitmap()));
1205
1206 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty())
1207 return;
1208
1209 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
1210 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
1211 dst_size_in_pixel.width(), dst_size_in_pixel.height());
1212 if (!bitmap->allocPixels())
1213 return;
1214 bitmap->setIsOpaque(true);
1215
1216 ImageTransportFactoryAndroid* factory =
1217 ImageTransportFactoryAndroid::GetInstance();
1218 GLHelper* gl_helper = factory->GetGLHelper();
1219 if (!gl_helper)
1220 return;
1221
1222 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock(
1223 new SkAutoLockPixels(*bitmap));
1224 uint8* pixels = static_cast<uint8*>(bitmap->getPixels());
1225
1226 scoped_ptr<cc::TextureMailbox> texture_mailbox = result->TakeTexture();
1227 DCHECK(texture_mailbox->IsTexture());
1228 if (!texture_mailbox->IsTexture())
1229 return;
1230
1231 scoped_callback_runner.Release();
1232
1233 gl_helper->CropScaleReadbackAndCleanMailbox(
1234 texture_mailbox->name(),
1235 texture_mailbox->sync_point(),
1236 result->size(),
1237 gfx::Rect(result->size()),
1238 dst_size_in_pixel,
1239 pixels,
1240 base::Bind(&CopyFromCompositingSurfaceFinished,
1241 callback,
1242 texture_mailbox->callback(),
1243 base::Passed(&bitmap),
1244 base::Passed(&bitmap_pixels_lock)));
1245 }
1246
1247 // static
1248 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult(
1249 const gfx::Size& dst_size_in_pixel,
1250 const base::Callback<void(bool, const SkBitmap&)>& callback,
1251 scoped_ptr<cc::CopyOutputResult> result) {
1252 DCHECK(result->HasBitmap());
1253 base::ScopedClosureRunner scoped_callback_runner(
1254 base::Bind(callback, false, SkBitmap()));
1255
1256 if (!result->HasBitmap() || result->IsEmpty() || result->size().IsEmpty())
1257 return;
1258
1259 scoped_ptr<SkBitmap> source = result->TakeBitmap();
1260 DCHECK(source);
1261 if (!source)
1262 return;
1263
1264 DCHECK_EQ(source->width(), dst_size_in_pixel.width());
1265 DCHECK_EQ(source->height(), dst_size_in_pixel.height());
1266
1267 scoped_callback_runner.Release();
1268 callback.Run(true, *source);
1269 }
1270
1271 // static
1156 void RenderWidgetHostViewPort::GetDefaultScreenInfo( 1272 void RenderWidgetHostViewPort::GetDefaultScreenInfo(
1157 WebKit::WebScreenInfo* results) { 1273 WebKit::WebScreenInfo* results) {
1158 const gfx::Display& display = 1274 const gfx::Display& display =
1159 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 1275 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
1160 results->rect = display.bounds(); 1276 results->rect = display.bounds();
1161 // TODO(husky): Remove any system controls from availableRect. 1277 // TODO(husky): Remove any system controls from availableRect.
1162 results->availableRect = display.work_area(); 1278 results->availableRect = display.work_area();
1163 results->deviceScaleFactor = display.device_scale_factor(); 1279 results->deviceScaleFactor = display.device_scale_factor();
1164 gfx::DeviceDisplayInfo info; 1280 gfx::DeviceDisplayInfo info;
1165 results->depth = info.GetBitsPerPixel(); 1281 results->depth = info.GetBitsPerPixel();
1166 results->depthPerComponent = info.GetBitsPerComponent(); 1282 results->depthPerComponent = info.GetBitsPerComponent();
1167 results->isMonochrome = (results->depthPerComponent == 0); 1283 results->isMonochrome = (results->depthPerComponent == 0);
1168 } 1284 }
1169 1285
1170 //////////////////////////////////////////////////////////////////////////////// 1286 ////////////////////////////////////////////////////////////////////////////////
1171 // RenderWidgetHostView, public: 1287 // RenderWidgetHostView, public:
1172 1288
1173 // static 1289 // static
1174 RenderWidgetHostView* 1290 RenderWidgetHostView*
1175 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 1291 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
1176 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 1292 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
1177 return new RenderWidgetHostViewAndroid(rwhi, NULL); 1293 return new RenderWidgetHostViewAndroid(rwhi, NULL);
1178 } 1294 }
1179 1295
1180 } // namespace content 1296 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698