Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
GrConvexPolyEffect Class Reference

#include <GrConvexPolyEffect.h>

Inheritance diagram for GrConvexPolyEffect:
GrFragmentProcessor GrProcessor

Public Member Functions

 ~GrConvexPolyEffect () override
 
const char * name () const override
 
std::unique_ptr< GrFragmentProcessorclone () const override
 
- Public Member Functions inherited from GrFragmentProcessor
const GrFragmentProcessorparent () const
 
std::unique_ptr< ProgramImplmakeProgramImpl () const
 
void addToKey (const GrShaderCaps &caps, skgpu::KeyBuilder *b) const
 
int numChildProcessors () const
 
int numNonNullChildProcessors () const
 
GrFragmentProcessorchildProcessor (int index)
 
const GrFragmentProcessorchildProcessor (int index) const
 
 SkDEBUGCODE (bool isInstantiated() const ;) bool willReadDstColor() const
 
bool isBlendFunction () const
 
bool usesSampleCoordsDirectly () const
 
bool usesSampleCoords () const
 
const SkSL::SampleUsagesampleUsage () const
 
bool compatibleWithCoverageAsAlpha () const
 
bool preservesOpaqueInput () const
 
bool hasConstantOutputForConstantInput (SkPMColor4f inputColor, SkPMColor4f *outputColor) const
 
bool hasConstantOutputForConstantInput () const
 
void clearConstantOutputForConstantInputFlag ()
 
bool isEqual (const GrFragmentProcessor &that) const
 
void visitProxies (const GrVisitProxyFunc &) const
 
void visitTextureEffects (const std::function< void(const GrTextureEffect &)> &) const
 
void visitWithImpls (const std::function< void(const GrFragmentProcessor &, ProgramImpl &)> &, ProgramImpl &) const
 
GrTextureEffectasTextureEffect ()
 
const GrTextureEffectasTextureEffect () const
 
- Public Member Functions inherited from GrProcessor
virtual ~GrProcessor ()=default
 
void * operator new (size_t size)
 
void * operator new (size_t object_size, size_t footer_size)
 
void operator delete (void *target)
 
void * operator new (size_t size, void *placement)
 
void operator delete (void *target, void *placement)
 
template<typename T >
const Tcast () const
 
ClassID classID () const
 

Static Public Member Functions

static GrFPResult Make (std::unique_ptr< GrFragmentProcessor > inputFP, GrClipEdgeType edgeType, int n, const float edges[])
 
static GrFPResult Make (std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, const SkPath &)
 
- Static Public Member Functions inherited from GrFragmentProcessor
static std::unique_ptr< GrFragmentProcessorMakeColor (SkPMColor4f color)
 
static std::unique_ptr< GrFragmentProcessorMulInputByChildAlpha (std::unique_ptr< GrFragmentProcessor > child)
 
static std::unique_ptr< GrFragmentProcessorApplyPaintAlpha (std::unique_ptr< GrFragmentProcessor > child)
 
static std::unique_ptr< GrFragmentProcessorModulateRGBA (std::unique_ptr< GrFragmentProcessor > child, const SkPMColor4f &color)
 
static std::unique_ptr< GrFragmentProcessorOverrideInput (std::unique_ptr< GrFragmentProcessor >, const SkPMColor4f &)
 
static std::unique_ptr< GrFragmentProcessorDisableCoverageAsAlpha (std::unique_ptr< GrFragmentProcessor >)
 
static std::unique_ptr< GrFragmentProcessorDestColor ()
 
static std::unique_ptr< GrFragmentProcessorSwizzleOutput (std::unique_ptr< GrFragmentProcessor >, const skgpu::Swizzle &)
 
static std::unique_ptr< GrFragmentProcessorClampOutput (std::unique_ptr< GrFragmentProcessor >)
 
static std::unique_ptr< GrFragmentProcessorCompose (std::unique_ptr< GrFragmentProcessor > f, std::unique_ptr< GrFragmentProcessor > g)
 
static std::unique_ptr< GrFragmentProcessorColorMatrix (std::unique_ptr< GrFragmentProcessor > child, const float matrix[20], bool unpremulInput, bool clampRGBOutput, bool premulOutput)
 
static std::unique_ptr< GrFragmentProcessorSurfaceColor ()
 
static std::unique_ptr< GrFragmentProcessorDeviceSpace (std::unique_ptr< GrFragmentProcessor >)
 
