blob: 27c096524cb90acefd7dd9d66feadae2b33e7de5 [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"
Brian Salomon48959462021-08-11 13:01:06 -040013#include "src/gpu/GrGeometryProcessor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#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 {
Chris Dalton97f85902021-07-14 03:16:22 -060026 kColorAttribute_GPFlag = 0x1,
27 kColorAttributeIsWide_GPFlag = 0x2,
28 kLocalCoordAttribute_GPFlag = 0x4,
29 kCoverageAttribute_GPFlag = 0x8,
30 kCoverageAttributeTweak_GPFlag = 0x10,
31 kCoverageAttributeUnclamped_GPFlag = 0x20,
joshualittb2aa7cb2015-08-05 11:05:22 -070032};
33
joshualitt4973d9d2014-11-08 09:24:25 -080034class DefaultGeoProc : public GrGeometryProcessor {
35public:
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050036 static GrGeometryProcessor* Make(SkArenaAlloc* arena,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050037 uint32_t gpTypeFlags,
38 const SkPMColor4f& color,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050039 const SkMatrix& viewMatrix,
40 const SkMatrix& localMatrix,
41 bool localCoordsWillBeRead,
42 uint8_t coverage) {
Mike Kleinf1241082020-12-14 15:59:09 -060043 return arena->make([&](void* ptr) {
44 return new (ptr) DefaultGeoProc(gpTypeFlags, color, viewMatrix, localMatrix, coverage,
45 localCoordsWillBeRead);
46 });
joshualitt4973d9d2014-11-08 09:24:25 -080047 }
48
mtklein36352bf2015-03-25 18:17:31 -070049 const char* name() const override { return "DefaultGeometryProcessor"; }
joshualitt4973d9d2014-11-08 09:24:25 -080050
Brian Salomonbab2d112021-08-11 09:59:56 -040051 void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
52 uint32_t key = fFlags;
53 key |= fCoverage == 0xff ? 0x80 : 0;
54 key |= fLocalCoordsWillBeRead ? 0x100 : 0;
joshualitt9b989322014-12-15 14:16:27 -080055
Brian Salomonbab2d112021-08-11 09:59:56 -040056 bool usesLocalMatrix = fLocalCoordsWillBeRead && !fInLocalCoords.isInitialized();
57 key = ProgramImpl::AddMatrixKeys(caps,
58 key,
59 fViewMatrix,
60 usesLocalMatrix ? fLocalMatrix : SkMatrix::I());
61 b->add32(key);
62 }
63
64 std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
65 return std::make_unique<Impl>();
66 }
67
68private:
69 class Impl : public ProgramImpl {
joshualitt4973d9d2014-11-08 09:24:25 -080070 public:
Brian Salomonbab2d112021-08-11 09:59:56 -040071 void setData(const GrGLSLProgramDataManager& pdman,
72 const GrShaderCaps& shaderCaps,
73 const GrGeometryProcessor& geomProc) override {
74 const DefaultGeoProc& dgp = geomProc.cast<DefaultGeoProc>();
joshualitt4973d9d2014-11-08 09:24:25 -080075
Brian Salomonbab2d112021-08-11 09:59:56 -040076 SetTransform(pdman, shaderCaps, fViewMatrixUniform, dgp.fViewMatrix, &fViewMatrixPrev);
77 SetTransform(pdman,
78 shaderCaps,
79 fLocalMatrixUniform,
80 dgp.fLocalMatrix,
81 &fLocalMatrixPrev);
82
83 if (!dgp.hasVertexColor() && dgp.fColor != fColor) {
84 pdman.set4fv(fColorUniform, 1, dgp.fColor.vec());
85 fColor = dgp.fColor;
86 }
87
88 if (dgp.fCoverage != fCoverage && !dgp.hasVertexCoverage()) {
89 pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.fCoverage));
90 fCoverage = dgp.fCoverage;
91 }
92 }
93
94 private:
mtklein36352bf2015-03-25 18:17:31 -070095 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
Robert Phillips787fd9d2021-03-22 14:48:09 -040096 const DefaultGeoProc& gp = args.fGeomProc.cast<DefaultGeoProc>();
egdaniel4ca2e602015-11-18 08:01:26 -080097 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
Chris Dalton60283612018-02-14 13:38:14 -070098 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
egdaniel0eafe792015-11-20 14:01:22 -080099 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
egdaniel7ea439b2015-12-03 09:20:44 -0800100 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
joshualitt4973d9d2014-11-08 09:24:25 -0800101
joshualittabb52a12015-01-13 15:02:10 -0800102 // emit attributes
egdaniel0eafe792015-11-20 14:01:22 -0800103 varyingHandler->emitAttributes(gp);
joshualitt2dd1ae02014-12-03 06:24:10 -0800104
Brian Osman80879d42019-01-07 16:15:27 -0500105 bool tweakAlpha = SkToBool(gp.fFlags & kCoverageAttributeTweak_GPFlag);
Chris Dalton97f85902021-07-14 03:16:22 -0600106 bool coverageNeedsSaturate = SkToBool(gp.fFlags & kCoverageAttributeUnclamped_GPFlag);
Brian Osman80879d42019-01-07 16:15:27 -0500107 SkASSERT(!tweakAlpha || gp.hasVertexCoverage());
Chris Dalton97f85902021-07-14 03:16:22 -0600108 SkASSERT(!tweakAlpha || !coverageNeedsSaturate);
Brian Osman80879d42019-01-07 16:15:27 -0500109
joshualitt2dd1ae02014-12-03 06:24:10 -0800110 // Setup pass through color
John Stiles4d7ac492021-03-09 20:16:43 -0500111 fragBuilder->codeAppendf("half4 %s;", args.fOutputColor);
Brian Osman80879d42019-01-07 16:15:27 -0500112 if (gp.hasVertexColor() || tweakAlpha) {
Chris Dalton27372882017-12-08 13:34:21 -0700113 GrGLSLVarying varying(kHalf4_GrSLType);
Brian Salomon3de0aee2017-01-29 09:34:17 -0500114 varyingHandler->addVarying("color", &varying);
Brian Osmanfa6d8652017-05-31 09:37:27 -0400115
Brian Osman8370fd12020-03-18 14:25:45 -0400116 // Start with the attribute or with uniform color
Brian Osman80879d42019-01-07 16:15:27 -0500117 if (gp.hasVertexColor()) {
118 vertBuilder->codeAppendf("half4 color = %s;", gp.fInColor.name());
119 } else {
120 const char* colorUniformName;
Ethan Nicholas16464c32020-04-06 13:53:05 -0400121 fColorUniform = uniformHandler->addUniform(nullptr,
122 kVertex_GrShaderFlag,
Brian Osman80879d42019-01-07 16:15:27 -0500123 kHalf4_GrSLType,
124 "Color",
125 &colorUniformName);
126 vertBuilder->codeAppendf("half4 color = %s;", colorUniformName);
127 }
Brian Osmanfa6d8652017-05-31 09:37:27 -0400128
Brian Osman80879d42019-01-07 16:15:27 -0500129 // Optionally fold coverage into alpha (color).
130 if (tweakAlpha) {
131 vertBuilder->codeAppendf("color = color * %s;", gp.fInCoverage.name());
132 }
Brian Osmanfa6d8652017-05-31 09:37:27 -0400133 vertBuilder->codeAppendf("%s = color;\n", varying.vsOut());
Brian Salomon3de0aee2017-01-29 09:34:17 -0500134 fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, varying.fsIn());
Brian Salomonbfd51832017-01-04 13:22:08 -0500135 } else {
136 this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
137 &fColorUniform);
joshualittb8c241a2015-05-19 08:23:30 -0700138 }
139
joshualittabb52a12015-01-13 15:02:10 -0800140 // Setup position
Brian Salomon5a328282021-04-14 10:32:25 -0400141 WriteOutputPosition(vertBuilder,
142 uniformHandler,
143 *args.fShaderCaps,
144 gpArgs,
145 gp.fInPosition.name(),
Brian Salomonbab2d112021-08-11 09:59:56 -0400146 gp.fViewMatrix,
Brian Salomon5a328282021-04-14 10:32:25 -0400147 &fViewMatrixUniform);
joshualitt4973d9d2014-11-08 09:24:25 -0800148
Brian Osman8370fd12020-03-18 14:25:45 -0400149 // emit transforms using either explicit local coords or positions
Michael Ludwig553db622020-06-19 10:47:30 -0400150 if (gp.fInLocalCoords.isInitialized()) {
Brian Salomonbab2d112021-08-11 09:59:56 -0400151 SkASSERT(gp.fLocalMatrix.isIdentity());
Michael Ludwig553db622020-06-19 10:47:30 -0400152 gpArgs->fLocalCoordVar = gp.fInLocalCoords.asShaderVar();
153 } else if (gp.fLocalCoordsWillBeRead) {
Brian Salomon5a328282021-04-14 10:32:25 -0400154 WriteLocalCoord(vertBuilder,
155 uniformHandler,
156 *args.fShaderCaps,
157 gpArgs,
158 gp.fInPosition.asShaderVar(),
Brian Salomonbab2d112021-08-11 09:59:56 -0400159 gp.fLocalMatrix,
Brian Salomon5a328282021-04-14 10:32:25 -0400160 &fLocalMatrixUniform);
Michael Ludwig553db622020-06-19 10:47:30 -0400161 }
joshualittabb52a12015-01-13 15:02:10 -0800162
joshualitt2dd1ae02014-12-03 06:24:10 -0800163 // Setup coverage as pass through
Brian Osman80879d42019-01-07 16:15:27 -0500164 if (gp.hasVertexCoverage() && !tweakAlpha) {
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400165 fragBuilder->codeAppendf("half alpha = 1.0;");
Brian Salomon48959462021-08-11 13:01:06 -0400166 varyingHandler->addPassThroughAttribute(gp.fInCoverage.asShaderVar(), "alpha");
Chris Dalton97f85902021-07-14 03:16:22 -0600167 if (coverageNeedsSaturate) {
168 fragBuilder->codeAppendf("half4 %s = half4(saturate(alpha));",
169 args.fOutputCoverage);
170 } else {
171 fragBuilder->codeAppendf("half4 %s = half4(alpha);", args.fOutputCoverage);
172 }
Brian Salomonbab2d112021-08-11 09:59:56 -0400173 } else if (gp.fCoverage == 0xff) {
John Stiles4d7ac492021-03-09 20:16:43 -0500174 fragBuilder->codeAppendf("const half4 %s = half4(1);", args.fOutputCoverage);
Brian Salomon8c852be2017-01-04 10:44:42 -0500175 } else {
176 const char* fragCoverage;
Ethan Nicholas16464c32020-04-06 13:53:05 -0400177 fCoverageUniform = uniformHandler->addUniform(nullptr,
178 kFragment_GrShaderFlag,
Ethan Nicholasf7b88202017-09-18 14:10:39 -0400179 kHalf_GrSLType,
Brian Salomon8c852be2017-01-04 10:44:42 -0500180 "Coverage",
181 &fragCoverage);
John Stiles4d7ac492021-03-09 20:16:43 -0500182 fragBuilder->codeAppendf("half4 %s = half4(%s);",
183 args.fOutputCoverage, fragCoverage);
joshualitt2dd1ae02014-12-03 06:24:10 -0800184 }
joshualitt4973d9d2014-11-08 09:24:25 -0800185 }
186
Brian Salomonbab2d112021-08-11 09:59:56 -0400187 SkMatrix fViewMatrixPrev = SkMatrix::InvalidMatrix();
188 SkMatrix fLocalMatrixPrev = SkMatrix::InvalidMatrix();
189 SkPMColor4f fColor = SK_PMColor4fILLEGAL;
190 uint8_t fCoverage = 0xFF;
Michael Ludwig553db622020-06-19 10:47:30 -0400191
joshualitt5559ca22015-05-21 15:50:36 -0700192 UniformHandle fViewMatrixUniform;
Michael Ludwig553db622020-06-19 10:47:30 -0400193 UniformHandle fLocalMatrixUniform;
joshualitt9b989322014-12-15 14:16:27 -0800194 UniformHandle fColorUniform;
195 UniformHandle fCoverageUniform;
joshualitt4973d9d2014-11-08 09:24:25 -0800196 };
197
Brian Salomonbab2d112021-08-11 09:59:56 -0400198 bool hasVertexColor() const { return fInColor.isInitialized(); }
199 bool hasVertexCoverage() const { return fInCoverage.isInitialized(); }
joshualitteb2a6762014-12-04 11:35:33 -0800200
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()) {
Chris Dalton97f85902021-07-14 03:16:22 -0600259 flags |= (d->fRandom->nextBool()) ? kCoverageAttributeTweak_GPFlag
260 : kCoverageAttributeUnclamped_GPFlag;
Brian Osman80879d42019-01-07 16:15:27 -0500261 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500262 }
263 if (d->fRandom->nextBool()) {
264 flags |= kLocalCoordAttribute_GPFlag;
joshualittb2aa7cb2015-08-05 11:05:22 -0700265 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800266
John Stiles391a9f62021-04-29 23:17:41 -0400267 GrColor color = GrRandomColor(d->fRandom);
268 SkMatrix viewMtx = GrTest::TestMatrix(d->fRandom);
269 SkMatrix localMtx = GrTest::TestMatrix(d->fRandom);
270 bool readsLocalCoords = d->fRandom->nextBool();
271 uint8_t coverage = GrRandomCoverage(d->fRandom);
Brian Osmanf0aee742020-03-12 09:28:44 -0400272 return DefaultGeoProc::Make(d->allocator(),
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400273 flags,
John Stiles391a9f62021-04-29 23:17:41 -0400274 SkPMColor4f::FromBytes_RGBA(color),
275 viewMtx,
276 localMtx,
277 readsLocalCoords,
278 coverage);
joshualitt4973d9d2014-11-08 09:24:25 -0800279}
Hal Canary6f6961e2017-01-31 13:50:44 -0500280#endif
joshualitt4973d9d2014-11-08 09:24:25 -0800281
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500282GrGeometryProcessor* GrDefaultGeoProcFactory::Make(SkArenaAlloc* arena,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500283 const Color& color,
284 const Coverage& coverage,
285 const LocalCoords& localCoords,
286 const SkMatrix& viewMatrix) {
joshualitte9d60952015-07-27 12:13:14 -0700287 uint32_t flags = 0;
Brian Salomon3de0aee2017-01-29 09:34:17 -0500288 if (Color::kPremulGrColorAttribute_Type == color.fType) {
289 flags |= kColorAttribute_GPFlag;
Brian Osman2a4c4df2018-12-20 14:06:54 -0500290 } else if (Color::kPremulWideColorAttribute_Type == color.fType) {
291 flags |= kColorAttribute_GPFlag | kColorAttributeIsWide_GPFlag;
Brian Salomon3de0aee2017-01-29 09:34:17 -0500292 }
Brian Osman80879d42019-01-07 16:15:27 -0500293 if (Coverage::kAttribute_Type == coverage.fType) {
294 flags |= kCoverageAttribute_GPFlag;
295 } else if (Coverage::kAttributeTweakAlpha_Type == coverage.fType) {
296 flags |= kCoverageAttribute_GPFlag | kCoverageAttributeTweak_GPFlag;
Chris Dalton97f85902021-07-14 03:16:22 -0600297 } else if (Coverage::kAttributeUnclamped_Type == coverage.fType) {
298 flags |= kCoverageAttribute_GPFlag | kCoverageAttributeUnclamped_GPFlag;
Brian Osman80879d42019-01-07 16:15:27 -0500299 }
Brian Salomon3de0aee2017-01-29 09:34:17 -0500300 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoordAttribute_GPFlag : 0;
joshualitte9d60952015-07-27 12:13:14 -0700301
302 uint8_t inCoverage = coverage.fCoverage;
joshualitt0d986d82015-07-28 10:01:18 -0700303 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type;
joshualitte9d60952015-07-27 12:13:14 -0700304
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500305 return DefaultGeoProc::Make(arena,
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400306 flags,
Brian Osmancf860852018-10-31 14:04:39 -0400307 color.fColor,
bungeman06ca8ec2016-06-09 08:01:03 -0700308 viewMatrix,
309 localCoords.fMatrix ? *localCoords.fMatrix : SkMatrix::I(),
310 localCoordsWillBeRead,
Brian Osman37064c12019-02-08 10:53:07 -0500311 inCoverage);
joshualitte9d60952015-07-27 12:13:14 -0700312}
joshualitt0d986d82015-07-28 10:01:18 -0700313
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500314GrGeometryProcessor* GrDefaultGeoProcFactory::MakeForDeviceSpace(SkArenaAlloc* arena,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500315 const Color& color,
316 const Coverage& coverage,
317 const LocalCoords& localCoords,
318 const SkMatrix& viewMatrix) {
joshualitt0d986d82015-07-28 10:01:18 -0700319 SkMatrix invert = SkMatrix::I();
joshualittdf0c5572015-08-03 11:35:28 -0700320 if (LocalCoords::kUnused_Type != localCoords.fType) {
321 SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType);
322 if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700323 return nullptr;
joshualittdf0c5572015-08-03 11:35:28 -0700324 }
joshualitt0d986d82015-07-28 10:01:18 -0700325
joshualittdf0c5572015-08-03 11:35:28 -0700326 if (localCoords.hasLocalMatrix()) {
Michael Ludwigef776042018-11-01 11:07:51 -0400327 invert.postConcat(*localCoords.fMatrix);
joshualittdf0c5572015-08-03 11:35:28 -0700328 }
joshualitt0d986d82015-07-28 10:01:18 -0700329 }
330
331 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert);
Brian Osmanf0aee742020-03-12 09:28:44 -0400332 return Make(arena, color, coverage, inverted, SkMatrix::I());
joshualitt0d986d82015-07-28 10:01:18 -0700333}