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