static std::unique_ptr< GrFragmentProcessorRect (std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, SkRect)
 
static GrFPResult Circle (std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, SkPoint center, float radius)
 
static GrFPResult Ellipse (std::unique_ptr< GrFragmentProcessor >, GrClipEdgeType, SkPoint center, SkPoint radii, const GrShaderCaps &)
 
static std::unique_ptr< GrFragmentProcessorHighPrecision (std::unique_ptr< GrFragmentProcessor >)
 

Static Public Attributes

static constexpr int kMaxEdges = 8
 

Private Member Functions

std::unique_ptr< ProgramImplonMakeProgramImpl () const override
 
void onAddToKey (const GrShaderCaps &, skgpu::KeyBuilder *) const override
 
bool onIsEqual (const GrFragmentProcessor &other) const override
 

Additional Inherited Members

- Public Types inherited from GrProcessor
enum  ClassID {
  kNull_ClassID , kAttributeTestProcessor_ClassID , kBigKeyProcessor_ClassID , kBlendFragmentProcessor_ClassID ,
  kBlockInputFragmentProcessor_ClassID , kButtCapStrokedCircleGeometryProcessor_ClassID , kCircleGeometryProcessor_ClassID , kCircularRRectEffect_ClassID ,
  kClockwiseTestProcessor_ClassID , kColorTableEffect_ClassID , kCoverageSetOpXP_ClassID , kCustomXP_ClassID ,
  kDashingCircleEffect_ClassID , kDashingLineEffect_ClassID , kDefaultGeoProc_ClassID , kDeviceSpace_ClassID ,
  kDIEllipseGeometryProcessor_ClassID , kDisableColorXP_ClassID , kDrawAtlasPathShader_ClassID , kEllipseGeometryProcessor_ClassID ,
  kEllipticalRRectEffect_ClassID , kFwidthSquircleTestProcessor_ClassID , kGP_ClassID , kGrBicubicEffect_ClassID ,
  kGrBitmapTextGeoProc_ClassID , kGrColorSpaceXformEffect_ClassID , kGrConicEffect_ClassID , kGrConvexPolyEffect_ClassID ,
  kGrDiffuseLightingEffect_ClassID , kGrDisplacementMapEffect_ClassID , kGrDistanceFieldA8TextGeoProc_ClassID , kGrDistanceFieldLCDTextGeoProc_ClassID ,
  kGrDistanceFieldPathGeoProc_ClassID , kGrFillRRectOp_Processor_ClassID , kGrGaussianConvolutionFragmentProcessor_ClassID , kGrMatrixConvolutionEffect_ClassID ,
  kGrMatrixEffect_ClassID , kGrMeshTestProcessor_ClassID , kGrMorphologyEffect_ClassID , kGrPerlinNoise2Effect_ClassID ,
  kGrPipelineDynamicStateTestProcessor_ClassID , kGrQuadEffect_ClassID , kGrRRectShadowGeoProc_ClassID , kGrSkSLFP_ClassID ,
  kGrSpecularLightingEffect_ClassID , kGrTextureEffect_ClassID , kGrUnrolledBinaryGradientColorizer_ClassID , kGrYUVtoRGBEffect_ClassID ,
  kHighPrecisionFragmentProcessor_ClassID , kLatticeGP_ClassID , kPDLCDXferProcessor_ClassID , kPorterDuffXferProcessor_ClassID ,
  kPremulFragmentProcessor_ClassID , kQuadEdgeEffect_ClassID , kQuadPerEdgeAAGeometryProcessor_ClassID , kSeriesFragmentProcessor_ClassID ,
  kShaderPDXferProcessor_ClassID , kSurfaceColorProcessor_ClassID , kSwizzleFragmentProcessor_ClassID , kTessellate_BoundingBoxShader_ClassID ,
  kTessellate_GrModulateAtlasCoverageEffect_ClassID , kTessellate_GrStrokeTessellationShader_ClassID , kTessellate_HullShader_ClassID , kTessellate_MiddleOutShader_ClassID ,
  kTessellate_SimpleTriangleShader_ClassID , kTessellationTestTriShader_ClassID , kTestFP_ClassID , kTestRectOp_ClassID ,
  kVertexColorSpaceBenchGP_ClassID , kVerticesGP_ClassID
}
 
