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 "include/private/SkColorData.h" 12 #include "include/private/base/SkAssert.h" 13 14 #include <cstdint> 15 16 class GrGeometryProcessor; 17 class SkArenaAlloc; 18 class SkMatrix; 19 20 /* 21 * A factory for creating default Geometry Processors which simply multiply position by the uniform 22 * view matrix and wire through color, coverage, UV coords if requested. 23 */ 24 namespace GrDefaultGeoProcFactory { 25 struct Color { 26 enum Type { 27 kPremulGrColorUniform_Type, 28 kPremulGrColorAttribute_Type, 29 kPremulWideColorAttribute_Type, 30 }; ColorColor31 explicit Color(const SkPMColor4f& color) 32 : fType(kPremulGrColorUniform_Type) 33 , fColor(color) {} ColorColor34 Color(Type type) 35 : fType(type) 36 , fColor(SK_PMColor4fILLEGAL) { 37 SkASSERT(type != kPremulGrColorUniform_Type); 38 } 39 40 Type fType; 41 SkPMColor4f fColor; 42 }; 43 44 struct Coverage { 45 enum Type { 46 kSolid_Type, 47 kUniform_Type, 48 kAttribute_Type, 49 kAttributeTweakAlpha_Type, 50 kAttributeUnclamped_Type, // Fragment shader will call saturate(coverage) before using. 51 // (Not compatible with 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 }; LocalCoordsLocalCoords68 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} LocalCoordsLocalCoords69 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { 70 SkASSERT(kUnused_Type != type); 71 } hasLocalMatrixLocalCoords72 bool hasLocalMatrix() const { return nullptr != fMatrix; } 73 74 Type fType; 75 const SkMatrix* fMatrix; 76 }; 77 78 GrGeometryProcessor* Make(SkArenaAlloc*, 79 const Color&, 80 const Coverage&, 81 const LocalCoords&, 82 const SkMatrix& viewMatrix); 83 84 /* 85 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position 86 * attribute. The view matrix must still be provided to compute correctly transformed 87 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. 88 */ 89 GrGeometryProcessor* MakeForDeviceSpace(SkArenaAlloc*, 90 const Color&, 91 const Coverage&, 92 const LocalCoords&, 93 const SkMatrix& viewMatrix); 94 } // namespace GrDefaultGeoProcFactory 95 96 #endif 97