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

Side by Side Diff: src/gpu/effects/GrOvalEffect.cpp

Issue 1709153002: Add more specialized fragment builders (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make MSVC happy Created 4 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
« no previous file with comments | « src/gpu/effects/GrMatrixConvolutionEffect.cpp ('k') | src/gpu/effects/GrRRectEffect.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrOvalEffect.h" 8 #include "GrOvalEffect.h"
9 9
10 #include "GrFragmentProcessor.h" 10 #include "GrFragmentProcessor.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 void GLCircleEffect::emitCode(EmitArgs& args) { 113 void GLCircleEffect::emitCode(EmitArgs& args) {
114 const CircleEffect& ce = args.fFp.cast<CircleEffect>(); 114 const CircleEffect& ce = args.fFp.cast<CircleEffect>();
115 const char *circleName; 115 const char *circleName;
116 // The circle uniform is (center.x, center.y, radius + 0.5, 1 / (radius + 0. 5)) for regular 116 // The circle uniform is (center.x, center.y, radius + 0.5, 1 / (radius + 0. 5)) for regular
117 // fills and (..., radius - 0.5, 1 / (radius - 0.5)) for inverse fills. 117 // fills and (..., radius - 0.5, 1 / (radius - 0.5)) for inverse fills.
118 fCircleUniform = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, 118 fCircleUniform = args.fUniformHandler->addUniform(kFragment_GrShaderFlag,
119 kVec4f_GrSLType, kDefault_ GrSLPrecision, 119 kVec4f_GrSLType, kDefault_ GrSLPrecision,
120 "circle", 120 "circle",
121 &circleName); 121 &circleName);
122 122
123 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 123 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
124 const char* fragmentPos = fragBuilder->fragmentPosition(); 124 const char* fragmentPos = fragBuilder->fragmentPosition();
125 125
126 SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType()); 126 SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType());
127 // TODO: Right now the distance to circle caclulation is performed in a spac e normalized to the 127 // TODO: Right now the distance to circle caclulation is performed in a spac e normalized to the
128 // radius and then denormalized. This is to prevent overflow on devices that have a "real" 128 // radius and then denormalized. This is to prevent overflow on devices that have a "real"
129 // mediump. It'd be nice to only to this on mediump devices but we currently don't have the 129 // mediump. It'd be nice to only to this on mediump devices but we currently don't have the
130 // caps here. 130 // caps here.
131 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) { 131 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) {
132 fragBuilder->codeAppendf("float d = (length((%s.xy - %s.xy) * %s.w) - 1. 0) * %s.z;", 132 fragBuilder->codeAppendf("float d = (length((%s.xy - %s.xy) * %s.w) - 1. 0) * %s.z;",
133 circleName, fragmentPos, circleName, circleName ); 133 circleName, fragmentPos, circleName, circleName );
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // that is normalized by the larger radius. The scale uniform will be scale, 1/scale. The 294 // that is normalized by the larger radius. The scale uniform will be scale, 1/scale. The
295 // inverse squared radii uniform values are already in this normalized space . The center is 295 // inverse squared radii uniform values are already in this normalized space . The center is
296 // not. 296 // not.
297 const char* scaleName = nullptr; 297 const char* scaleName = nullptr;
298 if (args.fGLSLCaps->floatPrecisionVaries()) { 298 if (args.fGLSLCaps->floatPrecisionVaries()) {
299 fScaleUniform = args.fUniformHandler->addUniform( 299 fScaleUniform = args.fUniformHandler->addUniform(
300 kFragment_GrShaderFlag, kVec2f_GrSLType, kDefault_GrSLPrecision, 300 kFragment_GrShaderFlag, kVec2f_GrSLType, kDefault_GrSLPrecision,
301 "scale", &scaleName); 301 "scale", &scaleName);
302 } 302 }
303 303
304 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 304 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
305 const char* fragmentPos = fragBuilder->fragmentPosition(); 305 const char* fragmentPos = fragBuilder->fragmentPosition();
306 306
307 // d is the offset to the ellipse center 307 // d is the offset to the ellipse center
308 fragBuilder->codeAppendf("vec2 d = %s.xy - %s.xy;", fragmentPos, ellipseName ); 308 fragBuilder->codeAppendf("vec2 d = %s.xy - %s.xy;", fragmentPos, ellipseName );
309 if (scaleName) { 309 if (scaleName) {
310 fragBuilder->codeAppendf("d *= %s.y;", scaleName); 310 fragBuilder->codeAppendf("d *= %s.y;", scaleName);
311 } 311 }
312 fragBuilder->codeAppendf("vec2 Z = d * %s.zw;", ellipseName); 312 fragBuilder->codeAppendf("vec2 Z = d * %s.zw;", ellipseName);
313 // implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1. 313 // implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1.
314 fragBuilder->codeAppend("float implicit = dot(Z, d) - 1.0;"); 314 fragBuilder->codeAppend("float implicit = dot(Z, d) - 1.0;");
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 w /= 2; 401 w /= 2;
402 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval .fTop + w), w); 402 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval .fTop + w), w);
403 } else { 403 } else {
404 w /= 2; 404 w /= 2;
405 h /= 2; 405 h /= 2;
406 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova l.fTop + h), w, h); 406 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova l.fTop + h), w, h);
407 } 407 }
408 408
409 return nullptr; 409 return nullptr;
410 } 410 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrMatrixConvolutionEffect.cpp ('k') | src/gpu/effects/GrRRectEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698