joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 10 | #include "GrInvariantOutput.h" |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 11 | #include "gl/GrGLGeometryProcessor.h" |
| 12 | #include "gl/builders/GrGLProgramBuilder.h" |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 13 | |
| 14 | /* |
| 15 | * The default Geometry Processor simply takes position and multiplies it by the uniform view |
| 16 | * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or |
| 17 | * local coords. |
| 18 | */ |
| 19 | class DefaultGeoProc : public GrGeometryProcessor { |
| 20 | public: |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 21 | static GrGeometryProcessor* Create(uint32_t gpTypeFlags, |
| 22 | GrColor color, |
| 23 | const SkMatrix& viewMatrix, |
| 24 | const SkMatrix& localMatrix, |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 25 | bool localCoordsWillBeRead, |
| 26 | bool coverageWillBeIgnored, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 27 | uint8_t coverage) { |
| 28 | return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, |
| 29 | color, |
| 30 | viewMatrix, |
| 31 | localMatrix, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 32 | coverage, |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 33 | localCoordsWillBeRead, |
| 34 | coverageWillBeIgnored)); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 35 | } |
| 36 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 37 | const char* name() const override { return "DefaultGeometryProcessor"; } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 38 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 39 | const Attribute* inPosition() const { return fInPosition; } |
| 40 | const Attribute* inColor() const { return fInColor; } |
| 41 | const Attribute* inLocalCoords() const { return fInLocalCoords; } |
| 42 | const Attribute* inCoverage() const { return fInCoverage; } |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 43 | GrColor color() const { return fColor; } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 44 | bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } |
| 45 | bool hasVertexColor() const { return SkToBool(fInColor); } |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 46 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 47 | const SkMatrix& localMatrix() const { return fLocalMatrix; } |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 48 | bool localCoordsWillBeRead() const { return fLocalCoordsWillBeRead; } |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 49 | uint8_t coverage() const { return fCoverage; } |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 50 | bool coverageWillBeIgnored() const { return fCoverageWillBeIgnored; } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 51 | bool hasVertexCoverage() const { return SkToBool(fInCoverage); } |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 52 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 53 | class GLProcessor : public GrGLGeometryProcessor { |
| 54 | public: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 55 | GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&) |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 56 | : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), fCoverage(0xff) {} |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 57 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 58 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 59 | const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 60 | GrGLGPBuilder* pb = args.fPB; |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 61 | GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
egdaniel | 29bee0f | 2015-04-29 11:54:42 -0700 | [diff] [blame] | 62 | GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 63 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 64 | // emit attributes |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 65 | vsBuilder->emitAttributes(gp); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 66 | |
| 67 | // Setup pass through color |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 68 | if (!gp.colorIgnored()) { |
| 69 | if (gp.hasVertexColor()) { |
| 70 | pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor); |
| 71 | } else { |
| 72 | this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
| 73 | } |
| 74 | } |
| 75 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 76 | // Setup position |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 77 | this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix(), |
| 78 | &fViewMatrixUniform); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 79 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 80 | if (gp.inLocalCoords()) { |
| 81 | // emit transforms with explicit local coords |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 82 | this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords()->fName, |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 83 | gp.localMatrix(), args.fTransformsIn, args.fTransformsOut); |
| 84 | } else { |
| 85 | // emit transforms with position |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 86 | this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 87 | gp.localMatrix(), args.fTransformsIn, args.fTransformsOut); |
| 88 | } |
| 89 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 90 | // Setup coverage as pass through |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 91 | if (!gp.coverageWillBeIgnored()) { |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 92 | if (gp.hasVertexCoverage()) { |
| 93 | fs->codeAppendf("float alpha = 1.0;"); |
| 94 | args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha"); |
| 95 | fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
| 96 | } else if (gp.coverage() == 0xff) { |
| 97 | fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
| 98 | } else { |
| 99 | const char* fragCoverage; |
| 100 | fCoverageUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
| 101 | kFloat_GrSLType, |
| 102 | kDefault_GrSLPrecision, |
| 103 | "Coverage", |
| 104 | &fragCoverage); |
| 105 | fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, fragCoverage); |
| 106 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 107 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 108 | } |
| 109 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 110 | static inline void GenKey(const GrGeometryProcessor& gp, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 111 | const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 112 | const GrGLSLCaps&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 113 | GrProcessorKeyBuilder* b) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 114 | const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 115 | uint32_t key = def.fFlags; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 116 | key |= def.colorIgnored() << 8; |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 117 | key |= def.coverageWillBeIgnored() << 9; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 118 | key |= def.hasVertexColor() << 10; |
| 119 | key |= def.hasVertexCoverage() << 11; |
| 120 | key |= def.coverage() == 0xff ? 0x1 << 12 : 0; |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 121 | key |= def.localCoordsWillBeRead() && def.localMatrix().hasPerspective() ? 0x1 << 24 : |
| 122 | 0x0; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 123 | key |= ComputePosKey(def.viewMatrix()) << 25; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 124 | b->add32(key); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 125 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 126 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 127 | virtual void setData(const GrGLProgramDataManager& pdman, |
| 128 | const GrPrimitiveProcessor& gp, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 129 | const GrBatchTracker& bt) override { |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 130 | const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 131 | |
| 132 | if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp.viewMatrix())) { |
| 133 | fViewMatrix = dgp.viewMatrix(); |
| 134 | GrGLfloat viewMatrix[3 * 3]; |
| 135 | GrGLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 136 | pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 137 | } |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 138 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 139 | if (dgp.color() != fColor && !dgp.hasVertexColor()) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 140 | GrGLfloat c[4]; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 141 | GrColorToRGBAFloat(dgp.color(), c); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 142 | pdman.set4fv(fColorUniform, 1, c); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 143 | fColor = dgp.color(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 144 | } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 145 | |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 146 | if (!dgp.coverageWillBeIgnored() && |
| 147 | dgp.coverage() != fCoverage && !dgp.hasVertexCoverage()) { |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 148 | pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverage())); |
| 149 | fCoverage = dgp.coverage(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 150 | } |
| 151 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 152 | |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 153 | void setTransformData(const GrPrimitiveProcessor& primProc, |
| 154 | const GrGLProgramDataManager& pdman, |
| 155 | int index, |
| 156 | const SkTArray<const GrCoordTransform*, true>& transforms) override { |
| 157 | this->setTransformDataHelper<DefaultGeoProc>(primProc, pdman, index, transforms); |
| 158 | } |
| 159 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 160 | private: |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 161 | SkMatrix fViewMatrix; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 162 | GrColor fColor; |
| 163 | uint8_t fCoverage; |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 164 | UniformHandle fViewMatrixUniform; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 165 | UniformHandle fColorUniform; |
| 166 | UniformHandle fCoverageUniform; |
| 167 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 168 | typedef GrGLGeometryProcessor INHERITED; |
| 169 | }; |
| 170 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 171 | virtual void getGLProcessorKey(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 172 | const GrGLSLCaps& caps, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 173 | GrProcessorKeyBuilder* b) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 174 | GLProcessor::GenKey(*this, bt, caps, b); |
| 175 | } |
| 176 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 177 | virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 178 | const GrGLSLCaps&) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 179 | return SkNEW_ARGS(GLProcessor, (*this, bt)); |
| 180 | } |
| 181 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 182 | private: |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 183 | DefaultGeoProc(uint32_t gpTypeFlags, |
| 184 | GrColor color, |
| 185 | const SkMatrix& viewMatrix, |
| 186 | const SkMatrix& localMatrix, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 187 | uint8_t coverage, |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 188 | bool localCoordsWillBeRead, |
| 189 | bool coverageWillBeIgnored) |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 190 | : fInPosition(NULL) |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 191 | , fInColor(NULL) |
| 192 | , fInLocalCoords(NULL) |
| 193 | , fInCoverage(NULL) |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 194 | , fColor(color) |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 195 | , fViewMatrix(viewMatrix) |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 196 | , fLocalMatrix(localMatrix) |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 197 | , fCoverage(coverage) |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 198 | , fFlags(gpTypeFlags) |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 199 | , fLocalCoordsWillBeRead(localCoordsWillBeRead) |
| 200 | , fCoverageWillBeIgnored(coverageWillBeIgnored) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 201 | this->initClassID<DefaultGeoProc>(); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 202 | bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_GPType); |
| 203 | bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLocalCoord_GPType); |
| 204 | bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCoverage_GPType); |
senorblanco | f2539d5 | 2015-05-20 14:03:42 -0700 | [diff] [blame] | 205 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType, |
| 206 | kHigh_GrSLPrecision)); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 207 | if (hasColor) { |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 208 | fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType)); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 209 | } |
| 210 | if (hasLocalCoord) { |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 211 | fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 212 | kVec2f_GrVertexAttribType)); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 213 | this->setHasLocalCoords(); |
| 214 | } |
| 215 | if (hasCoverage) { |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 216 | fInCoverage = &this->addVertexAttrib(Attribute("inCoverage", |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 217 | kFloat_GrVertexAttribType)); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 218 | } |
| 219 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 220 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 221 | const Attribute* fInPosition; |
| 222 | const Attribute* fInColor; |
| 223 | const Attribute* fInLocalCoords; |
| 224 | const Attribute* fInCoverage; |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 225 | GrColor fColor; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 226 | SkMatrix fViewMatrix; |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 227 | SkMatrix fLocalMatrix; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 228 | uint8_t fCoverage; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 229 | uint32_t fFlags; |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 230 | bool fLocalCoordsWillBeRead; |
| 231 | bool fCoverageWillBeIgnored; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 232 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 233 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 234 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 235 | typedef GrGeometryProcessor INHERITED; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); |
| 239 | |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 240 | GrGeometryProcessor* DefaultGeoProc::TestCreate(GrProcessorTestData* d) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 241 | uint32_t flags = 0; |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 242 | if (d->fRandom->nextBool()) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 243 | flags |= GrDefaultGeoProcFactory::kColor_GPType; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 244 | } |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 245 | if (d->fRandom->nextBool()) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 246 | flags |= GrDefaultGeoProcFactory::kCoverage_GPType; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 247 | } |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 248 | if (d->fRandom->nextBool()) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 249 | flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 250 | } |
| 251 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 252 | return DefaultGeoProc::Create(flags, |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 253 | GrRandomColor(d->fRandom), |
| 254 | GrTest::TestMatrix(d->fRandom), |
| 255 | GrTest::TestMatrix(d->fRandom), |
| 256 | d->fRandom->nextBool(), |
| 257 | d->fRandom->nextBool(), |
| 258 | GrRandomCoverage(d->fRandom)); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 259 | } |
| 260 | |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 261 | const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(const Color& color, |
| 262 | const Coverage& coverage, |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 263 | const LocalCoords& localCoords, |
| 264 | const SkMatrix& viewMatrix) { |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 265 | uint32_t flags = 0; |
| 266 | flags |= color.fType == Color::kAttribute_Type ? kColor_GPType : 0; |
| 267 | flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPType : 0; |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 268 | flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_GPType : 0; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 269 | |
| 270 | uint8_t inCoverage = coverage.fCoverage; |
| 271 | bool coverageWillBeIgnored = coverage.fType == Coverage::kNone_Type; |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 272 | bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 273 | |
| 274 | GrColor inColor = color.fColor; |
| 275 | return DefaultGeoProc::Create(flags, |
| 276 | inColor, |
| 277 | viewMatrix, |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 278 | localCoords.fMatrix ? *localCoords.fMatrix : SkMatrix::I(), |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 279 | localCoordsWillBeRead, |
| 280 | coverageWillBeIgnored, |
| 281 | inCoverage); |
| 282 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 283 | |
| 284 | const GrGeometryProcessor* GrDefaultGeoProcFactory::CreateForDeviceSpace( |
| 285 | const Color& color, |
| 286 | const Coverage& coverage, |
| 287 | const LocalCoords& localCoords, |
| 288 | const SkMatrix& viewMatrix) { |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 289 | SkMatrix invert = SkMatrix::I(); |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 290 | if (LocalCoords::kUnused_Type != localCoords.fType) { |
| 291 | SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType); |
| 292 | if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) { |
| 293 | SkDebugf("Could not invert\n"); |
| 294 | return NULL; |
| 295 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 296 | |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 297 | if (localCoords.hasLocalMatrix()) { |
| 298 | invert.preConcat(*localCoords.fMatrix); |
| 299 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 303 | return Create(color, coverage, inverted, SkMatrix::I()); |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 304 | } |