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 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 11 | #include "GrColorSpaceXform.h" |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 12 | #include "GrGeometryProcessor.h" |
| 13 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 14 | /* |
| 15 | * 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] | 16 | * view matrix and wire through color, coverage, UV coords if requested. |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 17 | */ |
joshualitt | 7a0d697 | 2015-07-28 10:20:08 -0700 | [diff] [blame] | 18 | namespace GrDefaultGeoProcFactory { |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 19 | // Structs for adding vertex attributes |
| 20 | struct PositionAttr { |
| 21 | SkPoint fPosition; |
| 22 | }; |
| 23 | |
| 24 | struct PositionCoverageAttr { |
| 25 | SkPoint fPosition; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 26 | float fCoverage; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | struct PositionColorAttr { |
| 30 | SkPoint fPosition; |
| 31 | SkColor fColor; |
| 32 | }; |
| 33 | |
| 34 | struct PositionColorCoverageAttr { |
| 35 | SkPoint fPosition; |
| 36 | SkColor fColor; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 37 | float fCoverage; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | struct PositionLocalCoordAttr { |
| 41 | SkPoint fPosition; |
| 42 | SkPoint fLocalCoord; |
| 43 | }; |
| 44 | |
| 45 | struct PositionLocalCoordCoverageAttr { |
| 46 | SkPoint fPosition; |
| 47 | SkPoint fLocalCoord; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 48 | float fCoverage; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | struct PositionColorLocalCoordAttr { |
| 52 | SkPoint fPosition; |
| 53 | GrColor fColor; |
| 54 | SkPoint fLocalCoord; |
| 55 | }; |
| 56 | |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 57 | struct PositionColorLocalCoordCoverageAttr { |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 58 | SkPoint fPosition; |
| 59 | GrColor fColor; |
| 60 | SkPoint fLocalCoord; |
senorblanco | f57372d | 2016-08-31 10:36:19 -0700 | [diff] [blame] | 61 | float fCoverage; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 64 | struct Color { |
| 65 | enum Type { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 66 | kPremulGrColorUniform_Type, |
| 67 | kPremulGrColorAttribute_Type, |
| 68 | kUnpremulSkColorAttribute_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 69 | }; |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 70 | explicit Color(GrColor color) |
| 71 | : fType(kPremulGrColorUniform_Type) |
| 72 | , fColor(color) |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 73 | , fColorSpaceXform(nullptr) {} |
| 74 | Color(Type type) |
| 75 | : fType(type) |
| 76 | , fColor(GrColor_ILLEGAL) |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 77 | , fColorSpaceXform(nullptr) { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 78 | SkASSERT(type != kPremulGrColorUniform_Type); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | Type fType; |
| 82 | GrColor fColor; |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 83 | |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 84 | // This only applies to SkColor. Any GrColors are assumed to have been color converted |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 85 | // during paint conversion. |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 86 | sk_sp<GrColorSpaceXform> fColorSpaceXform; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | struct Coverage { |
| 90 | enum Type { |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 91 | kSolid_Type, |
| 92 | kUniform_Type, |
| 93 | kAttribute_Type, |
| 94 | }; |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 95 | explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 96 | Coverage(Type type) : fType(type), fCoverage(0xff) { |
| 97 | SkASSERT(type != kUniform_Type); |
| 98 | } |
| 99 | |
| 100 | Type fType; |
| 101 | uint8_t fCoverage; |
| 102 | }; |
| 103 | |
| 104 | struct LocalCoords { |
| 105 | enum Type { |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 106 | kUnused_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 107 | kUsePosition_Type, |
| 108 | kHasExplicit_Type, |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 109 | kHasTransformed_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 110 | }; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 111 | LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 112 | LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { |
| 113 | SkASSERT(kUnused_Type != type); |
| 114 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 115 | bool hasLocalMatrix() const { return nullptr != fMatrix; } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 116 | |
| 117 | Type fType; |
| 118 | const SkMatrix* fMatrix; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 121 | struct Bones { |
| 122 | Bones(const float bones[], int boneCount) |
| 123 | : fBones(bones) |
| 124 | , fBoneCount(boneCount) {} |
| 125 | |
| 126 | const float* fBones; |
| 127 | int fBoneCount; |
| 128 | }; |
| 129 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 130 | sk_sp<GrGeometryProcessor> Make(const Color&, |
| 131 | const Coverage&, |
| 132 | const LocalCoords&, |
| 133 | const SkMatrix& viewMatrix); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 134 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 135 | /* |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 136 | * Use this factory to create a GrGeometryProcessor that expects a device space vertex position |
| 137 | * attribute. The view matrix must still be provided to compute correctly transformed |
| 138 | * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 139 | */ |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 140 | sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const Color&, |
| 141 | const Coverage&, |
| 142 | const LocalCoords&, |
| 143 | const SkMatrix& viewMatrix); |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * Use this factory to create a GrGeometryProcessor that supports skeletal animation through |
| 147 | * deformation of vertices using matrices that are passed in. This should only be called from |
| 148 | * GrDrawVerticesOp. |
| 149 | */ |
| 150 | sk_sp<GrGeometryProcessor> MakeWithBones(const Color&, |
| 151 | const Coverage&, |
| 152 | const LocalCoords&, |
| 153 | const Bones&, |
| 154 | const SkMatrix& viewMatrix); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | #endif |