blob: 7e8aa9f16db39eb4d4eceef56bc56275637a729e [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 {
joshualitt2dd1ae02014-12-03 06:24:10 -080067 const DefaultGeoProc& gp = args.fGP.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 Salomon7f235432017-08-16 09:41:48 -0400110 this->writeOutputPosition(vertBuilder,
111 uniformHandler,
112 gpArgs,
Brian Osman37064c12019-02-08 10:53:07 -0500113 gp.fInPosition.name(),
Brian Salomon7f235432017-08-16 09:41:48 -0400114 gp.viewMatrix(),
115 &fViewMatrixUniform);
joshualitt4973d9d2014-11-08 09:24:25 -0800116
Brian Osman8370fd12020-03-18 14:25:45 -0400117 // emit transforms using either explicit local coords or positions
Michael Ludwig553db622020-06-19 10:47:30 -0400118 if (gp.fInLocalCoords.isInitialized()) {
119 SkASSERT(gp.localMatrix().isIdentity());
120 gpArgs->fLocalCoordVar = gp.fInLocalCoords.asShaderVar();
121 } else if (gp.fLocalCoordsWillBeRead) {
122 this->writeLocalCoord(vertBuilder, uniformHandler, gpArgs,
123 gp.fInPosition.asShaderVar(), gp.localMatrix(),
124 &fLocalMatrixUniform);
125 }
joshualittabb52a12015-01-13 15:02:10 -0800126
joshualitt2dd1ae02014-12-03 06:24:10 -0800127 // Setup coverage as pass through
Brian Osman80879d42019-01-07 16:15:27 -0500128 if (gp.hasVertexCoverage() && !tweakAlpha) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400129 fragBuilder->codeAppendf("half alpha = 1.0;");
Brian Salomon92be2f72018-06-19 14:33:47 -0400130 varyingHandler->addPassThroughAttribute(gp.fInCoverage, "alpha");
John Stiles4d7ac492021-03-09 20:16:43 -0500131 fragBuilder->codeAppendf("half4 %s = half4(alpha);", args.fOutputCoverage);
Brian Salomon8c852be2017-01-04 10:44:42 -0500132 } else if (gp.coverage() == 0xff) {
John Stiles4d7ac492021-03-09 20:16:43 -0500133 fragBuilder->codeAppendf("const half4 %s = half4(1);", args.fOutputCoverage);
Brian Salomon8c852be2017-01-04 10:44:42 -0500134 } else {
135 const char* fragCoverage;
Ethan Nicholas16464c32020-04-06 13:53:05 -0400136 fCoverageUniform = uniformHandler->addUniform(nullptr,
137 kFragment_GrShaderFlag,
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400138 kHalf_GrSLType,
Brian Salomon8c852be2017-01-04 10:44:42 -0500139 "Coverage",
140 &fragCoverage);
John Stiles4d7ac492021-03-09 20:16:43 -0500141 fragBuilder->codeAppendf("half4 %s = half4(%s);",
142 args.fOutputCoverage, fragCoverage);
joshualitt2dd1ae02014-12-03 06:24:10 -0800143 }
joshualitt4973d9d2014-11-08 09:24:25 -0800144 }
145
joshualitt87f48d92014-12-04 10:41:40 -0800146 static inline void GenKey(const GrGeometryProcessor& gp,
Brian Salomon94efbf52016-11-29 13:43:05 -0500147 const GrShaderCaps&,
joshualitt87f48d92014-12-04 10:41:40 -0800148 GrProcessorKeyBuilder* b) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800149 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
joshualitt8fc6c2d2014-12-22 15:27:05 -0800150 uint32_t key = def.fFlags;
Brian Osman80879d42019-01-07 16:15:27 -0500151 key |= (def.coverage() == 0xff) ? 0x80 : 0;
Michael Ludwig553db622020-06-19 10:47:30 -0400152 key |= def.localCoordsWillBeRead() ? 0x100 : 0;
153
154 bool usesLocalMatrix = def.localCoordsWillBeRead() &&
155 !def.fInLocalCoords.isInitialized();
156 key = AddMatrixKeys(key, def.viewMatrix(),
157 usesLocalMatrix ? def.localMatrix() : SkMatrix::I());
joshualitt8fc6c2d2014-12-22 15:27:05 -0800158 b->add32(key);
joshualitt2dd1ae02014-12-03 06:24:10 -0800159 }
joshualitt4973d9d2014-11-08 09:24:25 -0800160
egdaniel018fb622015-10-28 07:26:40 -0700161 void setData(const GrGLSLProgramDataManager& pdman,
Brian Osman609f1592020-07-01 15:14:39 -0400162 const GrPrimitiveProcessor& gp) override {
joshualitte578a952015-05-14 10:09:13 -0700163 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>();
joshualitt5559ca22015-05-21 15:50:36 -0700164
Robert Phillipscd11e272021-01-06 11:31:38 -0500165 this->setTransform(pdman, fViewMatrixUniform, dgp.viewMatrix(), &fViewMatrixPrev);
166 this->setTransform(pdman, fLocalMatrixUniform, dgp.localMatrix(), &fLocalMatrixPrev);
joshualittee2af952014-12-30 09:04:15 -0800167
Brian Osman1be2b7c2018-10-29 16:07:15 -0400168 if (!dgp.hasVertexColor() && dgp.color() != fColor) {
Brian Osmancf860852018-10-31 14:04:39 -0400169 pdman.set4fv(fColorUniform, 1, dgp.color().vec());
joshualittb8c241a2015-05-19 08:23:30 -0700170 fColor = dgp.color();
joshualitt9b989322014-12-15 14:16:27 -0800171 }
joshualittb8c241a2015-05-19 08:23:30 -0700172
Brian Salomon8c852be2017-01-04 10:44:42 -0500173 if (dgp.coverage() != fCoverage && !dgp.hasVertexCoverage()) {
joshualittb8c241a2015-05-19 08:23:30 -0700174 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverage()));
175 fCoverage = dgp.coverage();
joshualitt9b989322014-12-15 14:16:27 -0800176 }
Ruiqi Maoc97a3392018-08-15 10:44:19 -0400177 }
178
179 private:
Robert Phillipscd11e272021-01-06 11:31:38 -0500180 SkMatrix fViewMatrixPrev;
181 SkMatrix fLocalMatrixPrev;
Brian Osmancf860852018-10-31 14:04:39 -0400182 SkPMColor4f fColor;
joshualitt9b989322014-12-15 14:16:27 -0800183 uint8_t fCoverage;
joshualitt5559ca22015-05-21 15:50:36 -0700184 UniformHandle fViewMatrixUniform;
Michael Ludwig553db622020-06-19 10:47:30 -0400185 UniformHandle fLocalMatrixUniform;
joshualitt9b989322014-12-15 14:16:27 -0800186 UniformHandle fColorUniform;
187 UniformHandle fCoverageUniform;
188
John Stiles7571f9e2020-09-02 22:42:33 -0400189 using INHERITED = GrGLSLGeometryProcessor;
joshualitt4973d9d2014-11-08 09:24:25 -0800190 };
191
Brian Salomon94efbf52016-11-29 13:43:05 -0500192 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
egdaniel57d3b032015-11-13 11:57:27 -0800193 GLSLProcessor::GenKey(*this, caps, b);
joshualitteb2a6762014-12-04 11:35:33 -0800194 }
195
Brian Salomon94efbf52016-11-29 13:43:05 -0500196 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override {
egdaniel57d3b032015-11-13 11:57:27 -0800197 return new GLSLProcessor();
joshualitteb2a6762014-12-04 11:35:33 -0800198 }
199
joshualitt4973d9d2014-11-08 09:24:25 -0800200private:
Brian Osmanf0aee742020-03-12 09:28:44 -0400201 DefaultGeoProc(uint32_t gpTypeFlags,
Brian Osmancf860852018-10-31 14:04:39 -0400202 const SkPMColor4f& color,
joshualitt8059eb92014-12-29 15:10:07 -0800203 const SkMatrix& viewMatrix,
204 const SkMatrix& localMatrix,
joshualittb8c241a2015-05-19 08:23:30 -0700205 uint8_t coverage,
Brian Osman37064c12019-02-08 10:53:07 -0500206 bool localCoordsWillBeRead)
Ethan Nicholasabff9562017-10-09 10:54:08 -0400207 : INHERITED(kDefaultGeoProc_ClassID)
208 , fColor(color)
Brian Salomon8c852be2017-01-04 10:44:42 -0500209 , fViewMatrix(viewMatrix)
210 , fLocalMatrix(localMatrix)
211 , fCoverage(coverage)
212 , fFlags(gpTypeFlags)
Brian Osman8370fd12020-03-18 14:25:45 -0400213 , fLocalCoordsWillBeRead(localCoordsWillBeRead) {
Brian Osmand4c29702018-09-14 16:16:55 -0400214 fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
Brian Salomon3de0aee2017-01-29 09:34:17 -0500215 if (fFlags & kColorAttribute_GPFlag) {
Brian Osman2a4c4df2018-12-20 14:06:54 -0500216 fInColor = MakeColorAttribute("inColor",
217 SkToBool(fFlags & kColorAttributeIsWide_GPFlag));
joshualitt2dd1ae02014-12-03 06:24:10 -0800218 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500219 if (fFlags & kLocalCoordAttribute_GPFlag) {
Brian Osmand4c29702018-09-14 16:16:55 -0400220 fInLocalCoords = {"inLocalCoord", kFloat2_GrVertexAttribType,
221 kFloat2_GrSLType};
joshualitt2dd1ae02014-12-03 06:24:10 -0800222 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500223 if (fFlags & kCoverageAttribute_GPFlag) {
Brian Osmand4c29702018-09-14 16:16:55 -0400224 fInCoverage = {"inCoverage", kFloat_GrVertexAttribType, kHalf_GrSLType};
joshualitt2dd1ae02014-12-03 06:24:10 -0800225 }
Brian Osman37064c12019-02-08 10:53:07 -0500226 this->setVertexAttributes(&fInPosition, 4);
Brian Salomon92be2f72018-06-19 14:33:47 -0400227 }
228
229 Attribute fInPosition;
230 Attribute fInColor;
231 Attribute fInLocalCoords;
232 Attribute fInCoverage;
Brian Osmancf860852018-10-31 14:04:39 -0400233 SkPMColor4f fColor;
joshualitte578a952015-05-14 10:09:13 -0700234 SkMatrix fViewMatrix;
joshualitte3ababe2015-05-15 07:56:07 -0700235 SkMatrix fLocalMatrix;
joshualitt9b989322014-12-15 14:16:27 -0800236 uint8_t fCoverage;
joshualitt2dd1ae02014-12-03 06:24:10 -0800237 uint32_t fFlags;
bsalomon7765a472015-07-08 11:26:37 -0700238 bool fLocalCoordsWillBeRead;
joshualitt4973d9d2014-11-08 09:24:25 -0800239
Brian Salomon0c26a9d2017-07-06 10:09:38 -0400240 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
joshualitt5478d422014-11-14 16:00:38 -0800241
John Stiles7571f9e2020-09-02 22:42:33 -0400242 using INHERITED = GrGeometryProcessor;
joshualitt4973d9d2014-11-08 09:24:25 -0800243};
244
245GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc);
246
Hal Canary6f6961e2017-01-31 13:50:44 -0500247#if GR_TEST_UTILS
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500248GrGeometryProcessor* DefaultGeoProc::TestCreate(GrProcessorTestData* d) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800249 uint32_t flags = 0;
joshualitt0067ff52015-07-08 14:26:19 -0700250 if (d->fRandom->nextBool()) {
Brian Salomon3de0aee2017-01-29 09:34:17 -0500251 flags |= kColorAttribute_GPFlag;
joshualitt4973d9d2014-11-08 09:24:25 -0800252 }
joshualitt0067ff52015-07-08 14:26:19 -0700253 if (d->fRandom->nextBool()) {
Brian Osman2a4c4df2018-12-20 14:06:54 -0500254 flags |= kColorAttributeIsWide_GPFlag;
255 }
256 if (d->fRandom->nextBool()) {
Brian Salomon3de0aee2017-01-29 09:34:17 -0500257 flags |= kCoverageAttribute_GPFlag;
Brian Osman80879d42019-01-07 16:15:27 -0500258 if (d->fRandom->nextBool()) {
259 flags |= kCoverageAttributeTweak_GPFlag;
260 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500261 }
262 if (d->fRandom->nextBool()) {
263 flags |= kLocalCoordAttribute_GPFlag;
joshualittb2aa7cb2015-08-05 11:05:22 -0700264 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800265
Brian Osmanf0aee742020-03-12 09:28:44 -0400266 return DefaultGeoProc::Make(d->allocator(),
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400267 flags,
Brian Osmancf860852018-10-31 14:04:39 -0400268 SkPMColor4f::FromBytes_RGBA(GrRandomColor(d->fRandom)),
bungeman06ca8ec2016-06-09 08:01:03 -0700269 GrTest::TestMatrix(d->fRandom),
270 GrTest::TestMatrix(d->fRandom),
271 d->fRandom->nextBool(),
Brian Osman37064c12019-02-08 10:53:07 -0500272 GrRandomCoverage(d->fRandom));
joshualitt4973d9d2014-11-08 09:24:25 -0800273}
Hal Canary6f6961e2017-01-31 13:50:44 -0500274#endif
joshualitt4973d9d2014-11-08 09:24:25 -0800275
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500276GrGeometryProcessor* GrDefaultGeoProcFactory::Make(SkArenaAlloc* arena,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500277 const Color& color,
278 const Coverage& coverage,
279 const LocalCoords& localCoords,
280 const SkMatrix& viewMatrix) {
joshualitte9d60952015-07-27 12:13:14 -0700281 uint32_t flags = 0;
Brian Salomon3de0aee2017-01-29 09:34:17 -0500282 if (Color::kPremulGrColorAttribute_Type == color.fType) {
283 flags |= kColorAttribute_GPFlag;
Brian Osman2a4c4df2018-12-20 14:06:54 -0500284 } else if (Color::kPremulWideColorAttribute_Type == color.fType) {
285 flags |= kColorAttribute_GPFlag | kColorAttributeIsWide_GPFlag;
Brian Salomon3de0aee2017-01-29 09:34:17 -0500286 }
Brian Osman80879d42019-01-07 16:15:27 -0500287 if (Coverage::kAttribute_Type == coverage.fType) {
288 flags |= kCoverageAttribute_GPFlag;
289 } else if (Coverage::kAttributeTweakAlpha_Type == coverage.fType) {
290 flags |= kCoverageAttribute_GPFlag | kCoverageAttributeTweak_GPFlag;
291 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500292 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoordAttribute_GPFlag : 0;
joshualitte9d60952015-07-27 12:13:14 -0700293
294 uint8_t inCoverage = coverage.fCoverage;
joshualitt0d986d82015-07-28 10:01:18 -0700295 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type;
joshualitte9d60952015-07-27 12:13:14 -0700296
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500297 return DefaultGeoProc::Make(arena,
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400298 flags,
Brian Osmancf860852018-10-31 14:04:39 -0400299 color.fColor,
bungeman06ca8ec2016-06-09 08:01:03 -0700300 viewMatrix,
301 localCoords.fMatrix ? *localCoords.fMatrix : SkMatrix::I(),
302 localCoordsWillBeRead,
Brian Osman37064c12019-02-08 10:53:07 -0500303 inCoverage);
joshualitte9d60952015-07-27 12:13:14 -0700304}
joshualitt0d986d82015-07-28 10:01:18 -0700305
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500306GrGeometryProcessor* GrDefaultGeoProcFactory::MakeForDeviceSpace(SkArenaAlloc* arena,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500307 const Color& color,
308 const Coverage& coverage,
309 const LocalCoords& localCoords,
310 const SkMatrix& viewMatrix) {
joshualitt0d986d82015-07-28 10:01:18 -0700311 SkMatrix invert = SkMatrix::I();
joshualittdf0c5572015-08-03 11:35:28 -0700312 if (LocalCoords::kUnused_Type != localCoords.fType) {
313 SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType);
314 if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700315 return nullptr;
joshualittdf0c5572015-08-03 11:35:28 -0700316 }
joshualitt0d986d82015-07-28 10:01:18 -0700317
joshualittdf0c5572015-08-03 11:35:28 -0700318 if (localCoords.hasLocalMatrix()) {
Michael Ludwigef776042018-11-01 11:07:51 -0400319 invert.postConcat(*localCoords.fMatrix);
joshualittdf0c5572015-08-03 11:35:28 -0700320 }
joshualitt0d986d82015-07-28 10:01:18 -0700321 }
322
323 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert);
Brian Osmanf0aee742020-03-12 09:28:44 -0400324 return Make(arena, color, coverage, inverted, SkMatrix::I());
joshualitt0d986d82015-07-28 10:01:18 -0700325}