Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: blimp/client/core/compositor/blimp_compositor.cc

Issue 2481213003: Make SurfaceFactory lifetime match frame_sink_id_ registration in BlimpCompositor (Closed)
Patch Set: remove bad DCHECK Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « blimp/client/core/compositor/blimp_compositor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 BlimpCompositor::BlimpCompositor( 131 BlimpCompositor::BlimpCompositor(
132 BlimpCompositorDependencies* compositor_dependencies, 132 BlimpCompositorDependencies* compositor_dependencies,
133 BlimpCompositorClient* client, 133 BlimpCompositorClient* client,
134 bool use_threaded_layer_tree_host) 134 bool use_threaded_layer_tree_host)
135 : use_threaded_layer_tree_host_(use_threaded_layer_tree_host), 135 : use_threaded_layer_tree_host_(use_threaded_layer_tree_host),
136 client_(client), 136 client_(client),
137 compositor_dependencies_(compositor_dependencies), 137 compositor_dependencies_(compositor_dependencies),
138 frame_sink_id_(compositor_dependencies_->GetEmbedderDependencies() 138 frame_sink_id_(compositor_dependencies_->GetEmbedderDependencies()
139 ->AllocateFrameSinkId()), 139 ->AllocateFrameSinkId()),
140 proxy_client_(nullptr), 140 proxy_client_(nullptr),
141 bound_to_proxy_(false),
141 compositor_frame_sink_request_pending_(false), 142 compositor_frame_sink_request_pending_(false),
142 layer_(cc::Layer::Create()), 143 layer_(cc::Layer::Create()),
143 remote_proto_channel_receiver_(nullptr), 144 remote_proto_channel_receiver_(nullptr),
144 outstanding_commits_(0U), 145 outstanding_commits_(0U),
145 weak_ptr_factory_(this) { 146 weak_ptr_factory_(this) {
146 DCHECK(thread_checker_.CalledOnValidThread()); 147 DCHECK(thread_checker_.CalledOnValidThread());
147 } 148 }
148 149
149 void BlimpCompositor::Initialize() { 150 void BlimpCompositor::Initialize() {
150 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>(); 151 surface_id_allocator_ = base::MakeUnique<cc::SurfaceIdAllocator>();
151 GetEmbedderDeps()->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); 152 GetEmbedderDeps()->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
153 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(
154 frame_sink_id_, GetEmbedderDeps()->GetSurfaceManager(), this);
152 host_ = CreateLayerTreeHost(); 155 host_ = CreateLayerTreeHost();
153 156
154 if (use_threaded_layer_tree_host_) { 157 if (use_threaded_layer_tree_host_) {
155 std::unique_ptr<cc::ClientPictureCache> client_picture_cache = 158 std::unique_ptr<cc::ClientPictureCache> client_picture_cache =
156 compositor_dependencies_->GetImageSerializationProcessor() 159 compositor_dependencies_->GetImageSerializationProcessor()
157 ->CreateClientPictureCache(); 160 ->CreateClientPictureCache();
158 compositor_state_deserializer_ = 161 compositor_state_deserializer_ =
159 base::MakeUnique<cc::CompositorStateDeserializer>( 162 base::MakeUnique<cc::CompositorStateDeserializer>(
160 host_.get(), std::move(client_picture_cache), this); 163 host_.get(), std::move(client_picture_cache), this);
161 } 164 }
(...skipping 15 matching lines...) Expand all
177 } 180 }
178 181
179 bool BlimpCompositor::HasPendingFrameUpdateFromEngine() const { 182 bool BlimpCompositor::HasPendingFrameUpdateFromEngine() const {
180 return pending_frame_update_.get() != nullptr; 183 return pending_frame_update_.get() != nullptr;
181 } 184 }
182 185
183 void BlimpCompositor::RequestCopyOfOutput( 186 void BlimpCompositor::RequestCopyOfOutput(
184 std::unique_ptr<cc::CopyOutputRequest> copy_request, 187 std::unique_ptr<cc::CopyOutputRequest> copy_request,
185 bool flush_pending_update) { 188 bool flush_pending_update) {
186 // If we don't have a FrameSink, fail right away. 189 // If we don't have a FrameSink, fail right away.
187 if (!surface_factory_) 190 if (!bound_to_proxy_)
188 return; 191 return;
189 192
190 if (!use_threaded_layer_tree_host_) { 193 if (!use_threaded_layer_tree_host_) {
191 RequestCopyOfOutputDeprecated(std::move(copy_request)); 194 RequestCopyOfOutputDeprecated(std::move(copy_request));
192 return; 195 return;
193 } 196 }
194 197
195 if (flush_pending_update) { 198 if (flush_pending_update) {
196 // Always request a commit when queuing the promise to make sure that any 199 // Always request a commit when queuing the promise to make sure that any
197 // frames pending draws are cleared from the pipeline. 200 // frames pending draws are cleared from the pipeline.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 const gfx::Vector2dF& elastic_overscroll_delta, 251 const gfx::Vector2dF& elastic_overscroll_delta,
249 float page_scale, 252 float page_scale,
250 float top_controls_delta) { 253 float top_controls_delta) {
251 DCHECK(use_threaded_layer_tree_host_); 254 DCHECK(use_threaded_layer_tree_host_);
252 compositor_state_deserializer_->ApplyViewportDeltas( 255 compositor_state_deserializer_->ApplyViewportDeltas(
253 inner_delta, outer_delta, elastic_overscroll_delta, page_scale, 256 inner_delta, outer_delta, elastic_overscroll_delta, page_scale,
254 top_controls_delta); 257 top_controls_delta);
255 } 258 }
256 259
257 void BlimpCompositor::RequestNewCompositorFrameSink() { 260 void BlimpCompositor::RequestNewCompositorFrameSink() {
258 DCHECK(!surface_factory_); 261 DCHECK(!bound_to_proxy_);
259 DCHECK(!compositor_frame_sink_request_pending_); 262 DCHECK(!compositor_frame_sink_request_pending_);
260 263
261 compositor_frame_sink_request_pending_ = true; 264 compositor_frame_sink_request_pending_ = true;
262 GetEmbedderDeps()->GetContextProviders( 265 GetEmbedderDeps()->GetContextProviders(
263 base::Bind(&BlimpCompositor::OnContextProvidersCreated, 266 base::Bind(&BlimpCompositor::OnContextProvidersCreated,
264 weak_ptr_factory_.GetWeakPtr())); 267 weak_ptr_factory_.GetWeakPtr()));
265 } 268 }
266 269
267 void BlimpCompositor::DidInitializeCompositorFrameSink() { 270 void BlimpCompositor::DidInitializeCompositorFrameSink() {
268 compositor_frame_sink_request_pending_ = false; 271 compositor_frame_sink_request_pending_ = false;
269 } 272 }
270 273
271 void BlimpCompositor::DidCommitAndDrawFrame() { 274 void BlimpCompositor::DidCommitAndDrawFrame() {
272 if (use_threaded_layer_tree_host_) 275 if (use_threaded_layer_tree_host_)
273 return; 276 return;
274 277
275 DCHECK_GT(outstanding_commits_, 0U); 278 DCHECK_GT(outstanding_commits_, 0U);
276 outstanding_commits_--; 279 outstanding_commits_--;
277 280
278 for (auto it = pending_commit_trackers_.begin(); 281 for (auto it = pending_commit_trackers_.begin();
279 it != pending_commit_trackers_.end();) { 282 it != pending_commit_trackers_.end();) {
280 if (--it->first == 0) { 283 if (--it->first == 0) {
281 if (surface_factory_) 284 if (bound_to_proxy_) {
282 surface_factory_->RequestCopyOfSurface(local_frame_id_, 285 surface_factory_->RequestCopyOfSurface(local_frame_id_,
283 std::move(it->second)); 286 std::move(it->second));
287 }
284 it = pending_commit_trackers_.erase(it); 288 it = pending_commit_trackers_.erase(it);
285 } else { 289 } else {
286 ++it; 290 ++it;
287 } 291 }
288 } 292 }
289 } 293 }
290 294
291 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) { 295 void BlimpCompositor::SetProtoReceiver(ProtoReceiver* receiver) {
292 DCHECK(!use_threaded_layer_tree_host_); 296 DCHECK(!use_threaded_layer_tree_host_);
293 remote_proto_channel_receiver_ = receiver; 297 remote_proto_channel_receiver_ = receiver;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } 368 }
365 369
366 // Returns a reference to the InputHandler owned by layer tree host. 370 // Returns a reference to the InputHandler owned by layer tree host.
367 const base::WeakPtr<cc::InputHandler>& BlimpCompositor::GetInputHandler() { 371 const base::WeakPtr<cc::InputHandler>& BlimpCompositor::GetInputHandler() {
368 return host_->GetInputHandler(); 372 return host_->GetInputHandler();
369 } 373 }
370 374
371 void BlimpCompositor::OnContextProvidersCreated( 375 void BlimpCompositor::OnContextProvidersCreated(
372 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, 376 const scoped_refptr<cc::ContextProvider>& compositor_context_provider,
373 const scoped_refptr<cc::ContextProvider>& worker_context_provider) { 377 const scoped_refptr<cc::ContextProvider>& worker_context_provider) {
374 DCHECK(!surface_factory_) << "Any connection to the old CompositorFrameSink " 378 DCHECK(!bound_to_proxy_) << "Any connection to the old CompositorFrameSink "
375 "should have been destroyed"; 379 "should have been destroyed";
376 380
377 // Make sure we still have a host and we're still expecting a 381 // Make sure we still have a host and we're still expecting a
378 // CompositorFrameSink. This can happen if the host dies while the request is 382 // CompositorFrameSink. This can happen if the host dies while the request is
379 // outstanding and we build a new one that hasn't asked for a surface yet. 383 // outstanding and we build a new one that hasn't asked for a surface yet.
380 if (!compositor_frame_sink_request_pending_) 384 if (!compositor_frame_sink_request_pending_)
381 return; 385 return;
382 386
383 // Try again if the context creation failed. 387 // Try again if the context creation failed.
384 if (!compositor_context_provider) { 388 if (!compositor_context_provider) {
385 GetEmbedderDeps()->GetContextProviders( 389 GetEmbedderDeps()->GetContextProviders(
386 base::Bind(&BlimpCompositor::OnContextProvidersCreated, 390 base::Bind(&BlimpCompositor::OnContextProvidersCreated,
387 weak_ptr_factory_.GetWeakPtr())); 391 weak_ptr_factory_.GetWeakPtr()));
388 return; 392 return;
389 } 393 }
390 394
391 auto compositor_frame_sink = base::MakeUnique<BlimpCompositorFrameSink>( 395 auto compositor_frame_sink = base::MakeUnique<BlimpCompositorFrameSink>(
392 std::move(compositor_context_provider), 396 std::move(compositor_context_provider),
393 std::move(worker_context_provider), 397 std::move(worker_context_provider),
394 GetEmbedderDeps()->GetGpuMemoryBufferManager(), nullptr, 398 GetEmbedderDeps()->GetGpuMemoryBufferManager(), nullptr,
395 base::ThreadTaskRunnerHandle::Get(), weak_ptr_factory_.GetWeakPtr()); 399 base::ThreadTaskRunnerHandle::Get(), weak_ptr_factory_.GetWeakPtr());
396 400
397 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); 401 host_->SetCompositorFrameSink(std::move(compositor_frame_sink));
398 } 402 }
399 403
400 void BlimpCompositor::BindToProxyClient( 404 void BlimpCompositor::BindToProxyClient(
401 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) { 405 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) {
402 DCHECK(thread_checker_.CalledOnValidThread()); 406 DCHECK(thread_checker_.CalledOnValidThread());
403 DCHECK(!surface_factory_); 407 DCHECK(!bound_to_proxy_);
404 408
409 bound_to_proxy_ = true;
405 proxy_client_ = proxy_client; 410 proxy_client_ = proxy_client;
406 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(
407 frame_sink_id_, GetEmbedderDeps()->GetSurfaceManager(), this);
408 } 411 }
409 412
410 void BlimpCompositor::SubmitCompositorFrame(cc::CompositorFrame frame) { 413 void BlimpCompositor::SubmitCompositorFrame(cc::CompositorFrame frame) {
411 DCHECK(thread_checker_.CalledOnValidThread()); 414 DCHECK(thread_checker_.CalledOnValidThread());
412 DCHECK(surface_factory_); 415 DCHECK(bound_to_proxy_);
413 416
414 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); 417 cc::RenderPass* root_pass = frame.render_pass_list.back().get();
415 gfx::Size surface_size = root_pass->output_rect.size(); 418 gfx::Size surface_size = root_pass->output_rect.size();
416 419
417 if (local_frame_id_.is_null() || current_surface_size_ != surface_size) { 420 if (local_frame_id_.is_null() || current_surface_size_ != surface_size) {
418 DestroyDelegatedContent(); 421 DestroyDelegatedContent();
419 DCHECK(layer_->children().empty()); 422 DCHECK(layer_->children().empty());
420 423
421 local_frame_id_ = surface_id_allocator_->GenerateId(); 424 local_frame_id_ = surface_id_allocator_->GenerateId();
422 surface_factory_->Create(local_frame_id_); 425 surface_factory_->Create(local_frame_id_);
(...skipping 21 matching lines...) Expand all
444 weak_ptr_factory_.GetWeakPtr())); 447 weak_ptr_factory_.GetWeakPtr()));
445 448
446 for (auto& copy_request : copy_requests_for_next_swap_) { 449 for (auto& copy_request : copy_requests_for_next_swap_) {
447 surface_factory_->RequestCopyOfSurface(local_frame_id_, 450 surface_factory_->RequestCopyOfSurface(local_frame_id_,
448 std::move(copy_request)); 451 std::move(copy_request));
449 } 452 }
450 copy_requests_for_next_swap_.clear(); 453 copy_requests_for_next_swap_.clear();
451 } 454 }
452 455
453 void BlimpCompositor::SubmitCompositorFrameAck() { 456 void BlimpCompositor::SubmitCompositorFrameAck() {
454 DCHECK(surface_factory_);
455 compositor_dependencies_->GetCompositorTaskRunner()->PostTask( 457 compositor_dependencies_->GetCompositorTaskRunner()->PostTask(
456 FROM_HERE, 458 FROM_HERE,
457 base::Bind(&BlimpCompositorFrameSinkProxyClient::SubmitCompositorFrameAck, 459 base::Bind(&BlimpCompositorFrameSinkProxyClient::SubmitCompositorFrameAck,
458 proxy_client_)); 460 proxy_client_));
459 } 461 }
460 462
461 void BlimpCompositor::MakeCopyRequestOnNextSwap( 463 void BlimpCompositor::MakeCopyRequestOnNextSwap(
462 std::unique_ptr<cc::CopyOutputRequest> copy_request) { 464 std::unique_ptr<cc::CopyOutputRequest> copy_request) {
463 copy_requests_for_next_swap_.push_back(std::move(copy_request)); 465 copy_requests_for_next_swap_.push_back(std::move(copy_request));
464 } 466 }
465 467
466 void BlimpCompositor::UnbindProxyClient() { 468 void BlimpCompositor::UnbindProxyClient() {
467 DCHECK(thread_checker_.CalledOnValidThread()); 469 DCHECK(thread_checker_.CalledOnValidThread());
468 DCHECK(surface_factory_); 470 DCHECK(bound_to_proxy_);
469 471
470 DestroyDelegatedContent(); 472 DestroyDelegatedContent();
471 surface_factory_.reset(); 473 surface_factory_->Reset();
474 bound_to_proxy_ = false;
472 proxy_client_ = nullptr; 475 proxy_client_ = nullptr;
473 } 476 }
474 477
475 void BlimpCompositor::ReturnResources( 478 void BlimpCompositor::ReturnResources(
476 const cc::ReturnedResourceArray& resources) { 479 const cc::ReturnedResourceArray& resources) {
477 DCHECK(surface_factory_); 480 DCHECK(bound_to_proxy_);
478 compositor_dependencies_->GetCompositorTaskRunner()->PostTask( 481 compositor_dependencies_->GetCompositorTaskRunner()->PostTask(
479 FROM_HERE, 482 FROM_HERE,
480 base::Bind( 483 base::Bind(
481 &BlimpCompositorFrameSinkProxyClient::ReclaimCompositorResources, 484 &BlimpCompositorFrameSinkProxyClient::ReclaimCompositorResources,
482 proxy_client_, resources)); 485 proxy_client_, resources));
483 } 486 }
484 487
485 void BlimpCompositor::DidUpdateLocalState() { 488 void BlimpCompositor::DidUpdateLocalState() {
486 client_state_dirty_ = true; 489 client_state_dirty_ = true;
487 } 490 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 556
554 return host; 557 return host;
555 } 558 }
556 559
557 void BlimpCompositor::DestroyLayerTreeHost() { 560 void BlimpCompositor::DestroyLayerTreeHost() {
558 DCHECK(host_); 561 DCHECK(host_);
559 562
560 // Tear down the output surface connection with the old LayerTreeHost 563 // Tear down the output surface connection with the old LayerTreeHost
561 // instance. 564 // instance.
562 DestroyDelegatedContent(); 565 DestroyDelegatedContent();
563 surface_factory_.reset();
564 566
565 // Destroy the old LayerTreeHost state. 567 // Destroy the old LayerTreeHost state.
566 host_.reset(); 568 host_.reset();
567 569
568 // Cancel any outstanding CompositorFrameSink requests. That way if we get an 570 // Cancel any outstanding CompositorFrameSink requests. That way if we get an
569 // async callback related to the old request we know to drop it. 571 // async callback related to the old request we know to drop it.
570 compositor_frame_sink_request_pending_ = false; 572 compositor_frame_sink_request_pending_ = false;
571 573
572 // Make sure we don't have a receiver at this point. 574 // Make sure we don't have a receiver at this point.
573 DCHECK(!remote_proto_channel_receiver_); 575 DCHECK(!remote_proto_channel_receiver_);
574 } 576 }
575 577
576 } // namespace client 578 } // namespace client
577 } // namespace blimp 579 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/core/compositor/blimp_compositor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698