2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrConvexPolyEffect_DEFINED
9 #define GrConvexPolyEffect_DEFINED
11 #include "GrDrawTargetCaps.h"
13 #include "GrVertexEffect.h"
15 class GrGLConvexPolyEffect;
19 * An effect that renders a convex polygon. It is intended to be used as a coverage effect.
20 * Bounding geometry is rendered and the effect computes coverage based on the fragment's
21 * position relative to the polygon.
23 class GrConvexPolyEffect : public GrEffect {
25 /** This could be expanded to include a AA hairline mode. If so, unify with GrBezierEffect's
31 kLastEdgeType = kFillAA_EdgeType,
35 kEdgeTypeCnt = kLastEdgeType + 1,
40 * edges is a set of n edge equations where n is limited to kMaxEdges. It contains 3*n values.
41 * The edges should form a convex polygon. The positive half-plane is considered to be the
42 * inside. The equations should be normalized such that the first two coefficients are a unit
45 * Currently the edges are specified in device space. In the future we may prefer to specify
46 * them in src space. There are a number of ways this could be accomplished but we'd probably
47 * have to modify the effect/shaderbuilder interface to make it possible (e.g. give access
48 * to the view matrix or untransformed positions in the fragment shader).
50 static GrEffectRef* Create(EdgeType edgeType, int n, const SkScalar edges[]) {
51 if (n <= 0 || n > kMaxEdges) {
54 return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrConvexPolyEffect,
55 (edgeType, n, edges))));
59 * Creates an effect that clips against the path. If the path is not a convex polygon, is
60 * inverse filled, or has too many edges, this will return NULL. If offset is non-NULL, then
61 * the path is translated by the vector.
63 static GrEffectRef* Create(EdgeType, const SkPath&, const SkVector* offset= NULL);
66 * Creates an effect that fills inside the rect with AA edges..
68 static GrEffectRef* CreateForAAFillRect(const SkRect&);
70 virtual ~GrConvexPolyEffect();
72 static const char* Name() { return "ConvexPoly"; }
74 EdgeType getEdgeType() const { return fEdgeType; }
76 int getEdgeCount() const { return fEdgeCount; }
78 const SkScalar* getEdges() const { return fEdges; }
80 typedef GrGLConvexPolyEffect GLEffect;
82 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
84 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
87 GrConvexPolyEffect(EdgeType edgeType, int n, const SkScalar edges[]);
89 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
93 SkScalar fEdges[3 * kMaxEdges];
95 GR_DECLARE_EFFECT_TEST;
97 typedef GrEffect INHERITED;