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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrColorSpaceXform.h" |
| 12 | #include "src/gpu/GrGeometryProcessor.h" |
| 13 | #include "src/gpu/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 | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 20 | struct Color { |
| 21 | enum Type { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 22 | kPremulGrColorUniform_Type, |
| 23 | kPremulGrColorAttribute_Type, |
Brian Osman | 2a4c4df | 2018-12-20 14:06:54 -0500 | [diff] [blame] | 24 | kPremulWideColorAttribute_Type, |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 25 | kUnpremulSkColorAttribute_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 26 | }; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 27 | explicit Color(const SkPMColor4f& color) |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 28 | : fType(kPremulGrColorUniform_Type) |
| 29 | , fColor(color) |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 30 | , fColorSpaceXform(nullptr) {} |
| 31 | Color(Type type) |
| 32 | : fType(type) |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 33 | , fColor(SK_PMColor4fILLEGAL) |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 34 | , fColorSpaceXform(nullptr) { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 35 | SkASSERT(type != kPremulGrColorUniform_Type); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | Type fType; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 39 | SkPMColor4f fColor; |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 40 | |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 41 | // 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] | 42 | // during paint conversion. |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 43 | sk_sp<GrColorSpaceXform> fColorSpaceXform; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | struct Coverage { |
| 47 | enum Type { |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 48 | kSolid_Type, |
| 49 | kUniform_Type, |
| 50 | kAttribute_Type, |
Brian Osman | 80879d4 | 2019-01-07 16:15:27 -0500 | [diff] [blame] | 51 | kAttributeTweakAlpha_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 52 | }; |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 53 | explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 54 | 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 { |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 64 | kUnused_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 65 | kUsePosition_Type, |
| 66 | kHasExplicit_Type, |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 67 | kHasTransformed_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 68 | }; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 69 | LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 70 | LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { |
| 71 | SkASSERT(kUnused_Type != type); |
| 72 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 73 | bool hasLocalMatrix() const { return nullptr != fMatrix; } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 74 | |
| 75 | Type fType; |
| 76 | const SkMatrix* fMatrix; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 79 | sk_sp<GrGeometryProcessor> Make(const GrShaderCaps*, |
| 80 | const Color&, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 81 | const Coverage&, |
| 82 | const LocalCoords&, |
| 83 | const SkMatrix& viewMatrix); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 84 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 85 | /* |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 86 | * Use this factory to create a GrGeometryProcessor that expects a device space vertex position |
| 87 | * attribute. The view matrix must still be provided to compute correctly transformed |
| 88 | * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 89 | */ |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 90 | sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const GrShaderCaps*, |
| 91 | const Color&, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 92 | const Coverage&, |
| 93 | const LocalCoords&, |
| 94 | const SkMatrix& viewMatrix); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | #endif |