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/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 if (rect.IsEmpty()) | 321 if (rect.IsEmpty()) |
322 return rect; | 322 return rect; |
323 | 323 |
324 rect.Union(controller.GetStartHandleRect()); | 324 rect.Union(controller.GetStartHandleRect()); |
325 rect.Union(controller.GetEndHandleRect()); | 325 rect.Union(controller.GetEndHandleRect()); |
326 return rect; | 326 return rect; |
327 } | 327 } |
328 | 328 |
329 } // anonymous namespace | 329 } // anonymous namespace |
330 | 330 |
331 ReadbackRequest::ReadbackRequest(float scale, | |
332 SkColorType color_type, | |
333 gfx::Rect src_subrect, | |
334 ReadbackRequestCallback& result_callback) | |
335 : scale_(scale), | |
336 color_type_(color_type), | |
337 src_subrect_(src_subrect), | |
338 result_callback_(result_callback) { | |
339 } | |
340 | |
341 ReadbackRequest::ReadbackRequest() { | |
342 } | |
343 | |
344 ReadbackRequest::~ReadbackRequest() { | |
345 } | |
346 | |
347 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( | 331 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( |
348 uint32 output_id, | 332 uint32 output_id, |
349 scoped_ptr<cc::CompositorFrame> output_frame) | 333 scoped_ptr<cc::CompositorFrame> output_frame) |
350 : output_surface_id(output_id), frame(output_frame.Pass()) {} | 334 : output_surface_id(output_id), frame(output_frame.Pass()) {} |
351 | 335 |
352 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} | 336 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} |
353 | 337 |
354 void RenderWidgetHostViewAndroid::OnContextLost() { | 338 void RenderWidgetHostViewAndroid::OnContextLost() { |
355 scoped_ptr<RenderWidgetHostIterator> widgets( | 339 scoped_ptr<RenderWidgetHostIterator> widgets( |
356 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | 340 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); |
(...skipping 23 matching lines...) Expand all Loading... |
380 locks_on_frame_count_(0), | 364 locks_on_frame_count_(0), |
381 observing_root_window_(false), | 365 observing_root_window_(false), |
382 weak_ptr_factory_(this) { | 366 weak_ptr_factory_(this) { |
383 host_->SetView(this); | 367 host_->SetView(this); |
384 SetContentViewCore(content_view_core); | 368 SetContentViewCore(content_view_core); |
385 } | 369 } |
386 | 370 |
387 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { | 371 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { |
388 SetContentViewCore(NULL); | 372 SetContentViewCore(NULL); |
389 DCHECK(ack_callbacks_.empty()); | 373 DCHECK(ack_callbacks_.empty()); |
390 DCHECK(readbacks_waiting_for_frame_.empty()); | |
391 if (resource_collection_.get()) | 374 if (resource_collection_.get()) |
392 resource_collection_->SetClient(NULL); | 375 resource_collection_->SetClient(NULL); |
393 DCHECK(!surface_factory_); | 376 DCHECK(!surface_factory_); |
394 DCHECK(surface_id_.is_null()); | 377 DCHECK(surface_id_.is_null()); |
395 } | 378 } |
396 | 379 |
397 | 380 |
398 bool RenderWidgetHostViewAndroid::OnMessageReceived( | 381 bool RenderWidgetHostViewAndroid::OnMessageReceived( |
399 const IPC::Message& message) { | 382 const IPC::Message& message) { |
400 bool handled = true; | 383 bool handled = true; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { | 424 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { |
442 // Ignore the given size as only the Java code has the power to | 425 // Ignore the given size as only the Java code has the power to |
443 // resize the view on Android. | 426 // resize the view on Android. |
444 default_size_ = size; | 427 default_size_ = size; |
445 } | 428 } |
446 | 429 |
447 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { | 430 void RenderWidgetHostViewAndroid::SetBounds(const gfx::Rect& rect) { |
448 SetSize(rect.size()); | 431 SetSize(rect.size()); |
449 } | 432 } |
450 | 433 |
451 void RenderWidgetHostViewAndroid::AbortPendingReadbackRequests() { | |
452 while (!readbacks_waiting_for_frame_.empty()) { | |
453 ReadbackRequest& readback_request = readbacks_waiting_for_frame_.front(); | |
454 readback_request.GetResultCallback().Run(SkBitmap(), READBACK_FAILED); | |
455 readbacks_waiting_for_frame_.pop(); | |
456 } | |
457 } | |
458 | |
459 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( | 434 void RenderWidgetHostViewAndroid::GetScaledContentBitmap( |
460 float scale, | 435 float scale, |
461 SkColorType color_type, | 436 SkColorType color_type, |
462 gfx::Rect src_subrect, | 437 gfx::Rect src_subrect, |
463 ReadbackRequestCallback& result_callback) { | 438 ReadbackRequestCallback& result_callback) { |
464 if (!host_ || host_->is_hidden()) { | 439 if (!host_ || host_->is_hidden() || !IsSurfaceAvailableForCopy()) { |
465 result_callback.Run(SkBitmap(), READBACK_NOT_SUPPORTED); | 440 result_callback.Run(SkBitmap(), READBACK_NOT_SUPPORTED); |
466 return; | 441 return; |
467 } | 442 } |
468 if (!IsSurfaceAvailableForCopy()) { | |
469 // The view is visible, probably the frame has not yet arrived. | |
470 // Just add the ReadbackRequest to queue and wait for frame arrival | |
471 // to get this request processed. | |
472 readbacks_waiting_for_frame_.push( | |
473 ReadbackRequest(scale, color_type, src_subrect, result_callback)); | |
474 return; | |
475 } | |
476 | |
477 gfx::Size bounds = layer_->bounds(); | 443 gfx::Size bounds = layer_->bounds(); |
478 if (src_subrect.IsEmpty()) | 444 if (src_subrect.IsEmpty()) |
479 src_subrect = gfx::Rect(bounds); | 445 src_subrect = gfx::Rect(bounds); |
480 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); | 446 DCHECK_LE(src_subrect.width() + src_subrect.x(), bounds.width()); |
481 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); | 447 DCHECK_LE(src_subrect.height() + src_subrect.y(), bounds.height()); |
482 const gfx::Display& display = | 448 const gfx::Display& display = |
483 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 449 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
484 float device_scale_factor = display.device_scale_factor(); | 450 float device_scale_factor = display.device_scale_factor(); |
485 DCHECK_GT(device_scale_factor, 0); | 451 DCHECK_GT(device_scale_factor, 0); |
486 gfx::Size dst_size( | 452 gfx::Size dst_size( |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 return; | 573 return; |
608 | 574 |
609 is_showing_ = false; | 575 is_showing_ = false; |
610 if (layer_.get() && locks_on_frame_count_ == 0) | 576 if (layer_.get() && locks_on_frame_count_ == 0) |
611 layer_->SetHideLayerAndSubtree(true); | 577 layer_->SetHideLayerAndSubtree(true); |
612 | 578 |
613 if (overscroll_controller_) | 579 if (overscroll_controller_) |
614 overscroll_controller_->Disable(); | 580 overscroll_controller_->Disable(); |
615 | 581 |
616 frame_evictor_->SetVisible(false); | 582 frame_evictor_->SetVisible(false); |
617 // We don't know if we will ever get a frame if we are hiding the renderer, so | |
618 // we need to cancel all requests | |
619 AbortPendingReadbackRequests(); | |
620 | 583 |
621 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); | 584 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); |
622 | 585 |
623 if (!host_ || host_->is_hidden()) | 586 if (!host_ || host_->is_hidden()) |
624 return; | 587 return; |
625 | 588 |
626 // Inform the renderer that we are being hidden so it can reduce its resource | 589 // Inform the renderer that we are being hidden so it can reduce its resource |
627 // utilization. | 590 // utilization. |
628 host_->WasHidden(); | 591 host_->WasHidden(); |
629 | 592 |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 | 1043 |
1081 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { | 1044 void RenderWidgetHostViewAndroid::DestroyDelegatedContent() { |
1082 RemoveLayers(); | 1045 RemoveLayers(); |
1083 frame_provider_ = NULL; | 1046 frame_provider_ = NULL; |
1084 if (!surface_id_.is_null()) { | 1047 if (!surface_id_.is_null()) { |
1085 DCHECK(surface_factory_.get()); | 1048 DCHECK(surface_factory_.get()); |
1086 surface_factory_->Destroy(surface_id_); | 1049 surface_factory_->Destroy(surface_id_); |
1087 surface_id_ = cc::SurfaceId(); | 1050 surface_id_ = cc::SurfaceId(); |
1088 } | 1051 } |
1089 layer_ = NULL; | 1052 layer_ = NULL; |
1090 // This gets called when ever any eviction, loosing resources, swapping | |
1091 // problems are encountered and so we abort any pending readbacks here. | |
1092 AbortPendingReadbackRequests(); | |
1093 } | 1053 } |
1094 | 1054 |
1095 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( | 1055 void RenderWidgetHostViewAndroid::CheckOutputSurfaceChanged( |
1096 uint32 output_surface_id) { | 1056 uint32 output_surface_id) { |
1097 if (output_surface_id == last_output_surface_id_) | 1057 if (output_surface_id == last_output_surface_id_) |
1098 return; | 1058 return; |
1099 // Drop the cc::DelegatedFrameResourceCollection so that we will not return | 1059 // Drop the cc::DelegatedFrameResourceCollection so that we will not return |
1100 // any resources from the old output surface with the new output surface id. | 1060 // any resources from the old output surface with the new output surface id. |
1101 if (resource_collection_.get()) { | 1061 if (resource_collection_.get()) { |
1102 resource_collection_->SetClient(NULL); | 1062 resource_collection_->SetClient(NULL); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 frame->delegated_frame_data->render_pass_list.back(); | 1198 frame->delegated_frame_data->render_pass_list.back(); |
1239 texture_size_in_layer_ = root_pass->output_rect.size(); | 1199 texture_size_in_layer_ = root_pass->output_rect.size(); |
1240 ComputeContentsSize(frame->metadata); | 1200 ComputeContentsSize(frame->metadata); |
1241 | 1201 |
1242 SwapDelegatedFrame(output_surface_id, frame->delegated_frame_data.Pass()); | 1202 SwapDelegatedFrame(output_surface_id, frame->delegated_frame_data.Pass()); |
1243 frame_evictor_->SwappedFrame(!host_->is_hidden()); | 1203 frame_evictor_->SwappedFrame(!host_->is_hidden()); |
1244 | 1204 |
1245 // As the metadata update may trigger view invalidation, always call it after | 1205 // As the metadata update may trigger view invalidation, always call it after |
1246 // any potential compositor scheduling. | 1206 // any potential compositor scheduling. |
1247 OnFrameMetadataUpdated(frame->metadata); | 1207 OnFrameMetadataUpdated(frame->metadata); |
1248 // Check if we have any pending readbacks, see if we have a frame available | |
1249 // and process them here. | |
1250 if (!readbacks_waiting_for_frame_.empty()) { | |
1251 while (!readbacks_waiting_for_frame_.empty()) { | |
1252 ReadbackRequest& readback_request = readbacks_waiting_for_frame_.front(); | |
1253 GetScaledContentBitmap(readback_request.GetScale(), | |
1254 readback_request.GetColorFormat(), | |
1255 readback_request.GetCaptureRect(), | |
1256 readback_request.GetResultCallback()); | |
1257 readbacks_waiting_for_frame_.pop(); | |
1258 } | |
1259 } | |
1260 } | 1208 } |
1261 | 1209 |
1262 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | 1210 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
1263 uint32 output_surface_id, | 1211 uint32 output_surface_id, |
1264 scoped_ptr<cc::CompositorFrame> frame) { | 1212 scoped_ptr<cc::CompositorFrame> frame) { |
1265 InternalSwapCompositorFrame(output_surface_id, frame.Pass()); | 1213 InternalSwapCompositorFrame(output_surface_id, frame.Pass()); |
1266 } | 1214 } |
1267 | 1215 |
1268 void RenderWidgetHostViewAndroid::RetainFrame( | 1216 void RenderWidgetHostViewAndroid::RetainFrame( |
1269 uint32 output_surface_id, | 1217 uint32 output_surface_id, |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 } | 1508 } |
1561 if (selection_controller_) | 1509 if (selection_controller_) |
1562 needs_animate |= selection_controller_->Animate(frame_time); | 1510 needs_animate |= selection_controller_->Animate(frame_time); |
1563 return needs_animate; | 1511 return needs_animate; |
1564 } | 1512 } |
1565 | 1513 |
1566 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() { | 1514 void RenderWidgetHostViewAndroid::EvictDelegatedFrame() { |
1567 if (layer_.get()) | 1515 if (layer_.get()) |
1568 DestroyDelegatedContent(); | 1516 DestroyDelegatedContent(); |
1569 frame_evictor_->DiscardedFrame(); | 1517 frame_evictor_->DiscardedFrame(); |
1570 // We are evicting the delegated frame, | |
1571 // so there should be no pending readback requests | |
1572 DCHECK(readbacks_waiting_for_frame_.empty()); | |
1573 } | 1518 } |
1574 | 1519 |
1575 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( | 1520 bool RenderWidgetHostViewAndroid::HasAcceleratedSurface( |
1576 const gfx::Size& desired_size) { | 1521 const gfx::Size& desired_size) { |
1577 NOTREACHED(); | 1522 NOTREACHED(); |
1578 return false; | 1523 return false; |
1579 } | 1524 } |
1580 | 1525 |
1581 void RenderWidgetHostViewAndroid::GetScreenInfo(blink::WebScreenInfo* result) { | 1526 void RenderWidgetHostViewAndroid::GetScreenInfo(blink::WebScreenInfo* result) { |
1582 // ScreenInfo isn't tied to the widget on Android. Always return the default. | 1527 // ScreenInfo isn't tied to the widget on Android. Always return the default. |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1896 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { | 1841 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { |
1897 if (Animate(begin_frame_time)) | 1842 if (Animate(begin_frame_time)) |
1898 SetNeedsAnimate(); | 1843 SetNeedsAnimate(); |
1899 } | 1844 } |
1900 | 1845 |
1901 void RenderWidgetHostViewAndroid::OnLostResources() { | 1846 void RenderWidgetHostViewAndroid::OnLostResources() { |
1902 ReleaseLocksOnSurface(); | 1847 ReleaseLocksOnSurface(); |
1903 if (layer_.get()) | 1848 if (layer_.get()) |
1904 DestroyDelegatedContent(); | 1849 DestroyDelegatedContent(); |
1905 DCHECK(ack_callbacks_.empty()); | 1850 DCHECK(ack_callbacks_.empty()); |
1906 // We should not loose a frame if we have readback requests pending. | |
1907 DCHECK(readbacks_waiting_for_frame_.empty()); | |
1908 } | 1851 } |
1909 | 1852 |
1910 // static | 1853 // static |
1911 void RenderWidgetHostViewAndroid:: | 1854 void RenderWidgetHostViewAndroid:: |
1912 PrepareTextureCopyOutputResultForDelegatedReadback( | 1855 PrepareTextureCopyOutputResultForDelegatedReadback( |
1913 const gfx::Size& dst_size_in_pixel, | 1856 const gfx::Size& dst_size_in_pixel, |
1914 SkColorType color_type, | 1857 SkColorType color_type, |
1915 const base::TimeTicks& start_time, | 1858 const base::TimeTicks& start_time, |
1916 scoped_refptr<cc::Layer> readback_layer, | 1859 scoped_refptr<cc::Layer> readback_layer, |
1917 ReadbackRequestCallback& callback, | 1860 ReadbackRequestCallback& callback, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2025 results->orientationAngle = display.RotationAsDegree(); | 1968 results->orientationAngle = display.RotationAsDegree(); |
2026 results->orientationType = | 1969 results->orientationType = |
2027 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1970 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
2028 gfx::DeviceDisplayInfo info; | 1971 gfx::DeviceDisplayInfo info; |
2029 results->depth = info.GetBitsPerPixel(); | 1972 results->depth = info.GetBitsPerPixel(); |
2030 results->depthPerComponent = info.GetBitsPerComponent(); | 1973 results->depthPerComponent = info.GetBitsPerComponent(); |
2031 results->isMonochrome = (results->depthPerComponent == 0); | 1974 results->isMonochrome = (results->depthPerComponent == 0); |
2032 } | 1975 } |
2033 | 1976 |
2034 } // namespace content | 1977 } // namespace content |
OLD | NEW |