- Protected Types inherited from GrFragmentProcessor
enum  OptimizationFlags : uint32_t {
  kNone_OptimizationFlags , kCompatibleWithCoverageAsAlpha_OptimizationFlag = 0x1 , kPreservesOpaqueInput_OptimizationFlag = 0x2 , kConstantOutputForConstantInput_OptimizationFlag = 0x4 ,
  kAll_OptimizationFlags
}
 
- Protected Member Functions inherited from GrFragmentProcessor
 GrFragmentProcessor (ClassID classID, OptimizationFlags optimizationFlags)
 
 GrFragmentProcessor (const GrFragmentProcessor &src)
 
OptimizationFlags optimizationFlags () const
 
void registerChild (std::unique_ptr< GrFragmentProcessor > child, SkSL::SampleUsage sampleUsage=SkSL::SampleUsage::PassThrough())
 
void cloneAndRegisterAllChildProcessors (const GrFragmentProcessor &src)
 
void setUsesSampleCoordsDirectly ()
 
void setWillReadDstColor ()
 
void setIsBlendFunction ()
 
void mergeOptimizationFlags (OptimizationFlags flags)
 
- Protected Member Functions inherited from GrProcessor
 GrProcessor (ClassID classID)
 
 GrProcessor (const GrProcessor &)=delete
 
GrProcessoroperator= (const GrProcessor &)=delete
 
- Static Protected Member Functions inherited from GrFragmentProcessor
static OptimizationFlags ModulateForSamplerOptFlags (SkAlphaType alphaType, bool samplingDecal)
 
static OptimizationFlags ModulateForClampedSamplerOptFlags (SkAlphaType alphaType)
 
static OptimizationFlags ProcessorOptimizationFlags (const GrFragmentProcessor *fp)
 
static SkPMColor4f ConstantOutputForConstantInput (const GrFragmentProcessor *fp, const SkPMColor4f &input)
 
- Protected Attributes inherited from GrProcessor
const ClassID fClassID
 

Detailed Description

An effect that renders a convex polygon. It is intended to be used as a coverage effect. Bounding geometry is rendered and the effect computes coverage based on the fragment's position relative to the polygon.

Definition at line 30 of file GrConvexPolyEffect.h.

Constructor & Destructor Documentation

◆ ~GrConvexPolyEffect()

GrConvexPolyEffect::~GrConvexPolyEffect ( )
override

Definition at line 104 of file GrConvexPolyEffect.cpp.

104{}

Member Function Documentation

◆ clone()

std::unique_ptr< GrFragmentProcessor > GrConvexPolyEffect::clone ( ) const
overridevirtual

Makes a copy of this fragment processor that draws equivalently to the original. If the processor has child processors they are cloned as well.

Implements GrFragmentProcessor.

Definition at line 193 of file GrConvexPolyEffect.cpp.

193 {
194 return std::unique_ptr<GrFragmentProcessor>(new GrConvexPolyEffect(*this));
195}

◆ Make() [1/2]

static GrFPResult GrConvexPolyEffect::Make ( std::unique_ptr< GrFragmentProcessor inputFP,
GrClipEdgeType  edgeType,
int  n,
const float  edges[] 
)
inlinestatic

edges is a set of n edge equations where n is limited to kMaxEdges. It contains 3*n values. The edges should form a convex polygon. The positive half-plane is considered to be the inside. The equations should be normalized such that the first two coefficients are a unit 2d vector.

Currently the edges are specified in device space. In the future we may prefer to specify them in src space. There are a number of ways this could be accomplished but we'd probably have to modify the effect/shaderbuilder interface to make it possible (e.g. give access to the view matrix or untransformed positions in the fragment shader).

Definition at line 45 of file GrConvexPolyEffect.h.

48 {
49 if (n <= 0 || n > kMaxEdges) {
50 return GrFPFailure(std::move(inputFP));
51 }
52
53 return GrFPSuccess(std::unique_ptr<GrFragmentProcessor>(
54 new GrConvexPolyEffect(std::move(inputFP), edgeType, n, edges)));
55 }
static GrFPResult GrFPSuccess(std::unique_ptr< GrFragmentProcessor > fp)
static GrFPResult GrFPFailure(std::unique_ptr< GrFragmentProcessor > fp)
static constexpr int kMaxEdges

◆ Make() [2/2]

GrFPResult GrConvexPolyEffect::Make ( std::unique_ptr< GrFragmentProcessor inputFP,
GrClipEdgeType  type,
const SkPath path 
)
static

