OLD | NEW |
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 #ifndef GrConvexPolyEffect_DEFINED | 8 #ifndef GrConvexPolyEffect_DEFINED |
9 #define GrConvexPolyEffect_DEFINED | 9 #define GrConvexPolyEffect_DEFINED |
10 | 10 |
11 #include "GrDrawTargetCaps.h" | 11 #include "GrDrawTargetCaps.h" |
12 #include "GrEffect.h" | 12 #include "GrProcessor.h" |
13 #include "GrTypesPriv.h" | 13 #include "GrTypesPriv.h" |
14 | 14 |
15 class GrGLConvexPolyEffect; | 15 class GrGLConvexPolyEffect; |
16 class SkPath; | 16 class SkPath; |
17 | 17 |
18 /** | 18 /** |
19 * An effect that renders a convex polygon. It is intended to be used as a cover
age effect. | 19 * An effect that renders a convex polygon. It is intended to be used as a cover
age effect. |
20 * Bounding geometry is rendered and the effect computes coverage based on the f
ragment's | 20 * Bounding geometry is rendered and the effect computes coverage based on the f
ragment's |
21 * position relative to the polygon. | 21 * position relative to the polygon. |
22 */ | 22 */ |
23 class GrConvexPolyEffect : public GrEffect { | 23 class GrConvexPolyEffect : public GrFragmentProcessor { |
24 public: | 24 public: |
25 enum { | 25 enum { |
26 kMaxEdges = 8, | 26 kMaxEdges = 8, |
27 }; | 27 }; |
28 | 28 |
29 /** | 29 /** |
30 * edges is a set of n edge equations where n is limited to kMaxEdges. It co
ntains 3*n values. | 30 * edges is a set of n edge equations where n is limited to kMaxEdges. It co
ntains 3*n values. |
31 * The edges should form a convex polygon. The positive half-plane is consid
ered to be the | 31 * The edges should form a convex polygon. The positive half-plane is consid
ered to be the |
32 * inside. The equations should be normalized such that the first two coeffi
cients are a unit | 32 * inside. The equations should be normalized such that the first two coeffi
cients are a unit |
33 * 2d vector. | 33 * 2d vector. |
34 * | 34 * |
35 * Currently the edges are specified in device space. In the future we may p
refer to specify | 35 * Currently the edges are specified in device space. In the future we may p
refer to specify |
36 * them in src space. There are a number of ways this could be accomplished
but we'd probably | 36 * them in src space. There are a number of ways this could be accomplished
but we'd probably |
37 * have to modify the effect/shaderbuilder interface to make it possible (e.
g. give access | 37 * have to modify the effect/shaderbuilder interface to make it possible (e.
g. give access |
38 * to the view matrix or untransformed positions in the fragment shader). | 38 * to the view matrix or untransformed positions in the fragment shader). |
39 */ | 39 */ |
40 static GrEffect* Create(GrEffectEdgeType edgeType, int n, const SkScalar edg
es[]) { | 40 static GrFragmentProcessor* Create(GrProcessorEdgeType edgeType, int n, |
41 if (n <= 0 || n > kMaxEdges || kHairlineAA_GrEffectEdgeType == edgeType)
{ | 41 const SkScalar edges[]) { |
| 42 if (n <= 0 || n > kMaxEdges || kHairlineAA_GrProcessorEdgeType == edgeTy
pe) { |
42 return NULL; | 43 return NULL; |
43 } | 44 } |
44 return SkNEW_ARGS(GrConvexPolyEffect, (edgeType, n, edges)); | 45 return SkNEW_ARGS(GrConvexPolyEffect, (edgeType, n, edges)); |
45 } | 46 } |
46 | 47 |
47 /** | 48 /** |
48 * Creates an effect that clips against the path. If the path is not a conve
x polygon, is | 49 * Creates an effect that clips against the path. If the path is not a conve
x polygon, is |
49 * inverse filled, or has too many edges, this will return NULL. If offset i
s non-NULL, then | 50 * inverse filled, or has too many edges, this will return NULL. If offset i
s non-NULL, then |
50 * the path is translated by the vector. | 51 * the path is translated by the vector. |
51 */ | 52 */ |
52 static GrEffect* Create(GrEffectEdgeType, const SkPath&, const SkVector* off
set = NULL); | 53 static GrFragmentProcessor* Create(GrProcessorEdgeType, const SkPath&, |
| 54 const SkVector* offset = NULL); |
53 | 55 |
54 /** | 56 /** |
55 * Creates an effect that fills inside the rect with AA edges.. | 57 * Creates an effect that fills inside the rect with AA edges.. |
56 */ | 58 */ |
57 static GrEffect* Create(GrEffectEdgeType, const SkRect&); | 59 static GrFragmentProcessor* Create(GrProcessorEdgeType, const SkRect&); |
58 | 60 |
59 virtual ~GrConvexPolyEffect(); | 61 virtual ~GrConvexPolyEffect(); |
60 | 62 |
61 static const char* Name() { return "ConvexPoly"; } | 63 static const char* Name() { return "ConvexPoly"; } |
62 | 64 |
63 GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 65 GrProcessorEdgeType getEdgeType() const { return fEdgeType; } |
64 | 66 |
65 int getEdgeCount() const { return fEdgeCount; } | 67 int getEdgeCount() const { return fEdgeCount; } |
66 | 68 |
67 const SkScalar* getEdges() const { return fEdges; } | 69 const SkScalar* getEdges() const { return fEdges; } |
68 | 70 |
69 typedef GrGLConvexPolyEffect GLEffect; | 71 typedef GrGLConvexPolyEffect GLProcessor; |
70 | 72 |
71 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | 73 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
72 | 74 |
73 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 75 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; |
74 | 76 |
75 private: | 77 private: |
76 GrConvexPolyEffect(GrEffectEdgeType edgeType, int n, const SkScalar edges[])
; | 78 GrConvexPolyEffect(GrProcessorEdgeType edgeType, int n, const SkScalar edges
[]); |
77 | 79 |
78 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | 80 virtual bool onIsEqual(const GrProcessor& other) const SK_OVERRIDE; |
79 | 81 |
80 GrEffectEdgeType fEdgeType; | 82 GrProcessorEdgeType fEdgeType; |
81 int fEdgeCount; | 83 int fEdgeCount; |
82 SkScalar fEdges[3 * kMaxEdges]; | 84 SkScalar fEdges[3 * kMaxEdges]; |
83 | 85 |
84 GR_DECLARE_EFFECT_TEST; | 86 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
85 | 87 |
86 typedef GrEffect INHERITED; | 88 typedef GrFragmentProcessor INHERITED; |
87 }; | 89 }; |
88 | 90 |
89 | 91 |
90 #endif | 92 #endif |
OLD | NEW |