michael@0: /* michael@0: * Copyright 2014 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef GrConvexPolyEffect_DEFINED michael@0: #define GrConvexPolyEffect_DEFINED michael@0: michael@0: #include "GrDrawTargetCaps.h" michael@0: #include "GrEffect.h" michael@0: #include "GrTypesPriv.h" michael@0: michael@0: class GrGLConvexPolyEffect; michael@0: class SkPath; michael@0: michael@0: /** michael@0: * An effect that renders a convex polygon. It is intended to be used as a coverage effect. michael@0: * Bounding geometry is rendered and the effect computes coverage based on the fragment's michael@0: * position relative to the polygon. michael@0: */ michael@0: class GrConvexPolyEffect : public GrEffect { michael@0: public: michael@0: enum { michael@0: kMaxEdges = 8, michael@0: }; michael@0: michael@0: /** michael@0: * edges is a set of n edge equations where n is limited to kMaxEdges. It contains 3*n values. michael@0: * The edges should form a convex polygon. The positive half-plane is considered to be the michael@0: * inside. The equations should be normalized such that the first two coefficients are a unit michael@0: * 2d vector. michael@0: * michael@0: * Currently the edges are specified in device space. In the future we may prefer to specify michael@0: * them in src space. There are a number of ways this could be accomplished but we'd probably michael@0: * have to modify the effect/shaderbuilder interface to make it possible (e.g. give access michael@0: * to the view matrix or untransformed positions in the fragment shader). michael@0: */ michael@0: static GrEffectRef* Create(GrEffectEdgeType edgeType, int n, const SkScalar edges[]) { michael@0: if (n <= 0 || n > kMaxEdges || kHairlineAA_GrEffectEdgeType == edgeType) { michael@0: return NULL; michael@0: } michael@0: return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrConvexPolyEffect, michael@0: (edgeType, n, edges)))); michael@0: } michael@0: michael@0: /** michael@0: * Creates an effect that clips against the path. If the path is not a convex polygon, is michael@0: * inverse filled, or has too many edges, this will return NULL. If offset is non-NULL, then michael@0: * the path is translated by the vector. michael@0: */ michael@0: static GrEffectRef* Create(GrEffectEdgeType, const SkPath&, const SkVector* offset = NULL); michael@0: michael@0: /** michael@0: * Creates an effect that fills inside the rect with AA edges.. michael@0: */ michael@0: static GrEffectRef* Create(GrEffectEdgeType, const SkRect&); michael@0: michael@0: virtual ~GrConvexPolyEffect(); michael@0: michael@0: static const char* Name() { return "ConvexPoly"; } michael@0: michael@0: GrEffectEdgeType getEdgeType() const { return fEdgeType; } michael@0: michael@0: int getEdgeCount() const { return fEdgeCount; } michael@0: michael@0: const SkScalar* getEdges() const { return fEdges; } michael@0: michael@0: typedef GrGLConvexPolyEffect GLEffect; michael@0: michael@0: virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; michael@0: michael@0: virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; michael@0: michael@0: private: michael@0: GrConvexPolyEffect(GrEffectEdgeType edgeType, int n, const SkScalar edges[]); michael@0: michael@0: virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; michael@0: michael@0: GrEffectEdgeType fEdgeType; michael@0: int fEdgeCount; michael@0: SkScalar fEdges[3 * kMaxEdges]; michael@0: michael@0: GR_DECLARE_EFFECT_TEST; michael@0: michael@0: typedef GrEffect INHERITED; michael@0: }; michael@0: michael@0: michael@0: #endif