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

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

Issue 13344002: Move edge GrEffects to locally defined classes (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: rebase to head revision Created 7 years, 8 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
« no previous file with comments | « src/gpu/effects/GrEllipseEdgeEffect.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrEllipseEdgeEffect.h"
9 #include "gl/GrGLEffect.h"
10 #include "gl/GrGLSL.h"
11 #include "GrTBackendEffectFactory.h"
12
13 class GrGLEllipseEdgeEffect : public GrGLEffect {
14 public:
15 GrGLEllipseEdgeEffect(const GrBackendEffectFactory& factory, const GrDrawEff ect&)
16 : INHERITED (factory) {}
17
18 virtual void emitCode(GrGLShaderBuilder* builder,
19 const GrDrawEffect& drawEffect,
20 EffectKey key,
21 const char* outputColor,
22 const char* inputColor,
23 const TextureSamplerArray& samplers) SK_OVERRIDE {
24 const GrEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<GrEllip seEdgeEffect>();
25
26 const char *vsCenterName, *fsCenterName;
27 const char *vsEdgeName, *fsEdgeName;
28
29 builder->addVarying(kVec2f_GrSLType, "EllipseCenter", &vsCenterName, &fs CenterName);
30 const SkString* attr0Name =
31 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[ 0]);
32 builder->vsCodeAppendf("\t%s = %s;\n", vsCenterName, attr0Name->c_str()) ;
33
34 builder->addVarying(kVec4f_GrSLType, "EllipseEdge", &vsEdgeName, &fsEdge Name);
35 const SkString* attr1Name =
36 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[ 1]);
37 builder->vsCodeAppendf("\t%s = %s;\n", vsEdgeName, attr1Name->c_str());
38
39 // translate to origin
40 builder->fsCodeAppendf("\tvec2 outerOffset = (%s.xy - %s.xy);\n",
41 builder->fragmentPosition(), fsCenterName);
42 builder->fsCodeAppend("\tvec2 innerOffset = outerOffset;\n");
43 // scale y by xRadius/yRadius
44 builder->fsCodeAppendf("\touterOffset.y *= %s.y;\n", fsEdgeName);
45 builder->fsCodeAppend("\tfloat dOuter = length(outerOffset);\n");
46 // compare outer lengths against xOuterRadius
47 builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.x-dOuter, 0.0, 1.0) ;\n", fsEdgeName);
48
49 if (ellipseEffect.isStroked()) {
50 builder->fsCodeAppendf("\tinnerOffset.y *= %s.w;\n", fsEdgeName);
51 builder->fsCodeAppend("\tfloat dInner = length(innerOffset);\n");
52
53 // compare inner lengths against xInnerRadius
54 builder->fsCodeAppendf("\tfloat innerAlpha = clamp(dInner-%s.z, 0.0, 1.0);\n", fsEdgeName);
55 builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n");
56 }
57
58 SkString modulate;
59 GrGLSLModulate4f(&modulate, inputColor, "edgeAlpha");
60 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str());
61 }
62
63 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&) {
64 const GrEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<GrEllip seEdgeEffect>();
65
66 return ellipseEffect.isStroked() ? 0x1 : 0x0;
67 }
68
69 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE {
70 }
71
72 private:
73 typedef GrGLEffect INHERITED;
74 };
75
76 ///////////////////////////////////////////////////////////////////////////////
77
78 GrEllipseEdgeEffect::GrEllipseEdgeEffect(bool stroke) : GrEffect() {
79 this->addVertexAttrib(kVec2f_GrSLType);
80 this->addVertexAttrib(kVec4f_GrSLType);
81
82 fStroke = stroke;
83 }
84
85 void GrEllipseEdgeEffect::getConstantColorComponents(GrColor* color, uint32_t* v alidFlags) const {
86 *validFlags = 0;
87 }
88
89 const GrBackendEffectFactory& GrEllipseEdgeEffect::getFactory() const {
90 return GrTBackendEffectFactory<GrEllipseEdgeEffect>::getInstance();
91 }
92
93 ///////////////////////////////////////////////////////////////////////////////
94
95 GR_DEFINE_EFFECT_TEST(GrEllipseEdgeEffect);
96
97 GrEffectRef* GrEllipseEdgeEffect::TestCreate(SkMWCRandom* random,
98 GrContext* context,
99 const GrDrawTargetCaps&,
100 GrTexture* textures[]) {
101 return GrEllipseEdgeEffect::Create(random->nextBool());
102 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrEllipseEdgeEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698