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

Side by Side Diff: cc/shader.cc

Issue 11649005: cc: Support anti-aliasing for solid color layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and add DrawQuad::AntiAliasing struct. Created 7 years, 11 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 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 return SHADER( 845 return SHADER(
846 precision mediump float; 846 precision mediump float;
847 uniform vec4 color; 847 uniform vec4 color;
848 void main() 848 void main()
849 { 849 {
850 gl_FragColor = color; 850 gl_FragColor = color;
851 } 851 }
852 ); 852 );
853 } 853 }
854 854
855 FragmentShaderColorAA::FragmentShaderColorAA()
856 : m_edgeLocation(-1)
857 , m_colorLocation(-1)
858 {
859 }
860
861 void FragmentShaderColorAA::init(WebGraphicsContext3D* context, unsigned program , bool usingBindUniform, int* baseUniformIndex)
862 {
863 static const char* shaderUniforms[] = {
864 "edge",
865 "color",
866 };
867 int locations[2];
868
869 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ;
870
871 m_edgeLocation = locations[0];
872 m_colorLocation = locations[1];
873 DCHECK(m_edgeLocation != -1 && m_colorLocation != -1);
874 }
875
876 std::string FragmentShaderColorAA::getShaderString() const
877 {
878 return SHADER(
879 precision mediump float;
880 uniform vec4 color;
881 uniform vec3 edge[8];
882 void main()
883 {
884 vec3 pos = vec3(gl_FragCoord.xy, 1);
885 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
886 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
887 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
888 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
889 float a4 = clamp(dot(edge[4], pos), 0.0, 1.0);
890 float a5 = clamp(dot(edge[5], pos), 0.0, 1.0);
891 float a6 = clamp(dot(edge[6], pos), 0.0, 1.0);
892 float a7 = clamp(dot(edge[7], pos), 0.0, 1.0);
893 gl_FragColor = color * min(min(a0, a2) * min(a1, a3), min(a4, a6) * min(a5, a7));
894 }
895 );
896 }
897
855 FragmentShaderCheckerboard::FragmentShaderCheckerboard() 898 FragmentShaderCheckerboard::FragmentShaderCheckerboard()
856 : m_alphaLocation(-1) 899 : m_alphaLocation(-1)
857 , m_texTransformLocation(-1) 900 , m_texTransformLocation(-1)
858 , m_frequencyLocation(-1) 901 , m_frequencyLocation(-1)
859 { 902 {
860 } 903 }
861 904
862 void FragmentShaderCheckerboard::init(WebGraphicsContext3D* context, unsigned pr ogram, bool usingBindUniform, int* baseUniformIndex) 905 void FragmentShaderCheckerboard::init(WebGraphicsContext3D* context, unsigned pr ogram, bool usingBindUniform, int* baseUniformIndex)
863 { 906 {
864 static const char* shaderUniforms[] = { 907 static const char* shaderUniforms[] = {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 vec4 color2 = color; 939 vec4 color2 = color;
897 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; 940 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy;
898 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 941 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
899 float picker = abs(coord.x - coord.y); 942 float picker = abs(coord.x - coord.y);
900 gl_FragColor = mix(color1, color2, picker) * alpha; 943 gl_FragColor = mix(color1, color2, picker) * alpha;
901 } 944 }
902 ); 945 );
903 } 946 }
904 947
905 } // namespace cc 948 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698