Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / gl / MozFramebuffer.h
blobdd51ef61546011cc1be2a7d699f811cace0f75f8
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 #ifndef MOZ_FRAMEBUFFER_H_
7 #define MOZ_FRAMEBUFFER_H_
9 #include "gfx2DGlue.h"
10 #include "GLConsts.h"
11 #include "GLContextTypes.h"
12 #include "mozilla/UniquePtr.h"
13 #include "mozilla/WeakPtr.h"
15 namespace mozilla {
16 namespace gl {
18 class DepthAndStencilBuffer final : public SupportsWeakPtr {
19 const WeakPtr<GLContext> mWeakGL;
20 const gfx::IntSize mSize;
22 public:
23 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DepthAndStencilBuffer)
25 const GLuint mDepthRB;
26 const GLuint mStencilRB;
28 static RefPtr<DepthAndStencilBuffer> Create(GLContext* const gl,
29 const gfx::IntSize& size,
30 const uint32_t samples);
32 RefPtr<GLContext> gl() const { return mWeakGL.get(); }
34 // 4 bytes per pixel (24-bit depth + 8-bit stencil).
35 uint64_t EstimateMemory() const {
36 return static_cast<uint64_t>(mSize.width) * 4 * mSize.height;
39 protected:
40 DepthAndStencilBuffer(GLContext* gl, const gfx::IntSize& size, GLuint depthRB,
41 GLuint stencilRB);
42 ~DepthAndStencilBuffer();
45 class MozFramebuffer final {
46 const WeakPtr<GLContext> mWeakGL;
48 public:
49 const gfx::IntSize mSize;
50 const uint32_t mSamples;
51 const GLuint mFB;
52 const GLenum mColorTarget;
54 private:
55 const RefPtr<DepthAndStencilBuffer> mDepthAndStencilBuffer;
56 const GLuint mColorName;
58 public:
59 // Create a new framebuffer with the specified properties.
60 static UniquePtr<MozFramebuffer> Create(GLContext* gl,
61 const gfx::IntSize& size,
62 uint32_t samples, bool depthStencil);
64 // Create a new framebuffer backed by an existing texture or buffer.
65 // Assumes that gl is the current context.
66 static UniquePtr<MozFramebuffer> CreateForBacking(
67 GLContext* gl, const gfx::IntSize& size, uint32_t samples,
68 bool depthStencil, GLenum colorTarget, GLuint colorName);
70 // Create a new framebuffer backed by an existing texture or buffer.
71 // Use the same GLContext, size, and samples as framebufferToShareWith.
72 // The new framebuffer will share its depth and stencil buffer with
73 // framebufferToShareWith. The depth and stencil buffers will be destroyed
74 // once the last MozFramebuffer using them is destroyed.
75 static UniquePtr<MozFramebuffer> CreateForBackingWithSharedDepthAndStencil(
76 const gfx::IntSize& size, const uint32_t samples, GLenum colorTarget,
77 GLuint colorName,
78 const RefPtr<DepthAndStencilBuffer>& depthAndStencilBuffer);
80 private:
81 MozFramebuffer(GLContext* gl, const gfx::IntSize& size, GLuint fb,
82 uint32_t samples,
83 RefPtr<DepthAndStencilBuffer> depthAndStencilBuffer,
84 GLenum colorTarget, GLuint colorName);
86 // gl must be the current context when this is called.
87 static UniquePtr<MozFramebuffer> CreateImpl(
88 GLContext* const gl, const gfx::IntSize& size, const uint32_t samples,
89 const RefPtr<DepthAndStencilBuffer>& depthAndStencilBuffer,
90 const GLenum colorTarget, const GLuint colorName);
92 public:
93 ~MozFramebuffer();
95 GLuint ColorTex() const {
96 if (mColorTarget == LOCAL_GL_RENDERBUFFER) return 0;
97 return mColorName;
99 const auto& GetDepthAndStencilBuffer() const {
100 return mDepthAndStencilBuffer;
102 bool HasDepth() const;
103 bool HasStencil() const;
106 } // namespace gl
107 } // namespace mozilla
109 #endif // MOZ_FRAMEBUFFER_H_