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_
19 #include "mozilla/gfx/Point.h"
20 #include "mozilla/UniquePtr.h"
33 class SwapChainPresenter final
{
34 friend class SwapChain
;
36 SwapChain
* mSwapChain
;
37 std::shared_ptr
<SharedSurface
> mBackBuffer
;
40 explicit SwapChainPresenter(SwapChain
& swapChain
);
41 ~SwapChainPresenter();
43 const auto& BackBuffer() const { return mBackBuffer
; }
45 std::shared_ptr
<SharedSurface
> SwapBackBuffer(std::shared_ptr
<SharedSurface
>,
52 class SwapChain final
{
53 friend class SwapChainPresenter
;
56 UniquePtr
<SurfaceFactory
> mFactory
;
59 std::queue
<std::shared_ptr
<SharedSurface
>> mPool
;
60 std::shared_ptr
<SharedSurface
> mFrontBuffer
;
61 std::function
<void()> mDestroyedCallback
;
64 std::shared_ptr
<SharedSurface
>
65 mPrevFrontBuffer
; // Hold this ref while it's in-flight.
67 SwapChainPresenter
* mPresenter
= nullptr;
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
);
86 } // namespace mozilla
88 #endif // SCREEN_BUFFER_H_