Bug 1318820 - Work around Android x86 GL_ES issues. r=kats draft
authorNick Alexander <nalexander@mozilla.com>
Sun, 20 Nov 2016 19:32:27 -0800
changeset 441738 d4e4d8232e3cd34b5200b39ad5092e88d934276d
parent 441737 adf089c1bb12d1f3ecd5a8702545050c6febc470
child 537626 63a998413cd72d14d54e6d9fe9195979c08c0fa1
push id36509
push usernalexander@mozilla.com
push dateMon, 21 Nov 2016 03:39:34 +0000
reviewerskats
bugs1318820, 40276036, 1303008
milestone53.0a1
Bug 1318820 - Work around Android x86 GL_ES issues. r=kats Several projects have witnessed this issue, which appears to be with the emulators themselves. I think the write-up at http://stackoverflow.com/a/40276036 is instructive, and suggested how to solve the issue. This should be harmless on real devices and does fix the issues for me on a local (previously failing!) x86 emulator. These issues have cropped up before; they were discussed at some length in https://bugzilla.mozilla.org/show_bug.cgi?id=1303008#c11, for example. MozReview-Commit-ID: DTxHYCMjTcg
gfx/gl/GLBlitHelper.cpp
gfx/gl/GLReadTexImageHelper.cpp
gfx/layers/opengl/GLBlitTextureImageHelper.cpp
gfx/layers/opengl/OGLShaderProgram.cpp
--- a/gfx/gl/GLBlitHelper.cpp
+++ b/gfx/gl/GLBlitHelper.cpp
@@ -88,18 +88,20 @@ GLBlitHelper::~GLBlitHelper()
 
 // Allowed to be destructive of state we restore in functions below.
 bool
 GLBlitHelper::InitTexQuadProgram(BlitType target)
 {
     const char kTexBlit_VertShaderSource[] = "\
         #version 100                                  \n\
         #ifdef GL_ES                                  \n\
+        #if !defined(mediump)                         \n\
         precision mediump float;                      \n\
         #endif                                        \n\
+        #endif                                        \n\
         attribute vec2 aPosition;                     \n\
                                                       \n\
         uniform float uYflip;                         \n\
         varying vec2 vTexCoord;                       \n\
                                                       \n\
         void main(void)                               \n\
         {                                             \n\
             vTexCoord = aPosition;                    \n\
@@ -108,36 +110,43 @@ GLBlitHelper::InitTexQuadProgram(BlitTyp
             gl_Position = vec4(vertPos, 0.0, 1.0);    \n\
         }                                             \n\
     ";
 
     const char kTex2DBlit_FragShaderSource[] = "\
         #version 100                                        \n\
         #ifdef GL_ES                                        \n\
         #ifdef GL_FRAGMENT_PRECISION_HIGH                   \n\
+        #if !defined(highp)                                 \n\
             precision highp float;                          \n\
+        #endif                                              \n\
         #else                                               \n\
+        #if !defined(mediump)                               \n\
             precision mediump float;                        \n\
         #endif                                              \n\
         #endif                                              \n\
+        #endif                                              \n\
         uniform sampler2D uTexUnit;                         \n\
                                                             \n\
         varying vec2 vTexCoord;                             \n\
                                                             \n\
         void main(void)                                     \n\
         {                                                   \n\
             gl_FragColor = texture2D(uTexUnit, vTexCoord);  \n\
         }                                                   \n\
     ";
 
     const char kTex2DRectBlit_FragShaderSource[] = "\
         #version 100                                                  \n\
         #ifdef GL_FRAGMENT_PRECISION_HIGH                             \n\
+        #if !defined(highp)                                           \n\
             precision highp float;                                    \n\
+        #endif                                                        \n\
         #else                                                         \n\
+        #if !defined(mediump)                                         \n\
             precision mediump float;                                  \n\
         #endif                                                        \n\
                                                                       \n\
         uniform sampler2D uTexUnit;                                   \n\
         uniform vec2 uTexCoordMult;                                   \n\
                                                                       \n\
         varying vec2 vTexCoord;                                       \n\
                                                                       \n\
@@ -147,20 +156,24 @@ GLBlitHelper::InitTexQuadProgram(BlitTyp
                                          vTexCoord * uTexCoordMult);  \n\
         }                                                             \n\
     ";
 #ifdef ANDROID /* MOZ_WIDGET_ANDROID */
     const char kTexExternalBlit_FragShaderSource[] = "\
         #version 100                                                    \n\
         #extension GL_OES_EGL_image_external : require                  \n\
         #ifdef GL_FRAGMENT_PRECISION_HIGH                               \n\
+        #if !defined(highp)                                             \n\
             precision highp float;                                      \n\
+        #endif                                                          \n\
         #else                                                           \n\
+        #if !defined(mediump)                                           \n\
             precision mediump float;                                    \n\
         #endif                                                          \n\
+        #endif                                                          \n\
         varying vec2 vTexCoord;                                         \n\
         uniform mat4 uTextureTransform;                                 \n\
         uniform samplerExternalOES uTexUnit;                            \n\
                                                                         \n\
         void main()                                                     \n\
         {                                                               \n\
             gl_FragColor = texture2D(uTexUnit,                          \n\
                 (uTextureTransform * vec4(vTexCoord, 0.0, 1.0)).xy);    \n\
@@ -185,18 +198,20 @@ GLBlitHelper::InitTexQuadProgram(BlitTyp
     For [0,1] instead of [0,255], and to 5 places:
     [R]   [1.16438,  0.00000,  1.79274]   [ Y - 0.06275]
     [G] = [1.16438, -0.21325, -0.53291] x [Cb - 0.50196]
     [B]   [1.16438,  2.11240,  0.00000]   [Cr - 0.50196]
     */
     const char kTexYUVPlanarBlit_FragShaderSource[] = "\
         #version 100                                                        \n\
         #ifdef GL_ES                                                        \n\
+        #if !defined(mediump)                                               \n\
         precision mediump float;                                            \n\
         #endif                                                              \n\
+        #endif                                                              \n\
         varying vec2 vTexCoord;                                             \n\
         uniform sampler2D uYTexture;                                        \n\
         uniform sampler2D uCbTexture;                                       \n\
         uniform sampler2D uCrTexture;                                       \n\
         uniform vec2 uYTexScale;                                            \n\
         uniform vec2 uCbCrTexScale;                                         \n\
         uniform mat3 uYuvColorMatrix;                                       \n\
         void main()                                                         \n\
--- a/gfx/gl/GLReadTexImageHelper.cpp
+++ b/gfx/gl/GLReadTexImageHelper.cpp
@@ -46,48 +46,56 @@ readTextureImageVS[] =
     "attribute vec2 aVertex;\n"
     "attribute vec2 aTexCoord;\n"
     "varying vec2 vTexCoord;\n"
     "void main() { gl_Position = vec4(aVertex, 0, 1); vTexCoord = aTexCoord; }";
 
 static const GLchar
 readTextureImageFS_TEXTURE_2D[] =
     "#ifdef GL_ES\n"
