Add YV12 video format support in TextureMapperShaderManager 91/9891/1
authorZhao Halley <halley.zhao@intel.com>
Tue, 10 Sep 2013 09:52:44 +0000 (17:52 +0800)
committerZhao Halley <halley.zhao@intel.com>
Tue, 10 Sep 2013 10:11:27 +0000 (18:11 +0800)
YV12 is usual format from sw video decoder, for example ogg/theora, vp8 decoder

Change-Id: I87459620debc3b738d1059f8e7b609864b4a2b78

Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp
Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h

index ef60fcb..8562fb5 100755 (executable)
@@ -618,6 +618,9 @@ void TextureMapperGL::drawTextures(uint32_t *textureIds, uint32_t textureCount,
     case EGL_TEXTURE_Y_UV_WL:
         shaderType = TextureMapperShaderManager::MultiTex_Y_UV;
         break;
+    case EGL_TEXTURE_Y_U_V_WL:
+        shaderType = TextureMapperShaderManager::MultiTex_Y_U_V;
+        break;
     default:
         shaderType = TextureMapperShaderManager::Simple;
         break;
index bddaffa..2e19637 100644 (file)
@@ -226,6 +226,12 @@ static const char* fragmentShaderSourceSolidColor =
     );
 
 #if PLATFORM(WAYLAND)
+#define FRAGMENT_CONVERT_YUV                                \
+    gl_FragColor.r = y + 1.59602678 * v;                    \
+    gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;   \
+    gl_FragColor.b = y + 2.01723214 * u;                    \
+    gl_FragColor.a = 1.0;
+
 static const char* fragmentShaderSourceMultiTex_Y_UV =
     FRAGMENT_SHADER(
         uniform sampler2D s_source;
@@ -236,10 +242,22 @@ static const char* fragmentShaderSourceMultiTex_Y_UV =
             float y = 1.16438356 * (texture2D(s_source, v_sourceTexCoord).x - 0.0625);
             float u = texture2D(s_source1, v_sourceTexCoord).r - 0.5;
             float v = texture2D(s_source1, v_sourceTexCoord).g - 0.5;
-            gl_FragColor.r = y + 1.59602678 * v;
-            gl_FragColor.g = y - 0.39176229 * u - 0.81296764 * v;
-            gl_FragColor.b = y + 2.01723214 * u;
-            gl_FragColor.a = 1.0;
+            FRAGMENT_CONVERT_YUV
+        }
+    );
+
+static const char* fragmentShaderSourceMultiTex_Y_U_V =
+    FRAGMENT_SHADER(
+        uniform sampler2D s_source;
+        uniform sampler2D s_source1;
+        uniform sampler2D s_source2;
+        varying highp vec2 v_sourceTexCoord;
+        void main(void)
+        {
+            float y = 1.16438356 * (texture2D(s_source, v_sourceTexCoord).x - 0.0625);
+            float u = texture2D(s_source1, v_sourceTexCoord).x - 0.5;
+            float v = texture2D(s_source2, v_sourceTexCoord).x - 0.5;
+            FRAGMENT_CONVERT_YUV
         }
     );
 #endif
@@ -258,6 +276,10 @@ PassRefPtr<TextureMapperShaderProgramMultiTex_Y_UV> TextureMapperShaderManager::
 {
     return static_pointer_cast<TextureMapperShaderProgramMultiTex_Y_UV>(getShaderProgram(MultiTex_Y_UV));
 }
+PassRefPtr<TextureMapperShaderProgramMultiTex_Y_U_V> TextureMapperShaderManager::multiTex_Y_U_V_Program()
+{
+    return static_pointer_cast<TextureMapperShaderProgramMultiTex_Y_U_V>(getShaderProgram(MultiTex_Y_U_V));
+}
 #endif
 PassRefPtr<TextureMapperShaderProgram> TextureMapperShaderManager::getShaderProgram(ShaderType shaderType)
 {
@@ -300,6 +322,9 @@ PassRefPtr<TextureMapperShaderProgram> TextureMapperShaderManager::getShaderProg
     case MultiTex_Y_UV:
         program = TextureMapperShaderProgramMultiTex_Y_UV::create();
         break;
+    case MultiTex_Y_U_V:
+        program = TextureMapperShaderProgramMultiTex_Y_U_V::create();
+        break;
 #endif
     case Invalid:
         ASSERT_NOT_REACHED();
@@ -474,6 +499,18 @@ TextureMapperShaderProgramMultiTex_Y_UV::TextureMapperShaderProgramMultiTex_Y_UV
     getUniformLocation(m_sourceTextureLocation[1], "s_source1");
     getUniformLocation(m_opacityLocation, "u_opacity");
 }
+
+TextureMapperShaderProgramMultiTex_Y_U_V::TextureMapperShaderProgramMultiTex_Y_U_V()
+    : TextureMapperShaderProgram(vertexShaderSourceSimple, fragmentShaderSourceMultiTex_Y_U_V)
+{
+    initializeProgram();
+    getUniformLocation(m_flipLocation, "u_flip");
+    getUniformLocation(m_matrixLocation, "u_matrix");
+    getUniformLocation(m_sourceTextureLocation[0], "s_source");
+    getUniformLocation(m_sourceTextureLocation[1], "s_source1");
+    getUniformLocation(m_sourceTextureLocation[2], "s_source2");
+    getUniformLocation(m_opacityLocation, "u_opacity");
+}
 #endif
 
 TextureMapperShaderManager::TextureMapperShaderManager()
index e5e53aa..1181b2a 100644 (file)
@@ -228,6 +228,17 @@ public:
 private:
     TextureMapperShaderProgramMultiTex_Y_UV();
 };
+
+class TextureMapperShaderProgramMultiTex_Y_U_V : public TextureMapperShaderProgram {
+public:
+    static PassRefPtr<TextureMapperShaderProgramMultiTex_Y_U_V> create()
+    {
+        return adoptRef(new TextureMapperShaderProgramMultiTex_Y_U_V());
+    }
+
+private:
+    TextureMapperShaderProgramMultiTex_Y_U_V();
+};
 #endif
 class TextureMapperShaderManager {
 public:
@@ -245,6 +256,7 @@ public:
         SolidColor,
 #if PLATFORM(WAYLAND)
         MultiTex_Y_UV,
+        MultiTex_Y_U_V,
 #endif
     };
 
@@ -261,6 +273,7 @@ public:
     PassRefPtr<TextureMapperShaderProgramAntialiasingNoMask> antialiasingNoMaskProgram();
 #if PLATFORM(WAYLAND)
     PassRefPtr<TextureMapperShaderProgramMultiTex_Y_UV> multiTex_Y_UV_Program();
+    PassRefPtr<TextureMapperShaderProgramMultiTex_Y_U_V> multiTex_Y_U_V_Program();
 #endif
 private:
     typedef HashMap<ShaderType, RefPtr<TextureMapperShaderProgram>, DefaultHash<int>::Hash, HashTraits<int> > TextureMapperShaderProgramMap;