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

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

Issue 1490283004: Create GLSLUniformHandler class for gpu backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up public api of uniformhandler Created 5 years 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 "glsl/GrGLSLFragmentProcessor.h" 13 #include "glsl/GrGLSLFragmentProcessor.h"
14 #include "glsl/GrGLSLFragmentShaderBuilder.h" 14 #include "glsl/GrGLSLFragmentShaderBuilder.h"
15 #include "glsl/GrGLSLProgramBuilder.h"
16 #include "glsl/GrGLSLProgramDataManager.h" 15 #include "glsl/GrGLSLProgramDataManager.h"
16 #include "glsl/GrGLSLUniformHandler.h"
17 17
18 ////////////////////////////////////////////////////////////////////////////// 18 //////////////////////////////////////////////////////////////////////////////
19 19
20 class CircleEffect : public GrFragmentProcessor { 20 class CircleEffect : public GrFragmentProcessor {
21 public: 21 public:
22 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente r, SkScalar radius); 22 static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPoint& cente r, SkScalar radius);
23 23
24 virtual ~CircleEffect() {}; 24 virtual ~CircleEffect() {};
25 25
26 const char* name() const override { return "Circle"; } 26 const char* name() const override { return "Circle"; }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 GLCircleEffect::GLCircleEffect(const GrProcessor&) { 113 GLCircleEffect::GLCircleEffect(const GrProcessor&) {
114 fPrevRadius = -1.f; 114 fPrevRadius = -1.f;
115 } 115 }
116 116
117 void GLCircleEffect::emitCode(EmitArgs& args) { 117 void GLCircleEffect::emitCode(EmitArgs& args) {
118 const CircleEffect& ce = args.fFp.cast<CircleEffect>(); 118 const CircleEffect& ce = args.fFp.cast<CircleEffect>();
119 const char *circleName; 119 const char *circleName;
120 // 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
121 // 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.
122 fCircleUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_V isibility, 122 fCircleUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFra gment_Visibility,
123 kVec4f_GrSLType, kDefault_GrSLPrecision , 123 kVec4f_GrSLType, kDefault_ GrSLPrecision,
124 "circle", 124 "circle",
125 &circleName); 125 &circleName);
126 126
127 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 127 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
128 const char* fragmentPos = fragBuilder->fragmentPosition(); 128 const char* fragmentPos = fragBuilder->fragmentPosition();
129 129
130 SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType()); 130 SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType());
131 // 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
132 // 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"
133 // 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
134 // caps here. 134 // caps here.
135 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) { 135 if (GrProcessorEdgeTypeIsInverseFill(ce.getEdgeType())) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 GLEllipseEffect::GLEllipseEffect(const GrProcessor& effect) { 285 GLEllipseEffect::GLEllipseEffect(const GrProcessor& effect) {
286 fPrevRadii.fX = -1.f; 286 fPrevRadii.fX = -1.f;
287 } 287 }
288 288
289 void GLEllipseEffect::emitCode(EmitArgs& args) { 289 void GLEllipseEffect::emitCode(EmitArgs& args) {
290 const EllipseEffect& ee = args.fFp.cast<EllipseEffect>(); 290 const EllipseEffect& ee = args.fFp.cast<EllipseEffect>();
291 const char *ellipseName; 291 const char *ellipseName;
292 // 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)
293 // 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.
294 fEllipseUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_ Visibility, 294 fEllipseUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFr agment_Visibility,
295 kVec4f_GrSLType, kHigh_GrSLPrecision, 295 kVec4f_GrSLType, kHigh_Gr SLPrecision,
296 "ellipse", 296 "ellipse",
297 &ellipseName); 297 &ellipseName);
298 298
299 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 299 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
300 const char* fragmentPos = fragBuilder->fragmentPosition(); 300 const char* fragmentPos = fragBuilder->fragmentPosition();
301 301
302 // d is the offset to the ellipse center 302 // d is the offset to the ellipse center
303 fragBuilder->codeAppendf("\t\tvec2 d = %s.xy - %s.xy;\n", fragmentPos, ellip seName); 303 fragBuilder->codeAppendf("\t\tvec2 d = %s.xy - %s.xy;\n", fragmentPos, ellip seName);
304 fragBuilder->codeAppendf("\t\tvec2 Z = d * %s.zw;\n", ellipseName); 304 fragBuilder->codeAppendf("\t\tvec2 Z = d * %s.zw;\n", ellipseName);
305 // 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.
306 fragBuilder->codeAppend("\t\tfloat implicit = dot(Z, d) - 1.0;\n"); 306 fragBuilder->codeAppend("\t\tfloat implicit = dot(Z, d) - 1.0;\n");
307 // 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.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 w /= 2; 372 w /= 2;
373 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);
374 } else { 374 } else {
375 w /= 2; 375 w /= 2;
376 h /= 2; 376 h /= 2;
377 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);
378 } 378 }
379 379
380 return nullptr; 380 return nullptr;
381 } 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