blob: 223c8016828b40f96215ddfc18b1c099752b9697 [file] [log] [blame]
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +00001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/private/GrTypesPriv.h"
12#include "src/gpu/GrCaps.h"
13#include "src/gpu/GrFragmentProcessor.h"
14#include "src/gpu/GrProcessor.h"
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000015
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000016class 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 */
joshualittb0a8a372014-09-23 09:50:21 -070023class GrConvexPolyEffect : public GrFragmentProcessor {
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000024public:
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000025 enum {
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000026 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 */
Ethan Nicholas0f3c7322017-11-09 14:51:17 -050040 static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType edgeType, int n,
Brian Salomonaff329b2017-08-11 09:40:37 -040041 const SkScalar edges[]) {
Ethan Nicholas1706f842017-11-10 11:58:19 -050042 if (n <= 0 || n > kMaxEdges || GrClipEdgeType::kHairlineAA == edgeType) {
halcanary96fcdcc2015-08-27 07:41:13 -070043 return nullptr;
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000044 }
Brian Salomonaff329b2017-08-11 09:40:37 -040045 return std::unique_ptr<GrFragmentProcessor>(new GrConvexPolyEffect(edgeType, n, edges));
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000046 }
47
48 /**
49 * Creates an effect that clips against the path. If the path is not a convex polygon, is
Brian Salomon9a767722017-03-13 17:57:28 -040050 * inverse filled, or has too many edges, this will return nullptr.
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000051 */
Ethan Nicholaseace9352018-10-15 20:09:54 +000052 static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType, const SkPath&);
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000053
commit-bot@chromium.orgf0539802014-02-08 19:31:05 +000054 /**
Ethan Nicholaseace9352018-10-15 20:09:54 +000055 * Creates an effect that fills inside the rect with AA edges..
commit-bot@chromium.orgf0539802014-02-08 19:31:05 +000056 */
Ethan Nicholaseace9352018-10-15 20:09:54 +000057 static std::unique_ptr<GrFragmentProcessor> Make(GrClipEdgeType, const SkRect&);
commit-bot@chromium.orgf0539802014-02-08 19:31:05 +000058
Brian Salomond3b65972017-03-22 12:05:03 -040059 ~GrConvexPolyEffect() override;
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000060
mtklein36352bf2015-03-25 18:17:31 -070061 const char* name() const override { return "ConvexPoly"; }
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000062
Brian Salomonaff329b2017-08-11 09:40:37 -040063 std::unique_ptr<GrFragmentProcessor> clone() const override;
Brian Salomonfcc527b2017-07-26 12:21:21 -040064
Ethan Nicholas0f3c7322017-11-09 14:51:17 -050065 GrClipEdgeType getEdgeType() const { return fEdgeType; }
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000066
67 int getEdgeCount() const { return fEdgeCount; }
68
69 const SkScalar* getEdges() const { return fEdges; }
70
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000071private:
Ethan Nicholas0f3c7322017-11-09 14:51:17 -050072 GrConvexPolyEffect(GrClipEdgeType edgeType, int n, const SkScalar edges[]);
Brian Salomonfcc527b2017-07-26 12:21:21 -040073 GrConvexPolyEffect(const GrConvexPolyEffect&);
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000074
egdaniel57d3b032015-11-13 11:57:27 -080075 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070076
Brian Salomon94efbf52016-11-29 13:43:05 -050077 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070078
mtklein36352bf2015-03-25 18:17:31 -070079 bool onIsEqual(const GrFragmentProcessor& other) const override;
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000080
Ethan Nicholas0f3c7322017-11-09 14:51:17 -050081 GrClipEdgeType fEdgeType;
82 int fEdgeCount;
83 SkScalar fEdges[3 * kMaxEdges];
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000084
Brian Salomon0c26a9d2017-07-06 10:09:38 -040085 GR_DECLARE_FRAGMENT_PROCESSOR_TEST
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000086
joshualittb0a8a372014-09-23 09:50:21 -070087 typedef GrFragmentProcessor INHERITED;
commit-bot@chromium.orgc3fe5492014-01-30 18:15:51 +000088};
89
90
91#endif