APZThreadUtils.h (2257B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_layers_APZThreadUtils_h 8 #define mozilla_layers_APZThreadUtils_h 9 10 #include "nsIEventTarget.h" 11 #include "nsINamed.h" 12 #include "nsITimer.h" 13 #include "nsString.h" 14 15 class nsISerialEventTarget; 16 17 namespace mozilla { 18 19 class Runnable; 20 21 namespace layers { 22 23 class APZThreadUtils { 24 public: 25 /** 26 * In the gtest environment everything runs on one thread, so we 27 * shouldn't assert that we're on a particular thread. This enables 28 * that behaviour. 29 */ 30 static void SetThreadAssertionsEnabled(bool aEnabled); 31 static bool GetThreadAssertionsEnabled(); 32 33 /** 34 * Set the controller thread. 35 */ 36 static void SetControllerThread(nsISerialEventTarget* aThread); 37 38 /** 39 * This can be used to assert that the current thread is the 40 * controller/UI thread (on which input events are received). 41 * This does nothing if thread assertions are disabled. 42 */ 43 static void AssertOnControllerThread(); 44 45 /** 46 * Run the given task on the APZ "controller thread" for this platform. If 47 * this function is called from the controller thread itself then the task is 48 * run immediately without getting queued. 49 */ 50 static void RunOnControllerThread( 51 RefPtr<Runnable>&& aTask, 52 nsIEventTarget::DispatchFlags flags = nsIEventTarget::DISPATCH_NORMAL); 53 54 /** 55 * Get the controller thread. 56 */ 57 static already_AddRefed<nsISerialEventTarget> GetControllerThread(); 58 59 /** 60 * Returns true if currently on APZ "controller thread". 61 */ 62 static bool IsControllerThread(); 63 64 /** 65 * Returns true if the controller thread is still alive. 66 */ 67 static bool IsControllerThreadAlive(); 68 69 /** 70 * Schedules a runnable to run on the controller thread at some time 71 * in the future. 72 */ 73 static void DelayedDispatch(already_AddRefed<Runnable> aRunnable, 74 int aDelayMs); 75 }; 76 77 } // namespace layers 78 } // namespace mozilla 79 80 #endif /* mozilla_layers_APZThreadUtils_h */