blob: 2761ae583e552444fefc3123cc71ea9f7592ba6c [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
Brian Osman80879d42019-01-07 16:15:27 -050080 if (gp.hasVertexColor() || tweakAlpha) {
Chris Dalton27372882017-12-08 13:34:21 -070081 GrGLSLVarying varying(kHalf4_GrSLType);
Brian Salomon3de0aee2017-01-29 09:34:17 -050082 varyingHandler->addVarying("color", &varying);
Brian Osmanfa6d8652017-05-31 09:37:27 -040083
Brian Osman8370fd12020-03-18 14:25:45 -040084 // Start with the attribute or with uniform color
Brian Osman80879d42019-01-07 16:15:27 -050085 if (gp.hasVertexColor()) {
86 vertBuilder->codeAppendf("half4 color = %s;", gp.fInColor.name());
87 } else {
88 const char* colorUniformName;
Ethan Nicholas16464c32020-04-06 13:53:05 -040089 fColorUniform = uniformHandler->addUniform(nullptr,
90 kVertex_GrShaderFlag,
Brian Osman80879d42019-01-07 16:15:27 -050091 kHalf4_GrSLType,
92 "Color",
93 &colorUniformName);
94 vertBuilder->codeAppendf("half4 color = %s;", colorUniformName);
95 }
Brian Osmanfa6d8652017-05-31 09:37:27 -040096
Brian Osman80879d42019-01-07 16:15:27 -050097 // Optionally fold coverage into alpha (color).
98 if (tweakAlpha) {
99 vertBuilder->codeAppendf("color = color * %s;", gp.fInCoverage.name());
100 }
Brian Osmanfa6d8652017-05-31 09:37:27 -0400101 vertBuilder->codeAppendf("%s = color;\n", varying.vsOut());
Brian Salomon3de0aee2017-01-29 09:34:17 -0500102 fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, varying.fsIn());
Brian Salomonbfd51832017-01-04 13:22:08 -0500103 } else {
104 this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
105 &fColorUniform);
joshualittb8c241a2015-05-19 08:23:30 -0700106 }
107
joshualittabb52a12015-01-13 15:02:10 -0800108 // Setup position
Brian Salomon7f235432017-08-16 09:41:48 -0400109 this->writeOutputPosition(vertBuilder,
110 uniformHandler,
111 gpArgs,
Brian Osman37064c12019-02-08 10:53:07 -0500112 gp.fInPosition.name(),
Brian Salomon7f235432017-08-16 09:41:48 -0400113 gp.viewMatrix(),
114 &fViewMatrixUniform);
joshualitt4973d9d2014-11-08 09:24:25 -0800115
Brian Osman8370fd12020-03-18 14:25:45 -0400116 // emit transforms using either explicit local coords or positions
Michael Ludwig553db622020-06-19 10:47:30 -0400117 if (gp.fInLocalCoords.isInitialized()) {
118 SkASSERT(gp.localMatrix().isIdentity());
119 gpArgs->fLocalCoordVar = gp.fInLocalCoords.asShaderVar();
120 } else if (gp.fLocalCoordsWillBeRead) {
121 this->writeLocalCoord(vertBuilder, uniformHandler, gpArgs,
122 gp.fInPosition.asShaderVar(), gp.localMatrix(),
123 &fLocalMatrixUniform);
124 }
joshualittabb52a12015-01-13 15:02:10 -0800125
joshualitt2dd1ae02014-12-03 06:24:10 -0800126 // Setup coverage as pass through
Brian Osman80879d42019-01-07 16:15:27 -0500127 if (gp.hasVertexCoverage() && !tweakAlpha) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400128 fragBuilder->codeAppendf("half alpha = 1.0;");
Brian Salomon92be2f72018-06-19 14:33:47 -0400129 varyingHandler->addPassThroughAttribute(gp.fInCoverage, "alpha");
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400130 fragBuilder->codeAppendf("%s = half4(alpha);", args.fOutputCoverage);
Brian Salomon8c852be2017-01-04 10:44:42 -0500131 } else if (gp.coverage() == 0xff) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400132 fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
Brian Salomon8c852be2017-01-04 10:44:42 -0500133 } else {
134 const char* fragCoverage;
Ethan Nicholas16464c32020-04-06 13:53:05 -0400135 fCoverageUniform = uniformHandler->addUniform(nullptr,
136 kFragment_GrShaderFlag,
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400137 kHalf_GrSLType,
Brian Salomon8c852be2017-01-04 10:44:42 -0500138 "Coverage",
139 &fragCoverage);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400140 fragBuilder->codeAppendf("%s = half4(%s);", args.fOutputCoverage, fragCoverage);
joshualitt2dd1ae02014-12-03 06:24:10 -0800141 }
joshualitt4973d9d2014-11-08 09:24:25 -0800142 }
143
joshualitt87f48d92014-12-04 10:41:40 -0800144 static inline void GenKey(const GrGeometryProcessor& gp,
Brian Salomon94efbf52016-11-29 13:43:05 -0500145 const GrShaderCaps&,
joshualitt87f48d92014-12-04 10:41:40 -0800146 GrProcessorKeyBuilder* b) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800147 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
joshualitt8fc6c2d2014-12-22 15:27:05 -0800148 uint32_t key = def.fFlags;
Brian Osman80879d42019-01-07 16:15:27 -0500149 key |= (def.coverage() == 0xff) ? 0x80 : 0;
Michael Ludwig553db622020-06-19 10:47:30 -0400150 key |= def.localCoordsWillBeRead() ? 0x100 : 0;
151
152 bool usesLocalMatrix = def.localCoordsWillBeRead() &&
153 !def.fInLocalCoords.isInitialized();
154 key = AddMatrixKeys(key, def.viewMatrix(),
155 usesLocalMatrix ? def.localMatrix() : SkMatrix::I());
joshualitt8fc6c2d2014-12-22 15:27:05 -0800156 b->add32(key);
joshualitt2dd1ae02014-12-03 06:24:10 -0800157 }
joshualitt4973d9d2014-11-08 09:24:25 -0800158
egdaniel018fb622015-10-28 07:26:40 -0700159 void setData(const GrGLSLProgramDataManager& pdman,
Brian Osman609f1592020-07-01 15:14:39 -0400160 const GrPrimitiveProcessor& gp) override {
joshualitte578a952015-05-14 10:09:13 -0700161 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>();
joshualitt5559ca22015-05-21 15:50:36 -0700162
Robert Phillipscd11e272021-01-06 11:31:38 -0500163 this->setTransform(pdman, fViewMatrixUniform, dgp.viewMatrix(), &fViewMatrixPrev);
164 this->setTransform(pdman, fLocalMatrixUniform, dgp.localMatrix(), &fLocalMatrixPrev);
joshualittee2af952014-12-30 09:04:15 -0800165
Brian Osman1be2b7c2018-10-29 16:07:15 -0400166 if (!dgp.hasVertexColor() && dgp.color() != fColor) {
Brian Osmancf860852018-10-31 14:04:39 -0400167 pdman.set4fv(fColorUniform, 1, dgp.color().vec());
joshualittb8c241a2015-05-19 08:23:30 -0700168 fColor = dgp.color();
joshualitt9b989322014-12-15 14:16:27 -0800169 }
joshualittb8c241a2015-05-19 08:23:30 -0700170
Brian Salomon8c852be2017-01-04 10:44:42 -0500171 if (dgp.coverage() != fCoverage && !dgp.hasVertexCoverage()) {
joshualittb8c241a2015-05-19 08:23:30 -0700172 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverage()));
173 fCoverage = dgp.coverage();
joshualitt9b989322014-12-15 14:16:27 -0800174 }
Ruiqi Maoc97a3392018-08-15 10:44:19 -0400175 }
176
177 private:
Robert Phillipscd11e272021-01-06 11:31:38 -0500178 SkMatrix fViewMatrixPrev;
179 SkMatrix fLocalMatrixPrev;
Brian Osmancf860852018-10-31 14:04:39 -0400180 SkPMColor4f fColor;
joshualitt9b989322014-12-15 14:16:27 -0800181 uint8_t fCoverage;
joshualitt5559ca22015-05-21 15:50:36 -0700182 UniformHandle fViewMatrixUniform;
Michael Ludwig553db622020-06-19 10:47:30 -0400183 UniformHandle fLocalMatrixUniform;
joshualitt9b989322014-12-15 14:16:27 -0800184 UniformHandle fColorUniform;
185 UniformHandle fCoverageUniform;
186
John Stiles7571f9e2020-09-02 22:42:33 -0400187 using INHERITED = GrGLSLGeometryProcessor;
joshualitt4973d9d2014-11-08 09:24:25 -0800188 };
189
Brian Salomon94efbf52016-11-29 13:43:05 -0500190 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
egdaniel57d3b032015-11-13 11:57:27 -0800191 GLSLProcessor::GenKey(*this, caps, b);
joshualitteb2a6762014-12-04 11:35:33 -0800192 }
193
Brian Salomon94efbf52016-11-29 13:43:05 -0500194 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override {
egdaniel57d3b032015-11-13 11:57:27 -0800195 return new GLSLProcessor();
joshualitteb2a6762014-12-04 11:35:33 -0800196 }
197
joshualitt4973d9d2014-11-08 09:24:25 -0800198private:
Brian Osmanf0aee742020-03-12 09:28:44 -0400199 DefaultGeoProc(uint32_t gpTypeFlags,
Brian Osmancf860852018-10-31 14:04:39 -0400200 const SkPMColor4f& color,
joshualitt8059eb92014-12-29 15:10:07 -0800201 const SkMatrix& viewMatrix,
202 const SkMatrix& localMatrix,
joshualittb8c241a2015-05-19 08:23:30 -0700203 uint8_t coverage,
Brian Osman37064c12019-02-08 10:53:07 -0500204 bool localCoordsWillBeRead)
Ethan Nicholasabff9562017-10-09 10:54:08 -0400205 : INHERITED(kDefaultGeoProc_ClassID)
206 , fColor(color)
Brian Salomon8c852be2017-01-04 10:44:42 -0500207 , fViewMatrix(viewMatrix)
208 , fLocalMatrix(localMatrix)
209 , fCoverage(coverage)
210 , fFlags(gpTypeFlags)
Brian Osman8370fd12020-03-18 14:25:45 -0400211 , fLocalCoordsWillBeRead(localCoordsWillBeRead) {
Brian Osmand4c29702018-09-14 16:16:55 -0400212 fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
Brian Salomon3de0aee2017-01-29 09:34:17 -0500213 if (fFlags & kColorAttribute_GPFlag) {
Brian Osman2a4c4df2018-12-20 14:06:54 -0500214 fInColor = MakeColorAttribute("inColor",
215 SkToBool(fFlags & kColorAttributeIsWide_GPFlag));
joshualitt2dd1ae02014-12-03 06:24:10 -0800216 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500217 if (fFlags & kLocalCoordAttribute_GPFlag) {
Brian Osmand4c29702018-09-14 16:16:55 -0400218 fInLocalCoords = {"inLocalCoord", kFloat2_GrVertexAttribType,
219 kFloat2_GrSLType};
joshualitt2dd1ae02014-12-03 06:24:10 -0800220 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500221 if (fFlags & kCoverageAttribute_GPFlag) {
Brian Osmand4c29702018-09-14 16:16:55 -0400222 fInCoverage = {"inCoverage", kFloat_GrVertexAttribType, kHalf_GrSLType};
joshualitt2dd1ae02014-12-03 06:24:10 -0800223 }
Brian Osman37064c12019-02-08 10:53:07 -0500224 this->setVertexAttributes(&fInPosition, 4);
Brian Salomon92be2f72018-06-19 14:33:47 -0400225 }
226
227 Attribute fInPosition;
228 Attribute fInColor;
229 Attribute fInLocalCoords;
230 Attribute fInCoverage;
Brian Osmancf860852018-10-31 14:04:39 -0400231 SkPMColor4f fColor;
joshualitte578a952015-05-14 10:09:13 -0700232 SkMatrix fViewMatrix;
joshualitte3ababe2015-05-15 07:56:07 -0700233 SkMatrix fLocalMatrix;
joshualitt9b989322014-12-15 14:16:27 -0800234 uint8_t fCoverage;
joshualitt2dd1ae02014-12-03 06:24:10 -0800235 uint32_t fFlags;
bsalomon7765a472015-07-08 11:26:37 -0700236 bool fLocalCoordsWillBeRead;
joshualitt4973d9d2014-11-08 09:24:25 -0800237
Brian Salomon0c26a9d2017-07-06 10:09:38 -0400238 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
joshualitt5478d422014-11-14 16:00:38 -0800239
John Stiles7571f9e2020-09-02 22:42:33 -0400240 using INHERITED = GrGeometryProcessor;
joshualitt4973d9d2014-11-08 09:24:25 -0800241};
242
243GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc);
244
Hal Canary6f6961e2017-01-31 13:50:44 -0500245#if GR_TEST_UTILS
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500246GrGeometryProcessor* DefaultGeoProc::TestCreate(GrProcessorTestData* d) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800247 uint32_t flags = 0;
joshualitt0067ff52015-07-08 14:26:19 -0700248 if (d->fRandom->nextBool()) {
Brian Salomon3de0aee2017-01-29 09:34:17 -0500249 flags |= kColorAttribute_GPFlag;
joshualitt4973d9d2014-11-08 09:24:25 -0800250 }
joshualitt0067ff52015-07-08 14:26:19 -0700251 if (d->fRandom->nextBool()) {
Brian Osman2a4c4df2018-12-20 14:06:54 -0500252 flags |= kColorAttributeIsWide_GPFlag;
253 }
254 if (d->fRandom->nextBool()) {
Brian Salomon3de0aee2017-01-29 09:34:17 -0500255 flags |= kCoverageAttribute_GPFlag;
Brian Osman80879d42019-01-07 16:15:27 -0500256 if (d->fRandom->nextBool()) {
257 flags |= kCoverageAttributeTweak_GPFlag;
258 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500259 }
260 if (d->fRandom->nextBool()) {
261 flags |= kLocalCoordAttribute_GPFlag;
joshualittb2aa7cb2015-08-05 11:05:22 -0700262 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800263
Brian Osmanf0aee742020-03-12 09:28:44 -0400264 return DefaultGeoProc::Make(d->allocator(),
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400265 flags,
Brian Osmancf860852018-10-31 14:04:39 -0400266 SkPMColor4f::FromBytes_RGBA(GrRandomColor(d->fRandom)),
bungeman06ca8ec2016-06-09 08:01:03 -0700267 GrTest::TestMatrix(d->fRandom),
268 GrTest::TestMatrix(d->fRandom),
269 d->fRandom->nextBool(),
Brian Osman37064c12019-02-08 10:53:07 -0500270 GrRandomCoverage(d->fRandom));
joshualitt4973d9d2014-11-08 09:24:25 -0800271}
Hal Canary6f6961e2017-01-31 13:50:44 -0500272#endif
joshualitt4973d9d2014-11-08 09:24:25 -0800273
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500274GrGeometryProcessor* GrDefaultGeoProcFactory::Make(SkArenaAlloc* arena,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500275 const Color& color,
276 const Coverage& coverage,
277 const LocalCoords& localCoords,
278 const SkMatrix& viewMatrix) {
joshualitte9d60952015-07-27 12:13:14 -0700279 uint32_t flags = 0;
Brian Salomon3de0aee2017-01-29 09:34:17 -0500280 if (Color::kPremulGrColorAttribute_Type == color.fType) {
281 flags |= kColorAttribute_GPFlag;
Brian Osman2a4c4df2018-12-20 14:06:54 -0500282 } else if (Color::kPremulWideColorAttribute_Type == color.fType) {
283 flags |= kColorAttribute_GPFlag | kColorAttributeIsWide_GPFlag;
Brian Salomon3de0aee2017-01-29 09:34:17 -0500284 }
Brian Osman80879d42019-01-07 16:15:27 -0500285 if (Coverage::kAttribute_Type == coverage.fType) {
286 flags |= kCoverageAttribute_GPFlag;
287 } else if (Coverage::kAttributeTweakAlpha_Type == coverage.fType) {
288 flags |= kCoverageAttribute_GPFlag | kCoverageAttributeTweak_GPFlag;
289 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500290 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoordAttribute_GPFlag : 0;
joshualitte9d60952015-07-27 12:13:14 -0700291
292 uint8_t inCoverage = coverage.fCoverage;
joshualitt0d986d82015-07-28 10:01:18 -0700293 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type;
joshualitte9d60952015-07-27 12:13:14 -0700294
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500295 return DefaultGeoProc::Make(arena,
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400296 flags,
Brian Osmancf860852018-10-31 14:04:39 -0400297 color.fColor,
bungeman06ca8ec2016-06-09 08:01:03 -0700298 viewMatrix,
299 localCoords.fMatrix ? *localCoords.fMatrix : SkMatrix::I(),
300 localCoordsWillBeRead,
Brian Osman37064c12019-02-08 10:53:07 -0500301 inCoverage);
joshualitte9d60952015-07-27 12:13:14 -0700302}
joshualitt0d986d82015-07-28 10:01:18 -0700303
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500304GrGeometryProcessor* GrDefaultGeoProcFactory::MakeForDeviceSpace(SkArenaAlloc* arena,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500305 const Color& color,
306 const Coverage& coverage,
307 const LocalCoords& localCoords,
308 const SkMatrix& viewMatrix) {
joshualitt0d986d82015-07-28 10:01:18 -0700309 SkMatrix invert = SkMatrix::I();
joshualittdf0c5572015-08-03 11:35:28 -0700310 if (LocalCoords::kUnused_Type != localCoords.fType) {
311 SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType);
312 if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700313 return nullptr;
joshualittdf0c5572015-08-03 11:35:28 -0700314 }
joshualitt0d986d82015-07-28 10:01:18 -0700315
joshualittdf0c5572015-08-03 11:35:28 -0700316 if (localCoords.hasLocalMatrix()) {
Michael Ludwigef776042018-11-01 11:07:51 -0400317 invert.postConcat(*localCoords.fMatrix);
joshualittdf0c5572015-08-03 11:35:28 -0700318 }
joshualitt0d986d82015-07-28 10:01:18 -0700319 }
320
321 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert);
Brian Osmanf0aee742020-03-12 09:28:44 -0400322 return Make(arena, color, coverage, inverted, SkMatrix::I());
joshualitt0d986d82015-07-28 10:01:18 -0700323}