From 5d8884c51dfe5f653df135e6d4fd59f0cfbb9e32 Mon Sep 17 00:00:00 2001 From: Zhao Halley Date: Tue, 10 Sep 2013 17:52:44 +0800 Subject: [PATCH] Add YV12 video format support in TextureMapperShaderManager YV12 is usual format from sw video decoder, for example ogg/theora, vp8 decoder Change-Id: I87459620debc3b738d1059f8e7b609864b4a2b78 --- .../platform/graphics/texmap/TextureMapperGL.cpp | 3 ++ .../graphics/texmap/TextureMapperShaderManager.cpp | 45 ++++++++++++++++++++-- .../graphics/texmap/TextureMapperShaderManager.h | 13 +++++++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp index ef60fcb..8562fb5 100755 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp @@ -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; diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp index bddaffa..2e19637 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.cpp @@ -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 TextureMapperShaderManager:: { return static_pointer_cast(getShaderProgram(MultiTex_Y_UV)); } +PassRefPtr TextureMapperShaderManager::multiTex_Y_U_V_Program() +{ + return static_pointer_cast(getShaderProgram(MultiTex_Y_U_V)); +} #endif PassRefPtr TextureMapperShaderManager::getShaderProgram(ShaderType shaderType) { @@ -300,6 +322,9 @@ PassRefPtr 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() diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h index e5e53aa..1181b2a 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderManager.h @@ -228,6 +228,17 @@ public: private: TextureMapperShaderProgramMultiTex_Y_UV(); }; + +class TextureMapperShaderProgramMultiTex_Y_U_V : public TextureMapperShaderProgram { +public: + static PassRefPtr 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 antialiasingNoMaskProgram(); #if PLATFORM(WAYLAND) PassRefPtr multiTex_Y_UV_Program(); + PassRefPtr multiTex_Y_U_V_Program(); #endif private: typedef HashMap, DefaultHash::Hash, HashTraits > TextureMapperShaderProgramMap; -- 2.7.4