blob: c3ef6935b6b346c9dbc696b22992441301899fc4 [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) {
Brian Osman8370fd12020-03-18 14:25:45 -040042 return arena->make<DefaultGeoProc>(gpTypeFlags, color, viewMatrix, localMatrix, coverage,
Brian Osmanf0aee742020-03-12 09:28:44 -040043 localCoordsWillBeRead);
joshualitt4973d9d2014-11-08 09:24:25 -080044 }
45
mtklein36352bf2015-03-25 18:17:31 -070046 const char* name() const override { return "DefaultGeometryProcessor"; }
joshualitt4973d9d2014-11-08 09:24:25 -080047
Brian Osmancf860852018-10-31 14:04:39 -040048 const SkPMColor4f& color() const { return fColor; }
Brian Salomon92be2f72018-06-19 14:33:47 -040049 bool hasVertexColor() const { return fInColor.isInitialized(); }
joshualitte578a952015-05-14 10:09:13 -070050 const SkMatrix& viewMatrix() const { return fViewMatrix; }
joshualitte3ababe2015-05-15 07:56:07 -070051 const SkMatrix& localMatrix() const { return fLocalMatrix; }
bsalomon7765a472015-07-08 11:26:37 -070052 bool localCoordsWillBeRead() const { return fLocalCoordsWillBeRead; }
joshualitt9b989322014-12-15 14:16:27 -080053 uint8_t coverage() const { return fCoverage; }
Brian Salomon92be2f72018-06-19 14:33:47 -040054 bool hasVertexCoverage() const { return fInCoverage.isInitialized(); }
joshualitt9b989322014-12-15 14:16:27 -080055
egdaniel57d3b032015-11-13 11:57:27 -080056 class GLSLProcessor : public GrGLSLGeometryProcessor {
joshualitt4973d9d2014-11-08 09:24:25 -080057 public:
egdaniel57d3b032015-11-13 11:57:27 -080058 GLSLProcessor()
Brian Osmancf860852018-10-31 14:04:39 -040059 : fViewMatrix(SkMatrix::InvalidMatrix())
Michael Ludwig553db622020-06-19 10:47:30 -040060 , fLocalMatrix(SkMatrix::InvalidMatrix())
Brian Osmancf860852018-10-31 14:04:39 -040061 , fColor(SK_PMColor4fILLEGAL)
62 , fCoverage(0xff) {}
joshualitt4973d9d2014-11-08 09:24:25 -080063
mtklein36352bf2015-03-25 18:17:31 -070064 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
joshualitt2dd1ae02014-12-03 06:24:10 -080065 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>();
egdaniel4ca2e602015-11-18 08:01:26 -080066 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
Chris Dalton60283612018-02-14 13:38:14 -070067 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
egdaniel0eafe792015-11-20 14:01:22 -080068 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
egdaniel7ea439b2015-12-03 09:20:44 -080069 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
joshualitt4973d9d2014-11-08 09:24:25 -080070
joshualittabb52a12015-01-13 15:02:10 -080071 // emit attributes
egdaniel0eafe792015-11-20 14:01:22 -080072 varyingHandler->emitAttributes(gp);
joshualitt2dd1ae02014-12-03 06:24:10 -080073
Brian Osman80879d42019-01-07 16:15:27 -050074 bool tweakAlpha = SkToBool(gp.fFlags & kCoverageAttributeTweak_GPFlag);
75 SkASSERT(!tweakAlpha || gp.hasVertexCoverage());
76
joshualitt2dd1ae02014-12-03 06:24:10 -080077 // Setup pass through color
Brian Osman80879d42019-01-07 16:15:27 -050078 if (gp.hasVertexColor() || tweakAlpha) {
Chris Dalton27372882017-12-08 13:34:21 -070079 GrGLSLVarying varying(kHalf4_GrSLType);
Brian Salomon3de0aee2017-01-29 09:34:17 -050080 varyingHandler->addVarying("color", &varying);
Brian Osmanfa6d8652017-05-31 09:37:27 -040081
Brian Osman8370fd12020-03-18 14:25:45 -040082 // Start with the attribute or with uniform color
Brian Osman80879d42019-01-07 16:15:27 -050083 if (gp.hasVertexColor()) {
84 vertBuilder->codeAppendf("half4 color = %s;", gp.fInColor.name());
85 } else {
86 const char* colorUniformName;
Ethan Nicholas16464c32020-04-06 13:53:05 -040087 fColorUniform = uniformHandler->addUniform(nullptr,
88 kVertex_GrShaderFlag,
Brian Osman80879d42019-01-07 16:15:27 -050089 kHalf4_GrSLType,
90 "Color",
91 &colorUniformName);
92 vertBuilder->codeAppendf("half4 color = %s;", colorUniformName);
93 }
Brian Osmanfa6d8652017-05-31 09:37:27 -040094
Brian Osman80879d42019-01-07 16:15:27 -050095 // Optionally fold coverage into alpha (color).
96 if (tweakAlpha) {
97 vertBuilder->codeAppendf("color = color * %s;", gp.fInCoverage.name());
98 }
Brian Osmanfa6d8652017-05-31 09:37:27 -040099 vertBuilder->codeAppendf("%s = color;\n", varying.vsOut());
Brian Salomon3de0aee2017-01-29 09:34:17 -0500100 fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, varying.fsIn());
Brian Salomonbfd51832017-01-04 13:22:08 -0500101 } else {
102 this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
103 &fColorUniform);
joshualittb8c241a2015-05-19 08:23:30 -0700104 }
105
joshualittabb52a12015-01-13 15:02:10 -0800106 // Setup position
Brian Salomon7f235432017-08-16 09:41:48 -0400107 this->writeOutputPosition(vertBuilder,
108 uniformHandler,
109 gpArgs,
Brian Osman37064c12019-02-08 10:53:07 -0500110 gp.fInPosition.name(),
Brian Salomon7f235432017-08-16 09:41:48 -0400111 gp.viewMatrix(),
112 &fViewMatrixUniform);
joshualitt4973d9d2014-11-08 09:24:25 -0800113
Brian Osman8370fd12020-03-18 14:25:45 -0400114 // emit transforms using either explicit local coords or positions
Michael Ludwig553db622020-06-19 10:47:30 -0400115 if (gp.fInLocalCoords.isInitialized()) {
116 SkASSERT(gp.localMatrix().isIdentity());
117 gpArgs->fLocalCoordVar = gp.fInLocalCoords.asShaderVar();
118 } else if (gp.fLocalCoordsWillBeRead) {
119 this->writeLocalCoord(vertBuilder, uniformHandler, gpArgs,
120 gp.fInPosition.asShaderVar(), gp.localMatrix(),
121 &fLocalMatrixUniform);
122 }
joshualittabb52a12015-01-13 15:02:10 -0800123
joshualitt2dd1ae02014-12-03 06:24:10 -0800124 // Setup coverage as pass through
Brian Osman80879d42019-01-07 16:15:27 -0500125 if (gp.hasVertexCoverage() && !tweakAlpha) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400126 fragBuilder->codeAppendf("half alpha = 1.0;");
Brian Salomon92be2f72018-06-19 14:33:47 -0400127 varyingHandler->addPassThroughAttribute(gp.fInCoverage, "alpha");
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400128 fragBuilder->codeAppendf("%s = half4(alpha);", args.fOutputCoverage);
Brian Salomon8c852be2017-01-04 10:44:42 -0500129 } else if (gp.coverage() == 0xff) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400130 fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
Brian Salomon8c852be2017-01-04 10:44:42 -0500131 } else {
132 const char* fragCoverage;
Ethan Nicholas16464c32020-04-06 13:53:05 -0400133 fCoverageUniform = uniformHandler->addUniform(nullptr,
134 kFragment_GrShaderFlag,
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400135 kHalf_GrSLType,
Brian Salomon8c852be2017-01-04 10:44:42 -0500136 "Coverage",
137 &fragCoverage);
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400138 fragBuilder->codeAppendf("%s = half4(%s);", args.fOutputCoverage, fragCoverage);
joshualitt2dd1ae02014-12-03 06:24:10 -0800139 }
joshualitt4973d9d2014-11-08 09:24:25 -0800140 }
141
joshualitt87f48d92014-12-04 10:41:40 -0800142 static inline void GenKey(const GrGeometryProcessor& gp,
Brian Salomon94efbf52016-11-29 13:43:05 -0500143 const GrShaderCaps&,
joshualitt87f48d92014-12-04 10:41:40 -0800144 GrProcessorKeyBuilder* b) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800145 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
joshualitt8fc6c2d2014-12-22 15:27:05 -0800146 uint32_t key = def.fFlags;
Brian Osman80879d42019-01-07 16:15:27 -0500147 key |= (def.coverage() == 0xff) ? 0x80 : 0;
Michael Ludwig553db622020-06-19 10:47:30 -0400148 key |= def.localCoordsWillBeRead() ? 0x100 : 0;
149
150 bool usesLocalMatrix = def.localCoordsWillBeRead() &&
151 !def.fInLocalCoords.isInitialized();
152 key = AddMatrixKeys(key, def.viewMatrix(),
153 usesLocalMatrix ? def.localMatrix() : SkMatrix::I());
joshualitt8fc6c2d2014-12-22 15:27:05 -0800154 b->add32(key);
joshualitt2dd1ae02014-12-03 06:24:10 -0800155 }
joshualitt4973d9d2014-11-08 09:24:25 -0800156
egdaniel018fb622015-10-28 07:26:40 -0700157 void setData(const GrGLSLProgramDataManager& pdman,
Brian Osman609f1592020-07-01 15:14:39 -0400158 const GrPrimitiveProcessor& gp) override {
joshualitte578a952015-05-14 10:09:13 -0700159 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>();
joshualitt5559ca22015-05-21 15:50:36 -0700160
Michael Ludwig553db622020-06-19 10:47:30 -0400161 this->setTransform(pdman, fViewMatrixUniform, dgp.viewMatrix(), &fViewMatrix);
162 this->setTransform(pdman, fLocalMatrixUniform, dgp.localMatrix(), &fLocalMatrix);
joshualittee2af952014-12-30 09:04:15 -0800163
Brian Osman1be2b7c2018-10-29 16:07:15 -0400164 if (!dgp.hasVertexColor() && dgp.color() != fColor) {
Brian Osmancf860852018-10-31 14:04:39 -0400165 pdman.set4fv(fColorUniform, 1, dgp.color().vec());
joshualittb8c241a2015-05-19 08:23:30 -0700166 fColor = dgp.color();
joshualitt9b989322014-12-15 14:16:27 -0800167 }
joshualittb8c241a2015-05-19 08:23:30 -0700168
Brian Salomon8c852be2017-01-04 10:44:42 -0500169 if (dgp.coverage() != fCoverage && !dgp.hasVertexCoverage()) {
joshualittb8c241a2015-05-19 08:23:30 -0700170 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverage()));
171 fCoverage = dgp.coverage();
joshualitt9b989322014-12-15 14:16:27 -0800172 }
Ruiqi Maoc97a3392018-08-15 10:44:19 -0400173 }
174
175 private:
joshualitt5559ca22015-05-21 15:50:36 -0700176 SkMatrix fViewMatrix;
Michael Ludwig553db622020-06-19 10:47:30 -0400177 SkMatrix fLocalMatrix;
Brian Osmancf860852018-10-31 14:04:39 -0400178 SkPMColor4f fColor;
joshualitt9b989322014-12-15 14:16:27 -0800179 uint8_t fCoverage;
joshualitt5559ca22015-05-21 15:50:36 -0700180 UniformHandle fViewMatrixUniform;
Michael Ludwig553db622020-06-19 10:47:30 -0400181 UniformHandle fLocalMatrixUniform;
joshualitt9b989322014-12-15 14:16:27 -0800182 UniformHandle fColorUniform;
183 UniformHandle fCoverageUniform;
184
egdaniele659a582015-11-13 09:55:43 -0800185 typedef GrGLSLGeometryProcessor INHERITED;
joshualitt4973d9d2014-11-08 09:24:25 -0800186 };
187
Brian Salomon94efbf52016-11-29 13:43:05 -0500188 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
egdaniel57d3b032015-11-13 11:57:27 -0800189 GLSLProcessor::GenKey(*this, caps, b);
joshualitteb2a6762014-12-04 11:35:33 -0800190 }
191
Brian Salomon94efbf52016-11-29 13:43:05 -0500192 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override {
egdaniel57d3b032015-11-13 11:57:27 -0800193 return new GLSLProcessor();
joshualitteb2a6762014-12-04 11:35:33 -0800194 }
195
joshualitt4973d9d2014-11-08 09:24:25 -0800196private:
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500197 friend class ::SkArenaAlloc; // for access to ctor
198
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
joshualitt2e3b3e32014-12-09 13:31:14 -0800240 typedef GrGeometryProcessor INHERITED;
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}