gfx/skia/trunk/src/gpu/effects/GrConvexPolyEffect.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial