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 | |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 11 | #include "GrCaps.h" |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 12 | #include "GrFragmentProcessor.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 13 | #include "GrProcessor.h" |
commit-bot@chromium.org | cabf4b2 | 2014-03-05 18:27:43 +0000 | [diff] [blame] | 14 | #include "GrTypesPriv.h" |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 15 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 16 | class GrInvariantOutput; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 17 | class SkPath; |
| 18 | |
| 19 | /** |
| 20 | * An effect that renders a convex polygon. It is intended to be used as a coverage effect. |
| 21 | * Bounding geometry is rendered and the effect computes coverage based on the fragment's |
| 22 | * position relative to the polygon. |
| 23 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 24 | class GrConvexPolyEffect : public GrFragmentProcessor { |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 25 | public: |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 26 | enum { |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 27 | kMaxEdges = 8, |
| 28 | }; |
| 29 | |
| 30 | /** |
| 31 | * edges is a set of n edge equations where n is limited to kMaxEdges. It contains 3*n values. |
| 32 | * The edges should form a convex polygon. The positive half-plane is considered to be the |
| 33 | * inside. The equations should be normalized such that the first two coefficients are a unit |
| 34 | * 2d vector. |
| 35 | * |
| 36 | * Currently the edges are specified in device space. In the future we may prefer to specify |
| 37 | * them in src space. There are a number of ways this could be accomplished but we'd probably |
| 38 | * have to modify the effect/shaderbuilder interface to make it possible (e.g. give access |
| 39 | * to the view matrix or untransformed positions in the fragment shader). |
| 40 | */ |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 41 | static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType edgeType, int n, |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 42 | const SkScalar edges[]) { |
Ethan Nicholas | 1706f84 | 2017-11-10 11:58:19 -0500 | [diff] [blame] | 43 | if (n <= 0 || n > kMaxEdges || GrClipEdgeType::kHairlineAA == edgeType) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 44 | return nullptr; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 45 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 46 | return std::unique_ptr<GrFragmentProcessor>(new GrConvexPolyEffect(edgeType, n, edges)); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Creates an effect that clips against the path. If the path is not a convex polygon, is |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 51 | * inverse filled, or has too many edges, this will return nullptr. |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 52 | */ |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 53 | static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType, const SkPath&); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 54 | |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 55 | /** |
| 56 | * Creates an effect that fills inside the rect with AA edges.. |
| 57 | */ |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 58 | static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType, const SkRect&); |
commit-bot@chromium.org | f053980 | 2014-02-08 19:31:05 +0000 | [diff] [blame] | 59 | |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 60 | ~GrConvexPolyEffect() override; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 61 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 62 | const char* name() const override { return "ConvexPoly"; } |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 63 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 64 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 65 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 66 | GrClipEdgeType getEdgeType() const { return fEdgeType; } |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 67 | |
| 68 | int getEdgeCount() const { return fEdgeCount; } |
| 69 | |
| 70 | const SkScalar* getEdges() const { return fEdges; } |
| 71 | |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 72 | private: |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 73 | GrConvexPolyEffect(GrClipEdgeType edgeType, int n, const SkScalar edges[]); |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 74 | GrConvexPolyEffect(const GrConvexPolyEffect&); |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 75 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 76 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 77 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 78 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 79 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 80 | bool onIsEqual(const GrFragmentProcessor& other) const override; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 81 | |
Ethan Nicholas | 0f3c732 | 2017-11-09 14:51:17 -0500 | [diff] [blame] | 82 | GrClipEdgeType fEdgeType; |
| 83 | int fEdgeCount; |
| 84 | SkScalar fEdges[3 * kMaxEdges]; |
commit-bot@chromium.org | c3fe549 | 2014-01-30 18:15:51 +0000 | [diff] [blame] | 85 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [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 |