Bug 741730 - Remove USE_GLES2 - r=romaxa
authorBenoit Jacob <bjacob@mozilla.com>
Tue, 10 Apr 2012 11:49:21 -0400
changeset 91313 fb6f8a081a475246f26b910cbc4f642c2e736209
parent 91312 469e2e5b18e5e0da7446b7823b1fe232fca8672d
child 91314 971f7705b978c90cc58228fd3471ed884c7bc1b3
push id8145
push userbjacob@mozilla.com
push dateTue, 10 Apr 2012 15:49:48 +0000
treeherdermozilla-inbound@971f7705b978 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersromaxa
bugs741730
milestone14.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 741730 - Remove USE_GLES2 - r=romaxa
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/layers/Makefile.in
gfx/layers/opengl/LayerManagerOGL.cpp
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -2333,21 +2333,17 @@ GLContext::UploadSurfaceToTexture(gfxASu
             NS_ASSERTION(false, "Unhandled image surface format!");
             format = 0;
             type = 0;
             shader = ShaderProgramType(0);
     }
 
     PRInt32 stride = imageSurface->Stride();
 
-#ifndef USE_GLES2
-    internalformat = LOCAL_GL_RGBA;
-#else
-    internalformat = format;
-#endif
+    internalformat = mIsGLES2 ? format : LOCAL_GL_RGBA;
 
     nsIntRegionRectIterator iter(paintRegion);
     const nsIntRect *iterRect;
 
     // Top left point of the region's bounding rectangle.
     nsIntPoint topLeft = paintRegion.GetBounds().TopLeft();
 
     while ((iterRect = iter.Next())) {
@@ -2405,164 +2401,167 @@ static GLint GetAddressAlignment(ptrdiff
 }
 
 void
 GLContext::TexImage2D(GLenum target, GLint level, GLint internalformat,
                       GLsizei width, GLsizei height, GLsizei stride,
                       GLint pixelsize, GLint border, GLenum format,
                       GLenum type, const GLvoid *pixels)
 {
-#ifdef USE_GLES2
-
-    NS_ASSERTION(format == internalformat,
-                 "format and internalformat not the same for glTexImage2D on GLES2");
-
-    if (!CanUploadNonPowerOfTwo()
-        && (stride != width * pixelsize
-        || !IsPowerOfTwo(width)
-        || !IsPowerOfTwo(height))) {
-
-        // Pad out texture width and height to the next power of two
-        // as we don't support/want non power of two texture uploads
-        GLsizei paddedWidth = NextPowerOfTwo(width);
-        GLsizei paddedHeight = NextPowerOfTwo(height);
-
-        GLvoid* paddedPixels = new unsigned char[paddedWidth * paddedHeight * pixelsize];
-
-        // Pad out texture data to be in a POT sized buffer for uploading to
-        // a POT sized texture
-        CopyAndPadTextureData(pixels, paddedPixels, width, height,
-                              paddedWidth, paddedHeight, stride, pixelsize);
+    if (mIsGLES2) {
+
+        NS_ASSERTION(format == internalformat,
+                    "format and internalformat not the same for glTexImage2D on GLES2");
+
+        if (!CanUploadNonPowerOfTwo()
+            && (stride != width * pixelsize
+            || !IsPowerOfTwo(width)
+            || !IsPowerOfTwo(height))) {
+
+            // Pad out texture width and height to the next power of two
+            // as we don't support/want non power of two texture uploads
+            GLsizei paddedWidth = NextPowerOfTwo(width);
+            GLsizei paddedHeight = NextPowerOfTwo(height);
+
+            GLvoid* paddedPixels = new unsigned char[paddedWidth * paddedHeight * pixelsize];
+
+            // Pad out texture data to be in a POT sized buffer for uploading to
+            // a POT sized texture
+            CopyAndPadTextureData(pixels, paddedPixels, width, height,
+                                  paddedWidth, paddedHeight, stride, pixelsize);
+
+            fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT,
+                    NS_MIN(GetAddressAlignment((ptrdiff_t)paddedPixels),
+                            GetAddressAlignment((ptrdiff_t)paddedWidth * pixelsize)));
+            fTexImage2D(target,
+                        border,
+                        internalformat,
+                        paddedWidth,
+                        paddedHeight,
+                        border,
+                        format,
+                        type,
+                        paddedPixels);
+            fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
+
+            delete[] static_cast<unsigned char*>(paddedPixels);
+            return;
+        }
+
+        if (stride == width * pixelsize) {
+            fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT,
+                    NS_MIN(GetAddressAlignment((ptrdiff_t)pixels),
+                            GetAddressAlignment((ptrdiff_t)stride)));
+            fTexImage2D(target,
+                        border,
+                        internalformat,
+                        width,
+                        height,
+                        border,
+                        format,
+                        type,
+                        pixels);
+            fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
+        } else {
+            // Use GLES-specific workarounds for GL_UNPACK_ROW_LENGTH; these are
+            // implemented in TexSubImage2D.
+            fTexImage2D(target,
+                        border,
+                        internalformat,
+                        width,
+                        height,
+                        border,
+                        format,
+                        type,
+                        NULL);
+            TexSubImage2D(target,
+                          level,
+                          0,
+                          0,
+                          width,
+                          height,
+                          stride,
+                          pixelsize,
+                          format,
+                          type,
+                          pixels);
+        }
+    } else {
+        // desktop GL (non-ES) path
 
         fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT,
-                 NS_MIN(GetAddressAlignment((ptrdiff_t)paddedPixels),
-                        GetAddressAlignment((ptrdiff_t)paddedWidth * pixelsize)));
+                    NS_MIN(GetAddressAlignment((ptrdiff_t)pixels),
+                            GetAddressAlignment((ptrdiff_t)stride)));
+        int rowLength = stride/pixelsize;
+        fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, rowLength);
         fTexImage2D(target,
-                    border,
-                    internalformat,
-                    paddedWidth,
-                    paddedHeight,
-                    border,
-                    format,
-                    type,
-                    paddedPixels);
-        fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
-
-        delete[] static_cast<unsigned char*>(paddedPixels);
-        return;
-    }
-
-    if (stride == width * pixelsize) {
-        fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT,
-                 NS_MIN(GetAddressAlignment((ptrdiff_t)pixels),
-                        GetAddressAlignment((ptrdiff_t)stride)));
-        fTexImage2D(target,
-                    border,
+                    level,
                     internalformat,
                     width,
                     height,
                     border,
                     format,
                     type,
                     pixels);
