Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 gfx::Rect(bitmap.size()), | 273 gfx::Rect(bitmap.size()), |
| 270 static_cast<unsigned char*> (bitmap.pixels())); | 274 static_cast<unsigned char*> (bitmap.pixels())); |
| 271 | 275 |
| 272 WebKit::WebGraphicsContext3D* context = | 276 WebKit::WebGraphicsContext3D* context = |
| 273 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | 277 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); |
| 274 context->deleteTexture(texture); | 278 context->deleteTexture(texture); |
| 275 | 279 |
| 276 return true; | 280 return true; |
| 277 } | 281 } |
| 278 | 282 |
| 283 bool RenderWidgetHostViewAndroid::PopulateBitmapWithContents( | |
|
no sievers
2013/08/07 18:41:43
So this is unneeded then?
pfeldman
2013/08/09 13:59:02
Correct. Removed.
| |
| 284 const gfx::Size& size, SkBitmap* bitmap) { | |
| 285 if (!CompositorImpl::IsInitialized() || | |
| 286 texture_id_in_layer_ == 0 || | |
| 287 texture_size_in_layer_.IsEmpty()) | |
| 288 return false; | |
| 289 | |
| 290 GLHelper* helper = ImageTransportFactoryAndroid::GetInstance()->GetGLHelper(); | |
| 291 | |
| 292 WebKit::WebGLId texture = helper->CopyAndScaleTexture( | |
| 293 texture_id_in_layer_, | |
| 294 texture_size_in_layer_, | |
| 295 size, | |
| 296 true, | |
| 297 GLHelper::SCALER_QUALITY_FAST); | |
| 298 if (texture == 0) | |
| 299 return false; | |
| 300 | |
| 301 helper->ReadbackTextureSync( | |
| 302 texture, | |
| 303 gfx::Rect(size), | |
| 304 static_cast<unsigned char*> (bitmap->getPixels())); | |
| 305 | |
| 306 WebKit::WebGraphicsContext3D* context = | |
| 307 ImageTransportFactoryAndroid::GetInstance()->GetContext3D(); | |
| 308 context->deleteTexture(texture); | |
| 309 | |
| 310 return true; | |
| 311 } | |
| 312 | |
| 279 bool RenderWidgetHostViewAndroid::HasValidFrame() const { | 313 bool RenderWidgetHostViewAndroid::HasValidFrame() const { |
| 280 return texture_id_in_layer_ != 0 && | 314 return texture_id_in_layer_ != 0 && |
| 281 content_view_core_ && | 315 content_view_core_ && |
| 282 !texture_size_in_layer_.IsEmpty(); | 316 !texture_size_in_layer_.IsEmpty(); |
| 283 } | 317 } |
| 284 | 318 |
| 285 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const { | 319 gfx::NativeView RenderWidgetHostViewAndroid::GetNativeView() const { |
| 286 return content_view_core_->GetViewAndroid(); | 320 return content_view_core_->GetViewAndroid(); |
| 287 } | 321 } |
| 288 | 322 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 } | 356 } |
| 323 | 357 |
| 324 bool RenderWidgetHostViewAndroid::HasFocus() const { | 358 bool RenderWidgetHostViewAndroid::HasFocus() const { |
| 325 if (!content_view_core_) | 359 if (!content_view_core_) |
| 326 return false; // ContentViewCore not created yet. | 360 return false; // ContentViewCore not created yet. |
| 327 | 361 |
| 328 return content_view_core_->HasFocus(); | 362 return content_view_core_->HasFocus(); |
| 329 } | 363 } |
| 330 | 364 |
| 331 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { | 365 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { |
| 332 NOTIMPLEMENTED(); | 366 NOTIMPLEMENTED(); |
|
no sievers
2013/08/07 19:51:28
return HasValidFrame()
pfeldman
2013/08/09 13:59:02
Done.
| |
| 333 return false; | 367 return false; |
| 334 } | 368 } |
| 335 | 369 |
| 336 void RenderWidgetHostViewAndroid::Show() { | 370 void RenderWidgetHostViewAndroid::Show() { |
| 337 if (are_layers_attached_) | 371 if (are_layers_attached_) |
| 338 return; | 372 return; |
| 339 | 373 |
| 340 are_layers_attached_ = true; | 374 are_layers_attached_ = true; |
| 341 AttachLayers(); | 375 AttachLayers(); |
| 342 } | 376 } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 | 567 |
| 534 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { | 568 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { |
| 535 RenderWidgetHostViewBase::SetBackground(background); | 569 RenderWidgetHostViewBase::SetBackground(background); |
| 536 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); | 570 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); |
| 537 } | 571 } |
| 538 | 572 |
| 539 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 573 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
| 540 const gfx::Rect& src_subrect, | 574 const gfx::Rect& src_subrect, |
| 541 const gfx::Size& dst_size, | 575 const gfx::Size& dst_size, |
| 542 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 576 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
| 543 NOTIMPLEMENTED(); | 577 if (!CanCopyToBitmap()) { |
| 544 callback.Run(false, SkBitmap()); | 578 callback.Run(false, SkBitmap()); |
| 579 return; | |
| 580 } | |
| 581 | |
| 582 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | |
| 583 scoped_ptr<cc::CopyOutputRequest> request = | |
| 584 cc::CopyOutputRequest::CreateRequest(base::Bind( | |
|
no sievers
2013/08/07 19:51:28
Should this create a bitmap request if we don't ha
Sami
2013/08/08 11:35:00
Yeah, no need to make a redundant copy in that cas
pfeldman
2013/08/09 13:59:02
Done.
| |
| 585 &RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceHasResult, | |
| 586 dst_size_in_pixel, | |
| 587 callback)); | |
| 588 gfx::Rect src_subrect_in_pixel = | |
| 589 ConvertRectToPixel(current_device_scale_factor_, src_subrect); | |
| 590 request->set_area(src_subrect_in_pixel); | |
| 591 layer_->RequestCopyOfOutput(request.Pass()); | |
| 545 } | 592 } |
| 546 | 593 |
| 547 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 594 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
| 548 const gfx::Rect& src_subrect, | 595 const gfx::Rect& src_subrect, |
| 549 const scoped_refptr<media::VideoFrame>& target, | 596 const scoped_refptr<media::VideoFrame>& target, |
| 550 const base::Callback<void(bool)>& callback) { | 597 const base::Callback<void(bool)>& callback) { |
| 551 NOTIMPLEMENTED(); | 598 NOTIMPLEMENTED(); |
| 552 callback.Run(false); | 599 callback.Run(false); |
| 553 } | 600 } |
| 554 | 601 |
| 602 bool RenderWidgetHostViewAndroid::CanCopyToBitmap() const { | |
| 603 return true; | |
| 604 } | |
| 605 | |
| 555 bool RenderWidgetHostViewAndroid::CanCopyToVideoFrame() const { | 606 bool RenderWidgetHostViewAndroid::CanCopyToVideoFrame() const { |
| 556 return false; | 607 return false; |
| 557 } | 608 } |
| 558 | 609 |
| 559 void RenderWidgetHostViewAndroid::ShowDisambiguationPopup( | 610 void RenderWidgetHostViewAndroid::ShowDisambiguationPopup( |
| 560 const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap) { | 611 const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap) { |
| 561 if (!content_view_core_) | 612 if (!content_view_core_) |
| 562 return; | 613 return; |
| 563 | 614 |
| 564 content_view_core_->ShowDisambiguationPopup(target_rect, zoomed_bitmap); | 615 content_view_core_->ShowDisambiguationPopup(target_rect, zoomed_bitmap); |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1146 } | 1197 } |
| 1147 | 1198 |
| 1148 void RenderWidgetHostViewAndroid::OnLostResources() { | 1199 void RenderWidgetHostViewAndroid::OnLostResources() { |
| 1149 if (texture_layer_) | 1200 if (texture_layer_) |
| 1150 texture_layer_->SetIsDrawable(false); | 1201 texture_layer_->SetIsDrawable(false); |
| 1151 texture_id_in_layer_ = 0; | 1202 texture_id_in_layer_ = 0; |
| 1152 RunAckCallbacks(); | 1203 RunAckCallbacks(); |
| 1153 } | 1204 } |
| 1154 | 1205 |
| 1155 // static | 1206 // static |
| 1207 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceHasResult( | |
| 1208 const gfx::Size& dst_size_in_pixel, | |
| 1209 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
| 1210 scoped_ptr<cc::CopyOutputResult> result) { | |
| 1211 if (result->IsEmpty() || result->size().IsEmpty()) { | |
| 1212 callback.Run(false, SkBitmap()); | |
| 1213 return; | |
| 1214 } | |
| 1215 | |
| 1216 if (result->HasTexture()) { | |
| 1217 PrepareTextureCopyOutputResult(dst_size_in_pixel, callback, result.Pass()); | |
| 1218 return; | |
| 1219 } | |
| 1220 | |
| 1221 DCHECK(result->HasBitmap()); | |
| 1222 PrepareBitmapCopyOutputResult(dst_size_in_pixel, callback, result.Pass()); | |
| 1223 } | |
| 1224 | |
| 1225 static void CopyFromCompositingSurfaceFinished( | |
| 1226 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
| 1227 const cc::TextureMailbox::ReleaseCallback& release_callback, | |
| 1228 scoped_ptr<SkBitmap> bitmap, | |
| 1229 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, | |
| 1230 bool result) { | |
| 1231 bitmap_pixels_lock.reset(); | |
| 1232 release_callback.Run(0, false); | |
| 1233 callback.Run(result, *bitmap); | |
| 1234 } | |
| 1235 | |
| 1236 // static | |
| 1237 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | |
| 1238 const gfx::Size& dst_size_in_pixel, | |
| 1239 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
| 1240 scoped_ptr<cc::CopyOutputResult> result) { | |
| 1241 base::ScopedClosureRunner scoped_callback_runner( | |
| 1242 base::Bind(callback, false, SkBitmap())); | |
| 1243 | |
| 1244 DCHECK(result->HasTexture()); | |
| 1245 if (!result->HasTexture()) | |
| 1246 return; | |
| 1247 | |
| 1248 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | |
| 1249 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | |
| 1250 dst_size_in_pixel.width(), dst_size_in_pixel.height()); | |
| 1251 if (!bitmap->allocPixels()) | |
| 1252 return; | |
| 1253 bitmap->setIsOpaque(true); | |
| 1254 | |
| 1255 ImageTransportFactoryAndroid* factory = | |
| 1256 ImageTransportFactoryAndroid::GetInstance(); | |
| 1257 GLHelper* gl_helper = factory->GetGLHelper(); | |
| 1258 if (!gl_helper) | |
| 1259 return; | |
| 1260 | |
| 1261 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | |
| 1262 new SkAutoLockPixels(*bitmap)); | |
| 1263 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | |
| 1264 | |
| 1265 scoped_ptr<cc::TextureMailbox> texture_mailbox = result->TakeTexture(); | |
| 1266 DCHECK(texture_mailbox->IsTexture()); | |
| 1267 if (!texture_mailbox->IsTexture()) | |
| 1268 return; | |
| 1269 | |
| 1270 scoped_callback_runner.Release(); | |
| 1271 | |
| 1272 gl_helper->CropScaleReadbackAndCleanMailbox( | |
| 1273 texture_mailbox->name(), | |
| 1274 texture_mailbox->sync_point(), | |
| 1275 result->size(), | |
| 1276 gfx::Rect(result->size()), | |
| 1277 dst_size_in_pixel, | |
| 1278 pixels, | |
| 1279 base::Bind(&CopyFromCompositingSurfaceFinished, | |
| 1280 callback, | |
| 1281 texture_mailbox->callback(), | |
| 1282 base::Passed(&bitmap), | |
| 1283 base::Passed(&bitmap_pixels_lock))); | |
| 1284 } | |
| 1285 | |
| 1286 // static | |
| 1287 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( | |
| 1288 const gfx::Size& dst_size_in_pixel, | |
| 1289 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
| 1290 scoped_ptr<cc::CopyOutputResult> result) { | |
| 1291 DCHECK(result->HasBitmap()); | |
| 1292 | |
| 1293 base::ScopedClosureRunner scoped_callback_runner( | |
| 1294 base::Bind(callback, false, SkBitmap())); | |
| 1295 if (!result->HasBitmap()) | |
| 1296 return; | |
| 1297 | |
| 1298 scoped_ptr<SkBitmap> source = result->TakeBitmap(); | |
| 1299 DCHECK(source); | |
| 1300 if (!source) | |
| 1301 return; | |
| 1302 | |
| 1303 scoped_callback_runner.Release(); | |
| 1304 | |
| 1305 SkBitmap bitmap = skia::ImageOperations::Resize( | |
|
no sievers
2013/08/07 19:51:28
Let's remove this and dcheck() that the dimensions
pfeldman
2013/08/09 13:59:02
Done.
| |
| 1306 *source, | |
| 1307 skia::ImageOperations::RESIZE_BEST, | |
| 1308 dst_size_in_pixel.width(), | |
| 1309 dst_size_in_pixel.height()); | |
| 1310 callback.Run(true, bitmap); | |
| 1311 } | |
| 1312 | |
| 1313 // static | |
| 1156 void RenderWidgetHostViewPort::GetDefaultScreenInfo( | 1314 void RenderWidgetHostViewPort::GetDefaultScreenInfo( |
| 1157 WebKit::WebScreenInfo* results) { | 1315 WebKit::WebScreenInfo* results) { |
| 1158 const gfx::Display& display = | 1316 const gfx::Display& display = |
| 1159 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 1317 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 1160 results->rect = display.bounds(); | 1318 results->rect = display.bounds(); |
| 1161 // TODO(husky): Remove any system controls from availableRect. | 1319 // TODO(husky): Remove any system controls from availableRect. |
| 1162 results->availableRect = display.work_area(); | 1320 results->availableRect = display.work_area(); |
| 1163 results->deviceScaleFactor = display.device_scale_factor(); | 1321 results->deviceScaleFactor = display.device_scale_factor(); |
| 1164 gfx::DeviceDisplayInfo info; | 1322 gfx::DeviceDisplayInfo info; |
| 1165 results->depth = info.GetBitsPerPixel(); | 1323 results->depth = info.GetBitsPerPixel(); |
| 1166 results->depthPerComponent = info.GetBitsPerComponent(); | 1324 results->depthPerComponent = info.GetBitsPerComponent(); |
| 1167 results->isMonochrome = (results->depthPerComponent == 0); | 1325 results->isMonochrome = (results->depthPerComponent == 0); |
| 1168 } | 1326 } |
| 1169 | 1327 |
| 1170 //////////////////////////////////////////////////////////////////////////////// | 1328 //////////////////////////////////////////////////////////////////////////////// |
| 1171 // RenderWidgetHostView, public: | 1329 // RenderWidgetHostView, public: |
| 1172 | 1330 |
| 1173 // static | 1331 // static |
| 1174 RenderWidgetHostView* | 1332 RenderWidgetHostView* |
| 1175 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1333 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
| 1176 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1334 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 1177 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1335 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
| 1178 } | 1336 } |
| 1179 | 1337 |
| 1180 } // namespace content | 1338 } // namespace content |
| OLD | NEW |