Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / gfx / gl / GLScreenBuffer.h
blobd2812497716b05ec14aa392d98075b8956a94cfe
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 GLuint Fb() const;
49 // -
51 class SwapChain final {
52 friend class SwapChainPresenter;
54 public:
55 UniquePtr<SurfaceFactory> mFactory;
57 private:
58 std::queue<std::shared_ptr<SharedSurface>> mPool;
59 std::shared_ptr<SharedSurface> mFrontBuffer;
60 std::function<void()> mDestroyedCallback;
62 public:
63 std::shared_ptr<SharedSurface>
64 mPrevFrontBuffer; // Hold this ref while it's in-flight.
65 private:
66 SwapChainPresenter* mPresenter = nullptr;
68 public:
69 SwapChain();
70 virtual ~SwapChain();
72 void ClearPool();
73 bool StoreRecycledSurface(const std::shared_ptr<SharedSurface>& surf);
74 const auto& FrontBuffer() const { return mFrontBuffer; }
75 UniquePtr<SwapChainPresenter> Acquire(const gfx::IntSize&, gfx::ColorSpace2);
77 void SetDestroyedCallback(std::function<void()>&& aDestroyedCallback) {
78 MOZ_ASSERT(!mDestroyedCallback);
79 mDestroyedCallback = std::move(aDestroyedCallback);
80 mPool = {};
84 } // namespace gl
85 } // namespace mozilla
87 #endif // SCREEN_BUFFER_H_