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 #ifndef GrEdgeEffect_DEFINED | |
9 #define GrEdgeEffect_DEFINED | |
10 | |
11 #include "GrEffect.h" | |
12 | |
13 class GrGLEdgeEffect; | |
14 | |
15 /** | |
16 * The output of this effect is one of three different edge types: hairlines, qu ads, | |
17 * and hairline quads. | |
18 */ | |
19 | |
20 class GrEdgeEffect : public GrEffect { | |
21 public: | |
22 enum EdgeType { | |
23 /* 1-pixel wide line | |
24 2D implicit device coord line eq (a*x + b*y +c = 0). 4th component un used. */ | |
25 kHairLine_EdgeType = 0, | |
26 /* Quadratic specified by 0=u^2-v canonical coords. u and v are the firs t | |
27 two components of the vertex attribute. Coverage is based on signed | |
28 distance with negative being inside, positive outside. The edge is sp ecified in | |
29 window space (y-down). If either the third or fourth component of the interpolated | |
30 vertex coord is > 0 then the pixel is considered outside the edge. Th is is used to | |
31 attempt to trim to a portion of the infinite quad. Requires shader de rivative | |
32 instruction support. */ | |
33 kQuad_EdgeType, | |
34 /* Similar to above but for hairline quadratics. Uses unsigned distance. | |
35 Coverage is min(0, 1-distance). 3rd & 4th component unused. Requires | |
36 shader derivative instruction support. */ | |
37 kHairQuad_EdgeType, | |
38 | |
39 kLast_EdgeType = kHairQuad_EdgeType | |
40 }; | |
41 static const int kEdgeTypeCount = kLast_EdgeType + 1; | |
42 | |
43 static GrEffectRef* Create(EdgeType type) { | |
44 // we go through this so we only have one copy of each effect | |
45 static GrEffectRef* gEdgeEffectRef[kEdgeTypeCount] = { | |
bsalomon
2013/03/26 13:41:50
XCode/clang did not like the SkAutoTUnref<GrEffect
| |
46 CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrEdgeEffect, (kHairLine_ EdgeType)))), | |
47 CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrEdgeEffect, (kQuad_Edge Type)))), | |
48 CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrEdgeEffect, (kHairQuad_ EdgeType)))), | |
49 }; | |
50 static SkAutoTUnref<GrEffectRef> gUnref0(gEdgeEffectRef[0]); | |
51 static SkAutoTUnref<GrEffectRef> gUnref1(gEdgeEffectRef[1]); | |
52 static SkAutoTUnref<GrEffectRef> gUnref2(gEdgeEffectRef[2]); | |
53 | |
54 gEdgeEffectRef[type]->ref(); | |
55 return gEdgeEffectRef[type]; | |
56 } | |
57 | |
58 virtual ~GrEdgeEffect() {} | |
59 | |
60 static const char* Name() { return "Edge"; } | |
61 | |
62 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; | |
63 | |
64 typedef GrGLEdgeEffect GLEffect; | |
65 | |
66 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | |
67 | |
robertphillips
2013/03/26 14:09:20
We don't usually bother with inlines on these
bsalomon
2013/03/26 14:45:30
Done.
| |
68 inline EdgeType edgeType() const { return fEdgeType; } | |
69 | |
70 private: | |
71 GrEdgeEffect(EdgeType edgeType); | |
72 | |
73 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { | |
74 const GrEdgeEffect& qee = CastEffect<GrEdgeEffect>(other); | |
75 return qee.fEdgeType == fEdgeType; | |
76 } | |
77 | |
78 EdgeType fEdgeType; | |
79 | |
80 GR_DECLARE_EFFECT_TEST; | |
81 | |
82 typedef GrEffect INHERITED; | |
83 }; | |
84 | |
85 #endif | |
OLD | NEW |