+    "#if !defined(mediump)\n"
     "precision mediump float;\n"
     "#endif\n"
+    "#endif\n"
     "varying vec2 vTexCoord;\n"
     "uniform sampler2D uTexture;\n"
     "void main() { gl_FragColor = texture2D(uTexture, vTexCoord); }";
 
 
 static const GLchar
 readTextureImageFS_TEXTURE_2D_BGRA[] =
     "#ifdef GL_ES\n"
+    "#if !defined(mediump)\n"
     "precision mediump float;\n"
     "#endif\n"
+    "#endif\n"
     "varying vec2 vTexCoord;\n"
     "uniform sampler2D uTexture;\n"
     "void main() { gl_FragColor = texture2D(uTexture, vTexCoord).bgra; }";
 
 static const GLchar
 readTextureImageFS_TEXTURE_EXTERNAL[] =
     "#extension GL_OES_EGL_image_external : require\n"
     "#ifdef GL_ES\n"
+    "#if !defined(mediump)\n"
     "precision mediump float;\n"
     "#endif\n"
+    "#endif\n"
     "varying vec2 vTexCoord;\n"
     "uniform samplerExternalOES uTexture;\n"
     "void main() { gl_FragColor = texture2D(uTexture, vTexCoord); }";
 
 static const GLchar
 readTextureImageFS_TEXTURE_RECTANGLE[] =
     "#extension GL_ARB_texture_rectangle\n"
     "#ifdef GL_ES\n"
+    "#if !defined(mediump)\n"
     "precision mediump float;\n"
     "#endif\n"
