Bug 1878275 [wpt PR 44378] - [wdspec] add a test for verifying local storage isolatio...
[gecko.git] / gfx / gl / GLScreenBuffer.h
blob0fc3df2a9da8359c4282acdcce6f2a9fbac9c21c
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */
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 /* GLScreenBuffer is the abstraction for the "default framebuffer" used
7 * by an offscreen GLContext. Since it's only for offscreen GLContext's,
8 * it's only useful for things like WebGL, and is NOT used by the
9 * compositor's GLContext. Remember that GLContext provides an abstraction
10 * so that even if you want to draw to the 'screen', even if that's not
11 * actually the screen, just draw to 0. This GLScreenBuffer class takes the
12 * logic handling out of GLContext.
15 #ifndef SCREEN_BUFFER_H_
16 #define SCREEN_BUFFER_H_
18 #include "GLTypes.h"
19 #include "mozilla/gfx/Point.h"
20 #include "mozilla/UniquePtr.h"
22 #include <functional>
23 #include <queue>
24 #include <memory>
26 namespace mozilla {
27 namespace gl {
29 class SharedSurface;
30 class SurfaceFactory;
31 class SwapChain;
33 class SwapChainPresenter final {
34 friend class SwapChain;
36 SwapChain* mSwapChain;
37 std::shared_ptr<SharedSurface> mBackBuffer;
39 public:
40 explicit SwapChainPresenter(SwapChain& swapChain);
41 ~SwapChainPresenter();
43 const auto& BackBuffer() const { return mBackBuffer; }
45 std::shared_ptr<SharedSurface> SwapBackBuffer(std::shared_ptr<SharedSurface>,
46 bool& aSuccess);
47 GLuint Fb() const;
50 // -
52 class SwapChain final {
53 friend class SwapChainPresenter;
55 public:
56 UniquePtr<SurfaceFactory> mFactory;
58 private:
59 std::queue<std::shared_ptr<SharedSurface>> mPool;
60 std::shared_ptr<SharedSurface> mFrontBuffer;
61 std::function<void()> mDestroyedCallback;
63 public:
64 std::shared_ptr<SharedSurface>
65 mPrevFrontBuffer; // Hold this ref while it's in-flight.
66 private:
67 SwapChainPresenter* mPresenter = nullptr;
69 public:
70 SwapChain();
71 virtual ~SwapChain();
73 void ClearPool();
74 bool StoreRecycledSurface(const std::shared_ptr<SharedSurface>& surf);
75 const auto& FrontBuffer() const { return mFrontBuffer; }
76 UniquePtr<SwapChainPresenter> Acquire(const gfx::IntSize&, gfx::ColorSpace2);
78 void SetDestroyedCallback(std::function<void()>&& aDestroyedCallback) {
79 MOZ_ASSERT(!mDestroyedCallback);
80 mDestroyedCallback = std::move(aDestroyedCallback);
81 mPool = {};
85 } // namespace gl
86 } // namespace mozilla
88 #endif // SCREEN_BUFFER_H_