Creates an effect that clips against the path. If the path is not a convex polygon, is inverse filled, or has too many edges, creation will fail.

Definition at line 35 of file GrConvexPolyEffect.cpp.

36 {
37 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || !path.isConvex()) {
38 return GrFPFailure(std::move(inputFP));
39 }
40
42 // The only way this should fail is if the clip is effectively a infinitely thin line. In that
43 // case nothing is inside the clip. It'd be nice to detect this at a higher level and either
44 // skip the draw or omit the clip element.
47 return GrFPSuccess(
49 }
50 // This could use ConstColor instead of ModulateRGBA but it would trigger a debug print
51 // about a coverage processor not being compatible with the alpha-as-coverage optimization.
52 // We don't really care about this unlikely case so we just use ModulateRGBA to suppress
53 // the print.
54 return GrFPSuccess(
56 }
57
58 SkScalar edges[3 * kMaxEdges];
59 SkPoint pts[4];
60 SkPath::Verb verb;
61 SkPath::Iter iter(path, true);
62
63 // SkPath considers itself convex so long as there is a convex contour within it,
64 // regardless of any degenerate contours such as a string of moveTos before it.
65 // Iterate here to consume any degenerate contours and only process the points
66 // on the actual convex contour.
67 int n = 0;
68 while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
69 switch (verb) {
72 break;
73 case SkPath::kLine_Verb: {
74 if (n >= kMaxEdges) {
75 return GrFPFailure(std::move(inputFP));
76 }
77 if (pts[0] != pts[1]) {
78 SkVector v = pts[1] - pts[0];
79 v.normalize();
80 if (SkPathFirstDirection::kCCW == dir) {
81 edges[3 * n] = v.fY;
82 edges[3 * n + 1] = -v.fX;
83 } else {
84 edges[3 * n] = -v.fY;
85 edges[3 * n + 1] = v.fX;
86 }
87 edges[3 * n + 2] = -(edges[3 * n] * pts[1].fX + edges[3 * n + 1] * pts[1].fY);
88 ++n;
89 }
90 break;
91 }
92 default:
93 // Non-linear segment so not a polygon.
94 return GrFPFailure(std::move(inputFP));
95 }
96 }
97
98 if (path.isInverseFillType()) {
100 }
101 return GrConvexPolyEffect::Make(std::move(inputFP), type, n, edges);
102}
static constexpr bool GrClipEdgeTypeIsInverseFill(const GrClipEdgeType edgeType)
static GrClipEdgeType GrInvertClipEdgeType(const GrClipEdgeType edgeType)
constexpr SkPMColor4f SK_PMColor4fWHITE
constexpr SkPMColor4f SK_PMColor4fTRANSPARENT
SkPathFirstDirection
Definition SkPathEnums.h:19
static GrFPResult Make(std::unique_ptr< GrFragmentProcessor > inputFP, GrClipEdgeType edgeType, int n, const float edges[])
static std::unique_ptr< GrFragmentProcessor > ModulateRGBA(std::unique_ptr< GrFragmentProcessor > child, const SkPMColor4f &color)
static SkPathFirstDirection ComputeFirstDirection(const SkPath &)
Definition SkPath.cpp:2563
@ kLine_SegmentMask
Definition SkPath.h:1437
@ kClose_Verb
Definition SkPath.h:1463
@ kMove_Verb
Definition SkPath.h:1458
@ kDone_Verb
Definition SkPath.h:1464
@ kLine_Verb
Definition SkPath.h:1459
float SkScalar
Definition extension.cpp:12
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition switches.h:145
float fX
x-axis value
float fY
y-axis value
bool normalize()
Definition SkPoint.cpp:22

◆ name()

const char * GrConvexPolyEffect::name ( ) const
inlineoverridevirtual

Human-meaningful string to identify this processor; may be embedded in generated shader code and must be a legal SkSL identifier prefix.

Implements GrProcessor.

Definition at line 65 of file GrConvexPolyEffect.h.

65{ return "ConvexPoly"; }

◆ onAddToKey()

void GrConvexPolyEffect::onAddToKey ( const GrShaderCaps caps,
skgpu::KeyBuilder b 
) const
overrideprivatevirtual

Implements GrFragmentProcessor.

Definition at line 106 of file GrConvexPolyEffect.cpp.

