| 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/proxy.h" | 5 #include "cc/trees/proxy.h" |
| 6 | 6 |
| 7 #include "cc/base/thread.h" | 7 #include "base/message_loop_proxy.h" |
| 8 #include "cc/base/thread_impl.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| 11 | 11 |
| 12 Thread* Proxy::MainThread() const { return main_thread_.get(); } | 12 base::SingleThreadTaskRunner* Proxy::MainThreadTaskRunner() const { |
| 13 return main_task_runner_.get(); |
| 14 } |
| 13 | 15 |
| 14 bool Proxy::HasImplThread() const { return impl_thread_; } | 16 bool Proxy::HasImplThread() const { return impl_task_runner_.get(); } |
| 15 | 17 |
| 16 Thread* Proxy::ImplThread() const { return impl_thread_.get(); } | 18 base::SingleThreadTaskRunner* Proxy::ImplThreadTaskRunner() const { |
| 17 | 19 return impl_task_runner_.get(); |
| 18 Thread* Proxy::CurrentThread() const { | |
| 19 if (MainThread() && MainThread()->BelongsToCurrentThread()) | |
| 20 return MainThread(); | |
| 21 if (ImplThread() && ImplThread()->BelongsToCurrentThread()) | |
| 22 return ImplThread(); | |
| 23 return NULL; | |
| 24 } | 20 } |
| 25 | 21 |
| 26 bool Proxy::IsMainThread() const { | 22 bool Proxy::IsMainThread() const { |
| 27 #ifndef NDEBUG | 23 #ifndef NDEBUG |
| 28 DCHECK(MainThread()); | 24 DCHECK(main_task_runner_.get()); |
| 29 if (impl_thread_is_overridden_) | 25 if (impl_thread_is_overridden_) |
| 30 return false; | 26 return false; |
| 31 return MainThread()->BelongsToCurrentThread(); | 27 return main_task_runner_->BelongsToCurrentThread(); |
| 32 #else | 28 #else |
| 33 return true; | 29 return true; |
| 34 #endif | 30 #endif |
| 35 } | 31 } |
| 36 | 32 |
| 37 bool Proxy::IsImplThread() const { | 33 bool Proxy::IsImplThread() const { |
| 38 #ifndef NDEBUG | 34 #ifndef NDEBUG |
| 39 if (impl_thread_is_overridden_) | 35 if (impl_thread_is_overridden_) |
| 40 return true; | 36 return true; |
| 41 return ImplThread() && ImplThread()->BelongsToCurrentThread(); | 37 if (!impl_task_runner_.get()) |
| 38 return false; |
| 39 return impl_task_runner_->BelongsToCurrentThread(); |
| 42 #else | 40 #else |
| 43 return true; | 41 return true; |
| 44 #endif | 42 #endif |
| 45 } | 43 } |
| 46 | 44 |
| 47 #ifndef NDEBUG | 45 #ifndef NDEBUG |
| 48 void Proxy::SetCurrentThreadIsImplThread(bool is_impl_thread) { | 46 void Proxy::SetCurrentThreadIsImplThread(bool is_impl_thread) { |
| 49 impl_thread_is_overridden_ = is_impl_thread; | 47 impl_thread_is_overridden_ = is_impl_thread; |
| 50 } | 48 } |
| 51 #endif | 49 #endif |
| 52 | 50 |
| 53 bool Proxy::IsMainThreadBlocked() const { | 51 bool Proxy::IsMainThreadBlocked() const { |
| 54 #ifndef NDEBUG | 52 #ifndef NDEBUG |
| 55 return is_main_thread_blocked_; | 53 return is_main_thread_blocked_; |
| 56 #else | 54 #else |
| 57 return true; | 55 return true; |
| 58 #endif | 56 #endif |
| 59 } | 57 } |
| 60 | 58 |
| 61 #ifndef NDEBUG | 59 #ifndef NDEBUG |
| 62 void Proxy::SetMainThreadBlocked(bool is_main_thread_blocked) { | 60 void Proxy::SetMainThreadBlocked(bool is_main_thread_blocked) { |
| 63 is_main_thread_blocked_ = is_main_thread_blocked; | 61 is_main_thread_blocked_ = is_main_thread_blocked; |
| 64 } | 62 } |
| 65 #endif | 63 #endif |
| 66 | 64 |
| 67 Proxy::Proxy(scoped_ptr<Thread> impl_thread) | 65 Proxy::Proxy( |
| 68 : main_thread_(ThreadImpl::CreateForCurrentThread()), | 66 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
| 67 : main_task_runner_(base::MessageLoopProxy::current()), |
| 69 #ifdef NDEBUG | 68 #ifdef NDEBUG |
| 70 impl_thread_(impl_thread.Pass()) {} | 69 impl_task_runner_(impl_task_runner) {} |
| 71 #else | 70 #else |
| 72 impl_thread_(impl_thread.Pass()), | 71 impl_task_runner_(impl_task_runner), |
| 73 impl_thread_is_overridden_(false), | 72 impl_thread_is_overridden_(false), |
| 74 is_main_thread_blocked_(false) {} | 73 is_main_thread_blocked_(false) {} |
| 75 #endif | 74 #endif |
| 76 | 75 |
| 77 Proxy::~Proxy() { | 76 Proxy::~Proxy() { |
| 78 DCHECK(IsMainThread()); | 77 DCHECK(IsMainThread()); |
| 79 } | 78 } |
| 80 | 79 |
| 81 } // namespace cc | 80 } // namespace cc |
| OLD | NEW |