OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/single_thread_proxy.h" | 5 #include "cc/trees/single_thread_proxy.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #if DCHECK_IS_ON() | 45 #if DCHECK_IS_ON() |
46 inside_impl_frame_(false), | 46 inside_impl_frame_(false), |
47 #endif | 47 #endif |
48 inside_draw_(false), | 48 inside_draw_(false), |
49 defer_commits_(false), | 49 defer_commits_(false), |
50 animate_requested_(false), | 50 animate_requested_(false), |
51 commit_requested_(false), | 51 commit_requested_(false), |
52 inside_synchronous_composite_(false), | 52 inside_synchronous_composite_(false), |
53 compositor_frame_sink_creation_requested_(false), | 53 compositor_frame_sink_creation_requested_(false), |
54 compositor_frame_sink_lost_(true), | 54 compositor_frame_sink_lost_(true), |
| 55 frame_sink_bound_weak_factory_(this), |
55 weak_factory_(this) { | 56 weak_factory_(this) { |
56 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 57 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
57 DCHECK(task_runner_provider_); | 58 DCHECK(task_runner_provider_); |
58 DCHECK(task_runner_provider_->IsMainThread()); | 59 DCHECK(task_runner_provider_->IsMainThread()); |
59 DCHECK(layer_tree_host); | 60 DCHECK(layer_tree_host); |
60 } | 61 } |
61 | 62 |
62 void SingleThreadProxy::Start() { | 63 void SingleThreadProxy::Start() { |
63 DebugScopedSetImplThread impl(task_runner_provider_); | 64 DebugScopedSetImplThread impl(task_runner_provider_); |
64 | 65 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 DCHECK(task_runner_provider_->IsMainThread()); | 117 DCHECK(task_runner_provider_->IsMainThread()); |
117 compositor_frame_sink_creation_callback_.Cancel(); | 118 compositor_frame_sink_creation_callback_.Cancel(); |
118 if (compositor_frame_sink_creation_requested_) | 119 if (compositor_frame_sink_creation_requested_) |
119 return; | 120 return; |
120 compositor_frame_sink_creation_requested_ = true; | 121 compositor_frame_sink_creation_requested_ = true; |
121 layer_tree_host_->RequestNewCompositorFrameSink(); | 122 layer_tree_host_->RequestNewCompositorFrameSink(); |
122 } | 123 } |
123 | 124 |
124 void SingleThreadProxy::ReleaseCompositorFrameSink() { | 125 void SingleThreadProxy::ReleaseCompositorFrameSink() { |
125 compositor_frame_sink_lost_ = true; | 126 compositor_frame_sink_lost_ = true; |
| 127 frame_sink_bound_weak_factory_.InvalidateWeakPtrs(); |
126 if (scheduler_on_impl_thread_) | 128 if (scheduler_on_impl_thread_) |
127 scheduler_on_impl_thread_->DidLoseCompositorFrameSink(); | 129 scheduler_on_impl_thread_->DidLoseCompositorFrameSink(); |
128 return layer_tree_host_impl_->ReleaseCompositorFrameSink(); | 130 return layer_tree_host_impl_->ReleaseCompositorFrameSink(); |
129 } | 131 } |
130 | 132 |
131 void SingleThreadProxy::SetCompositorFrameSink( | 133 void SingleThreadProxy::SetCompositorFrameSink( |
132 CompositorFrameSink* compositor_frame_sink) { | 134 CompositorFrameSink* compositor_frame_sink) { |
133 DCHECK(task_runner_provider_->IsMainThread()); | 135 DCHECK(task_runner_provider_->IsMainThread()); |
134 DCHECK(compositor_frame_sink_creation_requested_); | 136 DCHECK(compositor_frame_sink_creation_requested_); |
135 | 137 |
136 bool success; | 138 bool success; |
137 { | 139 { |
138 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); | 140 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
139 DebugScopedSetImplThread impl(task_runner_provider_); | 141 DebugScopedSetImplThread impl(task_runner_provider_); |
140 success = layer_tree_host_impl_->InitializeRenderer(compositor_frame_sink); | 142 success = layer_tree_host_impl_->InitializeRenderer(compositor_frame_sink); |
141 } | 143 } |
142 | 144 |
143 if (success) { | 145 if (success) { |
| 146 frame_sink_bound_weak_ptr_ = frame_sink_bound_weak_factory_.GetWeakPtr(); |
144 layer_tree_host_->DidInitializeCompositorFrameSink(); | 147 layer_tree_host_->DidInitializeCompositorFrameSink(); |
145 if (scheduler_on_impl_thread_) | 148 if (scheduler_on_impl_thread_) |
146 scheduler_on_impl_thread_->DidCreateAndInitializeCompositorFrameSink(); | 149 scheduler_on_impl_thread_->DidCreateAndInitializeCompositorFrameSink(); |
147 else if (!inside_synchronous_composite_) | 150 else if (!inside_synchronous_composite_) |
148 SetNeedsCommit(); | 151 SetNeedsCommit(); |
149 compositor_frame_sink_creation_requested_ = false; | 152 compositor_frame_sink_creation_requested_ = false; |
150 compositor_frame_sink_lost_ = false; | 153 compositor_frame_sink_lost_ = false; |
151 } else { | 154 } else { |
152 // DidFailToInitializeCompositorFrameSink is treated as a | 155 // DidFailToInitializeCompositorFrameSink is treated as a |
153 // RequestNewCompositorFrameSink, and so | 156 // RequestNewCompositorFrameSink, and so |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 void SingleThreadProxy::SetBeginFrameSource(BeginFrameSource* source) { | 421 void SingleThreadProxy::SetBeginFrameSource(BeginFrameSource* source) { |
419 if (scheduler_on_impl_thread_) | 422 if (scheduler_on_impl_thread_) |
420 scheduler_on_impl_thread_->SetBeginFrameSource(source); | 423 scheduler_on_impl_thread_->SetBeginFrameSource(source); |
421 } | 424 } |
422 | 425 |
423 void SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread() { | 426 void SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread() { |
424 TRACE_EVENT0("cc,benchmark", | 427 TRACE_EVENT0("cc,benchmark", |
425 "SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread"); | 428 "SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread"); |
426 if (scheduler_on_impl_thread_) | 429 if (scheduler_on_impl_thread_) |
427 scheduler_on_impl_thread_->DidReceiveCompositorFrameAck(); | 430 scheduler_on_impl_thread_->DidReceiveCompositorFrameAck(); |
428 layer_tree_host_->DidReceiveCompositorFrameAck(); | 431 // We do a PostTask here because freeing resources in some cases (such as in |
| 432 // TextureLayer) is PostTasked and we want to make sure ack is received after |
| 433 // resources are returned. |
| 434 task_runner_provider_->MainThreadTaskRunner()->PostTask( |
| 435 FROM_HERE, base::Bind(&SingleThreadProxy::DidReceiveCompositorFrameAck, |
| 436 frame_sink_bound_weak_ptr_)); |
429 } | 437 } |
430 | 438 |
431 void SingleThreadProxy::OnDrawForCompositorFrameSink( | 439 void SingleThreadProxy::OnDrawForCompositorFrameSink( |
432 bool resourceless_software_draw) { | 440 bool resourceless_software_draw) { |
433 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor."; | 441 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor."; |
434 } | 442 } |
435 | 443 |
436 void SingleThreadProxy::NeedsImplSideInvalidation() { | 444 void SingleThreadProxy::NeedsImplSideInvalidation() { |
437 DCHECK(scheduler_on_impl_thread_); | 445 DCHECK(scheduler_on_impl_thread_); |
438 scheduler_on_impl_thread_->SetNeedsImplSideInvalidation(); | 446 scheduler_on_impl_thread_->SetNeedsImplSideInvalidation(); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 | 795 |
788 void SingleThreadProxy::DidFinishImplFrame() { | 796 void SingleThreadProxy::DidFinishImplFrame() { |
789 layer_tree_host_impl_->DidFinishImplFrame(); | 797 layer_tree_host_impl_->DidFinishImplFrame(); |
790 #if DCHECK_IS_ON() | 798 #if DCHECK_IS_ON() |
791 DCHECK(inside_impl_frame_) | 799 DCHECK(inside_impl_frame_) |
792 << "DidFinishImplFrame called while not inside an impl frame!"; | 800 << "DidFinishImplFrame called while not inside an impl frame!"; |
793 inside_impl_frame_ = false; | 801 inside_impl_frame_ = false; |
794 #endif | 802 #endif |
795 } | 803 } |
796 | 804 |
| 805 void SingleThreadProxy::DidReceiveCompositorFrameAck() { |
| 806 layer_tree_host_->DidReceiveCompositorFrameAck(); |
| 807 } |
| 808 |
797 } // namespace cc | 809 } // namespace cc |
OLD | NEW |