Chromium Code Reviews| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/proxy.h" | 7 #include "cc/proxy.h" |
| 8 | 8 |
| 9 #include "webkit/compositor_bindings/ccthread_impl.h" | |
| 9 #include "cc/thread_task.h" | 10 #include "cc/thread_task.h" |
| 10 | 11 |
| 11 namespace cc { | 12 namespace cc { |
| 12 | 13 |
| 13 namespace { | 14 void Proxy::setMainThread(Thread* thread) |
| 14 #ifndef NDEBUG | 15 { |
| 15 bool implThreadIsOverridden = false; | 16 m_mainThread.reset(thread); |
| 16 bool s_isMainThreadBlocked = false; | |
| 17 base::PlatformThreadId threadIDOverridenToBeImplThread; | |
| 18 #endif | |
| 19 Thread* s_mainThread = 0; | |
| 20 Thread* s_implThread = 0; | |
| 21 } | 17 } |
| 22 | 18 |
| 23 void Proxy::setMainThread(Thread* thread) | 19 Thread* Proxy::mainThread() const |
| 24 { | 20 { |
| 25 s_mainThread = thread; | 21 return m_mainThread.get(); |
| 26 } | 22 } |
| 27 | 23 |
| 28 Thread* Proxy::mainThread() | 24 bool Proxy::hasImplThread() const |
| 29 { | 25 { |
| 30 return s_mainThread; | 26 return !!m_implThread.get(); |
| 31 } | |
| 32 | |
| 33 bool Proxy::hasImplThread() | |
| 34 { | |
| 35 return s_implThread; | |
| 36 } | 27 } |
| 37 | 28 |
| 38 void Proxy::setImplThread(Thread* thread) | 29 void Proxy::setImplThread(Thread* thread) |
| 39 { | 30 { |
| 40 s_implThread = thread; | 31 m_implThread.reset(thread); |
| 41 } | 32 } |
| 42 | 33 |
| 43 Thread* Proxy::implThread() | 34 Thread* Proxy::implThread() const |
| 44 { | 35 { |
| 45 return s_implThread; | 36 return m_implThread.get(); |
| 46 } | 37 } |
| 47 | 38 |
| 48 Thread* Proxy::currentThread() | 39 Thread* Proxy::currentThread() const |
| 49 { | 40 { |
| 50 base::PlatformThreadId currentThreadIdentifier = base::PlatformThread::Curre ntId(); | 41 base::PlatformThreadId currentThreadIdentifier = base::PlatformThread::Curre ntId(); |
| 51 if (s_mainThread && s_mainThread->threadID() == currentThreadIdentifier) | 42 if (mainThread() && mainThread()->threadID() == currentThreadIdentifier) |
| 52 return s_mainThread; | 43 return mainThread(); |
| 53 if (s_implThread && s_implThread->threadID() == currentThreadIdentifier) | 44 if (implThread() && implThread()->threadID() == currentThreadIdentifier) |
| 54 return s_implThread; | 45 return implThread(); |
| 55 return 0; | 46 return 0; |
| 56 } | 47 } |
| 57 | 48 |
| 58 bool Proxy::isMainThread() | 49 bool Proxy::isMainThread() const |
| 59 { | 50 { |
| 60 #ifndef NDEBUG | 51 #ifndef NDEBUG |
| 61 DCHECK(s_mainThread); | 52 DCHECK(mainThread()); |
| 62 if (implThreadIsOverridden && base::PlatformThread::CurrentId() == threadIDO verridenToBeImplThread) | 53 if (m_implThreadIsOverridden && base::PlatformThread::CurrentId() == m_threa dIDOverridenToBeImplThread) |
| 63 return false; | 54 return false; |
| 64 return base::PlatformThread::CurrentId() == s_mainThread->threadID(); | 55 return base::PlatformThread::CurrentId() == mainThread()->threadID(); |
| 65 #else | 56 #else |
| 66 return true; | 57 return true; |
| 67 #endif | 58 #endif |
| 68 } | 59 } |
| 69 | 60 |
| 70 bool Proxy::isImplThread() | 61 bool Proxy::isImplThread() const |
| 71 { | 62 { |
| 72 #ifndef NDEBUG | 63 #ifndef NDEBUG |
| 73 base::PlatformThreadId implThreadID = s_implThread ? s_implThread->threadID( ) : 0; | 64 base::PlatformThreadId implThreadID = implThread() ? implThread()->threadID( ) : 0; |
| 74 if (implThreadIsOverridden && base::PlatformThread::CurrentId() == threadIDO verridenToBeImplThread) | 65 if (m_implThreadIsOverridden && base::PlatformThread::CurrentId() == m_threa dIDOverridenToBeImplThread) |
| 75 return true; | 66 return true; |
| 76 return base::PlatformThread::CurrentId() == implThreadID; | 67 return base::PlatformThread::CurrentId() == implThreadID; |
| 77 #else | 68 #else |
| 78 return true; | 69 return true; |
| 79 #endif | 70 #endif |
| 80 } | 71 } |
| 81 | 72 |
| 82 #ifndef NDEBUG | 73 #ifndef NDEBUG |
| 83 void Proxy::setCurrentThreadIsImplThread(bool isImplThread) | 74 void Proxy::setCurrentThreadIsImplThread(bool isImplThread) |
| 84 { | 75 { |
| 85 implThreadIsOverridden = isImplThread; | 76 m_implThreadIsOverridden = isImplThread; |
| 86 if (isImplThread) | 77 if (isImplThread) |
| 87 threadIDOverridenToBeImplThread = base::PlatformThread::CurrentId(); | 78 m_threadIDOverridenToBeImplThread = base::PlatformThread::CurrentId(); |
| 88 } | 79 } |
| 89 #endif | 80 #endif |
| 90 | 81 |
| 91 bool Proxy::isMainThreadBlocked() | 82 bool Proxy::isMainThreadBlocked() const |
| 92 { | 83 { |
| 93 #ifndef NDEBUG | 84 #ifndef NDEBUG |
| 94 return s_isMainThreadBlocked; | 85 return m_isMainThreadBlocked; |
| 95 #else | 86 #else |
| 96 return true; | 87 return true; |
| 97 #endif | 88 #endif |
| 98 } | 89 } |
| 99 | 90 |
| 100 #ifndef NDEBUG | 91 #ifndef NDEBUG |
| 101 void Proxy::setMainThreadBlocked(bool isMainThreadBlocked) | 92 void Proxy::setMainThreadBlocked(bool isMainThreadBlocked) |
| 102 { | 93 { |
| 103 s_isMainThreadBlocked = isMainThreadBlocked; | 94 m_isMainThreadBlocked = isMainThreadBlocked; |
| 104 } | 95 } |
| 105 #endif | 96 #endif |
| 106 | 97 |
| 107 Proxy::Proxy() | 98 Proxy::Proxy(Thread* implThread) |
| 99 : m_mainThread(WebKit::CCThreadImpl::createForCurrentThread()) | |
| 100 , m_implThread(implThread) | |
| 101 #ifndef NDEBUG | |
| 102 , m_implThreadIsOverridden(false) | |
| 103 , m_isMainThreadBlocked(false) | |
| 104 #endif | |
| 108 { | 105 { |
|
danakj
2012/10/25 05:06:06
DCHECK(m_mainThread != m_implThread) ?
| |
| 109 DCHECK(isMainThread()); | |
| 110 } | 106 } |
| 111 | 107 |
| 112 Proxy::~Proxy() | 108 Proxy::~Proxy() |
| 113 { | 109 { |
| 114 DCHECK(isMainThread()); | 110 DCHECK(isMainThread()); |
| 115 } | 111 } |
| 116 | 112 |
| 117 } | 113 } |
| OLD | NEW |