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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/effects/GrConvexPolyEffect.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +/*
     1.5 + * Copyright 2014 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef GrConvexPolyEffect_DEFINED
    1.12 +#define GrConvexPolyEffect_DEFINED
    1.13 +
    1.14 +#include "GrDrawTargetCaps.h"
    1.15 +#include "GrEffect.h"
    1.16 +#include "GrTypesPriv.h"
    1.17 +
    1.18 +class GrGLConvexPolyEffect;
    1.19 +class SkPath;
    1.20 +
    1.21 +/**
    1.22 + * An effect that renders a convex polygon. It is intended to be used as a coverage effect.
    1.23 + * Bounding geometry is rendered and the effect computes coverage based on the fragment's
    1.24 + * position relative to the polygon.
    1.25 + */
    1.26 +class GrConvexPolyEffect : public GrEffect {
    1.27 +public:
    1.28 +    enum {
    1.29 +        kMaxEdges = 8,
    1.30 +    };
    1.31 +
    1.32 +    /**
    1.33 +     * edges is a set of n edge equations where n is limited to kMaxEdges. It contains 3*n values.
    1.34 +     * The edges should form a convex polygon. The positive half-plane is considered to be the
    1.35 +     * inside. The equations should be normalized such that the first two coefficients are a unit
    1.36 +     * 2d vector.
    1.37 +     *
    1.38 +     * Currently the edges are specified in device space. In the future we may prefer to specify
    1.39 +     * them in src space. There are a number of ways this could be accomplished but we'd probably
    1.40 +     * have to modify the effect/shaderbuilder interface to make it possible (e.g. give access
    1.41 +     * to the view matrix or untransformed positions in the fragment shader).
    1.42 +     */
    1.43 +    static GrEffectRef* Create(GrEffectEdgeType edgeType, int n, const SkScalar edges[]) {
    1.44 +        if (n <= 0 || n > kMaxEdges || kHairlineAA_GrEffectEdgeType == edgeType) {
    1.45 +            return NULL;
    1.46 +        }
    1.47 +        return CreateEffectRef(AutoEffectUnref(SkNEW_ARGS(GrConvexPolyEffect,
    1.48 +                                                          (edgeType, n, edges))));
    1.49 +    }
    1.50 +
    1.51 +    /**
    1.52 +     * Creates an effect that clips against the path. If the path is not a convex polygon, is
    1.53 +     * inverse filled, or has too many edges, this will return NULL. If offset is non-NULL, then
    1.54 +     * the path is translated by the vector.
    1.55 +     */
    1.56 +    static GrEffectRef* Create(GrEffectEdgeType, const SkPath&, const SkVector* offset = NULL);
    1.57 +
    1.58 +    /**
    1.59 +     * Creates an effect that fills inside the rect with AA edges..
    1.60 +     */
    1.61 +    static GrEffectRef* Create(GrEffectEdgeType, const SkRect&);
    1.62 +
    1.63 +    virtual ~GrConvexPolyEffect();
    1.64 +
    1.65 +    static const char* Name() { return "ConvexPoly"; }
    1.66 +
    1.67 +    GrEffectEdgeType getEdgeType() const { return fEdgeType; }
    1.68 +
    1.69 +    int getEdgeCount() const { return fEdgeCount; }
    1.70 +
    1.71 +    const SkScalar* getEdges() const { return fEdges; }
    1.72 +
    1.73 +    typedef GrGLConvexPolyEffect GLEffect;
    1.74 +
    1.75 +    virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
    1.76 +
    1.77 +    virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
    1.78 +
    1.79 +private:
    1.80 +    GrConvexPolyEffect(GrEffectEdgeType edgeType, int n, const SkScalar edges[]);
    1.81 +
    1.82 +    virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE;
    1.83 +
    1.84 +    GrEffectEdgeType    fEdgeType;
    1.85 +    int                 fEdgeCount;
    1.86 +    SkScalar            fEdges[3 * kMaxEdges];
    1.87 +
    1.88 +    GR_DECLARE_EFFECT_TEST;
    1.89 +
    1.90 +    typedef GrEffect INHERITED;
    1.91 +};
    1.92 +
    1.93 +
    1.94 +#endif

mercurial