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 | #ifndef GrDefaultGeoProcFactory_DEFINED |
| 9 | #define GrDefaultGeoProcFactory_DEFINED |
| 10 | |
| 11 | #include "GrGeometryProcessor.h" |
| 12 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 13 | /* |
| 14 | * A factory for creating default Geometry Processors which simply multiply position by the uniform |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 15 | * view matrix and wire through color, coverage, UV coords if requested. |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 16 | */ |
joshualitt | 7a0d697 | 2015-07-28 10:20:08 -0700 | [diff] [blame] | 17 | namespace GrDefaultGeoProcFactory { |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 18 | // Structs for adding vertex attributes |
| 19 | struct PositionAttr { |
| 20 | SkPoint fPosition; |
| 21 | }; |
| 22 | |
| 23 | struct PositionCoverageAttr { |
| 24 | SkPoint fPosition; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 25 | float fCoverage; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | struct PositionColorAttr { |
| 29 | SkPoint fPosition; |
| 30 | SkColor fColor; |
| 31 | }; |
| 32 | |
| 33 | struct PositionColorCoverageAttr { |
| 34 | SkPoint fPosition; |
| 35 | SkColor fColor; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 36 | float fCoverage; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | struct PositionLocalCoordAttr { |
| 40 | SkPoint fPosition; |
| 41 | SkPoint fLocalCoord; |
| 42 | }; |
| 43 | |
| 44 | struct PositionLocalCoordCoverageAttr { |
| 45 | SkPoint fPosition; |
| 46 | SkPoint fLocalCoord; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 47 | float fCoverage; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | struct PositionColorLocalCoordAttr { |
| 51 | SkPoint fPosition; |
| 52 | GrColor fColor; |
| 53 | SkPoint fLocalCoord; |
| 54 | }; |
| 55 | |
| 56 | struct PositionColorLocalCoordCoverage { |
| 57 | SkPoint fPosition; |
| 58 | GrColor fColor; |
| 59 | SkPoint fLocalCoord; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 60 | float fCoverage; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 63 | struct Color { |
| 64 | enum Type { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 65 | kPremulGrColorUniform_Type, |
| 66 | kPremulGrColorAttribute_Type, |
| 67 | kUnpremulSkColorAttribute_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 68 | }; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 69 | explicit Color(GrColor color) : fType(kPremulGrColorUniform_Type), fColor(color) {} |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 70 | Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 71 | SkASSERT(type != kPremulGrColorUniform_Type); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | Type fType; |
| 75 | GrColor fColor; |
| 76 | }; |
| 77 | |
| 78 | struct Coverage { |
| 79 | enum Type { |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 80 | kSolid_Type, |
| 81 | kUniform_Type, |
| 82 | kAttribute_Type, |
| 83 | }; |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 84 | explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 85 | Coverage(Type type) : fType(type), fCoverage(0xff) { |
| 86 | SkASSERT(type != kUniform_Type); |
| 87 | } |
| 88 | |
| 89 | Type fType; |
| 90 | uint8_t fCoverage; |
| 91 | }; |
| 92 | |
| 93 | struct LocalCoords { |
| 94 | enum Type { |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 95 | kUnused_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 96 | kUsePosition_Type, |
| 97 | kHasExplicit_Type, |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 98 | kHasTransformed_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 99 | }; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 100 | LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 101 | LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { |
| 102 | SkASSERT(kUnused_Type != type); |
| 103 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 104 | bool hasLocalMatrix() const { return nullptr != fMatrix; } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 105 | |
| 106 | Type fType; |
| 107 | const SkMatrix* fMatrix; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 110 | sk_sp<GrGeometryProcessor> Make(const Color&, |
| 111 | const Coverage&, |
| 112 | const LocalCoords&, |
| 113 | const SkMatrix& viewMatrix); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 114 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 115 | /* |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 116 | * Use this factory to create a GrGeometryProcessor that expects a device space vertex position |
| 117 | * attribute. The view matrix must still be provided to compute correctly transformed |
| 118 | * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 119 | */ |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 120 | sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const Color&, |
| 121 | const Coverage&, |
| 122 | const LocalCoords&, |
| 123 | const SkMatrix& viewMatrix); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | #endif |