+        fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, 0);
         fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
-    } else {
-        // Use GLES-specific workarounds for GL_UNPACK_ROW_LENGTH; these are
-        // implemented in TexSubImage2D.
-        fTexImage2D(target,
-                    border,
-                    internalformat,
-                    width,
-                    height,
-                    border,
-                    format,
-                    type,
-                    NULL);
-        TexSubImage2D(target,
-                      level,
-                      0,
-                      0,
-                      width,
-                      height,
-                      stride,
-                      pixelsize,
-                      format,
-                      type,
-                      pixels);
     }
-#else
-    fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT,
-                 NS_MIN(GetAddressAlignment((ptrdiff_t)pixels),
-                        GetAddressAlignment((ptrdiff_t)stride)));
-    int rowLength = stride/pixelsize;
-    fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, rowLength);
-    fTexImage2D(target,
-                level,
-                internalformat,
-                width,
-                height,
-                border,
-                format,
-                type,
-                pixels);
-    fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, 0);
-    fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
-#endif
 }
 
 void
 GLContext::TexSubImage2D(GLenum target, GLint level,
                          GLint xoffset, GLint yoffset,
                          GLsizei width, GLsizei height, GLsizei stride,
                          GLint pixelsize, GLenum format,
                          GLenum type, const GLvoid* pixels)
 {
-#ifdef USE_GLES2
-    if (stride == width * pixelsize) {
-        fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT,
-                 NS_MIN(GetAddressAlignment((ptrdiff_t)pixels),
-                        GetAddressAlignment((ptrdiff_t)stride)));
-        fTexSubImage2D(target,
-                       level,
-                       xoffset,
-                       yoffset,
-                       width,
-                       height,
-                       format,
-                       type,
-                       pixels);
-        fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
-    } else if (IsExtensionSupported(EXT_unpack_subimage)) {
-        TexSubImage2DWithUnpackSubimageGLES(target, level, xoffset, yoffset,
-                                            width, height, stride,
-                                            pixelsize, format, type, pixels);
-
+    if (mIsGLES2) {
+        if (stride == width * pixelsize) {
+            fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT,
+                    NS_MIN(GetAddressAlignment((ptrdiff_t)pixels),
+                            GetAddressAlignment((ptrdiff_t)stride)));
+            fTexSubImage2D(target,
+                          level,
+                          xoffset,
+                          yoffset,
+                          width,
+                          height,
+                          format,
+                          type,
+                          pixels);
+            fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
+        } else if (IsExtensionSupported(EXT_unpack_subimage)) {
+            TexSubImage2DWithUnpackSubimageGLES(target, level, xoffset, yoffset,
+                                                width, height, stride,
+                                                pixelsize, format, type, pixels);
+
+        } else {
+            TexSubImage2DWithoutUnpackSubimage(target, level, xoffset, yoffset,
+                                              width, height, stride,
+                                              pixelsize, format, type, pixels);
+        }
     } else {
-        TexSubImage2DWithoutUnpackSubimage(target, level, xoffset, yoffset,
-                                           width, height, stride,
-                                           pixelsize, format, type, pixels);
+        // desktop GL (non-ES) path
+        fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT,
+                    NS_MIN(GetAddressAlignment((ptrdiff_t)pixels),
+                            GetAddressAlignment((ptrdiff_t)stride)));
+        int rowLength = stride/pixelsize;
+        fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, rowLength);
+        fTexSubImage2D(target,
+                      level,
+                      xoffset,
+                      yoffset,
+                      width,
+                      height,
+                      format,
+                      type,
+                      pixels);
+        fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, 0);
+        fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
     }
