blob: dc36fc18dff7f09ef1a41a621a0cdca3d8c01bd1 [file] [log] [blame]
joshualitt4973d9d2014-11-08 09:24:25 -08001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrDefaultGeoProcFactory.h"
joshualitt4973d9d2014-11-08 09:24:25 -08009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkRefCnt.h"
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050011#include "src/core/SkArenaAlloc.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/GrCaps.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
14#include "src/gpu/glsl/GrGLSLGeometryProcessor.h"
15#include "src/gpu/glsl/GrGLSLUniformHandler.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/glsl/GrGLSLVarying.h"
17#include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h"
joshualitt4973d9d2014-11-08 09:24:25 -080018
19/*
20 * The default Geometry Processor simply takes position and multiplies it by the uniform view
21 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or
22 * local coords.
23 */
joshualittb2aa7cb2015-08-05 11:05:22 -070024
25enum GPFlag {
Brian Salomon3de0aee2017-01-29 09:34:17 -050026 kColorAttribute_GPFlag = 0x1,
Brian Osman8370fd12020-03-18 14:25:45 -040027 kColorAttributeIsWide_GPFlag = 0x2,
28 kLocalCoordAttribute_GPFlag = 0x4,
29 kCoverageAttribute_GPFlag = 0x8,
30 kCoverageAttributeTweak_GPFlag = 0x10,
joshualittb2aa7cb2015-08-05 11:05:22 -070031};
32
joshualitt4973d9d2014-11-08 09:24:25 -080033class DefaultGeoProc : public GrGeometryProcessor {
34public:
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050035 static GrGeometryProcessor* Make(SkArenaAlloc* arena,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050036 uint32_t gpTypeFlags,
37 const SkPMColor4f& color,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050038 const SkMatrix& viewMatrix,
39 const SkMatrix& localMatrix,
40 bool localCoordsWillBeRead,
41 uint8_t coverage) {
Mike Kleinf1241082020-12-14 15:59:09 -060042 return arena->make([&](void* ptr) {
43 return new (ptr) DefaultGeoProc(gpTypeFlags, color, viewMatrix, localMatrix, coverage,
44 localCoordsWillBeRead);
45 });
joshualitt4973d9d2014-11-08 09:24:25 -080046 }
47
mtklein36352bf2015-03-25 18:17:31 -070048 const char* name() const override { return "DefaultGeometryProcessor"; }
joshualitt4973d9d2014-11-08 09:24:25 -080049
Brian Osmancf860852018-10-31 14:04:39 -040050 const SkPMColor4f& color() const { return fColor; }
Brian Salomon92be2f72018-06-19 14:33:47 -040051 bool hasVertexColor() const { return fInColor.isInitialized(); }
joshualitte578a952015-05-14 10:09:13 -070052 const SkMatrix& viewMatrix() const { return fViewMatrix; }
joshualitte3ababe2015-05-15 07:56:07 -070053 const SkMatrix& localMatrix() const { return fLocalMatrix; }
bsalomon7765a472015-07-08 11:26:37 -070054 bool localCoordsWillBeRead() const { return fLocalCoordsWillBeRead; }
joshualitt9b989322014-12-15 14:16:27 -080055 uint8_t coverage() const { return fCoverage; }
Brian Salomon92be2f72018-06-19 14:33:47 -040056 bool hasVertexCoverage() const { return fInCoverage.isInitialized(); }
joshualitt9b989322014-12-15 14:16:27 -080057
egdaniel57d3b032015-11-13 11:57:27 -080058 class GLSLProcessor : public GrGLSLGeometryProcessor {
joshualitt4973d9d2014-11-08 09:24:25 -080059 public:
egdaniel57d3b032015-11-13 11:57:27 -080060 GLSLProcessor()
Robert Phillipscd11e272021-01-06 11:31:38 -050061 : fViewMatrixPrev(SkMatrix::InvalidMatrix())
62 , fLocalMatrixPrev(SkMatrix::InvalidMatrix())
Brian Osmancf860852018-10-31 14:04:39 -040063 , fColor(SK_PMColor4fILLEGAL)
64 , fCoverage(0xff) {}
joshualitt4973d9d2014-11-08 09:24:25 -080065
mtklein36352bf2015-03-25 18:17:31 -070066 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
Robert Phillips787fd9d2021-03-22 14:48:09 -040067 const DefaultGeoProc& gp = args.fGeomProc.cast<DefaultGeoProc>();
egdaniel4ca2e602015-11-18 08:01:26 -080068 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
Chris Dalton60283612018-02-14 13:38:14 -070069 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
egdaniel0eafe792015-11-20 14:01:22 -080070 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
egdaniel7ea439b2015-12-03 09:20:44 -080071 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
joshualitt4973d9d2014-11-08 09:24:25 -080072
joshualittabb52a12015-01-13 15:02:10 -080073 // emit attributes
egdaniel0eafe792015-11-20 14:01:22 -080074 varyingHandler->emitAttributes(gp);
joshualitt2dd1ae02014-12-03 06:24:10 -080075
Brian Osman80879d42019-01-07 16:15:27 -050076 bool tweakAlpha = SkToBool(gp.fFlags & kCoverageAttributeTweak_GPFlag);
77 SkASSERT(!tweakAlpha || gp.hasVertexCoverage());
78
joshualitt2dd1ae02014-12-03 06:24:10 -080079 // Setup pass through color
John Stiles4d7ac492021-03-09 20:16:43 -050080 fragBuilder->codeAppendf("half4 %s;", args.fOutputColor);
Brian Osman80879d42019-01-07 16:15:27 -050081 if (gp.hasVertexColor() || tweakAlpha) {
Chris Dalton27372882017-12-08 13:34:21 -070082 GrGLSLVarying varying(kHalf4_GrSLType);
Brian Salomon3de0aee2017-01-29 09:34:17 -050083 varyingHandler->addVarying("color", &varying);
Brian Osmanfa6d8652017-05-31 09:37:27 -040084
Brian Osman8370fd12020-03-18 14:25:45 -040085 // Start with the attribute or with uniform color
Brian Osman80879d42019-01-07 16:15:27 -050086 if (gp.hasVertexColor()) {
87 vertBuilder->codeAppendf("half4 color = %s;", gp.fInColor.name());
88 } else {
89 const char* colorUniformName;
Ethan Nicholas16464c32020-04-06 13:53:05 -040090 fColorUniform = uniformHandler->addUniform(nullptr,
91 kVertex_GrShaderFlag,
Brian Osman80879d42019-01-07 16:15:27 -050092 kHalf4_GrSLType,
93 "Color",
94 &colorUniformName);
95 vertBuilder->codeAppendf("half4 color = %s;", colorUniformName);
96 }
Brian Osmanfa6d8652017-05-31 09:37:27 -040097
Brian Osman80879d42019-01-07 16:15:27 -050098 // Optionally fold coverage into alpha (color).
99 if (tweakAlpha) {
100 vertBuilder->codeAppendf("color = color * %s;", gp.fInCoverage.name());
101 }
Brian Osmanfa6d8652017-05-31 09:37:27 -0400102 vertBuilder->codeAppendf("%s = color;\n", varying.vsOut());
Brian Salomon3de0aee2017-01-29 09:34:17 -0500103 fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, varying.fsIn());
Brian Salomonbfd51832017-01-04 13:22:08 -0500104 } else {
105 this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
106 &fColorUniform);
joshualittb8c241a2015-05-19 08:23:30 -0700107 }
108
joshualittabb52a12015-01-13 15:02:10 -0800109 // Setup position
Brian Salomon5a328282021-04-14 10:32:25 -0400110 WriteOutputPosition(vertBuilder,
111 uniformHandler,
112 *args.fShaderCaps,
113 gpArgs,
114 gp.fInPosition.name(),
115 gp.viewMatrix(),
116 &fViewMatrixUniform);
joshualitt4973d9d2014-11-08 09:24:25 -0800117
Brian Osman8370fd12020-03-18 14:25:45 -0400118 // emit transforms using either explicit local coords or positions
Michael Ludwig553db622020-06-19 10:47:30 -0400119 if (gp.fInLocalCoords.isInitialized()) {
120 SkASSERT(gp.localMatrix().isIdentity());
121 gpArgs->fLocalCoordVar = gp.fInLocalCoords.asShaderVar();
122 } else if (gp.fLocalCoordsWillBeRead) {
Brian Salomon5a328282021-04-14 10:32:25 -0400123 WriteLocalCoord(vertBuilder,
124 uniformHandler,
125 *args.fShaderCaps,
126 gpArgs,
127 gp.fInPosition.asShaderVar(),
128 gp.localMatrix(),
129 &fLocalMatrixUniform);
Michael Ludwig553db622020-06-19 10:47:30 -0400130 }
joshualittabb52a12015-01-13 15:02:10 -0800131
joshualitt2dd1ae02014-12-03 06:24:10 -0800132 // Setup coverage as pass through
Brian Osman80879d42019-01-07 16:15:27 -0500133 if (gp.hasVertexCoverage() && !tweakAlpha) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400134 fragBuilder->codeAppendf("half alpha = 1.0;");
Brian Salomon92be2f72018-06-19 14:33:47 -0400135 varyingHandler->addPassThroughAttribute(gp.fInCoverage, "alpha");
John Stiles4d7ac492021-03-09 20:16:43 -0500136 fragBuilder->codeAppendf("half4 %s = half4(alpha);", args.fOutputCoverage);
Brian Salomon8c852be2017-01-04 10:44:42 -0500137 } else if (gp.coverage() == 0xff) {
John Stiles4d7ac492021-03-09 20:16:43 -0500138 fragBuilder->codeAppendf("const half4 %s = half4(1);", args.fOutputCoverage);
Brian Salomon8c852be2017-01-04 10:44:42 -0500139 } else {
140 const char* fragCoverage;
Ethan Nicholas16464c32020-04-06 13:53:05 -0400141 fCoverageUniform = uniformHandler->addUniform(nullptr,
142 kFragment_GrShaderFlag,
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400143 kHalf_GrSLType,
Brian Salomon8c852be2017-01-04 10:44:42 -0500144 "Coverage",
145 &fragCoverage);
John Stiles4d7ac492021-03-09 20:16:43 -0500146 fragBuilder->codeAppendf("half4 %s = half4(%s);",
147 args.fOutputCoverage, fragCoverage);
joshualitt2dd1ae02014-12-03 06:24:10 -0800148 }
joshualitt4973d9d2014-11-08 09:24:25 -0800149 }
150
joshualitt87f48d92014-12-04 10:41:40 -0800151 static inline void GenKey(const GrGeometryProcessor& gp,
Brian Salomon5a328282021-04-14 10:32:25 -0400152 const GrShaderCaps& shaderCaps,
joshualitt87f48d92014-12-04 10:41:40 -0800153 GrProcessorKeyBuilder* b) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800154 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
joshualitt8fc6c2d2014-12-22 15:27:05 -0800155 uint32_t key = def.fFlags;
Brian Osman80879d42019-01-07 16:15:27 -0500156 key |= (def.coverage() == 0xff) ? 0x80 : 0;
Michael Ludwig553db622020-06-19 10:47:30 -0400157 key |= def.localCoordsWillBeRead() ? 0x100 : 0;
158
159 bool usesLocalMatrix = def.localCoordsWillBeRead() &&
160 !def.fInLocalCoords.isInitialized();
Brian Salomon5a328282021-04-14 10:32:25 -0400161 key = AddMatrixKeys(shaderCaps,
162 key,
163 def.viewMatrix(),
Michael Ludwig553db622020-06-19 10:47:30 -0400164 usesLocalMatrix ? def.localMatrix() : SkMatrix::I());
joshualitt8fc6c2d2014-12-22 15:27:05 -0800165 b->add32(key);
joshualitt2dd1ae02014-12-03 06:24:10 -0800166 }
joshualitt4973d9d2014-11-08 09:24:25 -0800167
egdaniel018fb622015-10-28 07:26:40 -0700168 void setData(const GrGLSLProgramDataManager& pdman,
Brian Salomon5a328282021-04-14 10:32:25 -0400169 const GrShaderCaps& shaderCaps,
Robert Phillips787fd9d2021-03-22 14:48:09 -0400170 const GrGeometryProcessor& geomProc) override {
171 const DefaultGeoProc& dgp = geomProc.cast<DefaultGeoProc>();
joshualitt5559ca22015-05-21 15:50:36 -0700172
Brian Salomon5a328282021-04-14 10:32:25 -0400173 SetTransform(pdman, shaderCaps, fViewMatrixUniform, dgp.viewMatrix(), &fViewMatrixPrev);
174 SetTransform(pdman,
175 shaderCaps,
176 fLocalMatrixUniform,
177 dgp.localMatrix(),
178 &fLocalMatrixPrev);
joshualittee2af952014-12-30 09:04:15 -0800179
Brian Osman1be2b7c2018-10-29 16:07:15 -0400180 if (!dgp.hasVertexColor() && dgp.color() != fColor) {
Brian Osmancf860852018-10-31 14:04:39 -0400181 pdman.set4fv(fColorUniform, 1, dgp.color().vec());
joshualittb8c241a2015-05-19 08:23:30 -0700182 fColor = dgp.color();
joshualitt9b989322014-12-15 14:16:27 -0800183 }
joshualittb8c241a2015-05-19 08:23:30 -0700184
Brian Salomon8c852be2017-01-04 10:44:42 -0500185 if (dgp.coverage() != fCoverage && !dgp.hasVertexCoverage()) {
joshualittb8c241a2015-05-19 08:23:30 -0700186 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverage()));
187 fCoverage = dgp.coverage();
joshualitt9b989322014-12-15 14:16:27 -0800188 }
Ruiqi Maoc97a3392018-08-15 10:44:19 -0400189 }
190
191 private:
Robert Phillipscd11e272021-01-06 11:31:38 -0500192 SkMatrix fViewMatrixPrev;
193 SkMatrix fLocalMatrixPrev;
Brian Osmancf860852018-10-31 14:04:39 -0400194 SkPMColor4f fColor;
joshualitt9b989322014-12-15 14:16:27 -0800195 uint8_t fCoverage;
joshualitt5559ca22015-05-21 15:50:36 -0700196 UniformHandle fViewMatrixUniform;
Michael Ludwig553db622020-06-19 10:47:30 -0400197 UniformHandle fLocalMatrixUniform;
joshualitt9b989322014-12-15 14:16:27 -0800198 UniformHandle fColorUniform;
199 UniformHandle fCoverageUniform;
200
John Stiles7571f9e2020-09-02 22:42:33 -0400201 using INHERITED = GrGLSLGeometryProcessor;
joshualitt4973d9d2014-11-08 09:24:25 -0800202 };
203
Brian Salomon94efbf52016-11-29 13:43:05 -0500204 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
egdaniel57d3b032015-11-13 11:57:27 -0800205 GLSLProcessor::GenKey(*this, caps, b);
joshualitteb2a6762014-12-04 11:35:33 -0800206 }
207
Robert Phillipsf10535f2021-03-23 09:30:45 -0400208 GrGLSLGeometryProcessor* createGLSLInstance(const GrShaderCaps&) const override {
egdaniel57d3b032015-11-13 11:57:27 -0800209 return new GLSLProcessor();
joshualitteb2a6762014-12-04 11:35:33 -0800210 }
211
joshualitt4973d9d2014-11-08 09:24:25 -0800212private:
Brian Osmanf0aee742020-03-12 09:28:44 -0400213 DefaultGeoProc(uint32_t gpTypeFlags,
Brian Osmancf860852018-10-31 14:04:39 -0400214 const SkPMColor4f& color,
joshualitt8059eb92014-12-29 15:10:07 -0800215 const SkMatrix& viewMatrix,
216 const SkMatrix& localMatrix,
joshualittb8c241a2015-05-19 08:23:30 -0700217 uint8_t coverage,
Brian Osman37064c12019-02-08 10:53:07 -0500218 bool localCoordsWillBeRead)
Ethan Nicholasabff9562017-10-09 10:54:08 -0400219 : INHERITED(kDefaultGeoProc_ClassID)
220 , fColor(color)
Brian Salomon8c852be2017-01-04 10:44:42 -0500221 , fViewMatrix(viewMatrix)
222 , fLocalMatrix(localMatrix)
223 , fCoverage(coverage)
224 , fFlags(gpTypeFlags)
Brian Osman8370fd12020-03-18 14:25:45 -0400225 , fLocalCoordsWillBeRead(localCoordsWillBeRead) {
Brian Osmand4c29702018-09-14 16:16:55 -0400226 fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
Brian Salomon3de0aee2017-01-29 09:34:17 -0500227 if (fFlags & kColorAttribute_GPFlag) {
Brian Osman2a4c4df2018-12-20 14:06:54 -0500228 fInColor = MakeColorAttribute("inColor",
229 SkToBool(fFlags & kColorAttributeIsWide_GPFlag));
joshualitt2dd1ae02014-12-03 06:24:10 -0800230 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500231 if (fFlags & kLocalCoordAttribute_GPFlag) {
Brian Osmand4c29702018-09-14 16:16:55 -0400232 fInLocalCoords = {"inLocalCoord", kFloat2_GrVertexAttribType,
233 kFloat2_GrSLType};
joshualitt2dd1ae02014-12-03 06:24:10 -0800234 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500235 if (fFlags & kCoverageAttribute_GPFlag) {
Brian Osmand4c29702018-09-14 16:16:55 -0400236 fInCoverage = {"inCoverage", kFloat_GrVertexAttribType, kHalf_GrSLType};
joshualitt2dd1ae02014-12-03 06:24:10 -0800237 }
Brian Osman37064c12019-02-08 10:53:07 -0500238 this->setVertexAttributes(&fInPosition, 4);
Brian Salomon92be2f72018-06-19 14:33:47 -0400239 }
240
241 Attribute fInPosition;
242 Attribute fInColor;
243 Attribute fInLocalCoords;
244 Attribute fInCoverage;
Brian Osmancf860852018-10-31 14:04:39 -0400245 SkPMColor4f fColor;
joshualitte578a952015-05-14 10:09:13 -0700246 SkMatrix fViewMatrix;
joshualitte3ababe2015-05-15 07:56:07 -0700247 SkMatrix fLocalMatrix;
joshualitt9b989322014-12-15 14:16:27 -0800248 uint8_t fCoverage;
joshualitt2dd1ae02014-12-03 06:24:10 -0800249 uint32_t fFlags;
bsalomon7765a472015-07-08 11:26:37 -0700250 bool fLocalCoordsWillBeRead;
joshualitt4973d9d2014-11-08 09:24:25 -0800251
Brian Salomon0c26a9d2017-07-06 10:09:38 -0400252 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
joshualitt5478d422014-11-14 16:00:38 -0800253
John Stiles7571f9e2020-09-02 22:42:33 -0400254 using INHERITED = GrGeometryProcessor;
joshualitt4973d9d2014-11-08 09:24:25 -0800255};
256
257GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc);
258
Hal Canary6f6961e2017-01-31 13:50:44 -0500259#if GR_TEST_UTILS
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500260GrGeometryProcessor* DefaultGeoProc::TestCreate(GrProcessorTestData* d) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800261 uint32_t flags = 0;
joshualitt0067ff52015-07-08 14:26:19 -0700262 if (d->fRandom->nextBool()) {
Brian Salomon3de0aee2017-01-29 09:34:17 -0500263 flags |= kColorAttribute_GPFlag;
joshualitt4973d9d2014-11-08 09:24:25 -0800264 }
joshualitt0067ff52015-07-08 14:26:19 -0700265 if (d->fRandom->nextBool()) {
Brian Osman2a4c4df2018-12-20 14:06:54 -0500266 flags |= kColorAttributeIsWide_GPFlag;
267 }
268 if (d->fRandom->nextBool()) {
Brian Salomon3de0aee2017-01-29 09:34:17 -0500269 flags |= kCoverageAttribute_GPFlag;
Brian Osman80879d42019-01-07 16:15:27 -0500270 if (d->fRandom->nextBool()) {
271 flags |= kCoverageAttributeTweak_GPFlag;
272 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500273 }
274 if (d->fRandom->nextBool()) {
275 flags |= kLocalCoordAttribute_GPFlag;
joshualittb2aa7cb2015-08-05 11:05:22 -0700276 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800277
Brian Osmanf0aee742020-03-12 09:28:44 -0400278 return DefaultGeoProc::Make(d->allocator(),
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400279 flags,
Brian Osmancf860852018-10-31 14:04:39 -0400280 SkPMColor4f::FromBytes_RGBA(GrRandomColor(d->fRandom)),
bungeman06ca8ec2016-06-09 08:01:03 -0700281 GrTest::TestMatrix(d->fRandom),
282 GrTest::TestMatrix(d->fRandom),
283 d->fRandom->nextBool(),
Brian Osman37064c12019-02-08 10:53:07 -0500284 GrRandomCoverage(d->fRandom));
joshualitt4973d9d2014-11-08 09:24:25 -0800285}
Hal Canary6f6961e2017-01-31 13:50:44 -0500286#endif
joshualitt4973d9d2014-11-08 09:24:25 -0800287
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500288GrGeometryProcessor* GrDefaultGeoProcFactory::Make(SkArenaAlloc* arena,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500289 const Color& color,
290 const Coverage& coverage,
291 const LocalCoords& localCoords,
292 const SkMatrix& viewMatrix) {
joshualitte9d60952015-07-27 12:13:14 -0700293 uint32_t flags = 0;
Brian Salomon3de0aee2017-01-29 09:34:17 -0500294 if (Color::kPremulGrColorAttribute_Type == color.fType) {
295 flags |= kColorAttribute_GPFlag;
Brian Osman2a4c4df2018-12-20 14:06:54 -0500296 } else if (Color::kPremulWideColorAttribute_Type == color.fType) {
297 flags |= kColorAttribute_GPFlag | kColorAttributeIsWide_GPFlag;
Brian Salomon3de0aee2017-01-29 09:34:17 -0500298 }
Brian Osman80879d42019-01-07 16:15:27 -0500299 if (Coverage::kAttribute_Type == coverage.fType) {
300 flags |= kCoverageAttribute_GPFlag;
301 } else if (Coverage::kAttributeTweakAlpha_Type == coverage.fType) {
302 flags |= kCoverageAttribute_GPFlag | kCoverageAttributeTweak_GPFlag;
303 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500304 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoordAttribute_GPFlag : 0;
joshualitte9d60952015-07-27 12:13:14 -0700305
306 uint8_t inCoverage = coverage.fCoverage;
joshualitt0d986d82015-07-28 10:01:18 -0700307 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type;
joshualitte9d60952015-07-27 12:13:14 -0700308
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500309 return DefaultGeoProc::Make(arena,
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400310 flags,
Brian Osmancf860852018-10-31 14:04:39 -0400311 color.fColor,
bungeman06ca8ec2016-06-09 08:01:03 -0700312 viewMatrix,
313 localCoords.fMatrix ? *localCoords.fMatrix : SkMatrix::I(),
314 localCoordsWillBeRead,
Brian Osman37064c12019-02-08 10:53:07 -0500315 inCoverage);
joshualitte9d60952015-07-27 12:13:14 -0700316}
joshualitt0d986d82015-07-28 10:01:18 -0700317
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500318GrGeometryProcessor* GrDefaultGeoProcFactory::MakeForDeviceSpace(SkArenaAlloc* arena,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500319 const Color& color,
320 const Coverage& coverage,
321 const LocalCoords& localCoords,
322 const SkMatrix& viewMatrix) {
joshualitt0d986d82015-07-28 10:01:18 -0700323 SkMatrix invert = SkMatrix::I();
joshualittdf0c5572015-08-03 11:35:28 -0700324 if (LocalCoords::kUnused_Type != localCoords.fType) {
325 SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType);
326 if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700327 return nullptr;
joshualittdf0c5572015-08-03 11:35:28 -0700328 }
joshualitt0d986d82015-07-28 10:01:18 -0700329
joshualittdf0c5572015-08-03 11:35:28 -0700330 if (localCoords.hasLocalMatrix()) {
Michael Ludwigef776042018-11-01 11:07:51 -0400331 invert.postConcat(*localCoords.fMatrix);
joshualittdf0c5572015-08-03 11:35:28 -0700332 }
joshualitt0d986d82015-07-28 10:01:18 -0700333 }
334
335 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert);
Brian Osmanf0aee742020-03-12 09:28:44 -0400336 return Make(arena, color, coverage, inverted, SkMatrix::I());
joshualitt0d986d82015-07-28 10:01:18 -0700337}