tor-browser

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

CanvasShutdownManager.h (1862B)


      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 #ifndef _include_gfx_ipc_CanvasShutdownManager_h__
      7 #define _include_gfx_ipc_CanvasShutdownManager_h__
      8 
      9 #include "mozilla/RefPtr.h"
     10 #include "mozilla/StaticMutex.h"
     11 #include "mozilla/ThreadLocal.h"
     12 #include "mozilla/layers/LayersTypes.h"
     13 #include <set>
     14 
     15 namespace mozilla {
     16 namespace dom {
     17 class CanvasRenderingContext2D;
     18 class StrongWorkerRef;
     19 class ThreadSafeWorkerRef;
     20 }  // namespace dom
     21 
     22 namespace gfx {
     23 
     24 class CanvasShutdownManager final {
     25 public:
     26  static CanvasShutdownManager* Get();
     27  static CanvasShutdownManager* MaybeGet();
     28  static void Shutdown();
     29 
     30  dom::ThreadSafeWorkerRef* GetWorkerRef() const { return mWorkerRef; }
     31  void AddShutdownObserver(dom::CanvasRenderingContext2D* aCanvas);
     32  void RemoveShutdownObserver(dom::CanvasRenderingContext2D* aCanvas);
     33 
     34  static void OnCompositorManagerRestored();
     35 
     36  void OnRemoteCanvasLost();
     37  void OnRemoteCanvasRestored();
     38  void OnRemoteCanvasReset(
     39      const nsTArray<layers::RemoteTextureOwnerId>& aOwnerIds);
     40 
     41 private:
     42  explicit CanvasShutdownManager(dom::StrongWorkerRef* aWorkerRef);
     43  CanvasShutdownManager();
     44  ~CanvasShutdownManager();
     45  void Destroy();
     46 
     47  static void MaybeRestoreRemoteCanvas();
     48 
     49  RefPtr<dom::ThreadSafeWorkerRef> mWorkerRef;
     50  std::set<dom::CanvasRenderingContext2D*> mActiveCanvas;
     51  static MOZ_THREAD_LOCAL(CanvasShutdownManager*) sLocalManager;
     52 
     53  static StaticMutex sManagersMutex;
     54  static std::set<CanvasShutdownManager*> sManagers;
     55 };
     56 
     57 }  // namespace gfx
     58 }  // namespace mozilla
     59 
     60 #endif  // _include_gfx_ipc_CanvasShutdownManager_h__