| 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/thread_proxy.h" | 5 #include "cc/trees/thread_proxy.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 struct ThreadProxy::SchedulerStateRequest { | 43 struct ThreadProxy::SchedulerStateRequest { |
| 44 CompletionEvent completion; | 44 CompletionEvent completion; |
| 45 scoped_ptr<base::Value> state; | 45 scoped_ptr<base::Value> state; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 scoped_ptr<Proxy> ThreadProxy::Create( | 48 scoped_ptr<Proxy> ThreadProxy::Create( |
| 49 LayerTreeHost* layer_tree_host, | 49 LayerTreeHost* layer_tree_host, |
| 50 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 50 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 51 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 51 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 52 return make_scoped_ptr( | 52 scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
| 53 new ThreadProxy(layer_tree_host, main_task_runner, impl_task_runner)); | 53 return make_scoped_ptr(new ThreadProxy(layer_tree_host, |
| 54 main_task_runner, |
| 55 impl_task_runner, |
| 56 external_begin_frame_source.Pass())); |
| 54 } | 57 } |
| 55 | 58 |
| 56 ThreadProxy::ThreadProxy( | 59 ThreadProxy::ThreadProxy( |
| 57 LayerTreeHost* layer_tree_host, | 60 LayerTreeHost* layer_tree_host, |
| 58 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 61 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 59 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) | 62 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 63 scoped_ptr<BeginFrameSource> external_begin_frame_source) |
| 60 : Proxy(main_task_runner, impl_task_runner), | 64 : Proxy(main_task_runner, impl_task_runner), |
| 61 main_thread_only_vars_unsafe_(this, layer_tree_host->id()), | 65 main_thread_only_vars_unsafe_(this, layer_tree_host->id()), |
| 62 main_thread_or_blocked_vars_unsafe_(layer_tree_host), | 66 main_thread_or_blocked_vars_unsafe_(layer_tree_host), |
| 63 compositor_thread_vars_unsafe_( | 67 compositor_thread_vars_unsafe_( |
| 64 this, | 68 this, |
| 65 layer_tree_host->id(), | 69 layer_tree_host->id(), |
| 66 layer_tree_host->rendering_stats_instrumentation()) { | 70 layer_tree_host->rendering_stats_instrumentation(), |
| 71 external_begin_frame_source.Pass()) { |
| 67 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); | 72 TRACE_EVENT0("cc", "ThreadProxy::ThreadProxy"); |
| 68 DCHECK(IsMainThread()); | 73 DCHECK(IsMainThread()); |
| 69 DCHECK(this->layer_tree_host()); | 74 DCHECK(this->layer_tree_host()); |
| 70 } | 75 } |
| 71 | 76 |
| 72 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy, | 77 ThreadProxy::MainThreadOnly::MainThreadOnly(ThreadProxy* proxy, |
| 73 int layer_tree_host_id) | 78 int layer_tree_host_id) |
| 74 : layer_tree_host_id(layer_tree_host_id), | 79 : layer_tree_host_id(layer_tree_host_id), |
| 75 animate_requested(false), | 80 animate_requested(false), |
| 76 commit_requested(false), | 81 commit_requested(false), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 92 ThreadProxy::MainThreadOrBlockedMainThread::~MainThreadOrBlockedMainThread() {} | 97 ThreadProxy::MainThreadOrBlockedMainThread::~MainThreadOrBlockedMainThread() {} |
| 93 | 98 |
| 94 PrioritizedResourceManager* | 99 PrioritizedResourceManager* |
| 95 ThreadProxy::MainThreadOrBlockedMainThread::contents_texture_manager() { | 100 ThreadProxy::MainThreadOrBlockedMainThread::contents_texture_manager() { |
| 96 return layer_tree_host->contents_texture_manager(); | 101 return layer_tree_host->contents_texture_manager(); |
| 97 } | 102 } |
| 98 | 103 |
| 99 ThreadProxy::CompositorThreadOnly::CompositorThreadOnly( | 104 ThreadProxy::CompositorThreadOnly::CompositorThreadOnly( |
| 100 ThreadProxy* proxy, | 105 ThreadProxy* proxy, |
| 101 int layer_tree_host_id, | 106 int layer_tree_host_id, |
| 102 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 107 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 108 scoped_ptr<BeginFrameSource> external_begin_frame_source) |
| 103 : layer_tree_host_id(layer_tree_host_id), | 109 : layer_tree_host_id(layer_tree_host_id), |
| 104 contents_texture_manager(NULL), | 110 contents_texture_manager(NULL), |
| 105 commit_completion_event(NULL), | 111 commit_completion_event(NULL), |
| 106 completion_event_for_commit_held_on_tree_activation(NULL), | 112 completion_event_for_commit_held_on_tree_activation(NULL), |
| 107 next_frame_is_newly_committed_frame(false), | 113 next_frame_is_newly_committed_frame(false), |
| 108 inside_draw(false), | 114 inside_draw(false), |
| 109 input_throttled_until_commit(false), | 115 input_throttled_until_commit(false), |
| 110 did_commit_after_animating(false), | 116 did_commit_after_animating(false), |
| 111 smoothness_priority_expiration_notifier( | 117 smoothness_priority_expiration_notifier( |
| 112 proxy->ImplThreadTaskRunner(), | 118 proxy->ImplThreadTaskRunner(), |
| 113 base::Bind(&ThreadProxy::RenewTreePriority, base::Unretained(proxy)), | 119 base::Bind(&ThreadProxy::RenewTreePriority, base::Unretained(proxy)), |
| 114 base::TimeDelta::FromMilliseconds( | 120 base::TimeDelta::FromMilliseconds( |
| 115 kSmoothnessTakesPriorityExpirationDelay * 1000)), | 121 kSmoothnessTakesPriorityExpirationDelay * 1000)), |
| 116 timing_history(rendering_stats_instrumentation), | 122 timing_history(rendering_stats_instrumentation), |
| 123 external_begin_frame_source(external_begin_frame_source.Pass()), |
| 117 weak_factory(proxy) { | 124 weak_factory(proxy) { |
| 118 } | 125 } |
| 119 | 126 |
| 120 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} | 127 ThreadProxy::CompositorThreadOnly::~CompositorThreadOnly() {} |
| 121 | 128 |
| 122 ThreadProxy::~ThreadProxy() { | 129 ThreadProxy::~ThreadProxy() { |
| 123 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); | 130 TRACE_EVENT0("cc", "ThreadProxy::~ThreadProxy"); |
| 124 DCHECK(IsMainThread()); | 131 DCHECK(IsMainThread()); |
| 125 DCHECK(!main().started); | 132 DCHECK(!main().started); |
| 126 } | 133 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 346 |
| 340 void ThreadProxy::DidSwapBuffersCompleteOnImplThread() { | 347 void ThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
| 341 TRACE_EVENT0("cc", "ThreadProxy::DidSwapBuffersCompleteOnImplThread"); | 348 TRACE_EVENT0("cc", "ThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
| 342 DCHECK(IsImplThread()); | 349 DCHECK(IsImplThread()); |
| 343 impl().scheduler->DidSwapBuffersComplete(); | 350 impl().scheduler->DidSwapBuffersComplete(); |
| 344 Proxy::MainThreadTaskRunner()->PostTask( | 351 Proxy::MainThreadTaskRunner()->PostTask( |
| 345 FROM_HERE, | 352 FROM_HERE, |
| 346 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); | 353 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); |
| 347 } | 354 } |
| 348 | 355 |
| 349 BeginFrameSource* ThreadProxy::ExternalBeginFrameSource() { | |
| 350 return impl().layer_tree_host_impl.get(); | |
| 351 } | |
| 352 | |
| 353 void ThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { | 356 void ThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { |
| 354 impl().layer_tree_host_impl->WillBeginImplFrame(args); | 357 impl().layer_tree_host_impl->WillBeginImplFrame(args); |
| 355 } | 358 } |
| 356 | 359 |
| 357 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { | 360 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
| 358 TRACE_EVENT1( | 361 TRACE_EVENT1( |
| 359 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); | 362 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
| 360 DCHECK(IsImplThread()); | 363 DCHECK(IsImplThread()); |
| 361 impl().scheduler->SetCanDraw(can_draw); | 364 impl().scheduler->SetCanDraw(can_draw); |
| 362 UpdateBackgroundAnimateTicking(); | 365 UpdateBackgroundAnimateTicking(); |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 DCHECK(IsMainThread()); | 1154 DCHECK(IsMainThread()); |
| 1152 layer_tree_host()->SetAnimationEvents(events.Pass()); | 1155 layer_tree_host()->SetAnimationEvents(events.Pass()); |
| 1153 } | 1156 } |
| 1154 | 1157 |
| 1155 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { | 1158 void ThreadProxy::InitializeImplOnImplThread(CompletionEvent* completion) { |
| 1156 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); | 1159 TRACE_EVENT0("cc", "ThreadProxy::InitializeImplOnImplThread"); |
| 1157 DCHECK(IsImplThread()); | 1160 DCHECK(IsImplThread()); |
| 1158 impl().layer_tree_host_impl = | 1161 impl().layer_tree_host_impl = |
| 1159 layer_tree_host()->CreateLayerTreeHostImpl(this); | 1162 layer_tree_host()->CreateLayerTreeHostImpl(this); |
| 1160 SchedulerSettings scheduler_settings(layer_tree_host()->settings()); | 1163 SchedulerSettings scheduler_settings(layer_tree_host()->settings()); |
| 1161 impl().scheduler = Scheduler::Create(this, | 1164 impl().scheduler = Scheduler::Create( |
| 1162 scheduler_settings, | 1165 this, |
| 1163 impl().layer_tree_host_id, | 1166 scheduler_settings, |
| 1164 ImplThreadTaskRunner(), | 1167 impl().layer_tree_host_id, |
| 1165 base::PowerMonitor::Get()); | 1168 ImplThreadTaskRunner(), |
| 1169 base::PowerMonitor::Get(), |
| 1170 impl().external_begin_frame_source.Pass()); |
| 1166 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); | 1171 impl().scheduler->SetVisible(impl().layer_tree_host_impl->visible()); |
| 1167 | |
| 1168 impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr(); | 1172 impl_thread_weak_ptr_ = impl().weak_factory.GetWeakPtr(); |
| 1169 completion->Signal(); | 1173 completion->Signal(); |
| 1170 } | 1174 } |
| 1171 | 1175 |
| 1172 void ThreadProxy::DeleteContentsTexturesOnImplThread( | 1176 void ThreadProxy::DeleteContentsTexturesOnImplThread( |
| 1173 CompletionEvent* completion) { | 1177 CompletionEvent* completion) { |
| 1174 TRACE_EVENT0("cc", "ThreadProxy::DeleteContentsTexturesOnImplThread"); | 1178 TRACE_EVENT0("cc", "ThreadProxy::DeleteContentsTexturesOnImplThread"); |
| 1175 DCHECK(IsImplThread()); | 1179 DCHECK(IsImplThread()); |
| 1176 DCHECK(IsMainThreadBlocked()); | 1180 DCHECK(IsMainThreadBlocked()); |
| 1177 layer_tree_host()->DeleteContentsTexturesOnImplThread( | 1181 layer_tree_host()->DeleteContentsTexturesOnImplThread( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 completion->Signal(); | 1219 completion->Signal(); |
| 1216 } | 1220 } |
| 1217 | 1221 |
| 1218 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { | 1222 void ThreadProxy::LayerTreeHostClosedOnImplThread(CompletionEvent* completion) { |
| 1219 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); | 1223 TRACE_EVENT0("cc", "ThreadProxy::LayerTreeHostClosedOnImplThread"); |
| 1220 DCHECK(IsImplThread()); | 1224 DCHECK(IsImplThread()); |
| 1221 DCHECK(IsMainThreadBlocked()); | 1225 DCHECK(IsMainThreadBlocked()); |
| 1222 layer_tree_host()->DeleteContentsTexturesOnImplThread( | 1226 layer_tree_host()->DeleteContentsTexturesOnImplThread( |
| 1223 impl().layer_tree_host_impl->resource_provider()); | 1227 impl().layer_tree_host_impl->resource_provider()); |
| 1224 impl().current_resource_update_controller = nullptr; | 1228 impl().current_resource_update_controller = nullptr; |
| 1225 impl().layer_tree_host_impl->SetNeedsBeginFrames(false); | |
| 1226 impl().scheduler = nullptr; | 1229 impl().scheduler = nullptr; |
| 1227 impl().layer_tree_host_impl = nullptr; | 1230 impl().layer_tree_host_impl = nullptr; |
| 1228 impl().weak_factory.InvalidateWeakPtrs(); | 1231 impl().weak_factory.InvalidateWeakPtrs(); |
| 1229 // We need to explicitly cancel the notifier, since it isn't using weak ptrs. | 1232 // We need to explicitly cancel the notifier, since it isn't using weak ptrs. |
| 1230 // TODO(vmpstr): We should see if we can make it use weak ptrs and still keep | 1233 // TODO(vmpstr): We should see if we can make it use weak ptrs and still keep |
| 1231 // the convention of having a weak ptr factory initialized last. Alternatively | 1234 // the convention of having a weak ptr factory initialized last. Alternatively |
| 1232 // we should moved the notifier (and RenewTreePriority) to LTHI. See | 1235 // we should moved the notifier (and RenewTreePriority) to LTHI. See |
| 1233 // crbug.com/411972 | 1236 // crbug.com/411972 |
| 1234 impl().smoothness_priority_expiration_notifier.Cancel(); | 1237 impl().smoothness_priority_expiration_notifier.Cancel(); |
| 1235 impl().contents_texture_manager = NULL; | 1238 impl().contents_texture_manager = NULL; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 | 1376 |
| 1374 impl().timing_history.DidActivateSyncTree(); | 1377 impl().timing_history.DidActivateSyncTree(); |
| 1375 } | 1378 } |
| 1376 | 1379 |
| 1377 void ThreadProxy::DidManageTiles() { | 1380 void ThreadProxy::DidManageTiles() { |
| 1378 DCHECK(IsImplThread()); | 1381 DCHECK(IsImplThread()); |
| 1379 impl().scheduler->DidManageTiles(); | 1382 impl().scheduler->DidManageTiles(); |
| 1380 } | 1383 } |
| 1381 | 1384 |
| 1382 } // namespace cc | 1385 } // namespace cc |
| OLD | NEW |