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