106 {
107 static_assert(kGrClipEdgeTypeCnt <= 8);
108 uint32_t key = (fEdgeCount << 3) | static_cast<int>(fEdgeType);
109 b->add32(key);
110}
static const int kGrClipEdgeTypeCnt
static bool b

◆ onIsEqual()

bool GrConvexPolyEffect::onIsEqual ( const GrFragmentProcessor ) const
overrideprivatevirtual

Subclass implements this to support isEqual(). It will only be called if it is known that the two processors are of the same subclass (i.e. have the same ClassID).

Implements GrFragmentProcessor.

Definition at line 197 of file GrConvexPolyEffect.cpp.

197 {
198 const GrConvexPolyEffect& cpe = other.cast<GrConvexPolyEffect>();
199 int n = 3*cpe.fEdgeCount;
200 return cpe.fEdgeType == fEdgeType &&
201 cpe.fEdgeCount == fEdgeCount &&
202 std::equal(cpe.fEdges.begin(), cpe.fEdges.begin() + n, fEdges.begin());
203}
const T & cast() const

◆ onMakeProgramImpl()

std::unique_ptr< GrFragmentProcessor::ProgramImpl > GrConvexPolyEffect::onMakeProgramImpl ( ) const
overrideprivatevirtual

Returns a new instance of the appropriate ProgramImpl subclass for the given GrFragmentProcessor. It will emit the appropriate code and live with the cached program to setup uniform data for each draw that uses the program.

Implements GrFragmentProcessor.

Definition at line 112 of file GrConvexPolyEffect.cpp.

112 {
113 class Impl : public ProgramImpl {
114 public:
115 void emitCode(EmitArgs& args) override {
117
118 const char *edgeArrayName;
119 fEdgeUniform = args.fUniformHandler->addUniformArray(&cpe,
122 "edgeArray",
123 cpe.fEdgeCount,
124 &edgeArrayName);
125 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
126 fragBuilder->codeAppend("half alpha = 1.0;\n"
127 "half edge;\n");
128 for (int i = 0; i < cpe.fEdgeCount; ++i) {
129 fragBuilder->codeAppendf("edge = dot(%s[%d], half3(sk_FragCoord.xy1));\n",
130 edgeArrayName, i);
131 if (GrClipEdgeTypeIsAA(cpe.fEdgeType)) {
132 fragBuilder->codeAppend("alpha *= saturate(edge);\n");
133 } else {
134 fragBuilder->codeAppend("alpha *= step(0.5, edge);\n");
135 }
136 }
137
138 if (GrClipEdgeTypeIsInverseFill(cpe.fEdgeType)) {
139 fragBuilder->codeAppend("alpha = 1.0 - alpha;\n");
140 }
141
142 SkString inputSample = this->invokeChild(/*childIndex=*/0, args);
143
144 fragBuilder->codeAppendf("return %s * alpha;\n", inputSample.c_str());
145 }
146
147 private:
148 void onSetData(const GrGLSLProgramDataManager& pdman,
149 const GrFragmentProcessor& fp) override {
150 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>();
151 size_t n = 3*cpe.fEdgeCount;
152 if (!std::equal(fPrevEdges.begin(), fPrevEdges.begin() + n, cpe.fEdges.begin())) {
153 pdman.set3fv(fEdgeUniform, cpe.fEdgeCount, cpe.fEdges.data());
154 std::copy_n(cpe.fEdges.begin(), n, fPrevEdges.begin());
155 }
156 }
157
158 GrGLSLProgramDataManager::UniformHandle fEdgeUniform;
159 std::array<float, 3 * GrConvexPolyEffect::kMaxEdges> fPrevEdges = {SK_FloatNaN};
160 };
161
162 return std::make_unique<Impl>();
163}
@ kFragment_GrShaderFlag
static constexpr bool GrClipEdgeTypeIsAA(const GrClipEdgeType edgeType)
constexpr float SK_FloatNaN
virtual void set3fv(UniformHandle, int arrayCount, const float v[]) const =0
void codeAppend(const char *str)
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
const char * c_str() const
Definition SkString.h:133
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint32_t fp

Member Data Documentation

◆ kMaxEdges

constexpr int GrConvexPolyEffect::kMaxEdges = 8
inlinestaticconstexpr

Definition at line 32 of file GrConvexPolyEffect.h.


The documentation for this class was generated from the following files: