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" |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 11 | #include "SkRefCnt.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 12 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 13 | #include "glsl/GrGLSLGeometryProcessor.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 14 | #include "glsl/GrGLSLVertexShaderBuilder.h" |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 15 | #include "glsl/GrGLSLVarying.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 16 | #include "glsl/GrGLSLUniformHandler.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 17 | #include "glsl/GrGLSLUtil.h" |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * The default Geometry Processor simply takes position and multiplies it by the uniform view |
| 21 | * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or |
| 22 | * local coords. |
| 23 | */ |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 24 | |
| 25 | enum GPFlag { |
| 26 | kColor_GPFlag = 0x1, |
| 27 | kLocalCoord_GPFlag = 0x2, |
| 28 | kCoverage_GPFlag= 0x4, |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 31 | class DefaultGeoProc : public GrGeometryProcessor { |
| 32 | public: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 33 | static sk_sp<GrGeometryProcessor> Make(uint32_t gpTypeFlags, |
| 34 | GrColor color, |
| 35 | const SkMatrix& viewMatrix, |
| 36 | const SkMatrix& localMatrix, |
| 37 | bool localCoordsWillBeRead, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 38 | uint8_t coverage) { |
| 39 | return sk_sp<GrGeometryProcessor>(new DefaultGeoProc( |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 40 | gpTypeFlags, color, viewMatrix, localMatrix, coverage, localCoordsWillBeRead)); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 41 | } |
| 42 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 43 | const char* name() const override { return "DefaultGeometryProcessor"; } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 44 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 45 | const Attribute* inPosition() const { return fInPosition; } |
| 46 | const Attribute* inColor() const { return fInColor; } |
| 47 | const Attribute* inLocalCoords() const { return fInLocalCoords; } |
| 48 | const Attribute* inCoverage() const { return fInCoverage; } |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 49 | GrColor color() const { return fColor; } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 50 | bool hasVertexColor() const { return SkToBool(fInColor); } |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 51 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 52 | const SkMatrix& localMatrix() const { return fLocalMatrix; } |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 53 | bool localCoordsWillBeRead() const { return fLocalCoordsWillBeRead; } |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 54 | uint8_t coverage() const { return fCoverage; } |
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 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 57 | class GLSLProcessor : public GrGLSLGeometryProcessor { |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 58 | public: |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 59 | GLSLProcessor() |
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 | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 64 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 65 | GrGLSLPPFragmentBuilder* fragBuilder = args.fFragBuilder; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 66 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 67 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 68 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 69 | // emit attributes |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 70 | varyingHandler->emitAttributes(gp); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 71 | |
| 72 | // Setup pass through color |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 73 | if (gp.hasVertexColor()) { |
| 74 | varyingHandler->addPassThroughAttribute(gp.inColor(), args.fOutputColor); |
| 75 | } else { |
| 76 | this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, |
| 77 | &fColorUniform); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 78 | } |
| 79 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 80 | // Setup position |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 81 | this->setupPosition(vertBuilder, |
| 82 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 83 | gpArgs, |
| 84 | gp.inPosition()->fName, |
| 85 | gp.viewMatrix(), |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 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 |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 90 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 91 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 92 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 93 | gpArgs->fPositionVar, |
| 94 | gp.inLocalCoords()->fName, |
| 95 | gp.localMatrix(), |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 96 | args.fFPCoordTransformHandler); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 97 | } else { |
| 98 | // emit transforms with position |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 99 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 100 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 101 | uniformHandler, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 102 | gpArgs->fPositionVar, |
| 103 | gp.inPosition()->fName, |
| 104 | gp.localMatrix(), |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 105 | args.fFPCoordTransformHandler); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 106 | } |
| 107 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 108 | // Setup coverage as pass through |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 109 | if (gp.hasVertexCoverage()) { |
| 110 | fragBuilder->codeAppendf("float alpha = 1.0;"); |
| 111 | varyingHandler->addPassThroughAttribute(gp.inCoverage(), "alpha"); |
| 112 | fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
| 113 | } else if (gp.coverage() == 0xff) { |
| 114 | fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
| 115 | } else { |
| 116 | const char* fragCoverage; |
| 117 | fCoverageUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, |
| 118 | kFloat_GrSLType, |
| 119 | kDefault_GrSLPrecision, |
| 120 | "Coverage", |
| 121 | &fragCoverage); |
| 122 | fragBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, fragCoverage); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 123 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 124 | } |
| 125 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 126 | static inline void GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 127 | const GrShaderCaps&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 128 | GrProcessorKeyBuilder* b) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 129 | const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 130 | uint32_t key = def.fFlags; |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 131 | key |= def.hasVertexColor() << 8; |
| 132 | key |= def.hasVertexCoverage() << 9; |
| 133 | key |= (def.coverage() == 0xff) ? (0x1 << 10) : 0; |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 134 | key |= (def.localCoordsWillBeRead() && def.localMatrix().hasPerspective()) ? (0x1 << 24) |
| 135 | : 0x0; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 136 | key |= ComputePosKey(def.viewMatrix()) << 25; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 137 | b->add32(key); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 138 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 139 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 140 | void setData(const GrGLSLProgramDataManager& pdman, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 141 | const GrPrimitiveProcessor& gp, |
| 142 | FPCoordTransformIter&& transformIter) override { |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 143 | const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 144 | |
| 145 | if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp.viewMatrix())) { |
| 146 | fViewMatrix = dgp.viewMatrix(); |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 147 | float viewMatrix[3 * 3]; |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 148 | GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 149 | pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 150 | } |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 151 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 152 | if (dgp.color() != fColor && !dgp.hasVertexColor()) { |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 153 | float c[4]; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 154 | GrColorToRGBAFloat(dgp.color(), c); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 155 | pdman.set4fv(fColorUniform, 1, c); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 156 | fColor = dgp.color(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 157 | } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 158 | |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 159 | if (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 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 163 | this->setTransformDataHelper(dgp.fLocalMatrix, pdman, &transformIter); |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 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 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 174 | typedef GrGLSLGeometryProcessor INHERITED; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 175 | }; |
| 176 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 177 | void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override { |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 178 | GLSLProcessor::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 181 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override { |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 182 | return new GLSLProcessor(); |
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, |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 191 | bool localCoordsWillBeRead) |
| 192 | : fInPosition(nullptr) |
| 193 | , fInColor(nullptr) |
| 194 | , fInLocalCoords(nullptr) |
| 195 | , fInCoverage(nullptr) |
| 196 | , fColor(color) |
| 197 | , fViewMatrix(viewMatrix) |
| 198 | , fLocalMatrix(localMatrix) |
| 199 | , fCoverage(coverage) |
| 200 | , fFlags(gpTypeFlags) |
| 201 | , fLocalCoordsWillBeRead(localCoordsWillBeRead) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 202 | this->initClassID<DefaultGeoProc>(); |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 203 | bool hasColor = SkToBool(gpTypeFlags & kColor_GPFlag); |
| 204 | bool hasExplicitLocalCoords = SkToBool(gpTypeFlags & kLocalCoord_GPFlag); |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 205 | bool hasCoverage = SkToBool(gpTypeFlags & kCoverage_GPFlag); |
bsalomon | 6cb807b | 2016-08-17 11:33:39 -0700 | [diff] [blame] | 206 | fInPosition = &this->addVertexAttrib("inPosition", kVec2f_GrVertexAttribType, |
| 207 | kHigh_GrSLPrecision); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 208 | if (hasColor) { |
bsalomon | 6cb807b | 2016-08-17 11:33:39 -0700 | [diff] [blame] | 209 | fInColor = &this->addVertexAttrib("inColor", kVec4ub_GrVertexAttribType); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 210 | } |
bsalomon | cc6aeee | 2016-09-12 12:02:11 -0700 | [diff] [blame] | 211 | if (hasExplicitLocalCoords) { |
Brian Salomon | 9b345e3 | 2016-10-05 12:09:26 -0400 | [diff] [blame] | 212 | fInLocalCoords = &this->addVertexAttrib("inLocalCoord", kVec2f_GrVertexAttribType, |
| 213 | kHigh_GrSLPrecision); |
bsalomon | cc6aeee | 2016-09-12 12:02:11 -0700 | [diff] [blame] | 214 | this->setHasExplicitLocalCoords(); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 215 | } |
| 216 | if (hasCoverage) { |
bsalomon | 6cb807b | 2016-08-17 11:33:39 -0700 | [diff] [blame] | 217 | fInCoverage = &this->addVertexAttrib("inCoverage", 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; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 231 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 232 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 233 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 234 | typedef GrGeometryProcessor INHERITED; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); |
| 238 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 239 | sk_sp<GrGeometryProcessor> DefaultGeoProc::TestCreate(GrProcessorTestData* d) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 240 | uint32_t flags = 0; |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 241 | if (d->fRandom->nextBool()) { |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 242 | flags |= kColor_GPFlag; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 243 | } |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 244 | if (d->fRandom->nextBool()) { |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 245 | flags |= kCoverage_GPFlag; |
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 | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 248 | flags |= kLocalCoord_GPFlag; |
| 249 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 250 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 251 | return DefaultGeoProc::Make(flags, |
| 252 | GrRandomColor(d->fRandom), |
| 253 | GrTest::TestMatrix(d->fRandom), |
| 254 | GrTest::TestMatrix(d->fRandom), |
| 255 | d->fRandom->nextBool(), |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 256 | GrRandomCoverage(d->fRandom)); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 257 | } |
| 258 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 259 | sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::Make(const Color& color, |
| 260 | const Coverage& coverage, |
| 261 | const LocalCoords& localCoords, |
| 262 | const SkMatrix& viewMatrix) { |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 263 | uint32_t flags = 0; |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 264 | flags |= color.fType == Color::kAttribute_Type ? kColor_GPFlag : 0; |
| 265 | flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPFlag : 0; |
| 266 | flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_GPFlag : 0; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 267 | |
| 268 | uint8_t inCoverage = coverage.fCoverage; |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 269 | bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 270 | |
| 271 | GrColor inColor = color.fColor; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 272 | return DefaultGeoProc::Make(flags, |
| 273 | inColor, |
| 274 | viewMatrix, |
| 275 | localCoords.fMatrix ? *localCoords.fMatrix : SkMatrix::I(), |
| 276 | localCoordsWillBeRead, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 277 | inCoverage); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 278 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 279 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 280 | sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::MakeForDeviceSpace( |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 281 | const Color& color, |
| 282 | const Coverage& coverage, |
| 283 | const LocalCoords& localCoords, |
| 284 | const SkMatrix& viewMatrix) { |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 285 | SkMatrix invert = SkMatrix::I(); |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 286 | if (LocalCoords::kUnused_Type != localCoords.fType) { |
| 287 | SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType); |
| 288 | if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) { |
| 289 | SkDebugf("Could not invert\n"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 290 | return nullptr; |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 291 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 292 | |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 293 | if (localCoords.hasLocalMatrix()) { |
| 294 | invert.preConcat(*localCoords.fMatrix); |
| 295 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 299 | return Make(color, coverage, inverted, SkMatrix::I()); |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 300 | } |