From 65e74dd0c0241c0126692ea6419d6b8a8f0a4c95 Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Mon, 28 Sep 2015 23:35:46 -0400 Subject: [PATCH] Bug 1149728. Move CreateXForOffscreen functions. r=jrmuizel --- gfx/gl/GLBlitHelper.cpp | 113 -------------------------------------- gfx/gl/GLBlitHelper.h | 42 -------------- gfx/gl/GLContext.cpp | 47 ++++++++++++++++ gfx/gl/GLContext.h | 22 ++++++++ gfx/gl/GLScreenBuffer.cpp | 67 ++++++++++++++++++++++ 5 files changed, 136 insertions(+), 155 deletions(-) diff --git a/gfx/gl/GLBlitHelper.cpp b/gfx/gl/GLBlitHelper.cpp index fd0eb8f948b..9c177211814 100644 --- a/gfx/gl/GLBlitHelper.cpp +++ b/gfx/gl/GLBlitHelper.cpp @@ -35,119 +35,6 @@ using mozilla::layers::PlanarYCbCrData; namespace mozilla { namespace gl { -static void -RenderbufferStorageBySamples(GLContext* aGL, GLsizei aSamples, - GLenum aInternalFormat, const gfx::IntSize& aSize) -{ - if (aSamples) { - aGL->fRenderbufferStorageMultisample(LOCAL_GL_RENDERBUFFER, - aSamples, - aInternalFormat, - aSize.width, aSize.height); - } else { - aGL->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER, - aInternalFormat, - aSize.width, aSize.height); - } -} - -GLuint -CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat, - GLenum aType, const gfx::IntSize& aSize, bool linear) -{ - GLuint tex = 0; - aGL->fGenTextures(1, &tex); - ScopedBindTexture autoTex(aGL, tex); - - aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, - LOCAL_GL_TEXTURE_MIN_FILTER, linear ? LOCAL_GL_LINEAR - : LOCAL_GL_NEAREST); - aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, - LOCAL_GL_TEXTURE_MAG_FILTER, linear ? LOCAL_GL_LINEAR - : LOCAL_GL_NEAREST); - aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, - LOCAL_GL_CLAMP_TO_EDGE); - aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, - LOCAL_GL_CLAMP_TO_EDGE); - - aGL->fTexImage2D(LOCAL_GL_TEXTURE_2D, - 0, - aInternalFormat, - aSize.width, aSize.height, - 0, - aFormat, - aType, - nullptr); - - return tex; -} - -GLuint -CreateTextureForOffscreen(GLContext* aGL, const GLFormats& aFormats, - const gfx::IntSize& aSize) -{ - MOZ_ASSERT(aFormats.color_texInternalFormat); - MOZ_ASSERT(aFormats.color_texFormat); - MOZ_ASSERT(aFormats.color_texType); - - return CreateTexture(aGL, - aFormats.color_texInternalFormat, - aFormats.color_texFormat, - aFormats.color_texType, - aSize); -} - - -GLuint -CreateRenderbuffer(GLContext* aGL, GLenum aFormat, GLsizei aSamples, - const gfx::IntSize& aSize) -{ - GLuint rb = 0; - aGL->fGenRenderbuffers(1, &rb); - ScopedBindRenderbuffer autoRB(aGL, rb); - - RenderbufferStorageBySamples(aGL, aSamples, aFormat, aSize); - - return rb; -} - - -void -CreateRenderbuffersForOffscreen(GLContext* aGL, const GLFormats& aFormats, - const gfx::IntSize& aSize, bool aMultisample, - GLuint* aColorMSRB, GLuint* aDepthRB, - GLuint* aStencilRB) -{ - GLsizei samples = aMultisample ? aFormats.samples : 0; - if (aColorMSRB) { - MOZ_ASSERT(aFormats.samples > 0); - MOZ_ASSERT(aFormats.color_rbFormat); - - *aColorMSRB = CreateRenderbuffer(aGL, aFormats.color_rbFormat, samples, aSize); - } - - if (aDepthRB && - aStencilRB && - aFormats.depthStencil) - { - *aDepthRB = CreateRenderbuffer(aGL, aFormats.depthStencil, samples, aSize); - *aStencilRB = *aDepthRB; - } else { - if (aDepthRB) { - MOZ_ASSERT(aFormats.depth); - - *aDepthRB = CreateRenderbuffer(aGL, aFormats.depth, samples, aSize); - } - - if (aStencilRB) { - MOZ_ASSERT(aFormats.stencil); - - *aStencilRB = CreateRenderbuffer(aGL, aFormats.stencil, samples, aSize); - } - } -} - - GLBlitHelper::GLBlitHelper(GLContext* gl) : mGL(gl) , mTexBlit_Buffer(0) diff --git a/gfx/gl/GLBlitHelper.h b/gfx/gl/GLBlitHelper.h index 9c5eaac2c77..7138ea4cc9d 100644 --- a/gfx/gl/GLBlitHelper.h +++ b/gfx/gl/GLBlitHelper.h @@ -28,48 +28,6 @@ namespace gl { class GLContext; -/** - * Helper function that creates a 2D texture aSize.width x aSize.height with - * storage type specified by aFormats. Returns GL texture object id. - * - * See mozilla::gl::CreateTexture. - */ -GLuint CreateTextureForOffscreen(GLContext* aGL, const GLFormats& aFormats, - const gfx::IntSize& aSize); - -/** - * Helper function that creates a 2D texture aSize.width x aSize.height with - * storage type aInternalFormat. Returns GL texture object id. - * - * Initialize textyre parameters to: - * GL_TEXTURE_MIN_FILTER = GL_LINEAR - * GL_TEXTURE_MAG_FILTER = GL_LINEAR - * GL_TEXTURE_WRAP_S = GL_CLAMP_TO_EDGE - * GL_TEXTURE_WRAP_T = GL_CLAMP_TO_EDGE - */ -GLuint CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat, - GLenum aType, const gfx::IntSize& aSize, bool linear = true); - -/** - * Helper function to create, potentially, multisample render buffers suitable - * for offscreen rendering. Buffers of size aSize.width x aSize.height with - * storage specified by aFormat. returns GL render buffer object id. - */ -GLuint CreateRenderbuffer(GLContext* aGL, GLenum aFormat, GLsizei aSamples, - const gfx::IntSize& aSize); - -/** - * Helper function to create, potentially, multisample render buffers suitable - * for offscreen rendering. Buffers of size aSize.width x aSize.height with - * storage specified by aFormats. GL render buffer object ids are returned via - * aColorMSRB, aDepthRB, and aStencilRB - */ -void CreateRenderbuffersForOffscreen(GLContext* aGL, const GLFormats& aFormats, - const gfx::IntSize& aSize, bool aMultisample, - GLuint* aColorMSRB, GLuint* aDepthRB, - GLuint* aStencilRB); - - /** Buffer blitting helper */ class GLBlitHelper final { diff --git a/gfx/gl/GLContext.cpp b/gfx/gl/GLContext.cpp index 5a1172ecfcd..b2cc0d64d31 100644 --- a/gfx/gl/GLContext.cpp +++ b/gfx/gl/GLContext.cpp @@ -2937,5 +2937,52 @@ GLContext::IsDrawingToDefaultFramebuffer() return Screen()->IsDrawFramebufferDefault(); } +GLuint +CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat, + GLenum aType, const gfx::IntSize& aSize, bool linear) +{ + GLuint tex = 0; + aGL->fGenTextures(1, &tex); + ScopedBindTexture autoTex(aGL, tex); + + aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, + LOCAL_GL_TEXTURE_MIN_FILTER, linear ? LOCAL_GL_LINEAR + : LOCAL_GL_NEAREST); + aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, + LOCAL_GL_TEXTURE_MAG_FILTER, linear ? LOCAL_GL_LINEAR + : LOCAL_GL_NEAREST); + aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, + LOCAL_GL_CLAMP_TO_EDGE); + aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, + LOCAL_GL_CLAMP_TO_EDGE); + + aGL->fTexImage2D(LOCAL_GL_TEXTURE_2D, + 0, + aInternalFormat, + aSize.width, aSize.height, + 0, + aFormat, + aType, + nullptr); + + return tex; +} + +GLuint +CreateTextureForOffscreen(GLContext* aGL, const GLFormats& aFormats, + const gfx::IntSize& aSize) +{ + MOZ_ASSERT(aFormats.color_texInternalFormat); + MOZ_ASSERT(aFormats.color_texFormat); + MOZ_ASSERT(aFormats.color_texType); + + return CreateTexture(aGL, + aFormats.color_texInternalFormat, + aFormats.color_texFormat, + aFormats.color_texType, + aSize); +} + + } /* namespace gl */ } /* namespace mozilla */ diff --git a/gfx/gl/GLContext.h b/gfx/gl/GLContext.h index 0eb97ae16bc..58501d63c04 100644 --- a/gfx/gl/GLContext.h +++ b/gfx/gl/GLContext.h @@ -3652,6 +3652,28 @@ MarkBitfieldByStrings(const std::vector& strList, } } +/** + * Helper function that creates a 2D texture aSize.width x aSize.height with + * storage type specified by aFormats. Returns GL texture object id. + * + * See mozilla::gl::CreateTexture. + */ +GLuint CreateTextureForOffscreen(GLContext* aGL, const GLFormats& aFormats, + const gfx::IntSize& aSize); + +/** + * Helper function that creates a 2D texture aSize.width x aSize.height with + * storage type aInternalFormat. Returns GL texture object id. + * + * Initialize textyre parameters to: + * GL_TEXTURE_MIN_FILTER = GL_LINEAR + * GL_TEXTURE_MAG_FILTER = GL_LINEAR + * GL_TEXTURE_WRAP_S = GL_CLAMP_TO_EDGE + * GL_TEXTURE_WRAP_T = GL_CLAMP_TO_EDGE + */ +GLuint CreateTexture(GLContext* aGL, GLenum aInternalFormat, GLenum aFormat, + GLenum aType, const gfx::IntSize& aSize, bool linear = true); + } /* namespace gl */ } /* namespace mozilla */ diff --git a/gfx/gl/GLScreenBuffer.cpp b/gfx/gl/GLScreenBuffer.cpp index d02876868ee..01905ede727 100755 --- a/gfx/gl/GLScreenBuffer.cpp +++ b/gfx/gl/GLScreenBuffer.cpp @@ -618,6 +618,73 @@ GLScreenBuffer::IsReadFramebufferDefault() const return SharedSurf()->mAttachType == AttachmentType::Screen; } +//////////////////////////////////////////////////////////////////////// +// Utils + +static void +RenderbufferStorageBySamples(GLContext* aGL, GLsizei aSamples, + GLenum aInternalFormat, const gfx::IntSize& aSize) +{ + if (aSamples) { + aGL->fRenderbufferStorageMultisample(LOCAL_GL_RENDERBUFFER, + aSamples, + aInternalFormat, + aSize.width, aSize.height); + } else { + aGL->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER, + aInternalFormat, + aSize.width, aSize.height); + } +} + +static GLuint +CreateRenderbuffer(GLContext* aGL, GLenum aFormat, GLsizei aSamples, + const gfx::IntSize& aSize) +{ + GLuint rb = 0; + aGL->fGenRenderbuffers(1, &rb); + ScopedBindRenderbuffer autoRB(aGL, rb); + + RenderbufferStorageBySamples(aGL, aSamples, aFormat, aSize); + + return rb; +} + +static void +CreateRenderbuffersForOffscreen(GLContext* aGL, const GLFormats& aFormats, + const gfx::IntSize& aSize, bool aMultisample, + GLuint* aColorMSRB, GLuint* aDepthRB, + GLuint* aStencilRB) +{ + GLsizei samples = aMultisample ? aFormats.samples : 0; + if (aColorMSRB) { + MOZ_ASSERT(aFormats.samples > 0); + MOZ_ASSERT(aFormats.color_rbFormat); + + *aColorMSRB = CreateRenderbuffer(aGL, aFormats.color_rbFormat, samples, aSize); + } + + if (aDepthRB && + aStencilRB && + aFormats.depthStencil) + { + *aDepthRB = CreateRenderbuffer(aGL, aFormats.depthStencil, samples, aSize); + *aStencilRB = *aDepthRB; + } else { + if (aDepthRB) { + MOZ_ASSERT(aFormats.depth); + + *aDepthRB = CreateRenderbuffer(aGL, aFormats.depth, samples, aSize); + } + + if (aStencilRB) { + MOZ_ASSERT(aFormats.stencil); + + *aStencilRB = CreateRenderbuffer(aGL, aFormats.stencil, samples, aSize); + } + } +} + //////////////////////////////////////////////////////////////////////// // DrawBuffer