Bug 942499 - Part 2: Move CanUploadNonPowerOfTwo out of GLContext; remove the gfx.textures.poweroftwo.force-enabled preference - r=gal,BenWa
authorBenoit Jacob <bjacob@mozilla.com>
Tue, 03 Dec 2013 13:44:38 -0500
changeset 173310 22a1c5c1371632d71b0babaa0d908172a8fb8069
parent 173309 7c7c405d9373a0ae722411613b841161bbbfc86d
child 173311 c789f25ca86e68ab8a8e15d74cd966c1bfbf0a13
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)
reviewersgal, BenWa
bugs942499
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 942499 - Part 2: Move CanUploadNonPowerOfTwo out of GLContext; remove the gfx.textures.poweroftwo.force-enabled preference - r=gal,BenWa
gfx/gl/GLBlitTextureImageHelper.cpp
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/GLUploadHelpers.cpp
gfx/gl/GLUploadHelpers.h
gfx/layers/opengl/CompositorOGL.cpp
modules/libpref/src/init/all.js
--- a/gfx/gl/GLBlitTextureImageHelper.cpp
+++ b/gfx/gl/GLBlitTextureImageHelper.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim: set ts=8 sts=4 et sw=4 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 "GLBlitTextureImageHelper.h"
+#include "GLUploadHelpers.h"
 #include "DecomposeIntoNoRepeatTriangles.h"
 #include "GLContext.h"
 #include "nsRect.h"
 #include "gfx2DGlue.h"
 #include "gfxUtils.h"
 
 namespace mozilla {
 namespace gl {
@@ -111,17 +112,17 @@ GLBlitTextureImageHelper::BlitTextureIma
             float dy0 = 2.0f * float(srcSubInDstRect.y) / float(dstSize.height) - 1.0f;
             float dx1 = 2.0f * float(srcSubInDstRect.x + srcSubInDstRect.width) / float(dstSize.width) - 1.0f;
             float dy1 = 2.0f * float(srcSubInDstRect.y + srcSubInDstRect.height) / float(dstSize.height) - 1.0f;
             mGL->PushViewportRect(nsIntRect(0, 0, dstSize.width, dstSize.height));
 
             RectTriangles rects;
 
             nsIntSize realTexSize = srcSize;
-            if (!mGL->CanUploadNonPowerOfTwo()) {
+            if (!CanUploadNonPowerOfTwo(mGL)) {
                 realTexSize = nsIntSize(gfx::NextPowerOfTwo(srcSize.width),
                                         gfx::NextPowerOfTwo(srcSize.height));
             }
 
             if (aSrc->GetWrapMode() == LOCAL_GL_REPEAT) {
                 rects.addRect(/* dest rectangle */
                         dx0, dy0, dx1, dy1,
                         /* tex coords */
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -1162,50 +1162,22 @@ GLContext::CanReadSRGBFromFBOTexture()
     if (major == 10 && minor <= 6) {
         return false;
     }
 #endif // XP_MACOSX
     return true;
 }
 
 
-bool GLContext::sPowerOfTwoForced = false;
-bool GLContext::sPowerOfTwoPrefCached = false;
-
 void
 GLContext::PlatformStartup()
 {
-  CacheCanUploadNPOT();
   RegisterStrongMemoryReporter(new GfxTexturesReporter());
 }
 
-void
-GLContext::CacheCanUploadNPOT()
-{
-    MOZ_ASSERT(NS_IsMainThread(), "Can't cache prefs off the main thread.");
-    MOZ_ASSERT(!sPowerOfTwoPrefCached, "Must only call this function once!");
-
-    sPowerOfTwoPrefCached = true;
-    mozilla::Preferences::AddBoolVarCache(&sPowerOfTwoForced,
-                                          "gfx.textures.poweroftwo.force-enabled");
-}
-
-bool
-GLContext::CanUploadNonPowerOfTwo()
-{
-    MOZ_ASSERT(sPowerOfTwoPrefCached);
-
-    if (!mWorkAroundDriverBugs)
-        return true;
-
-    // Some GPUs driver crash when uploading non power of two 565 textures.
-    return sPowerOfTwoForced ? false : (Renderer() != RendererAdreno200 &&
-                                        Renderer() != RendererAdreno205);
-}
-
 // Common code for checking for both GL extensions and GLX extensions.
 bool
 GLContext::ListHasExtension(const GLubyte *extensions, const char *extension)
 {
     // fix bug 612572 - we were crashing as we were calling this function with extensions==null
     if (extensions == nullptr || extension == nullptr)
         return false;
 
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -2472,24 +2472,17 @@ public:
     virtual void SetEGLSurfaceOverride(EGLSurface surf) {
         MOZ_CRASH("Must be called against a GLContextEGL.");
     }
 
     bool CanReadSRGBFromFBOTexture();
 
     static void PlatformStartup();
 
-protected:
-    static bool sPowerOfTwoForced;
-    static bool sPowerOfTwoPrefCached;
-    static void CacheCanUploadNPOT();
-
 public:
-    bool CanUploadNonPowerOfTwo();
-
     /**
      * If this context wraps a double-buffered target, swap the back
      * and front buffers.  It should be assumed that after a swap, the
      * contents of the new back buffer are undefined.
      */
     virtual bool SwapBuffers() { return false; }
 
     /**
--- a/gfx/gl/GLUploadHelpers.cpp
+++ b/gfx/gl/GLUploadHelpers.cpp
@@ -264,17 +264,17 @@ TexImage2DHelper(GLContext *gl,
                  GLint pixelsize, GLint border, GLenum format,
                  GLenum type, const GLvoid *pixels)
 {
     if (gl->IsGLES2()) {
 
         NS_ASSERTION(format == (GLenum)internalformat,
                     "format and internalformat not the same for glTexImage2D on GLES2");
 
-        if (!gl->CanUploadNonPowerOfTwo()
+        if (!CanUploadNonPowerOfTwo(gl)
             && (stride != width * pixelsize
             || !gfx::IsPowerOfTwo(width)
             || !gfx::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 = gfx::NextPowerOfTwo(width);
             GLsizei paddedHeight = gfx::NextPowerOfTwo(height);
@@ -582,10 +582,21 @@ UploadSurfaceToTexture(GLContext* gl,
         ImageFormatForSurfaceFormat(aSurface->GetFormat());
     data += DataOffset(aSrcPoint, stride, format);
     return UploadImageDataToTexture(gl, data, stride, format,
                                     aDstRegion, aTexture, aOverwrite,
                                     aPixelBuffer, aTextureUnit,
                                     aTextureTarget);
 }
 
+bool
+CanUploadNonPowerOfTwo(GLContext* gl)
+{
+    if (!gl->WorkAroundDriverBugs())
+        return true;
+
+    // Some GPUs driver crash when uploading non power of two 565 textures.
+    return gl->Renderer() != GLContext::RendererAdreno200 &&
+           gl->Renderer() != GLContext::RendererAdreno205;
+}
+
 }
 }
\ No newline at end of file
--- a/gfx/gl/GLUploadHelpers.h
+++ b/gfx/gl/GLUploadHelpers.h
@@ -91,13 +91,14 @@ UploadSurfaceToTexture(GLContext* gl,
                        GLuint& aTexture,
                        bool aOverwrite,
                        const nsIntPoint& aSrcPoint,
                        bool aPixelBuffer,
                        GLenum aTextureUnit,
                        GLenum aTextureTarget);
 
 bool CanUploadSubTextures(GLContext* gl);
+bool CanUploadNonPowerOfTwo(GLContext* gl);
 
 }
 }
 
 #endif
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -577,17 +577,17 @@ CompositorOGL::BindAndDrawQuadWithTextur
   // because we can't rely on full non-power-of-two texture support
   // (which is required for the REPEAT wrap mode).
 
   RectTriangles rects;
 
   GLenum wrapMode = aTexture->AsSourceOGL()->GetWrapMode();
 
   IntSize realTexSize = aTexture->GetSize();
-  if (!mGLContext->CanUploadNonPowerOfTwo()) {
+  if (!CanUploadNonPowerOfTwo(mGLContext)) {
     realTexSize = IntSize(NextPowerOfTwo(realTexSize.width),
                           NextPowerOfTwo(realTexSize.height));
   }
 
   // We need to convert back to actual texels here to get proper behaviour with
   // our GL helper functions. Should fix this sometime.
   // I want to vomit.
   IntRect texCoordRect = IntRect(NS_roundf(aTexCoordRect.x * aTexture->GetSize().width),
@@ -752,17 +752,17 @@ bool CompositorOGL::sDrawFPS = false;
  * Returns a size that is larger than and closest to aSize where both
  * width and height are powers of two.
  * If the OpenGL setup is capable of using non-POT textures, then it
  * will just return aSize.
  */
 static IntSize
 CalculatePOTSize(const IntSize& aSize, GLContext* gl)
 {
-  if (gl->CanUploadNonPowerOfTwo())
+  if (CanUploadNonPowerOfTwo(gl))
     return aSize;
 
   return IntSize(NextPowerOfTwo(aSize.width), NextPowerOfTwo(aSize.height));
 }
 
 void
 CompositorOGL::BeginFrame(const nsIntRegion& aInvalidRegion,
                           const Rect *aClipRectIn,
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -399,17 +399,16 @@ pref("gfx.canvas.azure.backends", "cairo
 pref("gfx.content.azure.backends", "cairo");
 #endif
 #endif
 
 #ifdef MOZ_WIDGET_GTK2
 pref("gfx.content.azure.backends", "cairo");
 #endif
 #ifdef ANDROID
-pref("gfx.textures.poweroftwo.force-enabled", false);
 pref("gfx.content.azure.backends", "cairo");
 #endif
 
 pref("gfx.work-around-driver-bugs", true);
 pref("gfx.prefer-mesa-llvmpipe", false);
 
 pref("accessibility.browsewithcaret", false);
 pref("accessibility.warn_on_browsewithcaret", true);