Bug 945023 - Extract CreateTextureXXX and friends from GLContext. r=bjacob
☠☠ backed out by 8e1d2c393849 ☠ ☠
authorDan Glastonbury <dglastonbury@mozilla.com>
Wed, 04 Dec 2013 15:41:22 +1000
changeset 173502 9d673e562fa695054a08f92e73f0773511845aed
parent 173501 aa4d322d811f42ed1f3d26d639c1f0df53be4e74
child 173503 638131799dd7dfe181c3da30acfaad5e26f8c880
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbjacob
bugs945023
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 945023 - Extract CreateTextureXXX and friends from GLContext. r=bjacob
gfx/gl/GLBlitHelper.cpp
gfx/gl/GLBlitHelper.h
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/GLScreenBuffer.cpp
gfx/gl/SharedSurfaceEGL.cpp
gfx/gl/SharedSurfaceGL.cpp
--- a/gfx/gl/GLBlitHelper.cpp
+++ b/gfx/gl/GLBlitHelper.cpp
@@ -7,16 +7,125 @@
 #include "GLBlitHelper.h"
 #include "GLContext.h"
 #include "ScopedGLHelpers.h"
 #include "mozilla/Preferences.h"
 
 namespace mozilla {
 namespace gl {
 
+static void
+RenderbufferStorageBySamples(GLContext* aGL, GLsizei aSamples,
+                             GLenum aInternalFormat, const gfxIntSize& 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 gfxIntSize& aSize)
+{
+    GLuint tex = 0;
+    aGL->fGenTextures(1, &tex);
+    ScopedBindTexture autoTex(aGL, tex);
+
+    aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
+    aGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
+    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 gfxIntSize& 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 gfxIntSize& 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 gfxIntSize& 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)
     , mTexBlit_VertShader(0)
     , mTex2DBlit_FragShader(0)
     , mTex2DRectBlit_FragShader(0)
     , mTex2DBlit_Program(0)
     , mTex2DRectBlit_Program(0)
@@ -320,17 +429,17 @@ GLBlitHelper::BlitFramebufferToFramebuff
     MOZ_ASSERT(!destFB || mGL->fIsFramebuffer(destFB));
 
     if (mGL->IsSupported(GLFeature::framebuffer_blit)) {
         BlitFramebufferToFramebuffer(srcFB, destFB,
                                      srcSize, destSize);
         return;
     }
 
-    GLuint tex = mGL->CreateTextureForOffscreen(srcFormats, srcSize);
+    GLuint tex = CreateTextureForOffscreen(mGL, srcFormats, srcSize);
     MOZ_ASSERT(tex);
 
     BlitFramebufferToTexture(srcFB, tex, srcSize, srcSize);
     BlitTextureToFramebuffer(tex, destFB, srcSize, destSize);
 
     mGL->fDeleteTextures(1, &tex);
 }
 
--- a/gfx/gl/GLBlitHelper.h
+++ b/gfx/gl/GLBlitHelper.h
@@ -13,16 +13,59 @@
 
 struct nsIntSize;
 
 namespace mozilla {
 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 gfxIntSize& 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 gfxIntSize& 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 aFormat. returns GL render buffer object id.
+ */
+GLuint CreateRenderbuffer(GLContext* aGL, GLenum aFormat, GLsizei aSamples,
+                          const gfxIntSize& 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 gfxIntSize& aSize, bool aMultisample,
+                                     GLuint* aColorMSRB, GLuint* aDepthRB,
+                                     GLuint* aStencilRB);
+
+
+/** Buffer blitting helper */
 class GLBlitHelper MOZ_FINAL
 {
     // The GLContext is the sole owner of the GLBlitHelper.
     GLContext* mGL;
 
     GLuint mTexBlit_Buffer;
     GLuint mTexBlit_VertShader;
     GLuint mTex2DBlit_FragShader;
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -1340,114 +1340,16 @@ GLContext::ChooseGLFormats(const Surface
         formats.depth = LOCAL_GL_DEPTH_COMPONENT24;
     }
 
     formats.stencil = LOCAL_GL_STENCIL_INDEX8;
 
     return formats;
 }
 
-GLuint
-GLContext::CreateTextureForOffscreen(const GLFormats& formats, const gfxIntSize& size)
-{
-    MOZ_ASSERT(formats.color_texInternalFormat);
-    MOZ_ASSERT(formats.color_texFormat);
-    MOZ_ASSERT(formats.color_texType);
-
-    return CreateTexture(formats.color_texInternalFormat,
-                         formats.color_texFormat,
-                         formats.color_texType,
-                         size);
-}
-
-GLuint
-GLContext::CreateTexture(GLenum internalFormat, GLenum format, GLenum type, const gfxIntSize& size)
-{
-    GLuint tex = 0;
-    fGenTextures(1, &tex);
-    ScopedBindTexture autoTex(this, tex);
-
-    fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
-    fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
-    fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
-    fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
-
-    fTexImage2D(LOCAL_GL_TEXTURE_2D,
-                0,
-                internalFormat,
-                size.width, size.height,
-                0,
-                format,
-                type,
-                nullptr);
-
-    return tex;
-}
-
-static inline void
-RenderbufferStorageBySamples(GLContext* gl, GLsizei samples, GLenum internalFormat, const gfxIntSize& size)
-{
-    if (samples) {
-        gl->fRenderbufferStorageMultisample(LOCAL_GL_RENDERBUFFER,
-                                            samples,
-                                            internalFormat,
-                                            size.width, size.height);
-    } else {
-        gl->fRenderbufferStorage(LOCAL_GL_RENDERBUFFER,
-                                 internalFormat,
-                                 size.width, size.height);
-    }
-}
-
-GLuint
-GLContext::CreateRenderbuffer(GLenum format, GLsizei samples, const gfxIntSize& size)
-{
-    GLuint rb = 0;
-    fGenRenderbuffers(1, &rb);
-    ScopedBindRenderbuffer autoRB(this, rb);
-
-    RenderbufferStorageBySamples(this, samples, format, size);
-
-    return rb;
-}
-
-void
-GLContext::CreateRenderbuffersForOffscreen(const GLFormats& formats, const gfxIntSize& size,
-                                           bool multisample,
-                                           GLuint* colorMSRB, GLuint* depthRB, GLuint* stencilRB)
-{
-    GLsizei samples = multisample ? formats.samples : 0;
-    if (colorMSRB) {
-        MOZ_ASSERT(formats.samples > 0);
-        MOZ_ASSERT(formats.color_rbFormat);
-
-        *colorMSRB = CreateRenderbuffer(formats.color_rbFormat, samples, size);
-    }
-
-    if (depthRB &&
-        stencilRB &&
-        formats.depthStencil)
-    {
-        *depthRB = CreateRenderbuffer(formats.depthStencil, samples, size);
-        *stencilRB = *depthRB;
-    } else {
-        if (depthRB) {
-            MOZ_ASSERT(formats.depth);
-
-            *depthRB = CreateRenderbuffer(formats.depth, samples, size);
-        }
-
-        if (stencilRB) {
-            MOZ_ASSERT(formats.stencil);
-
-            *stencilRB = CreateRenderbuffer(formats.stencil, samples, size);
-        }
-    }
-}
-
 bool
 GLContext::IsFramebufferComplete(GLuint fb, GLenum* pStatus)
 {
     MOZ_ASSERT(fb);
 
     ScopedBindFramebuffer autoFB(this, fb);
     MOZ_ASSERT(fIsFramebuffer(fb));
 
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -2817,35 +2817,18 @@ public:
     PixelBufferFormat QueryPixelFormat();
     void UpdatePixelFormat();
 
     const PixelBufferFormat& GetPixelFormat() const {
         MOZ_ASSERT(mPixelFormat);
         return *mPixelFormat;
     }
 
-
-    GLuint CreateTextureForOffscreen(const GLFormats& formats,
-                                     const gfxIntSize& size);
-    GLuint CreateTexture(GLenum internalFormat,
-                         GLenum format, GLenum type,
-                         const gfxIntSize& size);
-    GLuint CreateRenderbuffer(GLenum format,
-                              GLsizei samples,
-                              const gfxIntSize& size);
     bool IsFramebufferComplete(GLuint fb, GLenum* status = nullptr);
 
-    // Pass null to an RB arg to disable its creation.
-    void CreateRenderbuffersForOffscreen(const GLFormats& formats,
-                                         const gfxIntSize& size,
-                                         bool multisample,
-                                         GLuint* colorMSRB,
-                                         GLuint* depthRB,
-                                         GLuint* stencilRB);
-
     // Does not check completeness.
     void AttachBuffersToFB(GLuint colorTex, GLuint colorRB,
                            GLuint depthRB, GLuint stencilRB,
                            GLuint fb, GLenum target = LOCAL_GL_TEXTURE_2D);
 
     // Passing null is fine if the value you'd get is 0.
     bool AssembleOffscreenFBs(const GLuint colorMSRB,
                               const GLuint depthRB,
--- a/gfx/gl/GLScreenBuffer.cpp
+++ b/gfx/gl/GLScreenBuffer.cpp
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GLScreenBuffer.h"
 
 #include <cstring>
 #include "gfxImageSurface.h"
 #include "GLContext.h"
+#include "GLBlitHelper.h"
 #include "SharedSurfaceGL.h"
 #include "SurfaceStream.h"
 #ifdef MOZ_WIDGET_GONK
 #include "SharedSurfaceGralloc.h"
 #include "nsXULAppAPI.h"
 #endif
 #ifdef XP_MACOSX
 #include "SharedSurfaceIO.h"
@@ -542,18 +543,18 @@ DrawBuffer::Create(GLContext* const gl,
     } else {
         if (!formats.depth)
             pDepthRB = nullptr;
 
         if (!formats.stencil)
             pStencilRB = nullptr;
     }
 
-    gl->CreateRenderbuffersForOffscreen(formats, size, caps.antialias,
-                                        pColorMSRB, pDepthRB, pStencilRB);
+    CreateRenderbuffersForOffscreen(gl, formats, size, caps.antialias,
+                                    pColorMSRB, pDepthRB, pStencilRB);
 
     GLuint fb = 0;
     gl->fGenFramebuffers(1, &fb);
     gl->AttachBuffersToFB(0, colorMSRB, depthRB, stencilRB, fb);
     MOZ_ASSERT(gl->IsFramebufferComplete(fb));
 
     return new DrawBuffer(gl, size, fb, colorMSRB, depthRB, stencilRB);
 }
@@ -595,18 +596,18 @@ ReadBuffer::Create(GLContext* gl,
     }
 
     GLuint depthRB = 0;
     GLuint stencilRB = 0;
 
     GLuint* pDepthRB   = caps.depth   ? &depthRB   : nullptr;
     GLuint* pStencilRB = caps.stencil ? &stencilRB : nullptr;
 
-    gl->CreateRenderbuffersForOffscreen(formats, surf->Size(), caps.antialias,
-                                        nullptr, pDepthRB, pStencilRB);
+    CreateRenderbuffersForOffscreen(gl, formats, surf->Size(), caps.antialias,
+                                    nullptr, pDepthRB, pStencilRB);
 
     GLuint colorTex = 0;
     GLuint colorRB = 0;
     GLenum target = 0;
 
     switch (surf->AttachType()) {
     case AttachmentType::GLTexture:
         colorTex = surf->Texture();
--- a/gfx/gl/SharedSurfaceEGL.cpp
+++ b/gfx/gl/SharedSurfaceEGL.cpp
@@ -27,17 +27,17 @@ SharedSurface_EGLImage::Create(GLContext
 {
     GLLibraryEGL* egl = prodGL->GetLibraryEGL();
     MOZ_ASSERT(egl);
 
     if (!HasExtensions(egl, prodGL))
         return nullptr;
 
     MOZ_ALWAYS_TRUE(prodGL->MakeCurrent());
-    GLuint prodTex = prodGL->CreateTextureForOffscreen(formats, size);
+    GLuint prodTex = CreateTextureForOffscreen(prodGL, formats, size);
     if (!prodTex)
         return nullptr;
 
     return new SharedSurface_EGLImage(prodGL, egl,
                                       size, hasAlpha,
                                       formats, prodTex);
 }
 
@@ -125,17 +125,17 @@ static bool
 CreateTexturePipe(GLLibraryEGL* const egl, GLContext* const gl,
                   const GLFormats& formats, const gfxIntSize& size,
                   GLuint* const out_tex, EGLImage* const out_image)
 {
     MOZ_ASSERT(out_tex && out_image);
     *out_tex = 0;
     *out_image = 0;
 
-    GLuint tex = gl->CreateTextureForOffscreen(formats, size);
+    GLuint tex = CreateTextureForOffscreen(gl, formats, size);
     if (!tex)
         return false;
 
     EGLContext context = gl->GetEGLContext();
     MOZ_ASSERT(context);
     EGLClientBuffer buffer = reinterpret_cast<EGLClientBuffer>(tex);
     EGLImage image = egl->fCreateImage(egl->Display(), context,
                                        LOCAL_EGL_GL_TEXTURE_2D, buffer,
--- a/gfx/gl/SharedSurfaceGL.cpp
+++ b/gfx/gl/SharedSurfaceGL.cpp
@@ -242,20 +242,20 @@ SurfaceFactory_GL::ChooseBufferBits(cons
 
 SharedSurface_Basic*
 SharedSurface_Basic::Create(GLContext* gl,
                             const GLFormats& formats,
                             const gfxIntSize& size,
                             bool hasAlpha)
 {
     gl->MakeCurrent();
-    GLuint tex = gl->CreateTexture(formats.color_texInternalFormat,
-                                   formats.color_texFormat,
-                                   formats.color_texType,
-                                   size);
+    GLuint tex = CreateTexture(gl, formats.color_texInternalFormat,
+                               formats.color_texFormat,
+                               formats.color_texType,
+                               size);
 
     gfxImageFormat format = gfxImageFormatRGB24;
     switch (formats.color_texInternalFormat) {
     case LOCAL_GL_RGB:
     case LOCAL_GL_RGB8:
         if (formats.color_texType == LOCAL_GL_UNSIGNED_SHORT_5_6_5)
             format = gfxImageFormatRGB16_565;
         else
@@ -314,17 +314,17 @@ SharedSurface_GLTexture::Create(GLContex
                              const GLFormats& formats,
                              const gfxIntSize& size,
                              bool hasAlpha)
 {
     MOZ_ASSERT(prodGL);
     MOZ_ASSERT(!consGL || prodGL->SharesWith(consGL));
 
     prodGL->MakeCurrent();
-    GLuint tex = prodGL->CreateTextureForOffscreen(formats, size);
+    GLuint tex = CreateTextureForOffscreen(prodGL, formats, size);
 
     return new SharedSurface_GLTexture(prodGL, consGL, size, hasAlpha, tex);
 }
 
 SharedSurface_GLTexture::~SharedSurface_GLTexture()
 {
     if (!mGL->MakeCurrent())
         return;