tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CanvasRenderThread.h (2226B)


      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 _include_gfx_ipc_CanvasRenderThread_h__
      8 #define _include_gfx_ipc_CanvasRenderThread_h__
      9 
     10 #include "mozilla/AlreadyAddRefed.h"
     11 #include "mozilla/Mutex.h"
     12 #include "nsCOMPtr.h"
     13 #include "nsISupportsImpl.h"
     14 #include "nsTArray.h"
     15 
     16 class nsIRunnable;
     17 class nsIThread;
     18 
     19 namespace mozilla {
     20 
     21 namespace gfx {
     22 
     23 /**
     24 * This class represents the virtual thread for canvas rendering. Depending on
     25 * platform requirements and user configuration, canvas rendering may happen on
     26 * the Compositor thread, Render thread or the CanvasRender thread.
     27 */
     28 class CanvasRenderThread final {
     29  NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_DELETE_ON_MAIN_THREAD(
     30      CanvasRenderThread)
     31 
     32 public:
     33  /// Can only be called from the main thread, expected to be called at most
     34  /// once during a process' lifetime. Must be called after the Compositor and
     35  /// Render threads are initialized.
     36  static void Start();
     37 
     38  /// Can only be called from the main thread. Must be called before the
     39  /// Compositor and Render threads are shutdown.
     40  static void Shutdown();
     41 
     42  /// Can be called from any thread.
     43  static bool IsInCanvasRenderThread();
     44 
     45  /// Can be called from any thread.
     46  static bool IsInCanvasWorkerThread();
     47 
     48  /// Can be called from any thread.
     49  static bool IsInCanvasRenderOrWorkerThread();
     50 
     51  /// Can be called from any thread, may return nullptr late in shutdown.
     52  static already_AddRefed<nsIThread> GetCanvasRenderThread();
     53 
     54  static void Dispatch(already_AddRefed<nsIRunnable> aRunnable);
     55 
     56 private:
     57  CanvasRenderThread(nsCOMPtr<nsIThread>&& aThread, bool aCreatedThread);
     58  ~CanvasRenderThread();
     59 
     60  Mutex mMutex;
     61 
     62  nsCOMPtr<nsIThread> const mThread;
     63 
     64  // True if mThread points to CanvasRender thread, false if mThread points to
     65  // Compositor/Render thread.
     66  const bool mCreatedThread;
     67 };
     68 
     69 }  // namespace gfx
     70 }  // namespace mozilla
     71 
     72 #endif  // _include_gfx_ipc_CanvasRenderThread_h__