Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "mozilla/layers/APZThreadUtils.h"
7 :
8 : #include "mozilla/layers/Compositor.h"
9 :
10 : namespace mozilla {
11 : namespace layers {
12 :
13 : static bool sThreadAssertionsEnabled = true;
14 : static MessageLoop* sControllerThread;
15 :
16 : /*static*/ void
17 0 : APZThreadUtils::SetThreadAssertionsEnabled(bool aEnabled) {
18 0 : sThreadAssertionsEnabled = aEnabled;
19 0 : }
20 :
21 : /*static*/ bool
22 330 : APZThreadUtils::GetThreadAssertionsEnabled() {
23 330 : return sThreadAssertionsEnabled;
24 : }
25 :
26 : /*static*/ void
27 1 : APZThreadUtils::SetControllerThread(MessageLoop* aLoop)
28 : {
29 : // We must either be setting the initial controller thread, or removing it,
30 : // or re-using an existing controller thread.
31 1 : MOZ_ASSERT(!sControllerThread || !aLoop || sControllerThread == aLoop);
32 1 : sControllerThread = aLoop;
33 1 : }
34 :
35 : /*static*/ void
36 14 : APZThreadUtils::AssertOnControllerThread() {
37 14 : if (!GetThreadAssertionsEnabled()) {
38 0 : return;
39 : }
40 :
41 14 : MOZ_ASSERT(sControllerThread == MessageLoop::current());
42 : }
43 :
44 : /*static*/ void
45 316 : APZThreadUtils::AssertOnCompositorThread()
46 : {
47 316 : if (GetThreadAssertionsEnabled()) {
48 316 : Compositor::AssertOnCompositorThread();
49 : }
50 316 : }
51 :
52 : /*static*/ void
53 0 : APZThreadUtils::RunOnControllerThread(already_AddRefed<Runnable> aTask)
54 : {
55 0 : RefPtr<Runnable> task = aTask;
56 :
57 0 : if (!sControllerThread) {
58 : // Could happen on startup
59 0 : NS_WARNING("Dropping task posted to controller thread");
60 0 : return;
61 : }
62 :
63 0 : if (sControllerThread == MessageLoop::current()) {
64 0 : task->Run();
65 : } else {
66 0 : sControllerThread->PostTask(task.forget());
67 : }
68 : }
69 :
70 : /*static*/ bool
71 6 : APZThreadUtils::IsControllerThread()
72 : {
73 6 : return sControllerThread == MessageLoop::current();
74 : }
75 :
76 9 : NS_IMPL_ISUPPORTS(GenericNamedTimerCallbackBase, nsITimerCallback, nsINamed)
77 :
78 : } // namespace layers
79 : } // namespace mozilla
|