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/GrColorSpaceXform.h" 12 #include "src/gpu/GrGeometryProcessor.h" 13 #include "src/gpu/GrShaderCaps.h" 14 15 /* 16 * A factory for creating default Geometry Processors which simply multiply position by the uniform 17 * view matrix and wire through color, coverage, UV coords if requested. 18 */ 19 namespace GrDefaultGeoProcFactory { 20 struct Color { 21 enum Type { 22 kPremulGrColorUniform_Type, 23 kPremulGrColorAttribute_Type, 24 kPremulWideColorAttribute_Type, 25 kUnpremulSkColorAttribute_Type, 26 }; ColorColor27 explicit Color(const SkPMColor4f& color) 28 : fType(kPremulGrColorUniform_Type) 29 , fColor(color) 30 , fColorSpaceXform(nullptr) {} ColorColor31 Color(Type type) 32 : fType(type) 33 , fColor(SK_PMColor4fILLEGAL) 34 , fColorSpaceXform(nullptr) { 35 SkASSERT(type != kPremulGrColorUniform_Type); 36 } 37 38 Type fType; 39 SkPMColor4f fColor; 40 41 // This only applies to SkColor. Any GrColors are assumed to have been color converted 42 // during paint conversion. 43 sk_sp<GrColorSpaceXform> fColorSpaceXform; 44 }; 45 46 struct Coverage { 47 enum Type { 48 kSolid_Type, 49 kUniform_Type, 50 kAttribute_Type, 51 kAttributeTweakAlpha_Type, 52 }; CoverageCoverage53 explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} CoverageCoverage54 Coverage(Type type) : fType(type), fCoverage(0xff) { 55 SkASSERT(type != kUniform_Type); 56 } 57 58 Type fType; 59 uint8_t fCoverage; 60 }; 61 62 struct LocalCoords { 63 enum Type { 64 kUnused_Type, 65 kUsePosition_Type, 66 kHasExplicit_Type, 67 kHasTransformed_Type, 68 }; LocalCoordsLocalCoords69 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} LocalCoordsLocalCoords70 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { 71 SkASSERT(kUnused_Type != type); 72 } hasLocalMatrixLocalCoords73 bool hasLocalMatrix() const { return nullptr != fMatrix; } 74 75 Type fType; 76 const SkMatrix* fMatrix; 77 }; 78 79 sk_sp<GrGeometryProcessor> Make(const GrShaderCaps*, 80 const Color&, 81 const Coverage&, 82 const LocalCoords&, 83 const SkMatrix& viewMatrix); 84 85 /* 86 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position 87 * attribute. The view matrix must still be provided to compute correctly transformed 88 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. 89 */ 90 sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const GrShaderCaps*, 91 const Color&, 92 const Coverage&, 93 const LocalCoords&, 94 const SkMatrix& viewMatrix); 95 }; 96 97 #endif 98