Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / gfx / layers / SurfacePool.h
blobeecb398d85ad44cd57ca224610da3fa798ef8742
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/. */
6 #ifndef mozilla_layers_SurfacePool_h
7 #define mozilla_layers_SurfacePool_h
9 #include "mozilla/Maybe.h"
10 #include "mozilla/ThreadSafeWeakPtr.h"
12 #include "GLTypes.h"
13 #include "nsISupportsImpl.h"
14 #include "nsRegion.h"
16 namespace mozilla {
18 namespace gl {
19 class GLContext;
20 } // namespace gl
22 namespace layers {
24 class SurfacePoolHandle;
26 // A pool of surfaces for NativeLayers. Manages GL resources. Since GLContexts
27 // are bound to their creator thread, a pool should not be shared across
28 // threads. Call Create() to create an instance. Call GetHandleForGL() to obtain
29 // a handle that can be passed to NativeLayerRoot::CreateLayer.
30 class SurfacePool {
31 public:
32 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePool);
34 #if defined(XP_MACOSX) || defined(MOZ_WAYLAND)
35 static RefPtr<SurfacePool> Create(size_t aPoolSizeLimit);
36 #endif
38 // aGL can be nullptr.
39 virtual RefPtr<SurfacePoolHandle> GetHandleForGL(gl::GLContext* aGL) = 0;
40 virtual void DestroyGLResourcesForContext(gl::GLContext* aGL) = 0;
42 protected:
43 virtual ~SurfacePool() = default;
46 class SurfacePoolHandleCA;
47 class SurfacePoolHandleWayland;
49 // A handle to the process-wide surface pool. Users should create one handle per
50 // OS window, and call OnBeginFrame() and OnEndFrame() on the handle at
51 // appropriate times. OnBeginFrame() and OnEndFrame() should be called on the
52 // thread that the surface pool was created on.
53 // These handles are stored on NativeLayers that are created with them and keep
54 // the SurfacePool alive.
55 class SurfacePoolHandle {
56 public:
57 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePoolHandle);
58 virtual SurfacePoolHandleCA* AsSurfacePoolHandleCA() { return nullptr; }
59 virtual SurfacePoolHandleWayland* AsSurfacePoolHandleWayland() {
60 return nullptr;
63 virtual RefPtr<SurfacePool> Pool() = 0;
65 // Should be called every frame, in order to do rate-limited cleanup tasks.
66 virtual void OnBeginFrame() = 0;
67 virtual void OnEndFrame() = 0;
69 protected:
70 virtual ~SurfacePoolHandle() = default;
73 } // namespace layers
74 } // namespace mozilla
76 #endif // mozilla_layers_SurfacePool_h