diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /gfx/layers/SurfacePool.h | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/layers/SurfacePool.h')
-rw-r--r-- | gfx/layers/SurfacePool.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/gfx/layers/SurfacePool.h b/gfx/layers/SurfacePool.h new file mode 100644 index 0000000000..393042addd --- /dev/null +++ b/gfx/layers/SurfacePool.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_layers_SurfacePool_h +#define mozilla_layers_SurfacePool_h + +#include "mozilla/Maybe.h" +#include "mozilla/ThreadSafeWeakPtr.h" + +#include "GLTypes.h" +#include "nsISupportsImpl.h" +#include "nsRegion.h" + +namespace mozilla { + +namespace gl { +class GLContext; +} // namespace gl + +namespace layers { + +class SurfacePoolHandle; + +// A pool of surfaces for NativeLayers. Manages GL resources. Since GLContexts +// are bound to their creator thread, a pool should not be shared across +// threads. Call Create() to create an instance. Call GetHandleForGL() to obtain +// a handle that can be passed to NativeLayerRoot::CreateLayer. +class SurfacePool { + public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePool); + +#ifdef XP_MACOSX + static RefPtr<SurfacePool> Create(size_t aPoolSizeLimit); +#endif + + // aGL can be nullptr. + virtual RefPtr<SurfacePoolHandle> GetHandleForGL(gl::GLContext* aGL) = 0; + virtual void DestroyGLResourcesForContext(gl::GLContext* aGL) = 0; + + protected: + virtual ~SurfacePool() = default; +}; + +class SurfacePoolHandleCA; + +// A handle to the process-wide surface pool. Users should create one handle per +// OS window, and call OnBeginFrame() and OnEndFrame() on the handle at +// appropriate times. OnBeginFrame() and OnEndFrame() should be called on the +// thread that the surface pool was created on. +// These handles are stored on NativeLayers that are created with them and keep +// the SurfacePool alive. +class SurfacePoolHandle { + public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePoolHandle); + virtual SurfacePoolHandleCA* AsSurfacePoolHandleCA() { return nullptr; } + + virtual RefPtr<SurfacePool> Pool() = 0; + + // Should be called every frame, in order to do rate-limited cleanup tasks. + virtual void OnBeginFrame() = 0; + virtual void OnEndFrame() = 0; + + protected: + virtual ~SurfacePoolHandle() = default; +}; + +} // namespace layers +} // namespace mozilla + +#endif // mozilla_layers_SurfacePool_h |