Bug 1249189 - Use GL_RED to replace GL_ALPHA in YCbCr convert. r=jgilbert
authorEthan Lin <ethlin@mozilla.com>
Tue, 23 Feb 2016 01:51:00 +0100
changeset 324950 33a9e4482bcc32edfca58a1edb98eb22d993d0a3
parent 324949 6cacb08f6f5ca0f3345288c5ed4d707352a22fe9
child 324951 4ac661e25c72acd51c8c4fad4da64aa96e4fef11
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1249189
milestone47.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 1249189 - Use GL_RED to replace GL_ALPHA in YCbCr convert. r=jgilbert
gfx/gl/GLBlitHelper.cpp
gfx/gl/GLContext.h
--- a/gfx/gl/GLBlitHelper.cpp
+++ b/gfx/gl/GLBlitHelper.cpp
@@ -185,19 +185,19 @@ GLBlitHelper::InitTexQuadProgram(BlitTyp
         varying vec2 vTexCoord;                                             \n\
         uniform sampler2D uYTexture;                                        \n\
         uniform sampler2D uCbTexture;                                       \n\
         uniform sampler2D uCrTexture;                                       \n\
         uniform vec2 uYTexScale;                                            \n\
         uniform vec2 uCbCrTexScale;                                         \n\
         void main()                                                         \n\
         {                                                                   \n\
-            float y = texture2D(uYTexture, vTexCoord * uYTexScale).a;       \n\
-            float cb = texture2D(uCbTexture, vTexCoord * uCbCrTexScale).a;  \n\
-            float cr = texture2D(uCrTexture, vTexCoord * uCbCrTexScale).a;  \n\
+            float y = texture2D(uYTexture, vTexCoord * uYTexScale).r;       \n\
+            float cb = texture2D(uCbTexture, vTexCoord * uCbCrTexScale).r;  \n\
+            float cr = texture2D(uCrTexture, vTexCoord * uCbCrTexScale).r;  \n\
             y = (y - 0.06275) * 1.16438;                                    \n\
             cb = cb - 0.50196;                                              \n\
             cr = cr - 0.50196;                                              \n\
             gl_FragColor.r = y + cr * 1.59603;                              \n\
             gl_FragColor.g = y - 0.81297 * cr - 0.39176 * cb;               \n\
             gl_FragColor.b = y + cb * 2.01723;                              \n\
             gl_FragColor.a = 1.0;                                           \n\
         }                                                                   \n\
@@ -599,42 +599,56 @@ GLBlitHelper::BindAndUploadYUVTexture(Ch
                                       uint32_t width,
                                       uint32_t height,
                                       void* data,
                                       bool needsAllocation)
 {
     MOZ_ASSERT(which < Channel_Max, "Invalid channel!");
     GLuint* srcTexArr[3] = {&mSrcTexY, &mSrcTexCb, &mSrcTexCr};
     GLuint& tex = *srcTexArr[which];
+
+    // RED textures aren't valid in GLES2, and ALPHA textures are not valid in desktop GL Core Profiles.
+    // So use R8 textures on GL3.0+ and GLES3.0+, but LUMINANCE/LUMINANCE/UNSIGNED_BYTE otherwise.
+    GLenum format;
+    GLenum internalFormat;
+    if (mGL->IsAtLeast(gl::ContextProfile::OpenGLCore, 300) ||
+        mGL->IsAtLeast(gl::ContextProfile::OpenGLES, 300)) {
+        format = LOCAL_GL_RED;
+        internalFormat = LOCAL_GL_R8;
+    } else {
+        format = LOCAL_GL_LUMINANCE;
+        internalFormat = LOCAL_GL_LUMINANCE;
+    }
+
     if (!tex) {
         MOZ_ASSERT(needsAllocation);
-        tex = CreateTexture(mGL, LOCAL_GL_ALPHA, LOCAL_GL_ALPHA, LOCAL_GL_UNSIGNED_BYTE,
+        tex = CreateTexture(mGL, internalFormat, format, LOCAL_GL_UNSIGNED_BYTE,
                             gfx::IntSize(width, height), false);
     }
     mGL->fActiveTexture(LOCAL_GL_TEXTURE0 + which);
 
     mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, tex);
     if (!needsAllocation) {
         mGL->fTexSubImage2D(LOCAL_GL_TEXTURE_2D,
                             0,
                             0,
                             0,
                             width,
                             height,
-                            LOCAL_GL_ALPHA,
+                            format,
                             LOCAL_GL_UNSIGNED_BYTE,
                             data);
     } else {
         mGL->fTexImage2D(LOCAL_GL_TEXTURE_2D,
                          0,
-                         LOCAL_GL_ALPHA,
+                         internalFormat,
                          width,
                          height,
                          0,
-                         LOCAL_GL_ALPHA,
+                         format,
                          LOCAL_GL_UNSIGNED_BYTE,
                          data);
     }
 }
 
 void
 GLBlitHelper::BindAndUploadEGLImage(EGLImage image, GLuint target)
 {
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -280,18 +280,18 @@ public:
         MOZ_ASSERT(mProfile != ContextProfile::Unknown, "unknown context profile");
         MOZ_ASSERT(mVersion != 0, "unknown context version");
 
         if (version > mVersion) {
             return false;
         }
 
         if (profile == ContextProfile::OpenGL) {
-            return profile == ContextProfile::OpenGLCore ||
-                   profile == ContextProfile::OpenGLCompatibility;
+            return mProfile == ContextProfile::OpenGLCore ||
+                   mProfile == ContextProfile::OpenGLCompatibility;
         }
 
         return profile == mProfile;
     }
 
     /**
      * Return the version of the context.
      * Example :