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 { |
| 65 | kNone_Type, |
| 66 | kUniform_Type, |
| 67 | kAttribute_Type, |
| 68 | }; |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 69 | explicit Color(GrColor color) : fType(kUniform_Type), fColor(color) {} |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 70 | Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) { |
| 71 | SkASSERT(type != kUniform_Type); |
| 72 | |
| 73 | // TODO This is temporary |
| 74 | if (kAttribute_Type == type) { |
| 75 | fColor = GrColor_WHITE; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | Type fType; |
| 80 | GrColor fColor; |
| 81 | }; |
| 82 | |
| 83 | struct Coverage { |
| 84 | enum Type { |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 85 | kSolid_Type, |
| 86 | kUniform_Type, |
| 87 | kAttribute_Type, |
| 88 | }; |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 89 | explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 90 | Coverage(Type type) : fType(type), fCoverage(0xff) { |
| 91 | SkASSERT(type != kUniform_Type); |
| 92 | } |
| 93 | |
| 94 | Type fType; |
| 95 | uint8_t fCoverage; |
| 96 | }; |
| 97 | |
| 98 | struct LocalCoords { |
| 99 | enum Type { |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 100 | kUnused_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 101 | kUsePosition_Type, |
| 102 | kHasExplicit_Type, |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 103 | kHasTransformed_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 104 | }; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 105 | LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 106 | LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { |
| 107 | SkASSERT(kUnused_Type != type); |
| 108 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 109 | bool hasLocalMatrix() const { return nullptr != fMatrix; } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 110 | |
| 111 | Type fType; |
| 112 | const SkMatrix* fMatrix; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 113 | }; |
| 114 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 115 | sk_sp<GrGeometryProcessor> Make(const Color&, |
| 116 | const Coverage&, |
| 117 | const LocalCoords&, |
| 118 | const SkMatrix& viewMatrix); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 119 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 120 | /* |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 121 | * Use this factory to create a GrGeometryProcessor that expects a device space vertex position |
| 122 | * attribute. The view matrix must still be provided to compute correctly transformed |
| 123 | * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 124 | */ |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 125 | sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const Color&, |
| 126 | const Coverage&, |
| 127 | const LocalCoords&, |
| 128 | const SkMatrix& viewMatrix); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | #endif |