-#else
-    fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT,
-                 NS_MIN(GetAddressAlignment((ptrdiff_t)pixels),
-                        GetAddressAlignment((ptrdiff_t)stride)));
-    int rowLength = stride/pixelsize;
-    fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, rowLength);
-    fTexSubImage2D(target,
-                   level,
-                   xoffset,
-                   yoffset,
-                   width,
-                   height,
-                   format,
-                   type,
-                   pixels);
-    fPixelStorei(LOCAL_GL_UNPACK_ROW_LENGTH, 0);
-    fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
-#endif
 }
 
 void
 GLContext::TexSubImage2DWithUnpackSubimageGLES(GLenum target, GLint level,
                                                GLint xoffset, GLint yoffset,
                                                GLsizei width, GLsizei height,
                                                GLsizei stride, GLint pixelsize,
                                                GLenum format, GLenum type,
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -63,20 +63,16 @@
 #include "prlink.h"
 
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "nsRegion.h"
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 
-#if defined(MOZ_PLATFORM_MAEMO) || defined(ANDROID) || defined(MOZ_EGL_XRENDER_COMPOSITE)
-#define USE_GLES2 1
-#endif
-
 typedef char realGLboolean;
 
 #include "GLContextSymbols.h"
 
 namespace mozilla {
   namespace layers {
     class LayerManagerOGL;
     class ColorTextureLayerProgram;
@@ -526,21 +522,17 @@ public:
         mInternalBoundReadFBO(0),
 #ifdef DEBUG
         mInInternalBindingMode_DrawFBO(true),
         mInInternalBindingMode_ReadFBO(true),
 #endif
         mOffscreenFBOsDirty(false),
         mInitialized(false),
         mIsOffscreen(aIsOffscreen),
-#ifdef USE_GLES2
-        mIsGLES2(true),
-#else
         mIsGLES2(false),
-#endif
         mIsGlobalSharedContext(false),
         mHasRobustness(false),
         mContextLost(false),
         mVendor(-1),
         mRenderer(-1),
         mCreationFormat(aFormat),
         mSharedContext(aSharedContext),
         mOffscreenTexture(0),
--- a/gfx/layers/Makefile.in
+++ b/gfx/layers/Makefile.in
@@ -148,23 +148,16 @@ CPPSRCS += \
         ShadowLayersParent.cpp \
         $(NULL)
 
 ifdef MOZ_X11 #{
 EXPORTS_mozilla/layers += ShadowLayerUtilsX11.h
 CPPSRCS += ShadowLayerUtilsX11.cpp
 endif #}
 
-# Enable GLES2.0 under maemo
-ifdef MOZ_X11
-ifdef MOZ_PLATFORM_MAEMO
-DEFINES += -DUSE_GLES2
-endif
-endif
-
 ifdef MOZ_ENABLE_D3D10_LAYER
 EXPORTS_mozilla/layers += ShadowLayerUtilsD3D10.h
 DEFINES	+= -DMOZ_ENABLE_D3D10_LAYER
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 include $(topsrcdir)/ipc/chromium/chromium-config.mk
--- a/gfx/layers/opengl/LayerManagerOGL.cpp
+++ b/gfx/layers/opengl/LayerManagerOGL.cpp
@@ -254,25 +254,26 @@ LayerManagerOGL::Initialize(nsRefPtr<GLC
   /**
    * We'll test the ability here to bind NPOT textures to a framebuffer, if
    * this fails we'll try ARB_texture_rectangle.
    */
   mGLContext->fGenFramebuffers(1, &mBackBufferFBO);
 
   GLenum textureTargets[] = {
     LOCAL_GL_TEXTURE_2D,
-#ifndef USE_GLES2
-    LOCAL_GL_TEXTURE_RECTANGLE_ARB
-#endif
+    mGLContext->IsGLES2() ? LOCAL_GL_TEXTURE_RECTANGLE_ARB : 0
   };
 
   mFBOTextureTarget = LOCAL_GL_NONE;
 
   for (PRUint32 i = 0; i < ArrayLength(textureTargets); i++) {
     GLenum target = textureTargets[i];
+    if (!target)
+        continue;
+
     mGLContext->fGenTextures(1, &mBackBufferTexture);
     mGLContext->fBindTexture(target, mBackBufferTexture);
     mGLContext->fTexParameteri(target,
                                LOCAL_GL_TEXTURE_MIN_FILTER,
                                LOCAL_GL_NEAREST);
     mGLContext->fTexParameteri(target,
                                LOCAL_GL_TEXTURE_MAG_FILTER,
                                LOCAL_GL_NEAREST);
@@ -1045,26 +1046,26 @@ LayerManagerOGL::CopyToTarget(gfxContext
 
   nsRefPtr<gfxImageSurface> imageSurface =
     new gfxImageSurface(gfxIntSize(width, height),
                         gfxASurface::ImageFormatARGB32);
 
   mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER,
                                mGLContext->IsDoubleBuffered() ? 0 : mBackBufferFBO);
 
-#ifndef USE_GLES2
-  // GLES2 promises that binding to any custom FBO will attach
-  // to GL_COLOR_ATTACHMENT0 attachment point.
-  if (mGLContext->IsDoubleBuffered()) {
-    mGLContext->fReadBuffer(LOCAL_GL_BACK);
+  if (!mGLContext->IsGLES2()) {
+    // GLES2 promises that binding to any custom FBO will attach
+    // to GL_COLOR_ATTACHMENT0 attachment point.
+    if (mGLContext->IsDoubleBuffered()) {
+      mGLContext->fReadBuffer(LOCAL_GL_BACK);
+    }
+    else {
+      mGLContext->fReadBuffer(LOCAL_GL_COLOR_ATTACHMENT0);
+    }
   }
-  else {
-    mGLContext->fReadBuffer(LOCAL_GL_COLOR_ATTACHMENT0);
-  }
-#endif
 
   NS_ASSERTION(imageSurface->Stride() == width * 4,
                "Image Surfaces being created with weird stride!");
 
   mGLContext->ReadPixelsIntoImageSurface(0, 0, width, height, imageSurface);
 
   aTarget->SetOperator(gfxContext::OPERATOR_SOURCE);
   aTarget->Scale(1.0, -1.0);
@@ -1113,48 +1114,41 @@ GetFrameBufferInternalFormat(GLContext* 
                              nsIWidget* aWidget)
 {
   if (aCurrentFrameBuffer == 0) { // default framebuffer
     return aWidget->GetGLFrameBufferFormat();
   }
   return LOCAL_GL_RGBA;
 }
 
-static bool
-AreFormatsCompatibleForCopyTexImage2D(GLenum aF1, GLenum aF2)
-{
-  // GL requires that the implementation has to handle copies between
-  // different formats, so all are "compatible".  GLES does not
-  // require that.
-#ifdef USE_GLES2
-  return (aF1 == aF2);
-#else
-  return true;
-#endif
-}
-
 void
 LayerManagerOGL::CreateFBOWithTexture(const nsIntRect& aRect, InitMode aInit,
                                       GLuint aCurrentFrameBuffer,
                                       GLuint *aFBO, GLuint *aTexture)
 {
   GLuint tex, fbo;
 
   mGLContext->fActiveTexture(LOCAL_GL_TEXTURE0);
   mGLContext->fGenTextures(1, &tex);
   mGLContext->fBindTexture(mFBOTextureTarget, tex);
+
   if (aInit == InitModeCopy) {
     // We're going to create an RGBA temporary fbo.  But to
     // CopyTexImage() from the current framebuffer, the framebuffer's
     // format has to be compatible with the new texture's.  So we
     // check the format of the framebuffer here and take a slow path
     // if it's incompatible.
     GLenum format =
       GetFrameBufferInternalFormat(gl(), aCurrentFrameBuffer, mWidget);
-    if (AreFormatsCompatibleForCopyTexImage2D(format, LOCAL_GL_RGBA)) {
+ 
+    bool isFormatCompatibleWithRGBA
+        = gl()->IsGLES2() ? (format == LOCAL_GL_RGBA)
+                          : true;
+
+    if (isFormatCompatibleWithRGBA) {
       mGLContext->fCopyTexImage2D(mFBOTextureTarget,
                                   0,
                                   LOCAL_GL_RGBA,
                                   aRect.x, aRect.y,
                                   aRect.width, aRect.height,
                                   0);
     } else {
       // Curses, incompatible formats.  Take a slow path.