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

Side by Side Diff: Source/WebCore/platform/graphics/chromium/ShaderChromium.cpp

Issue 7590009: Merge 92255 - Source/WebCore: [Chromium] Use edge-distance method for layer anti-aliasing. (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/835/
Patch Set: Created 9 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 uniform vec4 texTransform; 143 uniform vec4 texTransform;
144 varying vec2 v_texCoord; 144 varying vec2 v_texCoord;
145 void main() 145 void main()
146 { 146 {
147 gl_Position = matrix * a_position; 147 gl_Position = matrix * a_position;
148 v_texCoord = a_texCoord * texTransform.zw + texTransform.xy; 148 v_texCoord = a_texCoord * texTransform.zw + texTransform.xy;
149 } 149 }
150 ); 150 );
151 } 151 }
152 152
153 VertexShaderQuad::VertexShaderQuad() 153 VertexShaderTile::VertexShaderTile()
154 : m_matrixLocation(-1) 154 : m_matrixLocation(-1)
155 , m_texTransformLocation(-1)
156 , m_pointLocation(-1) 155 , m_pointLocation(-1)
156 , m_vertexTexTransformLocation(-1)
157 { 157 {
158 } 158 }
159 159
160 void VertexShaderQuad::init(GraphicsContext3D* context, unsigned program) 160 void VertexShaderTile::init(GraphicsContext3D* context, unsigned program)
161 { 161 {
162 m_matrixLocation = context->getUniformLocation(program, "matrix"); 162 m_matrixLocation = context->getUniformLocation(program, "matrix");
163 m_texTransformLocation = context->getUniformLocation(program, "texTransform" );
164 m_pointLocation = context->getUniformLocation(program, "point"); 163 m_pointLocation = context->getUniformLocation(program, "point");
165 ASSERT(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_pointLoca tion != -1); 164 m_vertexTexTransformLocation = context->getUniformLocation(program, "vertexT exTransform");
165 ASSERT(m_matrixLocation != -1 && m_pointLocation != -1 && m_vertexTexTransfo rmLocation != -1);
166 } 166 }
167 167
168 String VertexShaderQuad::getShaderString() const 168 String VertexShaderTile::getShaderString() const
169 { 169 {
170 return SHADER( 170 return SHADER(
171 attribute vec4 a_position; 171 attribute vec4 a_position;
172 attribute vec2 a_texCoord; 172 attribute vec2 a_texCoord;
173 uniform mat4 matrix; 173 uniform mat4 matrix;
174 uniform vec4 texTransform;
175 uniform vec2 point[4]; 174 uniform vec2 point[4];
175 uniform vec4 vertexTexTransform;
176 varying vec2 v_texCoord; 176 varying vec2 v_texCoord;
177 void main() 177 void main()
178 { 178 {
179 vec2 complement = abs(a_texCoord - 1.0); 179 vec2 complement = abs(a_texCoord - 1.0);
180 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); 180 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w);
181 pos.xy += (complement.x * complement.y) * point[0]; 181 pos.xy += (complement.x * complement.y) * point[0];
182 pos.xy += (a_texCoord.x * complement.y) * point[1]; 182 pos.xy += (a_texCoord.x * complement.y) * point[1];
183 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; 183 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2];
184 pos.xy += (complement.x * a_texCoord.y) * point[3]; 184 pos.xy += (complement.x * a_texCoord.y) * point[3];
185 gl_Position = matrix * pos; 185 gl_Position = matrix * pos;
186 v_texCoord = pos.xy * texTransform.zw + texTransform.xy; 186 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy;
187 } 187 }
188 ); 188 );
189 } 189 }
190 190
191 FragmentTexAlphaBinding::FragmentTexAlphaBinding() 191 FragmentTexAlphaBinding::FragmentTexAlphaBinding()
192 : m_samplerLocation(-1) 192 : m_samplerLocation(-1)
193 , m_alphaLocation(-1) 193 , m_alphaLocation(-1)
194 { 194 {
195 } 195 }
196 196
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 uniform sampler2D s_texture; 240 uniform sampler2D s_texture;
241 uniform float alpha; 241 uniform float alpha;
242 void main() 242 void main()
243 { 243 {
244 vec4 texColor = texture2D(s_texture, v_texCoord); 244 vec4 texColor = texture2D(s_texture, v_texCoord);
245 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; 245 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha;
246 } 246 }
247 ); 247 );
248 } 248 }
249 249
250 FragmentTexAlphaAABinding::FragmentTexAlphaAABinding()
251 : m_samplerLocation(-1)
252 , m_alphaLocation(-1)
253 , m_fragmentTexTransformLocation(-1)
254 , m_edgeLocation(-1)
255 {
256 }
257
258 void FragmentTexAlphaAABinding::init(GraphicsContext3D* context, unsigned progra m)
259 {
260 m_samplerLocation = context->getUniformLocation(program, "s_texture");
261 m_alphaLocation = context->getUniformLocation(program, "alpha");
262 m_fragmentTexTransformLocation = context->getUniformLocation(program, "fragm entTexTransform");
263 m_edgeLocation = context->getUniformLocation(program, "edge");
264
265 ASSERT(m_samplerLocation != -1 && m_alphaLocation != -1 && m_fragmentTexTran sformLocation != -1 && m_edgeLocation != -1);
266 }
267
268 String FragmentShaderRGBATexAlphaAA::getShaderString() const
269 {
270 return SHADER(
271 precision mediump float;
272 varying vec2 v_texCoord;
273 uniform sampler2D s_texture;
274 uniform float alpha;
275 uniform vec4 fragmentTexTransform;
276 uniform vec3 edge[4];
277 void main()
278 {
279 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy;
280 vec4 texColor = texture2D(s_texture, texCoord);
281 vec3 pos = vec3(gl_FragCoord.xy, 1);
282 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
283 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
284 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
285 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
286 gl_FragColor = texColor * alpha * min(a0, a2) * min(a1, a3);
287 }
288 );
289 }
290
291 String FragmentShaderRGBATexSwizzleAlphaAA::getShaderString() const
292 {
293 return SHADER(
294 precision mediump float;
295 varying vec2 v_texCoord;
296 uniform sampler2D s_texture;
297 uniform float alpha;
298 uniform vec4 fragmentTexTransform;
299 uniform vec3 edge[4];
300 void main()
301 {
302 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.z w + fragmentTexTransform.xy;
303 vec4 texColor = texture2D(s_texture, texCoord);
304 vec3 pos = vec3(gl_FragCoord.xy, 1);
305 float a0 = clamp(dot(edge[0], pos), 0.0, 1.0);
306 float a1 = clamp(dot(edge[1], pos), 0.0, 1.0);
307 float a2 = clamp(dot(edge[2], pos), 0.0, 1.0);
308 float a3 = clamp(dot(edge[3], pos), 0.0, 1.0);
309 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha * min(a0, a2) * min(a1, a3);
310 }
311 );
312 }
313
250 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() 314 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask()
251 : m_samplerLocation(-1) 315 : m_samplerLocation(-1)
252 , m_maskSamplerLocation(-1) 316 , m_maskSamplerLocation(-1)
253 , m_alphaLocation(-1) 317 , m_alphaLocation(-1)
254 { 318 {
255 } 319 }
256 320
257 void FragmentShaderRGBATexAlphaMask::init(GraphicsContext3D* context, unsigned p rogram) 321 void FragmentShaderRGBATexAlphaMask::init(GraphicsContext3D* context, unsigned p rogram)
258 { 322 {
259 m_samplerLocation = context->getUniformLocation(program, "s_texture"); 323 m_samplerLocation = context->getUniformLocation(program, "s_texture");
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 void main() 410 void main()
347 { 411 {
348 gl_FragColor = vec4(color.xyz * color.w, color.w); 412 gl_FragColor = vec4(color.xyz * color.w, color.w);
349 } 413 }
350 ); 414 );
351 } 415 }
352 416
353 } // namespace WebCore 417 } // namespace WebCore
354 418
355 #endif // USE(ACCELERATED_COMPOSITING) 419 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698