| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { | 277 gfx::RectF GetSelectionRect(const ui::TouchSelectionController& controller) { |
| 278 gfx::RectF rect = controller.GetRectBetweenBounds(); | 278 gfx::RectF rect = controller.GetRectBetweenBounds(); |
| 279 if (rect.IsEmpty()) | 279 if (rect.IsEmpty()) |
| 280 return rect; | 280 return rect; |
| 281 | 281 |
| 282 rect.Union(controller.GetStartHandleRect()); | 282 rect.Union(controller.GetStartHandleRect()); |
| 283 rect.Union(controller.GetEndHandleRect()); | 283 rect.Union(controller.GetEndHandleRect()); |
| 284 return rect; | 284 return rect; |
| 285 } | 285 } |
| 286 | 286 |
| 287 scoped_refptr<cc::SurfaceLayer> CreateSurfaceLayer( |
| 288 const cc::SurfaceId& surface_id, |
| 289 const gfx::Size& size) { |
| 290 DCHECK(!surface_id.is_null()); |
| 291 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager(); |
| 292 DCHECK(manager); |
| 293 // manager must outlive compositors using it. |
| 294 scoped_refptr<cc::SurfaceLayer> surface_layer = cc::SurfaceLayer::Create( |
| 295 base::Bind(&SatisfyCallback, base::Unretained(manager)), |
| 296 base::Bind(&RequireCallback, base::Unretained(manager))); |
| 297 surface_layer->SetSurfaceId(surface_id, 1.f, size); |
| 298 surface_layer->SetBounds(size); |
| 299 surface_layer->SetIsDrawable(true); |
| 300 surface_layer->SetContentsOpaque(true); |
| 301 |
| 302 return surface_layer; |
| 303 } |
| 304 |
| 287 } // anonymous namespace | 305 } // anonymous namespace |
| 288 | 306 |
| 289 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( | 307 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( |
| 290 uint32_t output_id, | 308 uint32_t output_id, |
| 291 cc::CompositorFrame output_frame) | 309 cc::CompositorFrame output_frame) |
| 292 : output_surface_id(output_id), frame(std::move(output_frame)) {} | 310 : output_surface_id(output_id), frame(std::move(output_frame)) {} |
| 293 | 311 |
| 294 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} | 312 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} |
| 295 | 313 |
| 296 void RenderWidgetHostViewAndroid::OnContextLost() { | 314 void RenderWidgetHostViewAndroid::OnContextLost() { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 float device_scale_factor = display.device_scale_factor(); | 441 float device_scale_factor = display.device_scale_factor(); |
| 424 DCHECK_GT(device_scale_factor, 0); | 442 DCHECK_GT(device_scale_factor, 0); |
| 425 gfx::Size dst_size( | 443 gfx::Size dst_size( |
| 426 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor)); | 444 gfx::ScaleToCeiledSize(src_subrect.size(), scale / device_scale_factor)); |
| 427 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect); | 445 src_subrect = gfx::ConvertRectToDIP(device_scale_factor, src_subrect); |
| 428 | 446 |
| 429 CopyFromCompositingSurface(src_subrect, dst_size, result_callback, | 447 CopyFromCompositingSurface(src_subrect, dst_size, result_callback, |
| 430 preferred_color_type); | 448 preferred_color_type); |
| 431 } | 449 } |
| 432 | 450 |
| 433 scoped_refptr<cc::Layer> RenderWidgetHostViewAndroid::CreateDelegatedLayer() | |
| 434 const { | |
| 435 scoped_refptr<cc::Layer> delegated_layer; | |
| 436 DCHECK(!surface_id_.is_null()); | |
| 437 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager(); | |
| 438 DCHECK(manager); | |
| 439 // manager must outlive compositors using it. | |
| 440 scoped_refptr<cc::SurfaceLayer> surface_layer = cc::SurfaceLayer::Create( | |
| 441 base::Bind(&SatisfyCallback, base::Unretained(manager)), | |
| 442 base::Bind(&RequireCallback, base::Unretained(manager))); | |
| 443 surface_layer->SetSurfaceId(surface_id_, 1.f, texture_size_in_layer_); | |
| 444 delegated_layer = surface_layer; | |
| 445 delegated_layer->SetBounds(texture_size_in_layer_); | |
| 446 delegated_layer->SetIsDrawable(true); | |
| 447 delegated_layer->SetContentsOpaque(true); | |
| 448 | |
| 449 return delegated_layer; | |
| 450 } | |
| 451 | |
| 452 bool RenderWidgetHostViewAndroid::HasValidFrame() const { | 451 bool RenderWidgetHostViewAndroid::HasValidFrame() const { |
| 453 if (!content_view_core_) | 452 if (!content_view_core_) |
| 454 return false; | 453 return false; |
| 455 if (!layer_.get()) | 454 if (!layer_.get()) |
| 456 return false; | 455 return false; |
| 457 | 456 |
| 458 if (texture_size_in_layer_.IsEmpty()) | 457 if (texture_size_in_layer_.IsEmpty()) |
| 459 return false; | 458 return false; |
| 460 // This tell us whether a valid frame has arrived or not. | 459 // This tell us whether a valid frame has arrived or not. |
| 461 if (!frame_evictor_->HasFrame()) | 460 if (!frame_evictor_->HasFrame()) |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 if (surface_id_.is_null() || | 1001 if (surface_id_.is_null() || |
| 1003 texture_size_in_layer_ != current_surface_size_ || | 1002 texture_size_in_layer_ != current_surface_size_ || |
| 1004 location_bar_content_translation_ != | 1003 location_bar_content_translation_ != |
| 1005 frame.metadata.location_bar_content_translation || | 1004 frame.metadata.location_bar_content_translation || |
| 1006 current_viewport_selection_ != frame.metadata.selection) { | 1005 current_viewport_selection_ != frame.metadata.selection) { |
| 1007 RemoveLayers(); | 1006 RemoveLayers(); |
| 1008 if (!surface_id_.is_null()) | 1007 if (!surface_id_.is_null()) |
| 1009 surface_factory_->Destroy(surface_id_); | 1008 surface_factory_->Destroy(surface_id_); |
| 1010 surface_id_ = id_allocator_->GenerateId(); | 1009 surface_id_ = id_allocator_->GenerateId(); |
| 1011 surface_factory_->Create(surface_id_); | 1010 surface_factory_->Create(surface_id_); |
| 1012 layer_ = CreateDelegatedLayer(); | 1011 layer_ = CreateSurfaceLayer(surface_id_, texture_size_in_layer_); |
| 1013 | 1012 |
| 1014 DCHECK(layer_); | 1013 DCHECK(layer_); |
| 1015 | 1014 |
| 1016 current_surface_size_ = texture_size_in_layer_; | 1015 current_surface_size_ = texture_size_in_layer_; |
| 1017 location_bar_content_translation_ = | 1016 location_bar_content_translation_ = |
| 1018 frame.metadata.location_bar_content_translation; | 1017 frame.metadata.location_bar_content_translation; |
| 1019 current_viewport_selection_ = frame.metadata.selection; | 1018 current_viewport_selection_ = frame.metadata.selection; |
| 1020 AttachLayers(); | 1019 AttachLayers(); |
| 1021 } | 1020 } |
| 1022 | 1021 |
| 1023 cc::SurfaceFactory::DrawCallback ack_callback = | 1022 cc::SurfaceFactory::DrawCallback ack_callback = |
| 1024 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, | 1023 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, |
| 1025 weak_ptr_factory_.GetWeakPtr()); | 1024 weak_ptr_factory_.GetWeakPtr()); |
| 1026 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 1025 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
| 1027 ack_callback); | 1026 ack_callback); |
| 1028 } | 1027 } |
| 1029 | 1028 |
| 1030 void RenderWidgetHostViewAndroid::SwapDelegatedFrame( | 1029 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( |
| 1031 uint32_t output_surface_id, | 1030 uint32_t output_surface_id, |
| 1032 cc::CompositorFrame frame) { | 1031 cc::CompositorFrame frame) { |
| 1032 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
| 1033 DCHECK(frame.delegated_frame_data); |
| 1034 DCHECK(CompositorImpl::GetSurfaceManager()); |
| 1035 |
| 1036 if (locks_on_frame_count_ > 0) { |
| 1037 DCHECK(HasValidFrame()); |
| 1038 RetainFrame(output_surface_id, std::move(frame)); |
| 1039 return; |
| 1040 } |
| 1041 |
| 1042 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); |
| 1043 |
| 1044 cc::RenderPass* root_pass = |
| 1045 frame.delegated_frame_data->render_pass_list.back().get(); |
| 1046 texture_size_in_layer_ = root_pass->output_rect.size(); |
| 1047 |
| 1048 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); |
| 1049 |
| 1033 CheckOutputSurfaceChanged(output_surface_id); | 1050 CheckOutputSurfaceChanged(output_surface_id); |
| 1034 bool has_content = !texture_size_in_layer_.IsEmpty(); | 1051 bool has_content = !texture_size_in_layer_.IsEmpty(); |
| 1035 | 1052 |
| 1036 base::Closure ack_callback = | 1053 base::Closure ack_callback = |
| 1037 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, | 1054 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, |
| 1038 weak_ptr_factory_.GetWeakPtr(), | 1055 weak_ptr_factory_.GetWeakPtr(), |
| 1039 output_surface_id); | 1056 output_surface_id); |
| 1040 | 1057 |
| 1041 ack_callbacks_.push(ack_callback); | 1058 ack_callbacks_.push(ack_callback); |
| 1042 | 1059 |
| 1043 if (!has_content) { | 1060 if (!has_content) { |
| 1044 DestroyDelegatedContent(); | 1061 DestroyDelegatedContent(); |
| 1045 } else { | 1062 } else { |
| 1046 SubmitCompositorFrame(std::move(frame)); | 1063 SubmitCompositorFrame(std::move(frame)); |
| 1047 } | |
| 1048 | |
| 1049 if (layer_.get()) { | |
| 1050 layer_->SetIsDrawable(true); | 1064 layer_->SetIsDrawable(true); |
| 1051 layer_->SetContentsOpaque(true); | 1065 layer_->SetContentsOpaque(true); |
| 1052 layer_->SetBounds(texture_size_in_layer_); | 1066 layer_->SetBounds(texture_size_in_layer_); |
| 1053 } | 1067 } |
| 1054 | 1068 |
| 1055 if (host_->is_hidden()) | 1069 if (host_->is_hidden()) |
| 1056 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); | 1070 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); |
| 1057 } | |
| 1058 | |
| 1059 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( | |
| 1060 uint32_t output_surface_id, | |
| 1061 cc::CompositorFrame frame) { | |
| 1062 last_scroll_offset_ = frame.metadata.root_scroll_offset; | |
| 1063 if (!frame.delegated_frame_data) { | |
| 1064 LOG(ERROR) << "Non-delegated renderer path no longer supported"; | |
| 1065 return; | |
| 1066 } | |
| 1067 | |
| 1068 if (locks_on_frame_count_ > 0) { | |
| 1069 DCHECK(HasValidFrame()); | |
| 1070 RetainFrame(output_surface_id, std::move(frame)); | |
| 1071 return; | |
| 1072 } | |
| 1073 | |
| 1074 if (!CompositorImpl::GetSurfaceManager() && layer_.get() && | |
| 1075 layer_->layer_tree_host()) { | |
| 1076 for (size_t i = 0; i < frame.metadata.latency_info.size(); i++) { | |
| 1077 std::unique_ptr<cc::SwapPromise> swap_promise( | |
| 1078 new cc::LatencyInfoSwapPromise(frame.metadata.latency_info[i])); | |
| 1079 layer_->layer_tree_host()->QueueSwapPromise(std::move(swap_promise)); | |
| 1080 } | |
| 1081 } | |
| 1082 | |
| 1083 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); | |
| 1084 | |
| 1085 cc::RenderPass* root_pass = | |
| 1086 frame.delegated_frame_data->render_pass_list.back().get(); | |
| 1087 texture_size_in_layer_ = root_pass->output_rect.size(); | |
| 1088 | |
| 1089 cc::CompositorFrameMetadata metadata = frame.metadata.Clone(); | |
| 1090 | |
| 1091 SwapDelegatedFrame(output_surface_id, std::move(frame)); | |
| 1092 frame_evictor_->SwappedFrame(!host_->is_hidden()); | 1071 frame_evictor_->SwappedFrame(!host_->is_hidden()); |
| 1093 | 1072 |
| 1094 // As the metadata update may trigger view invalidation, always call it after | 1073 // As the metadata update may trigger view invalidation, always call it after |
| 1095 // any potential compositor scheduling. | 1074 // any potential compositor scheduling. |
| 1096 OnFrameMetadataUpdated(std::move(metadata)); | 1075 OnFrameMetadataUpdated(std::move(metadata)); |
| 1097 } | 1076 } |
| 1098 | 1077 |
| 1099 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | 1078 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
| 1100 uint32_t output_surface_id, | 1079 uint32_t output_surface_id, |
| 1101 cc::CompositorFrame frame) { | 1080 cc::CompositorFrame frame) { |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2011 case ui::MotionEvent::ACTION_UP: | 1990 case ui::MotionEvent::ACTION_UP: |
| 2012 case ui::MotionEvent::ACTION_POINTER_UP: | 1991 case ui::MotionEvent::ACTION_POINTER_UP: |
| 2013 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 1992 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
| 2014 delta.InMicroseconds(), 1, 1000000, 50); | 1993 delta.InMicroseconds(), 1, 1000000, 50); |
| 2015 default: | 1994 default: |
| 2016 return; | 1995 return; |
| 2017 } | 1996 } |
| 2018 } | 1997 } |
| 2019 | 1998 |
| 2020 } // namespace content | 1999 } // namespace content |
| OLD | NEW |