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
3 // found in the LICENSE file.
5 #include "cc/trees/proxy.h"
7 #include "base/message_loop/message_loop_proxy.h"
8 #include "base/single_thread_task_runner.h"
9 #include "cc/trees/blocking_task_runner.h"
13 base::SingleThreadTaskRunner
* Proxy::MainThreadTaskRunner() const {
14 return main_task_runner_
.get();
17 bool Proxy::HasImplThread() const { return !!impl_task_runner_
.get(); }
19 base::SingleThreadTaskRunner
* Proxy::ImplThreadTaskRunner() const {
20 return impl_task_runner_
.get();
23 bool Proxy::IsMainThread() const {
25 if (impl_thread_is_overridden_
)
28 bool is_main_thread
= base::PlatformThread::CurrentId() == main_thread_id_
;
29 if (is_main_thread
&& main_task_runner_
.get()) {
30 DCHECK(main_task_runner_
->BelongsToCurrentThread());
32 return is_main_thread
;
38 bool Proxy::IsImplThread() const {
40 if (impl_thread_is_overridden_
)
42 if (!impl_task_runner_
.get())
44 return impl_task_runner_
->BelongsToCurrentThread();
51 void Proxy::SetCurrentThreadIsImplThread(bool is_impl_thread
) {
52 impl_thread_is_overridden_
= is_impl_thread
;
56 bool Proxy::IsMainThreadBlocked() const {
58 return is_main_thread_blocked_
;
65 void Proxy::SetMainThreadBlocked(bool is_main_thread_blocked
) {
66 is_main_thread_blocked_
= is_main_thread_blocked
;
70 Proxy::Proxy(scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner
,
71 scoped_refptr
<base::SingleThreadTaskRunner
> impl_task_runner
)
73 : main_task_runner_(main_task_runner
),
74 impl_task_runner_(impl_task_runner
),
75 blocking_main_thread_task_runner_(
76 BlockingTaskRunner::Create(main_task_runner
)) {
78 : main_task_runner_(main_task_runner
),
79 impl_task_runner_(impl_task_runner
),
80 blocking_main_thread_task_runner_(
81 BlockingTaskRunner::Create(main_task_runner
)),
82 main_thread_id_(base::PlatformThread::CurrentId()),
83 impl_thread_is_overridden_(false),
84 is_main_thread_blocked_(false) {
89 DCHECK(IsMainThread());