OLD | NEW |
| (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 "GrCircleEdgeEffect.h" | |
9 #include "gl/GrGLEffect.h" | |
10 #include "gl/GrGLSL.h" | |
11 #include "GrTBackendEffectFactory.h" | |
12 | |
13 class GrGLCircleEdgeEffect : public GrGLEffect { | |
14 public: | |
15 GrGLCircleEdgeEffect(const GrBackendEffectFactory& factory, const GrDrawEffe
ct&) | |
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 GrCircleEdgeEffect& circleEffect = drawEffect.castEffect<GrCircleE
dgeEffect>(); | |
25 const char *vsName, *fsName; | |
26 builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName); | |
27 | |
28 const SkString* attrName = | |
29 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[
0]); | |
30 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); | |
31 | |
32 builder->fsCodeAppendf("\tfloat d = distance(%s.xy, %s.xy);\n", | |
33 builder->fragmentPosition(), fsName); | |
34 builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0);\n
", fsName); | |
35 if (circleEffect.isStroked()) { | |
36 builder->fsCodeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0, 1.
0);\n", fsName); | |
37 builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n"); | |
38 } | |
39 SkString modulate; | |
40 GrGLSLModulate4f(&modulate, inputColor, "edgeAlpha"); | |
41 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()); | |
42 } | |
43 | |
44 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&) { | |
45 const GrCircleEdgeEffect& circleEffect = drawEffect.castEffect<GrCircleE
dgeEffect>(); | |
46 | |
47 return circleEffect.isStroked() ? 0x1 : 0x0; | |
48 } | |
49 | |
50 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE { | |
51 } | |
52 | |
53 private: | |
54 typedef GrGLEffect INHERITED; | |
55 }; | |
56 | |
57 /////////////////////////////////////////////////////////////////////////////// | |
58 | |
59 GrCircleEdgeEffect::GrCircleEdgeEffect(bool stroke) : GrEffect() { | |
60 this->addVertexAttrib(kVec4f_GrSLType); | |
61 fStroke = stroke; | |
62 } | |
63 | |
64 void GrCircleEdgeEffect::getConstantColorComponents(GrColor* color, uint32_t* va
lidFlags) const { | |
65 *validFlags = 0; | |
66 } | |
67 | |
68 const GrBackendEffectFactory& GrCircleEdgeEffect::getFactory() const { | |
69 return GrTBackendEffectFactory<GrCircleEdgeEffect>::getInstance(); | |
70 } | |
71 | |
72 /////////////////////////////////////////////////////////////////////////////// | |
73 | |
74 GR_DEFINE_EFFECT_TEST(GrCircleEdgeEffect); | |
75 | |
76 GrEffectRef* GrCircleEdgeEffect::TestCreate(SkMWCRandom* random, | |
77 GrContext* context, | |
78 const GrDrawTargetCaps&, | |
79 GrTexture* textures[]) { | |
80 return GrCircleEdgeEffect::Create(random->nextBool()); | |
81 } | |
OLD | NEW |