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 #ifndef GrDefaultGeoProcFactory_DEFINED 9 #define GrDefaultGeoProcFactory_DEFINED 10 11 #include "src/gpu/ganesh/GrGeometryProcessor.h" 12 13 /* 14 * A factory for creating default Geometry Processors which simply multiply position by the uniform 15 * view matrix and wire through color, coverage, UV coords if requested. 16 */ 17 namespace GrDefaultGeoProcFactory { 18 struct Color { 19 enum Type { 20 kPremulGrColorUniform_Type, 21 kPremulGrColorAttribute_Type, 22 kPremulWideColorAttribute_Type, 23 }; ColorColor24 explicit Color(const SkPMColor4f& color) 25 : fType(kPremulGrColorUniform_Type) 26 , fColor(color) {} ColorColor27 Color(Type type) 28 : fType(type) 29 , fColor(SK_PMColor4fILLEGAL) { 30 SkASSERT(type != kPremulGrColorUniform_Type); 31 } 32 33 Type fType; 34 SkPMColor4f fColor; 35 }; 36 37 struct Coverage { 38 enum Type { 39 kSolid_Type, 40 kUniform_Type, 41 kAttribute_Type, 42 kAttributeTweakAlpha_Type, 43 kAttributeUnclamped_Type, // Fragment shader will call saturate(coverage) before using. 44 // (Not compatible with kAttributeTweakAlpha_Type.) 45 }; CoverageCoverage46 explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} CoverageCoverage47 Coverage(Type type) : fType(type), fCoverage(0xff) { 48 SkASSERT(type != kUniform_Type); 49 } 50 51 Type fType; 52 uint8_t fCoverage; 53 }; 54 55 struct LocalCoords { 56 enum Type { 57 kUnused_Type, 58 kUsePosition_Type, 59 kHasExplicit_Type, 60 }; LocalCoordsLocalCoords61 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} LocalCoordsLocalCoords62 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { 63 SkASSERT(kUnused_Type != type); 64 } hasLocalMatrixLocalCoords65 bool hasLocalMatrix() const { return nullptr != fMatrix; } 66 67 Type fType; 68 const SkMatrix* fMatrix; 69 }; 70 71 GrGeometryProcessor* Make(SkArenaAlloc*, 72 const Color&, 73 const Coverage&, 74 const LocalCoords&, 75 const SkMatrix& viewMatrix); 76 77 /* 78 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position 79 * attribute. The view matrix must still be provided to compute correctly transformed 80 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. 81 */ 82 GrGeometryProcessor* MakeForDeviceSpace(SkArenaAlloc*, 83 const Color&, 84 const Coverage&, 85 const LocalCoords&, 86 const SkMatrix& viewMatrix); 87 } // namespace GrDefaultGeoProcFactory 88 89 #endif 90