From a90a5cba08fdf6c0ceb95101c275108a152a3aed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:37 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- gfx/gl/GLContext.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'gfx/gl/GLContext.h') diff --git a/gfx/gl/GLContext.h b/gfx/gl/GLContext.h index eea26024ae..4ee256b053 100644 --- a/gfx/gl/GLContext.h +++ b/gfx/gl/GLContext.h @@ -45,6 +45,12 @@ #include "mozilla/GenericRefCounted.h" #include "mozilla/WeakPtr.h" +template +constexpr inline std::array make_array( + ElemT&& arg1, More&&... more) { + return {std::forward(arg1), std::forward(more)...}; +} + #ifdef MOZ_WIDGET_ANDROID # include "mozilla/ProfilerLabels.h" #endif @@ -797,8 +803,15 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr { AFTER_GL_CALL; } + void InvalidateFramebuffer(GLenum target) { + constexpr auto ATTACHMENTS = make_array(GLenum{LOCAL_GL_COLOR_ATTACHMENT0}, + LOCAL_GL_DEPTH_STENCIL_ATTACHMENT); + fInvalidateFramebuffer(target, ATTACHMENTS.size(), ATTACHMENTS.data()); + } + void fInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments) { + if (!mSymbols.fInvalidateFramebuffer) return; BeforeGLDrawCall(); BEFORE_GL_CALL; ASSERT_SYMBOL_PRESENT(fInvalidateFramebuffer); @@ -810,6 +823,7 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr { void fInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height) { + if (!mSymbols.fInvalidateSubFramebuffer) return; BeforeGLDrawCall(); BEFORE_GL_CALL; ASSERT_SYMBOL_PRESENT(fInvalidateSubFramebuffer); @@ -825,6 +839,13 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr { AFTER_GL_CALL; } + void BindSamplerTexture(GLuint texUnitId, GLuint samplerHandle, + GLenum texTarget, GLuint texHandle) { + fBindSampler(texUnitId, samplerHandle); + fActiveTexture(LOCAL_GL_TEXTURE0 + texUnitId); + fBindTexture(texTarget, texHandle); + } + void fBlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { BEFORE_GL_CALL; mSymbols.fBlendColor(red, green, blue, alpha); @@ -2028,7 +2049,11 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr { public: bool mElideDuplicateBindFramebuffers = false; - void fBindFramebuffer(const GLenum target, const GLuint fb) const { + // If e.g. GL_DRAW_FRAMEBUFFER isn't supported, will bind GL_FRAMEBUFFER. + void fBindFramebuffer(GLenum target, const GLuint fb) const { + if (!IsSupported(gl::GLFeature::framebuffer_blit)) { + target = LOCAL_GL_FRAMEBUFFER; + } if (mElideDuplicateBindFramebuffers) { MOZ_ASSERT(mCachedDrawFb == GetIntAs(LOCAL_GL_DRAW_FRAMEBUFFER_BINDING)); @@ -3861,6 +3886,30 @@ class Texture final { } }; +// - + +class Sampler final { + public: + const WeakPtr weakGl; + const GLuint name; + + private: + static GLuint Create(GLContext& gl) { + GLuint ret = 0; + gl.fGenSamplers(1, &ret); + return ret; + } + + public: + explicit Sampler(GLContext& gl) : weakGl(&gl), name(Create(gl)) {} + + ~Sampler() { + const RefPtr gl = weakGl.get(); + if (!gl || !gl->MakeCurrent()) return; + gl->fDeleteSamplers(1, &name); + } +}; + /** * Helper function that creates a 2D texture aSize.width x aSize.height with * storage type specified by aFormats. Returns GL texture object id. -- cgit v1.2.3