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"
13 #include "nsISupportsImpl.h"
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.
32 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePool
);
34 #if defined(XP_MACOSX) || defined(MOZ_WAYLAND)
35 static RefPtr
<SurfacePool
> Create(size_t aPoolSizeLimit
);
38 // aGL can be nullptr.
39 virtual RefPtr
<SurfacePoolHandle
> GetHandleForGL(gl::GLContext
* aGL
) = 0;
40 virtual void DestroyGLResourcesForContext(gl::GLContext
* aGL
) = 0;
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
{
57 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePoolHandle
);
58 virtual SurfacePoolHandleCA
* AsSurfacePoolHandleCA() { return nullptr; }
59 virtual SurfacePoolHandleWayland
* AsSurfacePoolHandleWayland() {
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;
70 virtual ~SurfacePoolHandle() = default;
74 } // namespace mozilla
76 #endif // mozilla_layers_SurfacePool_h