blob: 1b496b3657f99af3904eca94c6202b0639bedf7c [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
8#include "GrDefaultGeoProcFactory.h"
9
egdaniel605dd0f2014-11-12 08:35:25 -080010#include "GrInvariantOutput.h"
bungeman06ca8ec2016-06-09 08:01:03 -070011#include "SkRefCnt.h"
egdaniel2d721d32015-11-11 13:06:05 -080012#include "glsl/GrGLSLFragmentShaderBuilder.h"
egdaniele659a582015-11-13 09:55:43 -080013#include "glsl/GrGLSLGeometryProcessor.h"
egdaniel2d721d32015-11-11 13:06:05 -080014#include "glsl/GrGLSLVertexShaderBuilder.h"
egdaniel0eafe792015-11-20 14:01:22 -080015#include "glsl/GrGLSLVarying.h"
egdaniel7ea439b2015-12-03 09:20:44 -080016#include "glsl/GrGLSLUniformHandler.h"
egdaniel64c47282015-11-13 06:54:19 -080017#include "glsl/GrGLSLUtil.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 {
26 kColor_GPFlag = 0x1,
27 kLocalCoord_GPFlag = 0x2,
28 kCoverage_GPFlag= 0x4,
joshualittb2aa7cb2015-08-05 11:05:22 -070029};
30
joshualitt4973d9d2014-11-08 09:24:25 -080031class DefaultGeoProc : public GrGeometryProcessor {
32public:
bungeman06ca8ec2016-06-09 08:01:03 -070033 static sk_sp<GrGeometryProcessor> Make(uint32_t gpTypeFlags,
34 GrColor color,
35 const SkMatrix& viewMatrix,
36 const SkMatrix& localMatrix,
37 bool localCoordsWillBeRead,
38 bool coverageWillBeIgnored,
39 uint8_t coverage) {
40 return sk_sp<GrGeometryProcessor>(new DefaultGeoProc(
41 gpTypeFlags, color, viewMatrix, localMatrix, coverage,
42 localCoordsWillBeRead, coverageWillBeIgnored));
joshualitt4973d9d2014-11-08 09:24:25 -080043 }
44
mtklein36352bf2015-03-25 18:17:31 -070045 const char* name() const override { return "DefaultGeometryProcessor"; }
joshualitt4973d9d2014-11-08 09:24:25 -080046
joshualitt71c92602015-01-14 08:12:47 -080047 const Attribute* inPosition() const { return fInPosition; }
48 const Attribute* inColor() const { return fInColor; }
49 const Attribute* inLocalCoords() const { return fInLocalCoords; }
50 const Attribute* inCoverage() const { return fInCoverage; }
joshualitt88c23fc2015-05-13 14:18:07 -070051 GrColor color() const { return fColor; }
joshualittb8c241a2015-05-19 08:23:30 -070052 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
53 bool hasVertexColor() const { return SkToBool(fInColor); }
joshualitte578a952015-05-14 10:09:13 -070054 const SkMatrix& viewMatrix() const { return fViewMatrix; }
joshualitte3ababe2015-05-15 07:56:07 -070055 const SkMatrix& localMatrix() const { return fLocalMatrix; }
bsalomon7765a472015-07-08 11:26:37 -070056 bool localCoordsWillBeRead() const { return fLocalCoordsWillBeRead; }
joshualitt9b989322014-12-15 14:16:27 -080057 uint8_t coverage() const { return fCoverage; }
bsalomon7765a472015-07-08 11:26:37 -070058 bool coverageWillBeIgnored() const { return fCoverageWillBeIgnored; }
joshualittb8c241a2015-05-19 08:23:30 -070059 bool hasVertexCoverage() const { return SkToBool(fInCoverage); }
joshualitt9b989322014-12-15 14:16:27 -080060
egdaniel57d3b032015-11-13 11:57:27 -080061 class GLSLProcessor : public GrGLSLGeometryProcessor {
joshualitt4973d9d2014-11-08 09:24:25 -080062 public:
egdaniel57d3b032015-11-13 11:57:27 -080063 GLSLProcessor()
joshualitt5559ca22015-05-21 15:50:36 -070064 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), 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;
cdalton85285412016-02-18 12:37:07 -080069 GrGLSLPPFragmentBuilder* 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
76 // Setup pass through color
joshualittb8c241a2015-05-19 08:23:30 -070077 if (!gp.colorIgnored()) {
78 if (gp.hasVertexColor()) {
egdaniel0eafe792015-11-20 14:01:22 -080079 varyingHandler->addPassThroughAttribute(gp.inColor(), args.fOutputColor);
joshualittb8c241a2015-05-19 08:23:30 -070080 } else {
egdaniel7ea439b2015-12-03 09:20:44 -080081 this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
82 &fColorUniform);
joshualittb8c241a2015-05-19 08:23:30 -070083 }
84 }
85
joshualittabb52a12015-01-13 15:02:10 -080086 // Setup position
egdaniel7ea439b2015-12-03 09:20:44 -080087 this->setupPosition(vertBuilder,
88 uniformHandler,
egdaniel4ca2e602015-11-18 08:01:26 -080089 gpArgs,
90 gp.inPosition()->fName,
91 gp.viewMatrix(),
joshualitt5559ca22015-05-21 15:50:36 -070092 &fViewMatrixUniform);
joshualitt4973d9d2014-11-08 09:24:25 -080093
joshualittb2aa7cb2015-08-05 11:05:22 -070094 if (gp.hasExplicitLocalCoords()) {
joshualittabb52a12015-01-13 15:02:10 -080095 // emit transforms with explicit local coords
egdaniel7ea439b2015-12-03 09:20:44 -080096 this->emitTransforms(vertBuilder,
egdaniel0eafe792015-11-20 14:01:22 -080097 varyingHandler,
egdaniel7ea439b2015-12-03 09:20:44 -080098 uniformHandler,
egdaniel4ca2e602015-11-18 08:01:26 -080099 gpArgs->fPositionVar,
100 gp.inLocalCoords()->fName,
101 gp.localMatrix(),
bsalomon56b7dc42016-09-19 09:26:40 -0700102 args.fTransformsIn,
103 args.fTransformsOut);
joshualittabb52a12015-01-13 15:02:10 -0800104 } else {
105 // emit transforms with position
egdaniel7ea439b2015-12-03 09:20:44 -0800106 this->emitTransforms(vertBuilder,
egdaniel0eafe792015-11-20 14:01:22 -0800107 varyingHandler,
egdaniel7ea439b2015-12-03 09:20:44 -0800108 uniformHandler,
egdaniel4ca2e602015-11-18 08:01:26 -0800109 gpArgs->fPositionVar,
110 gp.inPosition()->fName,
111 gp.localMatrix(),
bsalomon56b7dc42016-09-19 09:26:40 -0700112 args.fTransformsIn,
113 args.fTransformsOut);
joshualittabb52a12015-01-13 15:02:10 -0800114 }
115
joshualitt2dd1ae02014-12-03 06:24:10 -0800116 // Setup coverage as pass through
bsalomon7765a472015-07-08 11:26:37 -0700117 if (!gp.coverageWillBeIgnored()) {
joshualittb8c241a2015-05-19 08:23:30 -0700118 if (gp.hasVertexCoverage()) {
egdaniel4ca2e602015-11-18 08:01:26 -0800119 fragBuilder->codeAppendf("float alpha = 1.0;");
egdaniel0eafe792015-11-20 14:01:22 -0800120 varyingHandler->addPassThroughAttribute(gp.inCoverage(), "alpha");
egdaniel4ca2e602015-11-18 08:01:26 -0800121 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
joshualittb8c241a2015-05-19 08:23:30 -0700122 } else if (gp.coverage() == 0xff) {
egdaniel4ca2e602015-11-18 08:01:26 -0800123 fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage);
joshualittb8c241a2015-05-19 08:23:30 -0700124 } else {
125 const char* fragCoverage;
cdalton5e58cee2016-02-11 12:49:47 -0800126 fCoverageUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
127 kFloat_GrSLType,
128 kDefault_GrSLPrecision,
129 "Coverage",
130 &fragCoverage);
egdaniel4ca2e602015-11-18 08:01:26 -0800131 fragBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, fragCoverage);
joshualittb8c241a2015-05-19 08:23:30 -0700132 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800133 }
joshualitt4973d9d2014-11-08 09:24:25 -0800134 }
135
joshualitt87f48d92014-12-04 10:41:40 -0800136 static inline void GenKey(const GrGeometryProcessor& gp,
jvanverthcfc18862015-04-28 08:48:20 -0700137 const GrGLSLCaps&,
joshualitt87f48d92014-12-04 10:41:40 -0800138 GrProcessorKeyBuilder* b) {
joshualitt2dd1ae02014-12-03 06:24:10 -0800139 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
joshualitt8fc6c2d2014-12-22 15:27:05 -0800140 uint32_t key = def.fFlags;
joshualittb8c241a2015-05-19 08:23:30 -0700141 key |= def.colorIgnored() << 8;
bsalomon7765a472015-07-08 11:26:37 -0700142 key |= def.coverageWillBeIgnored() << 9;
joshualittb8c241a2015-05-19 08:23:30 -0700143 key |= def.hasVertexColor() << 10;
144 key |= def.hasVertexCoverage() << 11;
145 key |= def.coverage() == 0xff ? 0x1 << 12 : 0;
bsalomon7765a472015-07-08 11:26:37 -0700146 key |= def.localCoordsWillBeRead() && def.localMatrix().hasPerspective() ? 0x1 << 24 :
147 0x0;
joshualitte578a952015-05-14 10:09:13 -0700148 key |= ComputePosKey(def.viewMatrix()) << 25;
joshualitt8fc6c2d2014-12-22 15:27:05 -0800149 b->add32(key);
joshualitt2dd1ae02014-12-03 06:24:10 -0800150 }
joshualitt4973d9d2014-11-08 09:24:25 -0800151
egdaniel018fb622015-10-28 07:26:40 -0700152 void setData(const GrGLSLProgramDataManager& pdman,
bsalomon56b7dc42016-09-19 09:26:40 -0700153 const GrPrimitiveProcessor& gp) override {
joshualitte578a952015-05-14 10:09:13 -0700154 const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>();
joshualitt5559ca22015-05-21 15:50:36 -0700155
156 if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp.viewMatrix())) {
157 fViewMatrix = dgp.viewMatrix();
egdaniel018fb622015-10-28 07:26:40 -0700158 float viewMatrix[3 * 3];
egdaniel64c47282015-11-13 06:54:19 -0800159 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix);
joshualitt5559ca22015-05-21 15:50:36 -0700160 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix);
161 }
joshualittee2af952014-12-30 09:04:15 -0800162
joshualittb8c241a2015-05-19 08:23:30 -0700163 if (dgp.color() != fColor && !dgp.hasVertexColor()) {
egdaniel018fb622015-10-28 07:26:40 -0700164 float c[4];
joshualittb8c241a2015-05-19 08:23:30 -0700165 GrColorToRGBAFloat(dgp.color(), c);
joshualitt9b989322014-12-15 14:16:27 -0800166 pdman.set4fv(fColorUniform, 1, c);
joshualittb8c241a2015-05-19 08:23:30 -0700167 fColor = dgp.color();
joshualitt9b989322014-12-15 14:16:27 -0800168 }
joshualittb8c241a2015-05-19 08:23:30 -0700169
bsalomon7765a472015-07-08 11:26:37 -0700170 if (!dgp.coverageWillBeIgnored() &&
171 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 }
bsalomon56b7dc42016-09-19 09:26:40 -0700175 }
176
177 void setTransformData(const GrPrimitiveProcessor& primProc,
178 const GrGLSLProgramDataManager& pdman,
179 int index,
180 const SkTArray<const GrCoordTransform*, true>& transforms) override {
181 this->setTransformDataHelper(primProc.cast<DefaultGeoProc>().fLocalMatrix, pdman, index,
182 transforms);
joshualitte3ababe2015-05-15 07:56:07 -0700183 }
184
joshualitt4973d9d2014-11-08 09:24:25 -0800185 private:
joshualitt5559ca22015-05-21 15:50:36 -0700186 SkMatrix fViewMatrix;
joshualitt9b989322014-12-15 14:16:27 -0800187 GrColor fColor;
188 uint8_t fCoverage;
joshualitt5559ca22015-05-21 15:50:36 -0700189 UniformHandle fViewMatrixUniform;
joshualitt9b989322014-12-15 14:16:27 -0800190 UniformHandle fColorUniform;
191 UniformHandle fCoverageUniform;
192
egdaniele659a582015-11-13 09:55:43 -0800193 typedef GrGLSLGeometryProcessor INHERITED;
joshualitt4973d9d2014-11-08 09:24:25 -0800194 };
195
egdaniel57d3b032015-11-13 11:57:27 -0800196 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override {
197 GLSLProcessor::GenKey(*this, caps, b);
joshualitteb2a6762014-12-04 11:35:33 -0800198 }
199
egdaniel57d3b032015-11-13 11:57:27 -0800200 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const override {
201 return new GLSLProcessor();
joshualitteb2a6762014-12-04 11:35:33 -0800202 }
203
joshualitt4973d9d2014-11-08 09:24:25 -0800204private:
joshualitt8059eb92014-12-29 15:10:07 -0800205 DefaultGeoProc(uint32_t gpTypeFlags,
206 GrColor color,
207 const SkMatrix& viewMatrix,
208 const SkMatrix& localMatrix,
joshualittb8c241a2015-05-19 08:23:30 -0700209 uint8_t coverage,
bsalomon7765a472015-07-08 11:26:37 -0700210 bool localCoordsWillBeRead,
211 bool coverageWillBeIgnored)
halcanary96fcdcc2015-08-27 07:41:13 -0700212 : fInPosition(nullptr)
213 , fInColor(nullptr)
214 , fInLocalCoords(nullptr)
215 , fInCoverage(nullptr)
joshualitt88c23fc2015-05-13 14:18:07 -0700216 , fColor(color)
joshualitte578a952015-05-14 10:09:13 -0700217 , fViewMatrix(viewMatrix)
joshualitte3ababe2015-05-15 07:56:07 -0700218 , fLocalMatrix(localMatrix)
joshualitt9b989322014-12-15 14:16:27 -0800219 , fCoverage(coverage)
joshualittb8c241a2015-05-19 08:23:30 -0700220 , fFlags(gpTypeFlags)
bsalomon7765a472015-07-08 11:26:37 -0700221 , fLocalCoordsWillBeRead(localCoordsWillBeRead)
222 , fCoverageWillBeIgnored(coverageWillBeIgnored) {
joshualitteb2a6762014-12-04 11:35:33 -0800223 this->initClassID<DefaultGeoProc>();
joshualittb2aa7cb2015-08-05 11:05:22 -0700224 bool hasColor = SkToBool(gpTypeFlags & kColor_GPFlag);
225 bool hasExplicitLocalCoords = SkToBool(gpTypeFlags & kLocalCoord_GPFlag);
joshualittb2aa7cb2015-08-05 11:05:22 -0700226 bool hasCoverage = SkToBool(gpTypeFlags & kCoverage_GPFlag);
bsalomon6cb807b2016-08-17 11:33:39 -0700227 fInPosition = &this->addVertexAttrib("inPosition", kVec2f_GrVertexAttribType,
228 kHigh_GrSLPrecision);
joshualitt2dd1ae02014-12-03 06:24:10 -0800229 if (hasColor) {
bsalomon6cb807b2016-08-17 11:33:39 -0700230 fInColor = &this->addVertexAttrib("inColor", kVec4ub_GrVertexAttribType);
joshualitt2dd1ae02014-12-03 06:24:10 -0800231 }
bsalomoncc6aeee2016-09-12 12:02:11 -0700232 if (hasExplicitLocalCoords) {
bsalomon6cb807b2016-08-17 11:33:39 -0700233 fInLocalCoords = &this->addVertexAttrib("inLocalCoord", kVec2f_GrVertexAttribType);
bsalomoncc6aeee2016-09-12 12:02:11 -0700234 this->setHasExplicitLocalCoords();
joshualitt2dd1ae02014-12-03 06:24:10 -0800235 }
236 if (hasCoverage) {
bsalomon6cb807b2016-08-17 11:33:39 -0700237 fInCoverage = &this->addVertexAttrib("inCoverage", kFloat_GrVertexAttribType);
joshualitt2dd1ae02014-12-03 06:24:10 -0800238 }
239 }
joshualitt4973d9d2014-11-08 09:24:25 -0800240
joshualitt71c92602015-01-14 08:12:47 -0800241 const Attribute* fInPosition;
242 const Attribute* fInColor;
243 const Attribute* fInLocalCoords;
244 const Attribute* fInCoverage;
joshualitt88c23fc2015-05-13 14:18:07 -0700245 GrColor 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;
251 bool fCoverageWillBeIgnored;
joshualitt4973d9d2014-11-08 09:24:25 -0800252
joshualitt2dd1ae02014-12-03 06:24:10 -0800253 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
joshualitt5478d422014-11-14 16:00:38 -0800254
joshualitt2e3b3e32014-12-09 13:31:14 -0800255 typedef GrGeometryProcessor INHERITED;
joshualitt4973d9d2014-11-08 09:24:25 -0800256};
257
258GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc);
259
bungeman06ca8ec2016-06-09 08:01:03 -0700260sk_sp<GrGeometryProcessor> 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()) {
joshualittb2aa7cb2015-08-05 11:05:22 -0700263 flags |= kColor_GPFlag;
joshualitt4973d9d2014-11-08 09:24:25 -0800264 }
joshualitt0067ff52015-07-08 14:26:19 -0700265 if (d->fRandom->nextBool()) {
joshualittb2aa7cb2015-08-05 11:05:22 -0700266 flags |= kCoverage_GPFlag;
joshualitt4973d9d2014-11-08 09:24:25 -0800267 }
joshualitt0067ff52015-07-08 14:26:19 -0700268 if (d->fRandom->nextBool()) {
joshualittb2aa7cb2015-08-05 11:05:22 -0700269 flags |= kLocalCoord_GPFlag;
270 }
joshualitt2dd1ae02014-12-03 06:24:10 -0800271
bungeman06ca8ec2016-06-09 08:01:03 -0700272 return DefaultGeoProc::Make(flags,
273 GrRandomColor(d->fRandom),
274 GrTest::TestMatrix(d->fRandom),
275 GrTest::TestMatrix(d->fRandom),
276 d->fRandom->nextBool(),
277 d->fRandom->nextBool(),
278 GrRandomCoverage(d->fRandom));
joshualitt4973d9d2014-11-08 09:24:25 -0800279}
280
bungeman06ca8ec2016-06-09 08:01:03 -0700281sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::Make(const Color& color,
282 const Coverage& coverage,
283 const LocalCoords& localCoords,
284 const SkMatrix& viewMatrix) {
joshualitte9d60952015-07-27 12:13:14 -0700285 uint32_t flags = 0;
joshualittb2aa7cb2015-08-05 11:05:22 -0700286 flags |= color.fType == Color::kAttribute_Type ? kColor_GPFlag : 0;
287 flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPFlag : 0;
288 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_GPFlag : 0;
joshualitte9d60952015-07-27 12:13:14 -0700289
290 uint8_t inCoverage = coverage.fCoverage;
291 bool coverageWillBeIgnored = coverage.fType == Coverage::kNone_Type;
joshualitt0d986d82015-07-28 10:01:18 -0700292 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type;
joshualitte9d60952015-07-27 12:13:14 -0700293
294 GrColor inColor = color.fColor;
bungeman06ca8ec2016-06-09 08:01:03 -0700295 return DefaultGeoProc::Make(flags,
296 inColor,
297 viewMatrix,
298 localCoords.fMatrix ? *localCoords.fMatrix : SkMatrix::I(),
299 localCoordsWillBeRead,
300 coverageWillBeIgnored,
301 inCoverage);
joshualitte9d60952015-07-27 12:13:14 -0700302}
joshualitt0d986d82015-07-28 10:01:18 -0700303
bungeman06ca8ec2016-06-09 08:01:03 -0700304sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::MakeForDeviceSpace(
joshualitt0d986d82015-07-28 10:01:18 -0700305 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)) {
313 SkDebugf("Could not invert\n");
halcanary96fcdcc2015-08-27 07:41:13 -0700314 return nullptr;
joshualittdf0c5572015-08-03 11:35:28 -0700315 }
joshualitt0d986d82015-07-28 10:01:18 -0700316
joshualittdf0c5572015-08-03 11:35:28 -0700317 if (localCoords.hasLocalMatrix()) {
318 invert.preConcat(*localCoords.fMatrix);
319 }
joshualitt0d986d82015-07-28 10:01:18 -0700320 }
321
322 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert);
bungeman06ca8ec2016-06-09 08:01:03 -0700323 return Make(color, coverage, inverted, SkMatrix::I());
joshualitt0d986d82015-07-28 10:01:18 -0700324}