tor-browser

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

SurfacePool.h (2315B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef mozilla_layers_SurfacePool_h
      7 #define mozilla_layers_SurfacePool_h
      8 
      9 #include "GLTypes.h"
     10 #include "nsISupportsImpl.h"
     11 #include "nsRegion.h"
     12 
     13 namespace mozilla {
     14 
     15 namespace gl {
     16 class GLContext;
     17 }  // namespace gl
     18 
     19 namespace layers {
     20 
     21 class SurfacePoolHandle;
     22 
     23 // A pool of surfaces for NativeLayers. Manages GL resources. Since GLContexts
     24 // are bound to their creator thread, a pool should not be shared across
     25 // threads. Call Create() to create an instance. Call GetHandleForGL() to obtain
     26 // a handle that can be passed to NativeLayerRoot::CreateLayer.
     27 class SurfacePool {
     28 public:
     29  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePool);
     30 
     31 #if defined(XP_DARWIN) || defined(MOZ_WAYLAND)
     32  static RefPtr<SurfacePool> Create(size_t aPoolSizeLimit);
     33 #endif
     34 
     35  // aGL can be nullptr.
     36  virtual RefPtr<SurfacePoolHandle> GetHandleForGL(gl::GLContext* aGL) = 0;
     37  virtual void DestroyGLResourcesForContext(gl::GLContext* aGL) = 0;
     38 
     39 protected:
     40  virtual ~SurfacePool() = default;
     41 };
     42 
     43 class SurfacePoolHandleCA;
     44 class SurfacePoolHandleWayland;
     45 
     46 // A handle to the process-wide surface pool. Users should create one handle per
     47 // OS window, and call OnBeginFrame() and OnEndFrame() on the handle at
     48 // appropriate times. OnBeginFrame() and OnEndFrame() should be called on the
     49 // thread that the surface pool was created on.
     50 // These handles are stored on NativeLayers that are created with them and keep
     51 // the SurfacePool alive.
     52 class SurfacePoolHandle {
     53 public:
     54  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePoolHandle);
     55  virtual SurfacePoolHandleCA* AsSurfacePoolHandleCA() { return nullptr; }
     56  virtual SurfacePoolHandleWayland* AsSurfacePoolHandleWayland() {
     57    return nullptr;
     58  }
     59 
     60  virtual RefPtr<SurfacePool> Pool() = 0;
     61 
     62  // Should be called every frame, in order to do rate-limited cleanup tasks.
     63  virtual void OnBeginFrame() = 0;
     64  virtual void OnEndFrame() = 0;
     65 
     66 protected:
     67  virtual ~SurfacePoolHandle() = default;
     68 };
     69 
     70 }  // namespace layers
     71 }  // namespace mozilla
     72 
     73 #endif  // mozilla_layers_SurfacePool_h