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