Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: cc/shader.cc

Issue 12157002: Adding YUVA support for enabling Alpha Playback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove files unrelated to cc/ Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/shader.h" 5 #include "cc/shader.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
10 10
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 float y_raw = texture2D(y_texture, v_texCoord).x; 885 float y_raw = texture2D(y_texture, v_texCoord).x;
886 float u_unsigned = texture2D(u_texture, v_texCoord).x; 886 float u_unsigned = texture2D(u_texture, v_texCoord).x;
887 float v_unsigned = texture2D(v_texture, v_texCoord).x; 887 float v_unsigned = texture2D(v_texture, v_texCoord).x;
888 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; 888 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj;
889 vec3 rgb = yuv_matrix * yuv; 889 vec3 rgb = yuv_matrix * yuv;
890 gl_FragColor = vec4(rgb, float(1)) * alpha; 890 gl_FragColor = vec4(rgb, float(1)) * alpha;
891 } 891 }
892 ); 892 );
893 } 893 }
894 894
895 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo()
896 : m_yTextureLocation(-1)
897 , m_uTextureLocation(-1)
898 , m_vTextureLocation(-1)
899 , m_aTextureLocation(-1)
900 , m_alphaLocation(-1)
901 , m_yuvMatrixLocation(-1)
902 , m_yuvAdjLocation(-1)
903 {
904 }
905
906 void FragmentShaderYUVAVideo::init(WebGraphicsContext3D* context, unsigned progr am, bool usingBindUniform, int* baseUniformIndex)
907 {
908 static const char* shaderUniforms[] = {
909 "y_texture",
910 "u_texture",
911 "v_texture",
912 "a_texture",
913 "alpha",
914 "cc_matrix",
915 "yuv_adj",
916 };
917 int locations[7];
918
919 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
920
921 m_yTextureLocation = locations[0];
922 m_uTextureLocation = locations[1];
923 m_vTextureLocation = locations[2];
924 m_aTextureLocation = locations[3];
925 m_alphaLocation = locations[4];
926 m_yuvMatrixLocation = locations[5];
927 m_yuvAdjLocation = locations[6];
928
929 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc ation != -1 && m_aTextureLocation != -1
930 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca tion != -1);
931 }
932
933 std::string FragmentShaderYUVAVideo::getShaderString() const
934 {
935 return SHADER(
936 precision mediump float;
937 precision mediump int;
938 varying vec2 y_texCoord;
939 varying vec2 uv_texCoord;
940 uniform sampler2D y_texture;
941 uniform sampler2D u_texture;
942 uniform sampler2D v_texture;
943 uniform sampler2D a_texture;
944 uniform float alpha;
945 uniform vec3 yuv_adj;
946 uniform mat3 cc_matrix;
947 void main()
948 {
949 float y_raw = texture2D(y_texture, y_texCoord).x;
950 float u_unsigned = texture2D(u_texture, uv_texCoord).x;
951 float v_unsigned = texture2D(v_texture, uv_texCoord).x;
952 float a_raw = texture2D(a_texture, y_texCoord).x;
953 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) yuv_adj;
jzern 2013/02/13 19:56:14 '+' yuv_adj ?
vigneshv 2013/02/15 18:05:02 Done.
954 vec3 rgb = cc_matrix * yuv;
955 gl_FragColor = vec4(rgb, float(1)) * (a_raw * alpha);
956 }
957 );
958 }
959
895 FragmentShaderColor::FragmentShaderColor() 960 FragmentShaderColor::FragmentShaderColor()
896 : m_colorLocation(-1) 961 : m_colorLocation(-1)
897 { 962 {
898 } 963 }
899 964
900 void FragmentShaderColor::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex) 965 void FragmentShaderColor::init(WebGraphicsContext3D* context, unsigned program, bool usingBindUniform, int* baseUniformIndex)
901 { 966 {
902 static const char* shaderUniforms[] = { 967 static const char* shaderUniforms[] = {
903 "color", 968 "color",
904 }; 969 };
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 vec4 color2 = color; 1031 vec4 color2 = color;
967 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; 1032 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy;
968 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 1033 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
969 float picker = abs(coord.x - coord.y); 1034 float picker = abs(coord.x - coord.y);
970 gl_FragColor = mix(color1, color2, picker) * alpha; 1035 gl_FragColor = mix(color1, color2, picker) * alpha;
971 } 1036 }
972 ); 1037 );
973 } 1038 }
974 1039
975 } // namespace cc 1040 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698