| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "blimp/client/core/compositor/blimp_compositor.h" | 5 #include "blimp/client/core/compositor/blimp_compositor.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
| 15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | 17 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" |
| 18 #include "blimp/client/core/compositor/delegated_output_surface.h" | 18 #include "blimp/client/core/compositor/blimp_compositor_frame_sink.h" |
| 19 #include "blimp/client/public/compositor/compositor_dependencies.h" | 19 #include "blimp/client/public/compositor/compositor_dependencies.h" |
| 20 #include "blimp/net/blimp_stats.h" | 20 #include "blimp/net/blimp_stats.h" |
| 21 #include "cc/animation/animation_host.h" | 21 #include "cc/animation/animation_host.h" |
| 22 #include "cc/layers/layer.h" | 22 #include "cc/layers/layer.h" |
| 23 #include "cc/layers/surface_layer.h" | 23 #include "cc/layers/surface_layer.h" |
| 24 #include "cc/output/output_surface.h" | 24 #include "cc/output/compositor_frame_sink.h" |
| 25 #include "cc/proto/compositor_message.pb.h" | 25 #include "cc/proto/compositor_message.pb.h" |
| 26 #include "cc/surfaces/surface.h" | 26 #include "cc/surfaces/surface.h" |
| 27 #include "cc/surfaces/surface_factory.h" | 27 #include "cc/surfaces/surface_factory.h" |
| 28 #include "cc/surfaces/surface_id_allocator.h" | 28 #include "cc/surfaces/surface_id_allocator.h" |
| 29 #include "cc/surfaces/surface_manager.h" | 29 #include "cc/surfaces/surface_manager.h" |
| 30 #include "cc/trees/layer_tree_host.h" | 30 #include "cc/trees/layer_tree_host.h" |
| 31 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 31 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
| 32 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
| 33 #include "ui/gl/gl_surface.h" | 33 #include "ui/gl/gl_surface.h" |
| 34 | 34 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 BlimpCompositor::BlimpCompositor( | 60 BlimpCompositor::BlimpCompositor( |
| 61 int render_widget_id, | 61 int render_widget_id, |
| 62 BlimpCompositorDependencies* compositor_dependencies, | 62 BlimpCompositorDependencies* compositor_dependencies, |
| 63 BlimpCompositorClient* client) | 63 BlimpCompositorClient* client) |
| 64 : render_widget_id_(render_widget_id), | 64 : render_widget_id_(render_widget_id), |
| 65 client_(client), | 65 client_(client), |
| 66 compositor_dependencies_(compositor_dependencies), | 66 compositor_dependencies_(compositor_dependencies), |
| 67 output_surface_(nullptr), | 67 proxy_client_(nullptr), |
| 68 output_surface_request_pending_(false), | 68 compositor_frame_sink_request_pending_(false), |
| 69 layer_(cc::Layer::Create()), | 69 layer_(cc::Layer::Create()), |
| 70 remote_proto_channel_receiver_(nullptr), | 70 remote_proto_channel_receiver_(nullptr), |
| 71 weak_ptr_factory_(this) { | 71 weak_ptr_factory_(this) { |
| 72 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
| 73 | 73 |
| 74 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>( | 74 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>( |
| 75 GetEmbedderDeps()->AllocateSurfaceClientId()); | 75 GetEmbedderDeps()->AllocateSurfaceClientId()); |
| 76 GetEmbedderDeps()->GetSurfaceManager()->RegisterSurfaceClientId( | 76 GetEmbedderDeps()->GetSurfaceManager()->RegisterSurfaceClientId( |
| 77 surface_id_allocator_->client_id()); | 77 surface_id_allocator_->client_id()); |
| 78 CreateLayerTreeHost(); | 78 CreateLayerTreeHost(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 89 void BlimpCompositor::SetVisible(bool visible) { | 89 void BlimpCompositor::SetVisible(bool visible) { |
| 90 host_->SetVisible(visible); | 90 host_->SetVisible(visible); |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool BlimpCompositor::OnTouchEvent(const ui::MotionEvent& motion_event) { | 93 bool BlimpCompositor::OnTouchEvent(const ui::MotionEvent& motion_event) { |
| 94 if (input_manager_) | 94 if (input_manager_) |
| 95 return input_manager_->OnTouchEvent(motion_event); | 95 return input_manager_->OnTouchEvent(motion_event); |
| 96 return false; | 96 return false; |
| 97 } | 97 } |
| 98 | 98 |
| 99 void BlimpCompositor::RequestNewOutputSurface() { | 99 void BlimpCompositor::RequestNewCompositorFrameSink() { |
| 100 DCHECK(!surface_factory_); | 100 DCHECK(!surface_factory_); |
| 101 DCHECK(!output_surface_request_pending_); | 101 DCHECK(!compositor_frame_sink_request_pending_); |
| 102 | 102 |
| 103 output_surface_request_pending_ = true; | 103 compositor_frame_sink_request_pending_ = true; |
| 104 GetEmbedderDeps()->GetContextProviders( | 104 GetEmbedderDeps()->GetContextProviders( |
| 105 base::Bind(&BlimpCompositor::OnContextProvidersCreated, | 105 base::Bind(&BlimpCompositor::OnContextProvidersCreated, |
| 106 weak_ptr_factory_.GetWeakPtr())); | 106 weak_ptr_factory_.GetWeakPtr())); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void BlimpCompositor::DidInitializeOutputSurface() { | 109 void BlimpCompositor::DidInitializeCompositorFrameSink() { |
| 110 output_surface_request_pending_ = false; | 110 compositor_frame_sink_request_pending_ = false; |
| 111 } | 111 } |
| 112 | 112 |
| 113 void BlimpCompositor::DidCommitAndDrawFrame() { | 113 void BlimpCompositor::DidCommitAndDrawFrame() { |
| 114 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); | 114 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) { | 117 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) { |
| 118 remote_proto_channel_receiver_ = receiver; | 118 remote_proto_channel_receiver_ = receiver; |
| 119 } | 119 } |
| 120 | 120 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 140 // We should have a receiver if we're getting compositor messages that | 140 // We should have a receiver if we're getting compositor messages that |
| 141 // are not INITIALIZE_IMPL or CLOSE_IMPL. | 141 // are not INITIALIZE_IMPL or CLOSE_IMPL. |
| 142 DCHECK(remote_proto_channel_receiver_); | 142 DCHECK(remote_proto_channel_receiver_); |
| 143 remote_proto_channel_receiver_->OnProtoReceived(std::move(message)); | 143 remote_proto_channel_receiver_->OnProtoReceived(std::move(message)); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 void BlimpCompositor::OnContextProvidersCreated( | 147 void BlimpCompositor::OnContextProvidersCreated( |
| 148 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, | 148 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, |
| 149 const scoped_refptr<cc::ContextProvider>& worker_context_provider) { | 149 const scoped_refptr<cc::ContextProvider>& worker_context_provider) { |
| 150 DCHECK(!surface_factory_) | 150 DCHECK(!surface_factory_) << "Any connection to the old CompositorFrameSink " |
| 151 << "Any connection to the old output surface should have been destroyed"; | 151 "should have been destroyed"; |
| 152 | 152 |
| 153 // Make sure we still have a host and we're still expecting an output surface. | 153 // Make sure we still have a host and we're still expecting an output surface. |
| 154 // This can happen if the host dies while the request is outstanding and we | 154 // This can happen if the host dies while the request is outstanding and we |
| 155 // build a new one that hasn't asked for a surface yet. | 155 // build a new one that hasn't asked for a surface yet. |
| 156 if (!output_surface_request_pending_) | 156 if (!compositor_frame_sink_request_pending_) |
| 157 return; | 157 return; |
| 158 | 158 |
| 159 // Try again if the context creation failed. | 159 // Try again if the context creation failed. |
| 160 if (!compositor_context_provider) { | 160 if (!compositor_context_provider) { |
| 161 GetEmbedderDeps()->GetContextProviders( | 161 GetEmbedderDeps()->GetContextProviders( |
| 162 base::Bind(&BlimpCompositor::OnContextProvidersCreated, | 162 base::Bind(&BlimpCompositor::OnContextProvidersCreated, |
| 163 weak_ptr_factory_.GetWeakPtr())); | 163 weak_ptr_factory_.GetWeakPtr())); |
| 164 return; | 164 return; |
| 165 } | 165 } |
| 166 | 166 |
| 167 std::unique_ptr<DelegatedOutputSurface> delegated_output_surface = | 167 auto compositor_frame_sink = base::MakeUnique<BlimpCompositorFrameSink>( |
| 168 base::MakeUnique<DelegatedOutputSurface>( | 168 std::move(compositor_context_provider), |
| 169 std::move(compositor_context_provider), | 169 std::move(worker_context_provider), base::ThreadTaskRunnerHandle::Get(), |
| 170 std::move(worker_context_provider), | 170 weak_ptr_factory_.GetWeakPtr()); |
| 171 base::ThreadTaskRunnerHandle::Get(), weak_ptr_factory_.GetWeakPtr()); | |
| 172 | 171 |
| 173 host_->SetOutputSurface(std::move(delegated_output_surface)); | 172 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); |
| 174 } | 173 } |
| 175 | 174 |
| 176 void BlimpCompositor::SendWebGestureEvent( | 175 void BlimpCompositor::SendWebGestureEvent( |
| 177 const blink::WebGestureEvent& gesture_event) { | 176 const blink::WebGestureEvent& gesture_event) { |
| 178 client_->SendWebGestureEvent(render_widget_id_, gesture_event); | 177 client_->SendWebGestureEvent(render_widget_id_, gesture_event); |
| 179 } | 178 } |
| 180 | 179 |
| 181 void BlimpCompositor::BindToOutputSurface( | 180 void BlimpCompositor::BindToProxyClient( |
| 182 base::WeakPtr<BlimpOutputSurface> output_surface) { | 181 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) { |
| 183 DCHECK(thread_checker_.CalledOnValidThread()); | 182 DCHECK(thread_checker_.CalledOnValidThread()); |
| 184 DCHECK(!surface_factory_); | 183 DCHECK(!surface_factory_); |
| 185 | 184 |
| 186 output_surface_ = output_surface; | 185 proxy_client_ = proxy_client; |
| 187 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( | 186 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( |
| 188 GetEmbedderDeps()->GetSurfaceManager(), this); | 187 GetEmbedderDeps()->GetSurfaceManager(), this); |
| 189 } | 188 } |
| 190 | 189 |
| 191 void BlimpCompositor::SwapCompositorFrame(cc::CompositorFrame frame) { | 190 void BlimpCompositor::SwapCompositorFrame(cc::CompositorFrame frame) { |
| 192 DCHECK(thread_checker_.CalledOnValidThread()); | 191 DCHECK(thread_checker_.CalledOnValidThread()); |
| 193 DCHECK(surface_factory_); | 192 DCHECK(surface_factory_); |
| 194 | 193 |
| 195 cc::RenderPass* root_pass = | 194 cc::RenderPass* root_pass = |
| 196 frame.delegated_frame_data->render_pass_list.back().get(); | 195 frame.delegated_frame_data->render_pass_list.back().get(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 215 content_layer->SetIsDrawable(true); | 214 content_layer->SetIsDrawable(true); |
| 216 content_layer->SetContentsOpaque(true); | 215 content_layer->SetContentsOpaque(true); |
| 217 | 216 |
| 218 layer_->AddChild(content_layer); | 217 layer_->AddChild(content_layer); |
| 219 } | 218 } |
| 220 | 219 |
| 221 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 220 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
| 222 base::Closure()); | 221 base::Closure()); |
| 223 } | 222 } |
| 224 | 223 |
| 225 void BlimpCompositor::UnbindOutputSurface() { | 224 void BlimpCompositor::UnbindProxyClient() { |
| 226 DCHECK(thread_checker_.CalledOnValidThread()); | 225 DCHECK(thread_checker_.CalledOnValidThread()); |
| 227 DCHECK(surface_factory_); | 226 DCHECK(surface_factory_); |
| 228 | 227 |
| 229 DestroyDelegatedContent(); | 228 DestroyDelegatedContent(); |
| 230 surface_factory_.reset(); | 229 surface_factory_.reset(); |
| 231 output_surface_ = nullptr; | 230 proxy_client_ = nullptr; |
| 232 } | 231 } |
| 233 | 232 |
| 234 void BlimpCompositor::ReturnResources( | 233 void BlimpCompositor::ReturnResources( |
| 235 const cc::ReturnedResourceArray& resources) { | 234 const cc::ReturnedResourceArray& resources) { |
| 236 DCHECK(surface_factory_); | 235 DCHECK(surface_factory_); |
| 237 compositor_dependencies_->GetCompositorTaskRunner()->PostTask( | 236 compositor_dependencies_->GetCompositorTaskRunner()->PostTask( |
| 238 FROM_HERE, base::Bind(&BlimpOutputSurface::ReclaimCompositorResources, | 237 FROM_HERE, |
| 239 output_surface_, resources)); | 238 base::Bind( |
| 239 &BlimpCompositorFrameSinkProxyClient::ReclaimCompositorResources, |
| 240 proxy_client_, resources)); |
| 240 } | 241 } |
| 241 | 242 |
| 242 CompositorDependencies* BlimpCompositor::GetEmbedderDeps() { | 243 CompositorDependencies* BlimpCompositor::GetEmbedderDeps() { |
| 243 return compositor_dependencies_->GetEmbedderDependencies(); | 244 return compositor_dependencies_->GetEmbedderDependencies(); |
| 244 } | 245 } |
| 245 | 246 |
| 246 void BlimpCompositor::DestroyDelegatedContent() { | 247 void BlimpCompositor::DestroyDelegatedContent() { |
| 247 if (surface_id_.is_null()) | 248 if (surface_id_.is_null()) |
| 248 return; | 249 return; |
| 249 | 250 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 264 params.gpu_memory_buffer_manager = | 265 params.gpu_memory_buffer_manager = |
| 265 GetEmbedderDeps()->GetGpuMemoryBufferManager(); | 266 GetEmbedderDeps()->GetGpuMemoryBufferManager(); |
| 266 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 267 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 267 params.image_serialization_processor = | 268 params.image_serialization_processor = |
| 268 compositor_dependencies_->GetImageSerializationProcessor(); | 269 compositor_dependencies_->GetImageSerializationProcessor(); |
| 269 | 270 |
| 270 cc::LayerTreeSettings* settings = | 271 cc::LayerTreeSettings* settings = |
| 271 compositor_dependencies_->GetLayerTreeSettings(); | 272 compositor_dependencies_->GetLayerTreeSettings(); |
| 272 // TODO(khushalsagar): This is a hack. Remove when we move the split point | 273 // TODO(khushalsagar): This is a hack. Remove when we move the split point |
| 273 // out. For details on why this is needed, see crbug.com/586210. | 274 // out. For details on why this is needed, see crbug.com/586210. |
| 274 settings->abort_commit_before_output_surface_creation = false; | 275 settings->abort_commit_before_compositor_frame_sink_creation = false; |
| 275 params.settings = settings; | 276 params.settings = settings; |
| 276 | 277 |
| 277 params.animation_host = cc::AnimationHost::CreateMainInstance(); | 278 params.animation_host = cc::AnimationHost::CreateMainInstance(); |
| 278 | 279 |
| 279 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner = | 280 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner = |
| 280 compositor_dependencies_->GetCompositorTaskRunner(); | 281 compositor_dependencies_->GetCompositorTaskRunner(); |
| 281 | 282 |
| 282 host_ = cc::LayerTreeHost::CreateRemoteClient( | 283 host_ = cc::LayerTreeHost::CreateRemoteClient( |
| 283 this /* remote_proto_channel */, compositor_task_runner, ¶ms); | 284 this /* remote_proto_channel */, compositor_task_runner, ¶ms); |
| 284 | 285 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 299 | 300 |
| 300 // Destroy the old LayerTreeHost state. | 301 // Destroy the old LayerTreeHost state. |
| 301 host_.reset(); | 302 host_.reset(); |
| 302 | 303 |
| 303 // Destroy the old input manager state. | 304 // Destroy the old input manager state. |
| 304 // It is important to destroy the LayerTreeHost before destroying the input | 305 // It is important to destroy the LayerTreeHost before destroying the input |
| 305 // manager as it has a reference to the cc::InputHandlerClient owned by the | 306 // manager as it has a reference to the cc::InputHandlerClient owned by the |
| 306 // BlimpInputManager. | 307 // BlimpInputManager. |
| 307 input_manager_.reset(); | 308 input_manager_.reset(); |
| 308 | 309 |
| 309 // Cancel any outstanding OutputSurface requests. That way if we get an async | 310 // Cancel any outstanding CompositorFrameSink requests. That way if we get an |
| 311 // async |
| 310 // callback related to the old request we know to drop it. | 312 // callback related to the old request we know to drop it. |
| 311 output_surface_request_pending_ = false; | 313 compositor_frame_sink_request_pending_ = false; |
| 312 | 314 |
| 313 // Make sure we don't have a receiver at this point. | 315 // Make sure we don't have a receiver at this point. |
| 314 DCHECK(!remote_proto_channel_receiver_); | 316 DCHECK(!remote_proto_channel_receiver_); |
| 315 } | 317 } |
| 316 | 318 |
| 317 } // namespace client | 319 } // namespace client |
| 318 } // namespace blimp | 320 } // namespace blimp |
| OLD | NEW |