| 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 282 |
| 283 rect.Union(controller.GetStartHandleRect()); | 283 rect.Union(controller.GetStartHandleRect()); |
| 284 rect.Union(controller.GetEndHandleRect()); | 284 rect.Union(controller.GetEndHandleRect()); |
| 285 return rect; | 285 return rect; |
| 286 } | 286 } |
| 287 | 287 |
| 288 } // anonymous namespace | 288 } // anonymous namespace |
| 289 | 289 |
| 290 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( | 290 RenderWidgetHostViewAndroid::LastFrameInfo::LastFrameInfo( |
| 291 uint32_t output_id, | 291 uint32_t output_id, |
| 292 std::unique_ptr<cc::CompositorFrame> output_frame) | 292 cc::CompositorFrame output_frame) |
| 293 : output_surface_id(output_id), frame(std::move(output_frame)) {} | 293 : output_surface_id(output_id), frame(std::move(output_frame)) {} |
| 294 | 294 |
| 295 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} | 295 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} |
| 296 | 296 |
| 297 void RenderWidgetHostViewAndroid::OnContextLost() { | 297 void RenderWidgetHostViewAndroid::OnContextLost() { |
| 298 std::unique_ptr<RenderWidgetHostIterator> widgets( | 298 std::unique_ptr<RenderWidgetHostIterator> widgets( |
| 299 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); | 299 RenderWidgetHostImpl::GetAllRenderWidgetHosts()); |
| 300 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 300 while (RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 301 if (widget->GetView()) { | 301 if (widget->GetView()) { |
| 302 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) | 302 static_cast<RenderWidgetHostViewAndroid*>(widget->GetView()) |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 return; | 988 return; |
| 989 DestroyDelegatedContent(); | 989 DestroyDelegatedContent(); |
| 990 surface_factory_.reset(); | 990 surface_factory_.reset(); |
| 991 if (!surface_returned_resources_.empty()) | 991 if (!surface_returned_resources_.empty()) |
| 992 SendReturnedDelegatedResources(last_output_surface_id_); | 992 SendReturnedDelegatedResources(last_output_surface_id_); |
| 993 | 993 |
| 994 last_output_surface_id_ = output_surface_id; | 994 last_output_surface_id_ = output_surface_id; |
| 995 } | 995 } |
| 996 | 996 |
| 997 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( | 997 void RenderWidgetHostViewAndroid::SubmitCompositorFrame( |
| 998 std::unique_ptr<cc::CompositorFrame> frame) { | 998 cc::CompositorFrame frame) { |
| 999 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager(); | 999 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager(); |
| 1000 if (!surface_factory_) { | 1000 if (!surface_factory_) { |
| 1001 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this)); | 1001 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this)); |
| 1002 } | 1002 } |
| 1003 if (surface_id_.is_null() || | 1003 if (surface_id_.is_null() || |
| 1004 texture_size_in_layer_ != current_surface_size_ || | 1004 texture_size_in_layer_ != current_surface_size_ || |
| 1005 location_bar_content_translation_ != | 1005 location_bar_content_translation_ != |
| 1006 frame->metadata.location_bar_content_translation || | 1006 frame.metadata.location_bar_content_translation || |
| 1007 current_viewport_selection_ != frame->metadata.selection) { | 1007 current_viewport_selection_ != frame.metadata.selection) { |
| 1008 RemoveLayers(); | 1008 RemoveLayers(); |
| 1009 if (!surface_id_.is_null()) | 1009 if (!surface_id_.is_null()) |
| 1010 surface_factory_->Destroy(surface_id_); | 1010 surface_factory_->Destroy(surface_id_); |
| 1011 surface_id_ = id_allocator_->GenerateId(); | 1011 surface_id_ = id_allocator_->GenerateId(); |
| 1012 surface_factory_->Create(surface_id_); | 1012 surface_factory_->Create(surface_id_); |
| 1013 layer_ = CreateDelegatedLayer(); | 1013 layer_ = CreateDelegatedLayer(); |
| 1014 | 1014 |
| 1015 DCHECK(layer_); | 1015 DCHECK(layer_); |
| 1016 | 1016 |
| 1017 current_surface_size_ = texture_size_in_layer_; | 1017 current_surface_size_ = texture_size_in_layer_; |
| 1018 location_bar_content_translation_ = | 1018 location_bar_content_translation_ = |
| 1019 frame->metadata.location_bar_content_translation; | 1019 frame.metadata.location_bar_content_translation; |
| 1020 current_viewport_selection_ = frame->metadata.selection; | 1020 current_viewport_selection_ = frame.metadata.selection; |
| 1021 AttachLayers(); | 1021 AttachLayers(); |
| 1022 } | 1022 } |
| 1023 | 1023 |
| 1024 cc::SurfaceFactory::DrawCallback ack_callback = | 1024 cc::SurfaceFactory::DrawCallback ack_callback = |
| 1025 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, | 1025 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, |
| 1026 weak_ptr_factory_.GetWeakPtr()); | 1026 weak_ptr_factory_.GetWeakPtr()); |
| 1027 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 1027 std::unique_ptr<cc::CompositorFrame> frame_copy(new cc::CompositorFrame); |
| 1028 *frame_copy = std::move(frame); |
| 1029 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame_copy), |
| 1028 ack_callback); | 1030 ack_callback); |
| 1029 } | 1031 } |
| 1030 | 1032 |
| 1031 void RenderWidgetHostViewAndroid::SwapDelegatedFrame( | 1033 void RenderWidgetHostViewAndroid::SwapDelegatedFrame( |
| 1032 uint32_t output_surface_id, | 1034 uint32_t output_surface_id, |
| 1033 std::unique_ptr<cc::CompositorFrame> frame) { | 1035 cc::CompositorFrame frame) { |
| 1034 CheckOutputSurfaceChanged(output_surface_id); | 1036 CheckOutputSurfaceChanged(output_surface_id); |
| 1035 bool has_content = !texture_size_in_layer_.IsEmpty(); | 1037 bool has_content = !texture_size_in_layer_.IsEmpty(); |
| 1036 | 1038 |
| 1037 // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the | 1039 // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the |
| 1038 // renderer frame, assuming that the browser compositor will scale | 1040 // renderer frame, assuming that the browser compositor will scale |
| 1039 // it back up to device scale. But on Android we put our browser layers in | 1041 // it back up to device scale. But on Android we put our browser layers in |
| 1040 // physical pixels and set our browser CC device_scale_factor to 1, so this | 1042 // physical pixels and set our browser CC device_scale_factor to 1, so this |
| 1041 // suppresses the transform. This line may need to be removed when fixing | 1043 // suppresses the transform. This line may need to be removed when fixing |
| 1042 // http://crbug.com/384134 or http://crbug.com/310763 | 1044 // http://crbug.com/384134 or http://crbug.com/310763 |
| 1043 frame->delegated_frame_data->device_scale_factor = 1.0f; | 1045 frame.delegated_frame_data->device_scale_factor = 1.0f; |
| 1044 | 1046 |
| 1045 base::Closure ack_callback = | 1047 base::Closure ack_callback = |
| 1046 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, | 1048 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, |
| 1047 weak_ptr_factory_.GetWeakPtr(), | 1049 weak_ptr_factory_.GetWeakPtr(), |
| 1048 output_surface_id); | 1050 output_surface_id); |
| 1049 | 1051 |
| 1050 ack_callbacks_.push(ack_callback); | 1052 ack_callbacks_.push(ack_callback); |
| 1051 | 1053 |
| 1052 if (!has_content) { | 1054 if (!has_content) { |
| 1053 DestroyDelegatedContent(); | 1055 DestroyDelegatedContent(); |
| 1054 } else { | 1056 } else { |
| 1055 SubmitCompositorFrame(std::move(frame)); | 1057 SubmitCompositorFrame(std::move(frame)); |
| 1056 } | 1058 } |
| 1057 | 1059 |
| 1058 if (layer_.get()) { | 1060 if (layer_.get()) { |
| 1059 layer_->SetIsDrawable(true); | 1061 layer_->SetIsDrawable(true); |
| 1060 layer_->SetContentsOpaque(true); | 1062 layer_->SetContentsOpaque(true); |
| 1061 layer_->SetBounds(texture_size_in_layer_); | 1063 layer_->SetBounds(texture_size_in_layer_); |
| 1062 } | 1064 } |
| 1063 | 1065 |
| 1064 if (host_->is_hidden()) | 1066 if (host_->is_hidden()) |
| 1065 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); | 1067 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); |
| 1066 } | 1068 } |
| 1067 | 1069 |
| 1068 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( | 1070 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( |
| 1069 uint32_t output_surface_id, | 1071 uint32_t output_surface_id, |
| 1070 std::unique_ptr<cc::CompositorFrame> frame) { | 1072 cc::CompositorFrame frame) { |
| 1071 last_scroll_offset_ = frame->metadata.root_scroll_offset; | 1073 last_scroll_offset_ = frame.metadata.root_scroll_offset; |
| 1072 if (!frame->delegated_frame_data) { | 1074 if (!frame.delegated_frame_data) { |
| 1073 LOG(ERROR) << "Non-delegated renderer path no longer supported"; | 1075 LOG(ERROR) << "Non-delegated renderer path no longer supported"; |
| 1074 return; | 1076 return; |
| 1075 } | 1077 } |
| 1076 | 1078 |
| 1077 if (locks_on_frame_count_ > 0) { | 1079 if (locks_on_frame_count_ > 0) { |
| 1078 DCHECK(HasValidFrame()); | 1080 DCHECK(HasValidFrame()); |
| 1079 RetainFrame(output_surface_id, std::move(frame)); | 1081 RetainFrame(output_surface_id, std::move(frame)); |
| 1080 return; | 1082 return; |
| 1081 } | 1083 } |
| 1082 | 1084 |
| 1083 if (!CompositorImpl::GetSurfaceManager() && layer_.get() && | 1085 if (!CompositorImpl::GetSurfaceManager() && layer_.get() && |
| 1084 layer_->layer_tree_host()) { | 1086 layer_->layer_tree_host()) { |
| 1085 for (size_t i = 0; i < frame->metadata.latency_info.size(); i++) { | 1087 for (size_t i = 0; i < frame.metadata.latency_info.size(); i++) { |
| 1086 std::unique_ptr<cc::SwapPromise> swap_promise( | 1088 std::unique_ptr<cc::SwapPromise> swap_promise( |
| 1087 new cc::LatencyInfoSwapPromise(frame->metadata.latency_info[i])); | 1089 new cc::LatencyInfoSwapPromise(frame.metadata.latency_info[i])); |
| 1088 layer_->layer_tree_host()->QueueSwapPromise(std::move(swap_promise)); | 1090 layer_->layer_tree_host()->QueueSwapPromise(std::move(swap_promise)); |
| 1089 } | 1091 } |
| 1090 } | 1092 } |
| 1091 | 1093 |
| 1092 DCHECK(!frame->delegated_frame_data->render_pass_list.empty()); | 1094 DCHECK(!frame.delegated_frame_data->render_pass_list.empty()); |
| 1093 | 1095 |
| 1094 cc::RenderPass* root_pass = | 1096 cc::RenderPass* root_pass = |
| 1095 frame->delegated_frame_data->render_pass_list.back().get(); | 1097 frame.delegated_frame_data->render_pass_list.back().get(); |
| 1096 texture_size_in_layer_ = root_pass->output_rect.size(); | 1098 texture_size_in_layer_ = root_pass->output_rect.size(); |
| 1097 | 1099 |
| 1098 cc::CompositorFrameMetadata metadata = frame->metadata; | 1100 cc::CompositorFrameMetadata metadata = frame.metadata; |
| 1099 | 1101 |
| 1100 SwapDelegatedFrame(output_surface_id, std::move(frame)); | 1102 SwapDelegatedFrame(output_surface_id, std::move(frame)); |
| 1101 frame_evictor_->SwappedFrame(!host_->is_hidden()); | 1103 frame_evictor_->SwappedFrame(!host_->is_hidden()); |
| 1102 | 1104 |
| 1103 // As the metadata update may trigger view invalidation, always call it after | 1105 // As the metadata update may trigger view invalidation, always call it after |
| 1104 // any potential compositor scheduling. | 1106 // any potential compositor scheduling. |
| 1105 OnFrameMetadataUpdated(metadata); | 1107 OnFrameMetadataUpdated(metadata); |
| 1106 } | 1108 } |
| 1107 | 1109 |
| 1108 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | 1110 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
| 1109 uint32_t output_surface_id, | 1111 uint32_t output_surface_id, |
| 1110 std::unique_ptr<cc::CompositorFrame> frame) { | 1112 cc::CompositorFrame frame) { |
| 1111 InternalSwapCompositorFrame(output_surface_id, std::move(frame)); | 1113 InternalSwapCompositorFrame(output_surface_id, std::move(frame)); |
| 1112 } | 1114 } |
| 1113 | 1115 |
| 1114 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { | 1116 void RenderWidgetHostViewAndroid::ClearCompositorFrame() { |
| 1115 DestroyDelegatedContent(); | 1117 DestroyDelegatedContent(); |
| 1116 } | 1118 } |
| 1117 | 1119 |
| 1118 void RenderWidgetHostViewAndroid::RetainFrame( | 1120 void RenderWidgetHostViewAndroid::RetainFrame(uint32_t output_surface_id, |
| 1119 uint32_t output_surface_id, | 1121 cc::CompositorFrame frame) { |
| 1120 std::unique_ptr<cc::CompositorFrame> frame) { | |
| 1121 DCHECK(locks_on_frame_count_); | 1122 DCHECK(locks_on_frame_count_); |
| 1122 | 1123 |
| 1123 // Store the incoming frame so that it can be swapped when all the locks have | 1124 // Store the incoming frame so that it can be swapped when all the locks have |
| 1124 // been released. If there is already a stored frame, then replace and skip | 1125 // been released. If there is already a stored frame, then replace and skip |
| 1125 // the previous one but make sure we still eventually send the ACK. Holding | 1126 // the previous one but make sure we still eventually send the ACK. Holding |
| 1126 // the ACK also blocks the renderer when its max_frames_pending is reached. | 1127 // the ACK also blocks the renderer when its max_frames_pending is reached. |
| 1127 if (last_frame_info_) { | 1128 if (last_frame_info_) { |
| 1128 base::Closure ack_callback = | 1129 base::Closure ack_callback = |
| 1129 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, | 1130 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, |
| 1130 weak_ptr_factory_.GetWeakPtr(), | 1131 weak_ptr_factory_.GetWeakPtr(), |
| (...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2021 case ui::MotionEvent::ACTION_UP: | 2022 case ui::MotionEvent::ACTION_UP: |
| 2022 case ui::MotionEvent::ACTION_POINTER_UP: | 2023 case ui::MotionEvent::ACTION_POINTER_UP: |
| 2023 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 2024 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
| 2024 delta.InMicroseconds(), 1, 1000000, 50); | 2025 delta.InMicroseconds(), 1, 1000000, 50); |
| 2025 default: | 2026 default: |
| 2026 return; | 2027 return; |
| 2027 } | 2028 } |
| 2028 } | 2029 } |
| 2029 | 2030 |
| 2030 } // namespace content | 2031 } // namespace content |
| OLD | NEW |