| 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 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 } | 1035 } |
| 1036 DestroyDelegatedContent(); | 1036 DestroyDelegatedContent(); |
| 1037 surface_factory_.reset(); | 1037 surface_factory_.reset(); |
| 1038 if (!surface_returned_resources_.empty()) | 1038 if (!surface_returned_resources_.empty()) |
| 1039 SendReturnedDelegatedResources(last_output_surface_id_); | 1039 SendReturnedDelegatedResources(last_output_surface_id_); |
| 1040 | 1040 |
| 1041 last_output_surface_id_ = output_surface_id; | 1041 last_output_surface_id_ = output_surface_id; |
| 1042 } | 1042 } |
| 1043 | 1043 |
| 1044 void RenderWidgetHostViewAndroid::SubmitFrame( | 1044 void RenderWidgetHostViewAndroid::SubmitFrame( |
| 1045 scoped_ptr<cc::DelegatedFrameData> frame_data) { | 1045 scoped_ptr<cc::CompositorFrame> frame) { |
| 1046 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager(); | 1046 cc::SurfaceManager* manager = CompositorImpl::GetSurfaceManager(); |
| 1047 if (manager) { | 1047 if (manager) { |
| 1048 if (!surface_factory_) { | 1048 if (!surface_factory_) { |
| 1049 surface_factory_ = make_scoped_ptr(new cc::SurfaceFactory(manager, this)); | 1049 surface_factory_ = make_scoped_ptr(new cc::SurfaceFactory(manager, this)); |
| 1050 } | 1050 } |
| 1051 if (surface_id_.is_null() || | 1051 if (surface_id_.is_null() || |
| 1052 texture_size_in_layer_ != current_surface_size_) { | 1052 texture_size_in_layer_ != current_surface_size_) { |
| 1053 RemoveLayers(); | 1053 RemoveLayers(); |
| 1054 if (!surface_id_.is_null()) | 1054 if (!surface_id_.is_null()) |
| 1055 surface_factory_->Destroy(surface_id_); | 1055 surface_factory_->Destroy(surface_id_); |
| 1056 surface_id_ = id_allocator_->GenerateId(); | 1056 surface_id_ = id_allocator_->GenerateId(); |
| 1057 surface_factory_->Create(surface_id_); | 1057 surface_factory_->Create(surface_id_); |
| 1058 layer_ = CreateDelegatedLayer(); | 1058 layer_ = CreateDelegatedLayer(); |
| 1059 | 1059 |
| 1060 DCHECK(layer_); | 1060 DCHECK(layer_); |
| 1061 | 1061 |
| 1062 current_surface_size_ = texture_size_in_layer_; | 1062 current_surface_size_ = texture_size_in_layer_; |
| 1063 AttachLayers(); | 1063 AttachLayers(); |
| 1064 } | 1064 } |
| 1065 scoped_ptr<cc::CompositorFrame> compositor_frame = | |
| 1066 make_scoped_ptr(new cc::CompositorFrame()); | |
| 1067 compositor_frame->delegated_frame_data = frame_data.Pass(); | |
| 1068 | 1065 |
| 1069 cc::SurfaceFactory::DrawCallback ack_callback = | 1066 cc::SurfaceFactory::DrawCallback ack_callback = |
| 1070 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, | 1067 base::Bind(&RenderWidgetHostViewAndroid::RunAckCallbacks, |
| 1071 weak_ptr_factory_.GetWeakPtr()); | 1068 weak_ptr_factory_.GetWeakPtr()); |
| 1072 surface_factory_->SubmitFrame(surface_id_, compositor_frame.Pass(), | 1069 surface_factory_->SubmitFrame(surface_id_, frame.Pass(), ack_callback); |
| 1073 ack_callback); | |
| 1074 } else { | 1070 } else { |
| 1075 if (!resource_collection_.get()) { | 1071 if (!resource_collection_.get()) { |
| 1076 resource_collection_ = new cc::DelegatedFrameResourceCollection; | 1072 resource_collection_ = new cc::DelegatedFrameResourceCollection; |
| 1077 resource_collection_->SetClient(this); | 1073 resource_collection_->SetClient(this); |
| 1078 } | 1074 } |
| 1079 if (!frame_provider_.get() || | 1075 if (!frame_provider_.get() || |
| 1080 texture_size_in_layer_ != frame_provider_->frame_size()) { | 1076 texture_size_in_layer_ != frame_provider_->frame_size()) { |
| 1081 RemoveLayers(); | 1077 RemoveLayers(); |
| 1082 frame_provider_ = new cc::DelegatedFrameProvider( | 1078 frame_provider_ = new cc::DelegatedFrameProvider( |
| 1083 resource_collection_.get(), frame_data.Pass()); | 1079 resource_collection_.get(), frame->delegated_frame_data.Pass()); |
| 1084 layer_ = cc::DelegatedRendererLayer::Create(Compositor::LayerSettings(), | 1080 layer_ = cc::DelegatedRendererLayer::Create(Compositor::LayerSettings(), |
| 1085 frame_provider_); | 1081 frame_provider_); |
| 1086 AttachLayers(); | 1082 AttachLayers(); |
| 1087 } else { | 1083 } else { |
| 1088 frame_provider_->SetFrameData(frame_data.Pass()); | 1084 frame_provider_->SetFrameData(frame->delegated_frame_data.Pass()); |
| 1089 } | 1085 } |
| 1090 } | 1086 } |
| 1091 } | 1087 } |
| 1092 | 1088 |
| 1093 void RenderWidgetHostViewAndroid::SwapDelegatedFrame( | 1089 void RenderWidgetHostViewAndroid::SwapDelegatedFrame( |
| 1094 uint32 output_surface_id, | 1090 uint32 output_surface_id, |
| 1095 scoped_ptr<cc::DelegatedFrameData> frame_data) { | 1091 scoped_ptr<cc::CompositorFrame> frame) { |
| 1096 CheckOutputSurfaceChanged(output_surface_id); | 1092 CheckOutputSurfaceChanged(output_surface_id); |
| 1097 bool has_content = !texture_size_in_layer_.IsEmpty(); | 1093 bool has_content = !texture_size_in_layer_.IsEmpty(); |
| 1098 | 1094 |
| 1099 // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the | 1095 // DelegatedRendererLayerImpl applies the inverse device_scale_factor of the |
| 1100 // renderer frame, assuming that the browser compositor will scale | 1096 // renderer frame, assuming that the browser compositor will scale |
| 1101 // it back up to device scale. But on Android we put our browser layers in | 1097 // it back up to device scale. But on Android we put our browser layers in |
| 1102 // physical pixels and set our browser CC device_scale_factor to 1, so this | 1098 // physical pixels and set our browser CC device_scale_factor to 1, so this |
| 1103 // suppresses the transform. This line may need to be removed when fixing | 1099 // suppresses the transform. This line may need to be removed when fixing |
| 1104 // http://crbug.com/384134 or http://crbug.com/310763 | 1100 // http://crbug.com/384134 or http://crbug.com/310763 |
| 1105 frame_data->device_scale_factor = 1.0f; | 1101 frame->delegated_frame_data->device_scale_factor = 1.0f; |
| 1106 | 1102 |
| 1107 if (!has_content) { | 1103 if (!has_content) { |
| 1108 DestroyDelegatedContent(); | 1104 DestroyDelegatedContent(); |
| 1109 } else { | 1105 } else { |
| 1110 SubmitFrame(frame_data.Pass()); | 1106 SubmitFrame(frame.Pass()); |
| 1111 } | 1107 } |
| 1112 | 1108 |
| 1113 if (layer_.get()) { | 1109 if (layer_.get()) { |
| 1114 layer_->SetIsDrawable(true); | 1110 layer_->SetIsDrawable(true); |
| 1115 layer_->SetContentsOpaque(true); | 1111 layer_->SetContentsOpaque(true); |
| 1116 layer_->SetBounds(content_size_in_layer_); | 1112 layer_->SetBounds(content_size_in_layer_); |
| 1117 } | 1113 } |
| 1118 | 1114 |
| 1119 base::Closure ack_callback = | 1115 base::Closure ack_callback = |
| 1120 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, | 1116 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1146 LOG(ERROR) << "Non-delegated renderer path no longer supported"; | 1142 LOG(ERROR) << "Non-delegated renderer path no longer supported"; |
| 1147 return; | 1143 return; |
| 1148 } | 1144 } |
| 1149 | 1145 |
| 1150 if (locks_on_frame_count_ > 0) { | 1146 if (locks_on_frame_count_ > 0) { |
| 1151 DCHECK(HasValidFrame()); | 1147 DCHECK(HasValidFrame()); |
| 1152 RetainFrame(output_surface_id, frame.Pass()); | 1148 RetainFrame(output_surface_id, frame.Pass()); |
| 1153 return; | 1149 return; |
| 1154 } | 1150 } |
| 1155 | 1151 |
| 1156 if (layer_.get() && layer_->layer_tree_host()) { | 1152 if (!CompositorImpl::GetSurfaceManager() && layer_.get() && |
| 1153 layer_->layer_tree_host()) { |
| 1157 for (size_t i = 0; i < frame->metadata.latency_info.size(); i++) { | 1154 for (size_t i = 0; i < frame->metadata.latency_info.size(); i++) { |
| 1158 scoped_ptr<cc::SwapPromise> swap_promise( | 1155 scoped_ptr<cc::SwapPromise> swap_promise( |
| 1159 new cc::LatencyInfoSwapPromise(frame->metadata.latency_info[i])); | 1156 new cc::LatencyInfoSwapPromise(frame->metadata.latency_info[i])); |
| 1160 layer_->layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); | 1157 layer_->layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); |
| 1161 } | 1158 } |
| 1162 } | 1159 } |
| 1163 | 1160 |
| 1164 DCHECK(!frame->delegated_frame_data->render_pass_list.empty()); | 1161 DCHECK(!frame->delegated_frame_data->render_pass_list.empty()); |
| 1165 | 1162 |
| 1166 cc::RenderPass* root_pass = | 1163 cc::RenderPass* root_pass = |
| 1167 frame->delegated_frame_data->render_pass_list.back(); | 1164 frame->delegated_frame_data->render_pass_list.back(); |
| 1168 texture_size_in_layer_ = root_pass->output_rect.size(); | 1165 texture_size_in_layer_ = root_pass->output_rect.size(); |
| 1169 ComputeContentsSize(frame->metadata); | 1166 ComputeContentsSize(frame->metadata); |
| 1170 | 1167 |
| 1171 SwapDelegatedFrame(output_surface_id, frame->delegated_frame_data.Pass()); | 1168 cc::CompositorFrameMetadata metadata = frame->metadata; |
| 1169 |
| 1170 SwapDelegatedFrame(output_surface_id, frame.Pass()); |
| 1172 frame_evictor_->SwappedFrame(!host_->is_hidden()); | 1171 frame_evictor_->SwappedFrame(!host_->is_hidden()); |
| 1173 | 1172 |
| 1174 // As the metadata update may trigger view invalidation, always call it after | 1173 // As the metadata update may trigger view invalidation, always call it after |
| 1175 // any potential compositor scheduling. | 1174 // any potential compositor scheduling. |
| 1176 OnFrameMetadataUpdated(frame->metadata); | 1175 OnFrameMetadataUpdated(metadata); |
| 1177 } | 1176 } |
| 1178 | 1177 |
| 1179 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | 1178 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
| 1180 uint32 output_surface_id, | 1179 uint32 output_surface_id, |
| 1181 scoped_ptr<cc::CompositorFrame> frame) { | 1180 scoped_ptr<cc::CompositorFrame> frame) { |
| 1182 InternalSwapCompositorFrame(output_surface_id, frame.Pass()); | 1181 InternalSwapCompositorFrame(output_surface_id, frame.Pass()); |
| 1183 } | 1182 } |
| 1184 | 1183 |
| 1185 void RenderWidgetHostViewAndroid::RetainFrame( | 1184 void RenderWidgetHostViewAndroid::RetainFrame( |
| 1186 uint32 output_surface_id, | 1185 uint32 output_surface_id, |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 results->orientationAngle = display.RotationAsDegree(); | 2045 results->orientationAngle = display.RotationAsDegree(); |
| 2047 results->orientationType = | 2046 results->orientationType = |
| 2048 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 2047 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
| 2049 gfx::DeviceDisplayInfo info; | 2048 gfx::DeviceDisplayInfo info; |
| 2050 results->depth = info.GetBitsPerPixel(); | 2049 results->depth = info.GetBitsPerPixel(); |
| 2051 results->depthPerComponent = info.GetBitsPerComponent(); | 2050 results->depthPerComponent = info.GetBitsPerComponent(); |
| 2052 results->isMonochrome = (results->depthPerComponent == 0); | 2051 results->isMonochrome = (results->depthPerComponent == 0); |
| 2053 } | 2052 } |
| 2054 | 2053 |
| 2055 } // namespace content | 2054 } // namespace content |
| OLD | NEW |