commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrConvexPolyEffect_DEFINED |
| 9 | #define GrConvexPolyEffect_DEFINED |
| 10 | |
| 11 | #include "GrDrawTargetCaps.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 12 | #include "GrProcessor.h" |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 13 | #include "GrTypesPriv.h" |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 14 | |
| 15 | class GrGLConvexPolyEffect; |
| 16 | class SkPath; |
| 17 | |
| 18 | /** |
| 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. |
| 22 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 23 | class GrConvexPolyEffect : public GrFragmentProcessor { |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 24 | public: |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 25 | enum { |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 26 | kMaxEdges = 8, |
| 27 | }; |
| 28 | |
| 29 | /** |
| 30 | * edges is a set of n edge equations where n is limited to kMaxEdges. It contains 3*n values. |
| 31 | * The edges should form a convex polygon. The positive half-plane is considered to be the |
| 32 | * inside. The equations should be normalized such that the first two coefficients are a unit |
| 33 | * 2d vector. |
| 34 | * |
| 35 | * Currently the edges are specified in device space. In the future we may prefer to specify |
| 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 |
| 38 | * to the view matrix or untransformed positions in the fragment shader). |
| 39 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 40 | static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, int n, |
| 41 | const SkScalar edges[]) { |
| 42 | if (n <= 0 || n > kMaxEdges || kHairlineAA_GrProcessorEdgeType == edgeType) { |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 43 | return NULL; |
| 44 | } |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 45 | return SkNEW_ARGS(GrConvexPolyEffect, (edgeType, n, edges)); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Creates an effect that clips against the path. If the path is not a convex polygon, is |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 50 | * inverse filled, or has too many edges, this will return NULL. If offset is non-NULL, then |
| 51 | * the path is translated by the vector. |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 52 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 53 | static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkPath&, |
| 54 | const SkVector* offset = NULL); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 55 | |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 56 | /** |
| 57 | * Creates an effect that fills inside the rect with AA edges.. |
| 58 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 59 | static GrFragmentProcessor* Create(GrPrimitiveEdgeType, const SkRect&); |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 60 | |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 61 | virtual ~GrConvexPolyEffect(); |
| 62 | |
| 63 | static const char* Name() { return "ConvexPoly"; } |
| 64 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 65 | GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 66 | |
| 67 | int getEdgeCount() const { return fEdgeCount; } |
| 68 | |
| 69 | const SkScalar* getEdges() const { return fEdges; } |
| 70 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 71 | typedef GrGLConvexPolyEffect GLProcessor; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 72 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 73 | virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 74 | |
| 75 | private: |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 76 | GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, const SkScalar edges[]); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 77 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame^] | 78 | virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 79 | |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 80 | virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE; |
| 81 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 82 | GrPrimitiveEdgeType fEdgeType; |
| 83 | int fEdgeCount; |
| 84 | SkScalar fEdges[3 * kMaxEdges]; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 85 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 86 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 87 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 88 | typedef GrFragmentProcessor INHERITED; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | |
| 92 | #endif |