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, |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 27 | bool opaqueVertexColors, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 28 | uint8_t coverage) { |
| 29 | return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, |
| 30 | color, |
| 31 | viewMatrix, |
| 32 | localMatrix, |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 33 | opaqueVertexColors, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 34 | coverage)); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 35 | } |
| 36 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 37 | const char* name() const override { return "DefaultGeometryProcessor"; } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 38 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 39 | const Attribute* inPosition() const { return fInPosition; } |
| 40 | const Attribute* inColor() const { return fInColor; } |
| 41 | const Attribute* inLocalCoords() const { return fInLocalCoords; } |
| 42 | const Attribute* inCoverage() const { return fInCoverage; } |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 43 | uint8_t coverage() const { return fCoverage; } |
| 44 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 45 | void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 46 | BatchTracker* local = bt->cast<BatchTracker>(); |
| 47 | local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, |
| 48 | SkToBool(fInColor)); |
| 49 | |
| 50 | bool hasVertexCoverage = SkToBool(fInCoverage) && !init.fCoverageIgnored; |
| 51 | bool covIsSolidWhite = !hasVertexCoverage && 0xff == this->coverage(); |
egdaniel | 7dfc27c | 2015-05-08 12:48:35 -0700 | [diff] [blame] | 52 | if (init.fCoverageIgnored) { |
| 53 | local->fInputCoverageType = kIgnored_GrGPInput; |
| 54 | } else if (covIsSolidWhite) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 55 | local->fInputCoverageType = kAllOnes_GrGPInput; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 56 | } else if (hasVertexCoverage) { |
| 57 | SkASSERT(fInCoverage); |
| 58 | local->fInputCoverageType = kAttribute_GrGPInput; |
| 59 | } else { |
egdaniel | 7dfc27c | 2015-05-08 12:48:35 -0700 | [diff] [blame] | 60 | local->fInputCoverageType = kUniform_GrGPInput; |
| 61 | local->fCoverage = this->coverage(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 62 | } |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 63 | local->fUsesLocalCoords = init.fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 64 | } |
| 65 | |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 66 | bool onCanMakeEqual(const GrBatchTracker& m, |
| 67 | const GrGeometryProcessor& that, |
| 68 | const GrBatchTracker& t) const override { |
| 69 | const BatchTracker& mine = m.cast<BatchTracker>(); |
| 70 | const BatchTracker& theirs = t.cast<BatchTracker>(); |
| 71 | return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 72 | that, theirs.fUsesLocalCoords) && |
| 73 | CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 74 | theirs.fInputColorType, theirs.fColor) && |
| 75 | CanCombineOutput(mine.fInputCoverageType, mine.fCoverage, |
| 76 | theirs.fInputCoverageType, theirs.fCoverage); |
| 77 | } |
| 78 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 79 | class GLProcessor : public GrGLGeometryProcessor { |
| 80 | public: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 81 | GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&) |
| 82 | : fColor(GrColor_ILLEGAL), fCoverage(0xff) {} |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 83 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 84 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 85 | const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 86 | GrGLGPBuilder* pb = args.fPB; |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 87 | GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
egdaniel | 29bee0f | 2015-04-29 11:54:42 -0700 | [diff] [blame] | 88 | GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 89 | const BatchTracker& local = args.fBT.cast<BatchTracker>(); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 90 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 91 | // emit attributes |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 92 | vsBuilder->emitAttributes(gp); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 93 | |
| 94 | // Setup pass through color |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 95 | this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, gp.inColor(), |
| 96 | &fColorUniform); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 97 | // Setup position |
joshualitt | dd21987 | 2015-02-12 14:48:42 -0800 | [diff] [blame] | 98 | this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatrix()); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 99 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 100 | if (gp.inLocalCoords()) { |
| 101 | // emit transforms with explicit local coords |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 102 | this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords()->fName, |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 103 | gp.localMatrix(), args.fTransformsIn, args.fTransformsOut); |
| 104 | } else { |
| 105 | // emit transforms with position |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 106 | this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 107 | gp.localMatrix(), args.fTransformsIn, args.fTransformsOut); |
| 108 | } |
| 109 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 110 | // Setup coverage as pass through |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 111 | if (kUniform_GrGPInput == local.fInputCoverageType) { |
| 112 | const char* fragCoverage; |
| 113 | fCoverageUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
| 114 | kFloat_GrSLType, |
| 115 | kDefault_GrSLPrecision, |
| 116 | "Coverage", |
| 117 | &fragCoverage); |
| 118 | fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, fragCoverage); |
| 119 | } else if (kAttribute_GrGPInput == local.fInputCoverageType) { |
| 120 | SkASSERT(gp.inCoverage()); |
| 121 | fs->codeAppendf("float alpha = 1.0;"); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 122 | args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha"); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 123 | fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
| 124 | } else if (kAllOnes_GrGPInput == local.fInputCoverageType) { |
| 125 | fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 126 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 127 | } |
| 128 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 129 | static inline void GenKey(const GrGeometryProcessor& gp, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 130 | const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 131 | const GrGLSLCaps&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 132 | GrProcessorKeyBuilder* b) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 133 | const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 134 | const BatchTracker& local = bt.cast<BatchTracker>(); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 135 | uint32_t key = def.fFlags; |
| 136 | key |= local.fInputColorType << 8 | local.fInputCoverageType << 16; |
| 137 | key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24 : 0x0; |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 138 | key |= ComputePosKey(gp.viewMatrix()) << 25; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 139 | b->add32(key); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 140 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 141 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 142 | virtual void setData(const GrGLProgramDataManager& pdman, |
| 143 | const GrPrimitiveProcessor& gp, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 144 | const GrBatchTracker& bt) override { |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 145 | this->setUniformViewMatrix(pdman, gp.viewMatrix()); |
| 146 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 147 | const BatchTracker& local = bt.cast<BatchTracker>(); |
| 148 | if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 149 | GrGLfloat c[4]; |
| 150 | GrColorToRGBAFloat(local.fColor, c); |
| 151 | pdman.set4fv(fColorUniform, 1, c); |
| 152 | fColor = local.fColor; |
| 153 | } |
| 154 | if (kUniform_GrGPInput == local.fInputCoverageType && local.fCoverage != fCoverage) { |
| 155 | pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(local.fCoverage)); |
| 156 | fCoverage = local.fCoverage; |
| 157 | } |
| 158 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 159 | |
| 160 | private: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 161 | GrColor fColor; |
| 162 | uint8_t fCoverage; |
| 163 | UniformHandle fColorUniform; |
| 164 | UniformHandle fCoverageUniform; |
| 165 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 166 | typedef GrGLGeometryProcessor INHERITED; |
| 167 | }; |
| 168 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 169 | virtual void getGLProcessorKey(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 170 | const GrGLSLCaps& caps, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 171 | GrProcessorKeyBuilder* b) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 172 | GLProcessor::GenKey(*this, bt, caps, b); |
| 173 | } |
| 174 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 175 | virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 176 | const GrGLSLCaps&) const override { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 177 | return SkNEW_ARGS(GLProcessor, (*this, bt)); |
| 178 | } |
| 179 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 180 | private: |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 181 | DefaultGeoProc(uint32_t gpTypeFlags, |
| 182 | GrColor color, |
| 183 | const SkMatrix& viewMatrix, |
| 184 | const SkMatrix& localMatrix, |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 185 | bool opaqueVertexColors, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 186 | uint8_t coverage) |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 187 | : INHERITED(color, viewMatrix, localMatrix, opaqueVertexColors) |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 188 | , fInPosition(NULL) |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 189 | , fInColor(NULL) |
| 190 | , fInLocalCoords(NULL) |
| 191 | , fInCoverage(NULL) |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 192 | , fCoverage(coverage) |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 193 | , fFlags(gpTypeFlags) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 194 | this->initClassID<DefaultGeoProc>(); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 195 | bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_GPType); |
| 196 | bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLocalCoord_GPType); |
| 197 | bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCoverage_GPType); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 198 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 199 | if (hasColor) { |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 200 | fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType)); |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 201 | this->setHasVertexColor(); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 202 | } |
| 203 | if (hasLocalCoord) { |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 204 | fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 205 | kVec2f_GrVertexAttribType)); |
| 206 | this->setHasLocalCoords(); |
| 207 | } |
| 208 | if (hasCoverage) { |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 209 | fInCoverage = &this->addVertexAttrib(Attribute("inCoverage", |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 210 | kFloat_GrVertexAttribType)); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 211 | } |
| 212 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 213 | |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 214 | bool onIsEqual(const GrGeometryProcessor& other) const override { |
| 215 | const DefaultGeoProc& gp = other.cast<DefaultGeoProc>(); |
| 216 | return gp.fFlags == this->fFlags; |
| 217 | } |
| 218 | |
| 219 | void onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 220 | if (fInCoverage) { |
| 221 | out->setUnknownSingleComponent(); |
| 222 | } else { |
| 223 | // uniform coverage |
| 224 | out->setKnownSingleComponent(this->coverage()); |
| 225 | } |
| 226 | } |
| 227 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 228 | struct BatchTracker { |
| 229 | GrGPInput fInputColorType; |
| 230 | GrGPInput fInputCoverageType; |
| 231 | GrColor fColor; |
| 232 | GrColor fCoverage; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 233 | bool fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 234 | }; |
| 235 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 236 | const Attribute* fInPosition; |
| 237 | const Attribute* fInColor; |
| 238 | const Attribute* fInLocalCoords; |
| 239 | const Attribute* fInCoverage; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 240 | uint8_t fCoverage; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 241 | uint32_t fFlags; |
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 | |
| 250 | GrGeometryProcessor* DefaultGeoProc::TestCreate(SkRandom* random, |
| 251 | GrContext*, |
| 252 | const GrDrawTargetCaps& caps, |
| 253 | GrTexture*[]) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 254 | uint32_t flags = 0; |
| 255 | if (random->nextBool()) { |
| 256 | flags |= GrDefaultGeoProcFactory::kColor_GPType; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 257 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 258 | if (random->nextBool()) { |
| 259 | flags |= GrDefaultGeoProcFactory::kCoverage_GPType; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 260 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 261 | if (random->nextBool()) { |
| 262 | flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; |
| 263 | } |
| 264 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 265 | return DefaultGeoProc::Create(flags, |
| 266 | GrRandomColor(random), |
joshualitt | 4eaf9ce | 2015-04-28 13:31:18 -0700 | [diff] [blame] | 267 | GrTest::TestMatrix(random), |
| 268 | GrTest::TestMatrix(random), |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 269 | random->nextBool(), |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 270 | GrRandomCoverage(random)); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 271 | } |
| 272 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 273 | const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(uint32_t gpTypeFlags, |
| 274 | GrColor color, |
| 275 | const SkMatrix& viewMatrix, |
| 276 | const SkMatrix& localMatrix, |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 277 | bool opaqueVertexColors, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 278 | uint8_t coverage) { |
| 279 | return DefaultGeoProc::Create(gpTypeFlags, |
| 280 | color, |
| 281 | viewMatrix, |
| 282 | localMatrix, |
joshualitt | 50cb76b | 2015-04-28 09:17:05 -0700 | [diff] [blame] | 283 | opaqueVertexColors, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 284 | coverage); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 285 | } |