+    "#endif\n"
     "varying vec2 vTexCoord;\n"
     "uniform sampler2DRect uTexture;\n"
     "void main() { gl_FragColor = texture2DRect(uTexture, vTexCoord).bgra; }";
 
 GLuint
 GLReadTexImageHelper::TextureImageProgramFor(GLenum aTextureTarget,
                                              int aConfig)
 {
--- a/gfx/layers/opengl/GLBlitTextureImageHelper.cpp
+++ b/gfx/layers/opengl/GLBlitTextureImageHelper.cpp
@@ -215,17 +215,17 @@ GLBlitTextureImageHelper::UseBlitProgram
     const char *blitVSSrc =
         "attribute vec2 aVertex;"
         "attribute vec2 aTexCoord;"
         "varying vec2 vTexCoord;"
         "void main() {"
         "  vTexCoord = aTexCoord;"
         "  gl_Position = vec4(aVertex, 0.0, 1.0);"
         "}";
-    const char *blitFSSrc = "#ifdef GL_ES\nprecision mediump float;\n#endif\n"
+    const char *blitFSSrc = "#ifdef GL_ES\n#if !defined(mediump)\nprecision mediump float;\n#endif\n#endif\n"
         "uniform sampler2D uSrcTexture;"
         "varying vec2 vTexCoord;"
         "void main() {"
         "  gl_FragColor = texture2D(uSrcTexture, vTexCoord);"
         "}";
 
     gl->fShaderSource(shaders[0], 1, (const GLchar**) &blitVSSrc, nullptr);
     gl->fShaderSource(shaders[1], 1, (const GLchar**) &blitFSSrc, nullptr);
--- a/gfx/layers/opengl/OGLShaderProgram.cpp
+++ b/gfx/layers/opengl/OGLShaderProgram.cpp
@@ -175,20 +175,24 @@ ProgramProfileOGL::GetProfileFor(ShaderC
   ProgramProfileOGL result;
   ostringstream fs, vs;
 
   AddUniforms(result);
 
   gfx::CompositionOp blendOp = aConfig.mCompositionOp;
 
   vs << "#ifdef GL_ES" << endl;
+  vs << "#if defined(mediump)" << endl;
   vs << "#define EDGE_PRECISION mediump" << endl;
   vs << "#else" << endl;
   vs << "#define EDGE_PRECISION" << endl;
   vs << "#endif" << endl;
+  vs << "#else" << endl;
+  vs << "#define EDGE_PRECISION" << endl;
+  vs << "#endif" << endl;
   vs << "uniform mat4 uMatrixProj;" << endl;
   vs << "uniform vec4 uLayerRects[4];" << endl;
   vs << "uniform mat4 uLayerTransform;" << endl;
   if (aConfig.mFeatures & ENABLE_DEAA) {
     vs << "uniform mat4 uLayerTransformInverse;" << endl;
     vs << "uniform EDGE_PRECISION vec3 uSSEdges[4];" << endl;
     vs << "uniform vec2 uVisibleCenter;" << endl;
     vs << "uniform vec2 uViewportSize;" << endl;
@@ -321,20 +325,30 @@ ProgramProfileOGL::GetProfileFor(ShaderC
 
   if (aConfig.mFeatures & ENABLE_TEXTURE_RECT) {
     fs << "#extension GL_ARB_texture_rectangle : require" << endl;
   }
   if (aConfig.mFeatures & ENABLE_TEXTURE_EXTERNAL) {
     fs << "#extension GL_OES_EGL_image_external : require" << endl;
   }
   fs << "#ifdef GL_ES" << endl;
+  fs << "#if !defined(mediump)" << endl;
   fs << "precision mediump float;" << endl;
+  fs << "#endif" << endl;
+  fs << "#if defined(lowp)" << endl;
   fs << "#define COLOR_PRECISION lowp" << endl;
+  fs << "#else" << endl;
+  fs << "#define COLOR_PRECISION" << endl;
+  fs << "#endif" << endl;
+  fs << "#if defined(mediump)" << endl;
   fs << "#define EDGE_PRECISION mediump" << endl;
   fs << "#else" << endl;
+  fs << "#define EDGE_PRECISION" << endl;
+  fs << "#endif" << endl;
+  fs << "#else" << endl;
   fs << "#define COLOR_PRECISION" << endl;
   fs << "#define EDGE_PRECISION" << endl;
   fs << "#endif" << endl;
   if (aConfig.mFeatures & ENABLE_RENDER_COLOR) {
     fs << "uniform COLOR_PRECISION vec4 uRenderColor;" << endl;
   } else {
     // for tiling, texcoord can be greater than the lowfp range
     fs << "varying vec2 vTexCoord;" << endl;