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/. */
7 #ifndef _include_gfx_ipc_CanvasRenderThread_h__
8 #define _include_gfx_ipc_CanvasRenderThread_h__
10 #include "mozilla/AlreadyAddRefed.h"
11 #include "mozilla/Mutex.h"
13 #include "nsISupportsImpl.h"
26 * This class represents the virtual thread for canvas rendering. Depending on
27 * platform requirements and user configuration, canvas rendering may happen on
28 * the Compositor thread, Render thread or the CanvasRender thread.
30 class CanvasRenderThread final
{
31 NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_DELETE_ON_MAIN_THREAD(
35 /// Can only be called from the main thread, expected to be called at most
36 /// once during a process' lifetime. Must be called after the Compositor and
37 /// Render threads are initialized.
40 /// Can only be called from the main thread. Must be called before the
41 /// Compositor and Render threads are shutdown.
42 static void Shutdown();
44 /// Can be called from any thread.
45 static bool IsInCanvasRenderThread();
47 /// Can be called from any thread.
48 static bool IsInCanvasWorkerThread();
50 /// Can be called from any thread.
51 static bool IsInCanvasRenderOrWorkerThread();
53 /// Can be called from any thread, may return nullptr late in shutdown.
54 static already_AddRefed
<nsIThread
> GetCanvasRenderThread();
56 static already_AddRefed
<TaskQueue
> CreateWorkerTaskQueue();
58 static void ShutdownWorkerTaskQueue(TaskQueue
* aTaskQueue
);
60 static void FinishShutdownWorkerTaskQueue(TaskQueue
* aTaskQueue
);
62 static void Dispatch(already_AddRefed
<nsIRunnable
> aRunnable
);
65 CanvasRenderThread(nsCOMPtr
<nsIThread
>&& aThread
,
66 nsCOMPtr
<nsIThreadPool
>&& aWorkers
, bool aCreatedThread
);
67 ~CanvasRenderThread();
71 nsCOMPtr
<nsIThread
> const mThread
;
73 nsCOMPtr
<nsIThreadPool
> const mWorkers
;
75 nsTArray
<RefPtr
<TaskQueue
>> mPendingShutdownTaskQueues
MOZ_GUARDED_BY(mMutex
);
77 // True if mThread points to CanvasRender thread, false if mThread points to
78 // Compositor/Render thread.
79 const bool mCreatedThread
;
83 } // namespace mozilla
85 #endif // _include_gfx_ipc_CanvasRenderThread_h__