| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrDefaultGeoProcFactory.h" | 8 #include "GrDefaultGeoProcFactory.h" |
| 9 | 9 |
| 10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
| 11 #include "SkRefCnt.h" |
| 11 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 12 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 12 #include "glsl/GrGLSLGeometryProcessor.h" | 13 #include "glsl/GrGLSLGeometryProcessor.h" |
| 13 #include "glsl/GrGLSLVertexShaderBuilder.h" | 14 #include "glsl/GrGLSLVertexShaderBuilder.h" |
| 14 #include "glsl/GrGLSLVarying.h" | 15 #include "glsl/GrGLSLVarying.h" |
| 15 #include "glsl/GrGLSLUniformHandler.h" | 16 #include "glsl/GrGLSLUniformHandler.h" |
| 16 #include "glsl/GrGLSLUtil.h" | 17 #include "glsl/GrGLSLUtil.h" |
| 17 | 18 |
| 18 /* | 19 /* |
| 19 * The default Geometry Processor simply takes position and multiplies it by the
uniform view | 20 * The default Geometry Processor simply takes position and multiplies it by the
uniform view |
| 20 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per
vertex color or | 21 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per
vertex color or |
| 21 * local coords. | 22 * local coords. |
| 22 */ | 23 */ |
| 23 | 24 |
| 24 enum GPFlag { | 25 enum GPFlag { |
| 25 kColor_GPFlag = 0x1, | 26 kColor_GPFlag = 0x1, |
| 26 kLocalCoord_GPFlag = 0x2, | 27 kLocalCoord_GPFlag = 0x2, |
| 27 kCoverage_GPFlag= 0x4, | 28 kCoverage_GPFlag= 0x4, |
| 28 kTransformedLocalCoord_GPFlag = 0x8, | 29 kTransformedLocalCoord_GPFlag = 0x8, |
| 29 }; | 30 }; |
| 30 | 31 |
| 31 class DefaultGeoProc : public GrGeometryProcessor { | 32 class DefaultGeoProc : public GrGeometryProcessor { |
| 32 public: | 33 public: |
| 33 static GrGeometryProcessor* Create(uint32_t gpTypeFlags, | 34 static sk_sp<GrGeometryProcessor> Make(uint32_t gpTypeFlags, |
| 34 GrColor color, | 35 GrColor color, |
| 35 const SkMatrix& viewMatrix, | 36 const SkMatrix& viewMatrix, |
| 36 const SkMatrix& localMatrix, | 37 const SkMatrix& localMatrix, |
| 37 bool localCoordsWillBeRead, | 38 bool localCoordsWillBeRead, |
| 38 bool coverageWillBeIgnored, | 39 bool coverageWillBeIgnored, |
| 39 uint8_t coverage) { | 40 uint8_t coverage) { |
| 40 return new DefaultGeoProc(gpTypeFlags, color, viewMatrix, localMatrix, c
overage, | 41 return sk_sp<GrGeometryProcessor>(new DefaultGeoProc( |
| 41 localCoordsWillBeRead, coverageWillBeIgnored); | 42 gpTypeFlags, color, viewMatrix, localMatrix, coverage, |
| 43 localCoordsWillBeRead, coverageWillBeIgnored)); |
| 42 } | 44 } |
| 43 | 45 |
| 44 const char* name() const override { return "DefaultGeometryProcessor"; } | 46 const char* name() const override { return "DefaultGeometryProcessor"; } |
| 45 | 47 |
| 46 const Attribute* inPosition() const { return fInPosition; } | 48 const Attribute* inPosition() const { return fInPosition; } |
| 47 const Attribute* inColor() const { return fInColor; } | 49 const Attribute* inColor() const { return fInColor; } |
| 48 const Attribute* inLocalCoords() const { return fInLocalCoords; } | 50 const Attribute* inLocalCoords() const { return fInLocalCoords; } |
| 49 const Attribute* inCoverage() const { return fInCoverage; } | 51 const Attribute* inCoverage() const { return fInCoverage; } |
| 50 GrColor color() const { return fColor; } | 52 GrColor color() const { return fColor; } |
| 51 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } | 53 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 bool fLocalCoordsWillBeRead; | 266 bool fLocalCoordsWillBeRead; |
| 265 bool fCoverageWillBeIgnored; | 267 bool fCoverageWillBeIgnored; |
| 266 | 268 |
| 267 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 269 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
| 268 | 270 |
| 269 typedef GrGeometryProcessor INHERITED; | 271 typedef GrGeometryProcessor INHERITED; |
| 270 }; | 272 }; |
| 271 | 273 |
| 272 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); | 274 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); |
| 273 | 275 |
| 274 const GrGeometryProcessor* DefaultGeoProc::TestCreate(GrProcessorTestData* d) { | 276 sk_sp<GrGeometryProcessor> DefaultGeoProc::TestCreate(GrProcessorTestData* d) { |
| 275 uint32_t flags = 0; | 277 uint32_t flags = 0; |
| 276 if (d->fRandom->nextBool()) { | 278 if (d->fRandom->nextBool()) { |
| 277 flags |= kColor_GPFlag; | 279 flags |= kColor_GPFlag; |
| 278 } | 280 } |
| 279 if (d->fRandom->nextBool()) { | 281 if (d->fRandom->nextBool()) { |
| 280 flags |= kCoverage_GPFlag; | 282 flags |= kCoverage_GPFlag; |
| 281 } | 283 } |
| 282 if (d->fRandom->nextBool()) { | 284 if (d->fRandom->nextBool()) { |
| 283 flags |= kLocalCoord_GPFlag; | 285 flags |= kLocalCoord_GPFlag; |
| 284 } | 286 } |
| 285 if (d->fRandom->nextBool()) { | 287 if (d->fRandom->nextBool()) { |
| 286 flags |= kTransformedLocalCoord_GPFlag; | 288 flags |= kTransformedLocalCoord_GPFlag; |
| 287 } | 289 } |
| 288 | 290 |
| 289 return DefaultGeoProc::Create(flags, | 291 return DefaultGeoProc::Make(flags, |
| 290 GrRandomColor(d->fRandom), | 292 GrRandomColor(d->fRandom), |
| 291 GrTest::TestMatrix(d->fRandom), | 293 GrTest::TestMatrix(d->fRandom), |
| 292 GrTest::TestMatrix(d->fRandom), | 294 GrTest::TestMatrix(d->fRandom), |
| 293 d->fRandom->nextBool(), | 295 d->fRandom->nextBool(), |
| 294 d->fRandom->nextBool(), | 296 d->fRandom->nextBool(), |
| 295 GrRandomCoverage(d->fRandom)); | 297 GrRandomCoverage(d->fRandom)); |
| 296 } | 298 } |
| 297 | 299 |
| 298 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(const Color& color, | 300 sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::Make(const Color& color, |
| 299 const Coverage& cover
age, | 301 const Coverage& coverag
e, |
| 300 const LocalCoords& lo
calCoords, | 302 const LocalCoords& loca
lCoords, |
| 301 const SkMatrix& viewM
atrix) { | 303 const SkMatrix& viewMat
rix) { |
| 302 uint32_t flags = 0; | 304 uint32_t flags = 0; |
| 303 flags |= color.fType == Color::kAttribute_Type ? kColor_GPFlag : 0; | 305 flags |= color.fType == Color::kAttribute_Type ? kColor_GPFlag : 0; |
| 304 flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPFlag : 0; | 306 flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPFlag : 0; |
| 305 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_G
PFlag : 0; | 307 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_G
PFlag : 0; |
| 306 flags |= localCoords.fType == LocalCoords::kHasTransformed_Type ? | 308 flags |= localCoords.fType == LocalCoords::kHasTransformed_Type ? |
| 307 kTransformedLocalCoord_GPFlag : 0; | 309 kTransformedLocalCoord_GPFlag : 0; |
| 308 | 310 |
| 309 uint8_t inCoverage = coverage.fCoverage; | 311 uint8_t inCoverage = coverage.fCoverage; |
| 310 bool coverageWillBeIgnored = coverage.fType == Coverage::kNone_Type; | 312 bool coverageWillBeIgnored = coverage.fType == Coverage::kNone_Type; |
| 311 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; | 313 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; |
| 312 | 314 |
| 313 GrColor inColor = color.fColor; | 315 GrColor inColor = color.fColor; |
| 314 return DefaultGeoProc::Create(flags, | 316 return DefaultGeoProc::Make(flags, |
| 315 inColor, | 317 inColor, |
| 316 viewMatrix, | 318 viewMatrix, |
| 317 localCoords.fMatrix ? *localCoords.fMatrix : S
kMatrix::I(), | 319 localCoords.fMatrix ? *localCoords.fMatrix : SkM
atrix::I(), |
| 318 localCoordsWillBeRead, | 320 localCoordsWillBeRead, |
| 319 coverageWillBeIgnored, | 321 coverageWillBeIgnored, |
| 320 inCoverage); | 322 inCoverage); |
| 321 } | 323 } |
| 322 | 324 |
| 323 const GrGeometryProcessor* GrDefaultGeoProcFactory::CreateForDeviceSpace( | 325 sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::MakeForDeviceSpace( |
| 324 const Color
& color, | 326 const Color
& color, |
| 325 const Cover
age& coverage, | 327 const Cover
age& coverage, |
| 326 const Local
Coords& localCoords, | 328 const Local
Coords& localCoords, |
| 327 const SkMat
rix& viewMatrix) { | 329 const SkMat
rix& viewMatrix) { |
| 328 SkMatrix invert = SkMatrix::I(); | 330 SkMatrix invert = SkMatrix::I(); |
| 329 if (LocalCoords::kUnused_Type != localCoords.fType) { | 331 if (LocalCoords::kUnused_Type != localCoords.fType) { |
| 330 SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType); | 332 SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType); |
| 331 if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) { | 333 if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) { |
| 332 SkDebugf("Could not invert\n"); | 334 SkDebugf("Could not invert\n"); |
| 333 return nullptr; | 335 return nullptr; |
| 334 } | 336 } |
| 335 | 337 |
| 336 if (localCoords.hasLocalMatrix()) { | 338 if (localCoords.hasLocalMatrix()) { |
| 337 invert.preConcat(*localCoords.fMatrix); | 339 invert.preConcat(*localCoords.fMatrix); |
| 338 } | 340 } |
| 339 } | 341 } |
| 340 | 342 |
| 341 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); | 343 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
| 342 return Create(color, coverage, inverted, SkMatrix::I()); | 344 return Make(color, coverage, inverted, SkMatrix::I()); |
| 343 } | 345 } |
| OLD | NEW |