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

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

Issue 1438003003: Move all ShaderBuilder files to GLSL (Closed) Base URL: https://skia.googlesource.com/skia.git@glslProgBuild
Patch Set: nits Created 5 years, 1 month 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 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"
11 #include "GrInvariantOutput.h" 11 #include "GrInvariantOutput.h"
12 #include "SkRect.h" 12 #include "SkRect.h"
13 #include "gl/GrGLFragmentProcessor.h" 13 #include "gl/GrGLFragmentProcessor.h"
14 #include "gl/builders/GrGLProgramBuilder.h" 14 #include "glsl/GrGLSLFragmentShaderBuilder.h"
15 #include "glsl/GrGLSLProgramBuilder.h"
15 #include "glsl/GrGLSLProgramDataManager.h" 16 #include "glsl/GrGLSLProgramDataManager.h"
16 17
17 ////////////////////////////////////////////////////////////////////////////// 18 //////////////////////////////////////////////////////////////////////////////
18 19
19 class CircleEffect : public GrFragmentProcessor { 20 class CircleEffect : public GrFragmentProcessor {
20 public: 21 public:
21 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente r, SkScalar radius); 22 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente r, SkScalar radius);
22 23
23 virtual ~CircleEffect() {}; 24 virtual ~CircleEffect() {};
24 25
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 112
112 GLCircleEffect::GLCircleEffect(const GrProcessor&) { 113 GLCircleEffect::GLCircleEffect(const GrProcessor&) {
113 fPrevRadius = -1.f; 114 fPrevRadius = -1.f;
114 } 115 }
115 116
116 void GLCircleEffect::emitCode(EmitArgs& args) { 117 void GLCircleEffect::emitCode(EmitArgs& args) {
117 const CircleEffect& ce = args.fFp.cast<CircleEffect>(); 118 const CircleEffect& ce = args.fFp.cast<CircleEffect>();
118 const char *circleName; 119 const char *circleName;
119 // The circle uniform is (center.x, center.y, radius + 0.5, 1 / (radius + 0. 5)) for regular 120 // The circle uniform is (center.x, center.y, radius + 0.5, 1 / (radius + 0. 5)) for regular
120 // fills and (..., radius - 0.5, 1 / (radius - 0.5)) for inverse fills. 121 // fills and (..., radius - 0.5, 1 / (radius - 0.5)) for inverse fills.
121 fCircleUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Vis ibility, 122 fCircleUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_V isibility,
122 kVec4f_GrSLType, kDefault_GrSLPrecision , 123 kVec4f_GrSLType, kDefault_GrSLPrecision ,
123 "circle", 124 "circle",
124 &circleName); 125 &circleName);
125 126
126 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); 127 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder() ;
127 const char* fragmentPos = fsBuilder->fragmentPosition(); 128 const char* fragmentPos = fsBuilder->fragmentPosition();
128 129
129 SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType()); 130 SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType());
130 // TODO: Right now the distance to circle caclulation is performed in a spac e normalized to the 131 // TODO: Right now the distance to circle caclulation is performed in a spac e normalized to the
131 // radius and then denormalized. This is to prevent overflow on devices that have a "real" 132 // radius and then denormalized. This is to prevent overflow on devices that have a "real"
132 // mediump. It'd be nice to only to this on mediump devices but we currently don't have the 133 // mediump. It'd be nice to only to this on mediump devices but we currently don't have the
133 // caps here. 134 // caps here.
134 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) { 135 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) {
135 fsBuilder->codeAppendf("\t\tfloat d = (length((%s.xy - %s.xy) * %s.w) - 1.0) * %s.z;\n", 136 fsBuilder->codeAppendf("\t\tfloat d = (length((%s.xy - %s.xy) * %s.w) - 1.0) * %s.z;\n",
136 circleName, fragmentPos, circleName, circleName) ; 137 circleName, fragmentPos, circleName, circleName) ;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 284
284 GLEllipseEffect::GLEllipseEffect(const GrProcessor& effect) { 285 GLEllipseEffect::GLEllipseEffect(const GrProcessor& effect) {
285 fPrevRadii.fX = -1.f; 286 fPrevRadii.fX = -1.f;
286 } 287 }
287 288
288 void GLEllipseEffect::emitCode(EmitArgs& args) { 289 void GLEllipseEffect::emitCode(EmitArgs& args) {
289 const EllipseEffect& ee = args.fFp.cast<EllipseEffect>(); 290 const EllipseEffect& ee = args.fFp.cast<EllipseEffect>();
290 const char *ellipseName; 291 const char *ellipseName;
291 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2) 292 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2)
292 // The last two terms can underflow on mediump, so we use highp. 293 // The last two terms can underflow on mediump, so we use highp.
293 fEllipseUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Vi sibility, 294 fEllipseUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_ Visibility,
294 kVec4f_GrSLType, kHigh_GrSLPrecision, 295 kVec4f_GrSLType, kHigh_GrSLPrecision,
295 "ellipse", 296 "ellipse",
296 &ellipseName); 297 &ellipseName);
297 298
298 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); 299 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder() ;
299 const char* fragmentPos = fsBuilder->fragmentPosition(); 300 const char* fragmentPos = fsBuilder->fragmentPosition();
300 301
301 // d is the offset to the ellipse center 302 // d is the offset to the ellipse center
302 fsBuilder->codeAppendf("\t\tvec2 d = %s.xy - %s.xy;\n", fragmentPos, ellipse Name); 303 fsBuilder->codeAppendf("\t\tvec2 d = %s.xy - %s.xy;\n", fragmentPos, ellipse Name);
303 fsBuilder->codeAppendf("\t\tvec2 Z = d * %s.zw;\n", ellipseName); 304 fsBuilder->codeAppendf("\t\tvec2 Z = d * %s.zw;\n", ellipseName);
304 // implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1. 305 // implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1.
305 fsBuilder->codeAppend("\t\tfloat implicit = dot(Z, d) - 1.0;\n"); 306 fsBuilder->codeAppend("\t\tfloat implicit = dot(Z, d) - 1.0;\n");
306 // grad_dot is the squared length of the gradient of the implicit. 307 // grad_dot is the squared length of the gradient of the implicit.
307 fsBuilder->codeAppendf("\t\tfloat grad_dot = 4.0 * dot(Z, Z);\n"); 308 fsBuilder->codeAppendf("\t\tfloat grad_dot = 4.0 * dot(Z, Z);\n");
308 // avoid calling inversesqrt on zero. 309 // avoid calling inversesqrt on zero.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 w /= 2; 372 w /= 2;
372 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval .fTop + w), w); 373 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval .fTop + w), w);
373 } else { 374 } else {
374 w /= 2; 375 w /= 2;
375 h /= 2; 376 h /= 2;
376 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova l.fTop + h), w, h); 377 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova l.fTop + h), w, h);
377 } 378 }
378 379
379 return nullptr; 380 return nullptr;
380 } 381 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrMatrixConvolutionEffect.cpp ('k') | src/gpu/effects/GrPorterDuffXferProcessor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698