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/DataMutex.h"
11 #include "mozilla/layers/SynchronousTask.h"
12 #include "mozilla/StaticPtr.h"
13 #include "nsISupportsImpl.h"
16 namespace mozilla::gfx
{
18 class CanvasRenderThread final
{
19 NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_DELETE_ON_MAIN_THREAD(
23 /// Can be called from any thread, may return nullptr late in shutdown.
24 static CanvasRenderThread
* Get();
26 /// Can only be called from the main thread, expected to be called at most
27 /// once during a process' lifetime.
30 /// Can only be called from the main thread.
31 static void ShutDown();
33 /// Can be called from any thread.
34 static bool IsInCanvasRenderThread();
36 /// Can be called from any thread, may return nullptr late in shutdown.
37 static already_AddRefed
<nsIThread
> GetCanvasRenderThread();
40 explicit CanvasRenderThread(RefPtr
<nsIThread
> aThread
);
41 ~CanvasRenderThread();
43 void PostRunnable(already_AddRefed
<nsIRunnable
> aRunnable
);
45 RefPtr
<nsIThread
> const mThread
;
48 } // namespace mozilla::gfx
50 #endif // _include_gfx_ipc_CanvasRenderThread_h__