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/. */ 5 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. 13 */ 14 15 #ifndef SCREEN_BUFFER_H_ 16 #define SCREEN_BUFFER_H_ 17 18 #include "GLTypes.h" 19 #include "mozilla/gfx/Point.h" 20 #include "mozilla/UniquePtr.h" 21 22 #include <queue> 23 #include <memory> 24 25 namespace mozilla { 26 namespace gl { 27 28 class SharedSurface; 29 class SurfaceFactory; 30 class SwapChain; 31 32 class SwapChainPresenter final { 33 friend class SwapChain; 34 35 SwapChain* mSwapChain; 36 std::shared_ptr<SharedSurface> mBackBuffer; 37 38 public: 39 explicit SwapChainPresenter(SwapChain& swapChain); 40 ~SwapChainPresenter(); 41 BackBuffer()42 const auto& BackBuffer() const { return mBackBuffer; } 43 44 std::shared_ptr<SharedSurface> SwapBackBuffer(std::shared_ptr<SharedSurface>); 45 GLuint Fb() const; 46 }; 47 48 // - 49 50 class SwapChain final { 51 friend class SwapChainPresenter; 52 53 public: 54 UniquePtr<SurfaceFactory> mFactory; 55 56 private: 57 std::queue<std::shared_ptr<SharedSurface>> mPool; 58 std::shared_ptr<SharedSurface> mFrontBuffer; 59 60 public: 61 std::shared_ptr<SharedSurface> 62 mPrevFrontBuffer; // Hold this ref while it's in-flight. 63 private: 64 SwapChainPresenter* mPresenter = nullptr; 65 66 public: 67 SwapChain(); 68 virtual ~SwapChain(); 69 70 void ClearPool(); FrontBuffer()71 const auto& FrontBuffer() const { return mFrontBuffer; } 72 UniquePtr<SwapChainPresenter> Acquire(const gfx::IntSize&); 73 }; 74 75 } // namespace gl 76 } // namespace mozilla 77 78 #endif // SCREEN_BUFFER_H_ 79