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

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

Powered by Google App Engine
This is Rietveld 408576698