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