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 | #include "GrDefaultGeoProcFactory.h" |
| 9 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 10 | #include "GrCaps.h" |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 11 | #include "SkRefCnt.h" |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 12 | #include "glsl/GrGLSLColorSpaceXformHelper.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 13 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 14 | #include "glsl/GrGLSLGeometryProcessor.h" |
Chris Dalton | c17bf32 | 2017-10-24 10:59:03 -0600 | [diff] [blame] | 15 | #include "glsl/GrGLSLVertexGeoBuilder.h" |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 16 | #include "glsl/GrGLSLVarying.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 17 | #include "glsl/GrGLSLUniformHandler.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 18 | #include "glsl/GrGLSLUtil.h" |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 19 | |
| 20 | /* |
| 21 | * The default Geometry Processor simply takes position and multiplies it by the uniform view |
| 22 | * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or |
| 23 | * local coords. |
| 24 | */ |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 25 | |
| 26 | enum GPFlag { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 27 | kColorAttribute_GPFlag = 0x1, |
| 28 | kColorAttributeIsSkColor_GPFlag = 0x2, |
Brian Osman | 2a4c4df | 2018-12-20 14:06:54 -0500 | [diff] [blame] | 29 | kColorAttributeIsWide_GPFlag = 0x4, |
| 30 | kLocalCoordAttribute_GPFlag = 0x8, |
| 31 | kCoverageAttribute_GPFlag = 0x10, |
Brian Osman | ded032c | 2019-01-07 19:14:13 +0000 | [diff] [blame] | 32 | kBonesAttribute_GPFlag = 0x20, |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 35 | static constexpr int kNumVec2sPerBone = 3; // Our bone matrices are 3x2 matrices passed in as |
| 36 | // vec2s in column major order, and thus there are 3 |
| 37 | // vec2s per bone. |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 38 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 39 | class DefaultGeoProc : public GrGeometryProcessor { |
| 40 | public: |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 41 | static sk_sp<GrGeometryProcessor> Make(const GrShaderCaps* shaderCaps, |
| 42 | uint32_t gpTypeFlags, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 43 | const SkPMColor4f& color, |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 44 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 45 | const SkMatrix& viewMatrix, |
| 46 | const SkMatrix& localMatrix, |
| 47 | bool localCoordsWillBeRead, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 48 | uint8_t coverage, |
| 49 | const float* bones, |
| 50 | int boneCount) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 51 | return sk_sp<GrGeometryProcessor>(new DefaultGeoProc( |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 52 | shaderCaps, gpTypeFlags, color, std::move(colorSpaceXform), viewMatrix, localMatrix, |
| 53 | coverage, localCoordsWillBeRead, bones, boneCount)); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 54 | } |
| 55 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 56 | const char* name() const override { return "DefaultGeometryProcessor"; } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 57 | |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 58 | const SkPMColor4f& color() const { return fColor; } |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 59 | bool hasVertexColor() const { return fInColor.isInitialized(); } |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 60 | const SkMatrix& viewMatrix() const { return fViewMatrix; } |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 61 | const SkMatrix& localMatrix() const { return fLocalMatrix; } |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 62 | bool localCoordsWillBeRead() const { return fLocalCoordsWillBeRead; } |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 63 | uint8_t coverage() const { return fCoverage; } |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 64 | bool hasVertexCoverage() const { return fInCoverage.isInitialized(); } |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 65 | const float* bones() const { return fBones; } |
| 66 | int boneCount() const { return fBoneCount; } |
| 67 | bool hasBones() const { return SkToBool(fBones); } |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 68 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 69 | class GLSLProcessor : public GrGLSLGeometryProcessor { |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 70 | public: |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 71 | GLSLProcessor() |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 72 | : fViewMatrix(SkMatrix::InvalidMatrix()) |
| 73 | , fColor(SK_PMColor4fILLEGAL) |
| 74 | , fCoverage(0xff) {} |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 75 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 76 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 77 | const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 78 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
Chris Dalton | 6028361 | 2018-02-14 13:38:14 -0700 | [diff] [blame] | 79 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 80 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 81 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 82 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 83 | // emit attributes |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 84 | varyingHandler->emitAttributes(gp); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 85 | |
| 86 | // Setup pass through color |
Brian Osman | ded032c | 2019-01-07 19:14:13 +0000 | [diff] [blame] | 87 | if (gp.hasVertexColor()) { |
Chris Dalton | 2737288 | 2017-12-08 13:34:21 -0700 | [diff] [blame] | 88 | GrGLSLVarying varying(kHalf4_GrSLType); |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 89 | varyingHandler->addVarying("color", &varying); |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 90 | |
Brian Osman | ded032c | 2019-01-07 19:14:13 +0000 | [diff] [blame] | 91 | // There are several optional steps to process the color. Start with the attribute: |
| 92 | vertBuilder->codeAppendf("half4 color = %s;", gp.fInColor.name()); |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 93 | |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 94 | // For SkColor, do a red/blue swap, possible color space conversion, and premul |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 95 | if (gp.fFlags & kColorAttributeIsSkColor_GPFlag) { |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 96 | vertBuilder->codeAppend("color = color.bgra;"); |
| 97 | |
| 98 | if (gp.fColorSpaceXform) { |
| 99 | fColorSpaceHelper.emitCode(uniformHandler, gp.fColorSpaceXform.get(), |
| 100 | kVertex_GrShaderFlag); |
| 101 | SkString xformedColor; |
| 102 | vertBuilder->appendColorGamutXform(&xformedColor, "color", |
| 103 | &fColorSpaceHelper); |
| 104 | vertBuilder->codeAppendf("color = %s;", xformedColor.c_str()); |
| 105 | } |
| 106 | |
| 107 | vertBuilder->codeAppend("color = half4(color.rgb * color.a, color.a);"); |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 108 | } |
| 109 | |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 110 | vertBuilder->codeAppendf("%s = color;\n", varying.vsOut()); |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 111 | fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, varying.fsIn()); |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 112 | } else { |
| 113 | this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, |
| 114 | &fColorUniform); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 117 | // Setup bone transforms |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 118 | // NOTE: This code path is currently unused. Benchmarks have found that for all |
| 119 | // reasonable cases of skinned vertices, the overhead involved in copying and uploading |
| 120 | // bone data makes performing the transformations on the CPU faster than doing so on |
| 121 | // the GPU. This is being kept here in case that changes. |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 122 | const char* transformedPositionName = gp.fInPosition.name(); |
| 123 | if (gp.hasBones()) { |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 124 | // Set up the uniform for the bones. |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 125 | const char* vertBonesUniformName; |
| 126 | fBonesUniform = uniformHandler->addUniformArray(kVertex_GrShaderFlag, |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 127 | kFloat2_GrSLType, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 128 | "Bones", |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 129 | kMaxBones * kNumVec2sPerBone, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 130 | &vertBonesUniformName); |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 131 | |
| 132 | // Set up the bone application function. |
| 133 | SkString applyBoneFunctionName; |
| 134 | this->emitApplyBoneFunction(vertBuilder, |
| 135 | vertBonesUniformName, |
| 136 | &applyBoneFunctionName); |
| 137 | |
| 138 | // Apply the world transform to the position first. |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 139 | vertBuilder->codeAppendf( |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 140 | "float2 worldPosition = %s(0, %s);" |
| 141 | "float2 transformedPosition = float2(0, 0);" |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 142 | "for (int i = 0; i < 4; i++) {", |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 143 | applyBoneFunctionName.c_str(), |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 144 | gp.fInPosition.name()); |
| 145 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 146 | // If the GPU supports unsigned integers, then we can read the index. Otherwise, |
| 147 | // we have to estimate it given the float representation. |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 148 | if (args.fShaderCaps->unsignedSupport()) { |
| 149 | vertBuilder->codeAppendf( |
| 150 | " byte index = %s[i];", |
| 151 | gp.fInBoneIndices.name()); |
| 152 | } else { |
| 153 | vertBuilder->codeAppendf( |
| 154 | " byte index = byte(floor(%s[i] * 255 + 0.5));", |
| 155 | gp.fInBoneIndices.name()); |
| 156 | } |
| 157 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 158 | // Get the weight and apply the transformation. |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 159 | vertBuilder->codeAppendf( |
| 160 | " float weight = %s[i];" |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 161 | " transformedPosition += %s(index, worldPosition) * weight;" |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 162 | "}", |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 163 | gp.fInBoneWeights.name(), |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 164 | applyBoneFunctionName.c_str()); |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 165 | transformedPositionName = "transformedPosition"; |
| 166 | } |
| 167 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 168 | // Setup position |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 169 | this->writeOutputPosition(vertBuilder, |
| 170 | uniformHandler, |
| 171 | gpArgs, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 172 | transformedPositionName, |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 173 | gp.viewMatrix(), |
| 174 | &fViewMatrixUniform); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 175 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 176 | if (gp.fInLocalCoords.isInitialized()) { |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 177 | // emit transforms with explicit local coords |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 178 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 179 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 180 | uniformHandler, |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 181 | gp.fInLocalCoords.asShaderVar(), |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 182 | gp.localMatrix(), |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 183 | args.fFPCoordTransformHandler); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 184 | } else { |
| 185 | // emit transforms with position |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 186 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 187 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 188 | uniformHandler, |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 189 | gp.fInPosition.asShaderVar(), |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 190 | gp.localMatrix(), |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 191 | args.fFPCoordTransformHandler); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 192 | } |
| 193 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 194 | // Setup coverage as pass through |
Brian Osman | ded032c | 2019-01-07 19:14:13 +0000 | [diff] [blame] | 195 | if (gp.hasVertexCoverage()) { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 196 | fragBuilder->codeAppendf("half alpha = 1.0;"); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 197 | varyingHandler->addPassThroughAttribute(gp.fInCoverage, "alpha"); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 198 | fragBuilder->codeAppendf("%s = half4(alpha);", args.fOutputCoverage); |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 199 | } else if (gp.coverage() == 0xff) { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 200 | fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage); |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 201 | } else { |
| 202 | const char* fragCoverage; |
| 203 | fCoverageUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 204 | kHalf_GrSLType, |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 205 | "Coverage", |
| 206 | &fragCoverage); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 207 | fragBuilder->codeAppendf("%s = half4(%s);", args.fOutputCoverage, fragCoverage); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 208 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 209 | } |
| 210 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 211 | static inline void GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 212 | const GrShaderCaps&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 213 | GrProcessorKeyBuilder* b) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 214 | const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 215 | uint32_t key = def.fFlags; |
Brian Osman | ded032c | 2019-01-07 19:14:13 +0000 | [diff] [blame] | 216 | key |= (def.coverage() == 0xff) ? 0x40 : 0; |
| 217 | key |= (def.localCoordsWillBeRead() && def.localMatrix().hasPerspective()) ? 0x80 : 0x0; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 218 | key |= ComputePosKey(def.viewMatrix()) << 20; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 219 | b->add32(key); |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 220 | b->add32(GrColorSpaceXform::XformKey(def.fColorSpaceXform.get())); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 221 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 222 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 223 | void setData(const GrGLSLProgramDataManager& pdman, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 224 | const GrPrimitiveProcessor& gp, |
| 225 | FPCoordTransformIter&& transformIter) override { |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 226 | const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 227 | |
| 228 | if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp.viewMatrix())) { |
| 229 | fViewMatrix = dgp.viewMatrix(); |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 230 | float viewMatrix[3 * 3]; |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 231 | GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 232 | pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 233 | } |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 234 | |
Brian Osman | 1be2b7c | 2018-10-29 16:07:15 -0400 | [diff] [blame] | 235 | if (!dgp.hasVertexColor() && dgp.color() != fColor) { |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 236 | pdman.set4fv(fColorUniform, 1, dgp.color().vec()); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 237 | fColor = dgp.color(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 238 | } |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 239 | |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 240 | if (dgp.coverage() != fCoverage && !dgp.hasVertexCoverage()) { |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 241 | pdman.set1f(fCoverageUniform, GrNormalizeByteToFloat(dgp.coverage())); |
| 242 | fCoverage = dgp.coverage(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 243 | } |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 244 | this->setTransformDataHelper(dgp.fLocalMatrix, pdman, &transformIter); |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 245 | |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 246 | fColorSpaceHelper.setData(pdman, dgp.fColorSpaceXform.get()); |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 247 | |
| 248 | if (dgp.hasBones()) { |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 249 | pdman.set2fv(fBonesUniform, dgp.boneCount() * kNumVec2sPerBone, dgp.bones()); |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 250 | } |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 251 | } |
| 252 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 253 | private: |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 254 | void emitApplyBoneFunction(GrGLSLVertexBuilder* vertBuilder, |
| 255 | const char* vertBonesUniformName, |
| 256 | SkString* funcName) { |
| 257 | // The bone matrices are passed in as 3x2 matrices in column-major order as groups |
| 258 | // of 3 float2s. This code takes those float2s and performs the matrix operation on |
| 259 | // a given matrix and float2. |
Nico Weber | e50efdf | 2018-10-01 14:40:44 -0400 | [diff] [blame] | 260 | const GrShaderVar gApplyBoneArgs[] = { |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 261 | GrShaderVar("index", kByte_GrSLType), |
| 262 | GrShaderVar("vec", kFloat2_GrSLType), |
| 263 | }; |
| 264 | SkString body; |
| 265 | body.appendf( |
| 266 | " float2 c0 = %s[index * 3];" |
| 267 | " float2 c1 = %s[index * 3 + 1];" |
| 268 | " float2 c2 = %s[index * 3 + 2];" |
| 269 | " float x = c0.x * vec.x + c1.x * vec.y + c2.x;" |
| 270 | " float y = c0.y * vec.x + c1.y * vec.y + c2.y;" |
| 271 | " return float2(x, y);", |
| 272 | vertBonesUniformName, |
| 273 | vertBonesUniformName, |
| 274 | vertBonesUniformName); |
| 275 | vertBuilder->emitFunction(kFloat2_GrSLType, |
| 276 | "applyBone", |
| 277 | SK_ARRAY_COUNT(gApplyBoneArgs), |
| 278 | gApplyBoneArgs, |
| 279 | body.c_str(), |
| 280 | funcName); |
| 281 | } |
| 282 | |
| 283 | private: |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 284 | SkMatrix fViewMatrix; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 285 | SkPMColor4f fColor; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 286 | uint8_t fCoverage; |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 287 | UniformHandle fViewMatrixUniform; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 288 | UniformHandle fColorUniform; |
| 289 | UniformHandle fCoverageUniform; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 290 | UniformHandle fBonesUniform; |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 291 | GrGLSLColorSpaceXformHelper fColorSpaceHelper; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 292 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 293 | typedef GrGLSLGeometryProcessor INHERITED; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 294 | }; |
| 295 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 296 | void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override { |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 297 | GLSLProcessor::GenKey(*this, caps, b); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 300 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override { |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 301 | return new GLSLProcessor(); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 302 | } |
| 303 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 304 | private: |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 305 | DefaultGeoProc(const GrShaderCaps* shaderCaps, |
| 306 | uint32_t gpTypeFlags, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 307 | const SkPMColor4f& color, |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 308 | sk_sp<GrColorSpaceXform> colorSpaceXform, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 309 | const SkMatrix& viewMatrix, |
| 310 | const SkMatrix& localMatrix, |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 311 | uint8_t coverage, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 312 | bool localCoordsWillBeRead, |
| 313 | const float* bones, |
| 314 | int boneCount) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 315 | : INHERITED(kDefaultGeoProc_ClassID) |
| 316 | , fColor(color) |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 317 | , fViewMatrix(viewMatrix) |
| 318 | , fLocalMatrix(localMatrix) |
| 319 | , fCoverage(coverage) |
| 320 | , fFlags(gpTypeFlags) |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 321 | , fLocalCoordsWillBeRead(localCoordsWillBeRead) |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 322 | , fColorSpaceXform(std::move(colorSpaceXform)) |
| 323 | , fBones(bones) |
| 324 | , fBoneCount(boneCount) { |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 325 | fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType}; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 326 | if (fFlags & kColorAttribute_GPFlag) { |
Brian Osman | 2a4c4df | 2018-12-20 14:06:54 -0500 | [diff] [blame] | 327 | fInColor = MakeColorAttribute("inColor", |
| 328 | SkToBool(fFlags & kColorAttributeIsWide_GPFlag)); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 329 | } |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 330 | if (fFlags & kLocalCoordAttribute_GPFlag) { |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 331 | fInLocalCoords = {"inLocalCoord", kFloat2_GrVertexAttribType, |
| 332 | kFloat2_GrSLType}; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 333 | } |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 334 | if (fFlags & kCoverageAttribute_GPFlag) { |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 335 | fInCoverage = {"inCoverage", kFloat_GrVertexAttribType, kHalf_GrSLType}; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 336 | } |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 337 | if (fFlags & kBonesAttribute_GPFlag) { |
| 338 | SkASSERT(bones && (boneCount > 0)); |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 339 | // GLSL 1.10 and 1.20 don't support integer attributes. |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 340 | GrVertexAttribType indicesCPUType = kByte4_GrVertexAttribType; |
| 341 | GrSLType indicesGPUType = kByte4_GrSLType; |
| 342 | if (!shaderCaps->unsignedSupport()) { |
| 343 | indicesCPUType = kUByte4_norm_GrVertexAttribType; |
| 344 | indicesGPUType = kHalf4_GrSLType; |
| 345 | } |
| 346 | fInBoneIndices = {"inBoneIndices", indicesCPUType, indicesGPUType}; |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 347 | fInBoneWeights = {"inBoneWeights", kUByte4_norm_GrVertexAttribType, |
| 348 | kHalf4_GrSLType}; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 349 | } |
Brian Osman | f04fb3c | 2018-11-12 15:34:00 -0500 | [diff] [blame] | 350 | this->setVertexAttributes(&fInPosition, 6); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | Attribute fInPosition; |
| 354 | Attribute fInColor; |
| 355 | Attribute fInLocalCoords; |
| 356 | Attribute fInCoverage; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 357 | Attribute fInBoneIndices; |
| 358 | Attribute fInBoneWeights; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 359 | SkPMColor4f fColor; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 360 | SkMatrix fViewMatrix; |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 361 | SkMatrix fLocalMatrix; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 362 | uint8_t fCoverage; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 363 | uint32_t fFlags; |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 364 | bool fLocalCoordsWillBeRead; |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 365 | sk_sp<GrColorSpaceXform> fColorSpaceXform; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 366 | const float* fBones; |
| 367 | int fBoneCount; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 368 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 369 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 370 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 371 | typedef GrGeometryProcessor INHERITED; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 372 | }; |
| 373 | |
| 374 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); |
| 375 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 376 | #if GR_TEST_UTILS |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 377 | static constexpr int kNumFloatsPerBone = 6; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 378 | static constexpr int kTestBoneCount = 4; |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 379 | static constexpr float kTestBones[kTestBoneCount * kNumFloatsPerBone] = { |
| 380 | 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, |
| 381 | 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, |
| 382 | 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, |
| 383 | 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 384 | }; |
| 385 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 386 | sk_sp<GrGeometryProcessor> DefaultGeoProc::TestCreate(GrProcessorTestData* d) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 387 | uint32_t flags = 0; |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 388 | if (d->fRandom->nextBool()) { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 389 | flags |= kColorAttribute_GPFlag; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 390 | } |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 391 | if (d->fRandom->nextBool()) { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 392 | flags |= kColorAttributeIsSkColor_GPFlag; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 393 | } |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 394 | if (d->fRandom->nextBool()) { |
Brian Osman | 2a4c4df | 2018-12-20 14:06:54 -0500 | [diff] [blame] | 395 | flags |= kColorAttributeIsWide_GPFlag; |
| 396 | } |
| 397 | if (d->fRandom->nextBool()) { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 398 | flags |= kCoverageAttribute_GPFlag; |
| 399 | } |
| 400 | if (d->fRandom->nextBool()) { |
| 401 | flags |= kLocalCoordAttribute_GPFlag; |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 402 | } |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 403 | if (d->fRandom->nextBool()) { |
| 404 | flags |= kBonesAttribute_GPFlag; |
| 405 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 406 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 407 | return DefaultGeoProc::Make(d->caps()->shaderCaps(), |
| 408 | flags, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 409 | SkPMColor4f::FromBytes_RGBA(GrRandomColor(d->fRandom)), |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 410 | GrTest::TestColorXform(d->fRandom), |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 411 | GrTest::TestMatrix(d->fRandom), |
| 412 | GrTest::TestMatrix(d->fRandom), |
| 413 | d->fRandom->nextBool(), |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 414 | GrRandomCoverage(d->fRandom), |
| 415 | kTestBones, |
| 416 | kTestBoneCount); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 417 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 418 | #endif |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 419 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 420 | sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::Make(const GrShaderCaps* shaderCaps, |
| 421 | const Color& color, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 422 | const Coverage& coverage, |
| 423 | const LocalCoords& localCoords, |
| 424 | const SkMatrix& viewMatrix) { |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 425 | uint32_t flags = 0; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 426 | if (Color::kPremulGrColorAttribute_Type == color.fType) { |
| 427 | flags |= kColorAttribute_GPFlag; |
| 428 | } else if (Color::kUnpremulSkColorAttribute_Type == color.fType) { |
| 429 | flags |= kColorAttribute_GPFlag | kColorAttributeIsSkColor_GPFlag; |
Brian Osman | 2a4c4df | 2018-12-20 14:06:54 -0500 | [diff] [blame] | 430 | } else if (Color::kPremulWideColorAttribute_Type == color.fType) { |
| 431 | flags |= kColorAttribute_GPFlag | kColorAttributeIsWide_GPFlag; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 432 | } |
Brian Osman | ded032c | 2019-01-07 19:14:13 +0000 | [diff] [blame] | 433 | flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverageAttribute_GPFlag : 0; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 434 | flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoordAttribute_GPFlag : 0; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 435 | |
| 436 | uint8_t inCoverage = coverage.fCoverage; |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 437 | bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 438 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 439 | return DefaultGeoProc::Make(shaderCaps, |
| 440 | flags, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 441 | color.fColor, |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 442 | color.fColorSpaceXform, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 443 | viewMatrix, |
| 444 | localCoords.fMatrix ? *localCoords.fMatrix : SkMatrix::I(), |
| 445 | localCoordsWillBeRead, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 446 | inCoverage, |
| 447 | nullptr, |
| 448 | 0); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 449 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 450 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 451 | sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::MakeForDeviceSpace( |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 452 | const GrShaderCaps* shaderCaps, |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 453 | const Color& color, |
| 454 | const Coverage& coverage, |
| 455 | const LocalCoords& localCoords, |
| 456 | const SkMatrix& viewMatrix) { |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 457 | SkMatrix invert = SkMatrix::I(); |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 458 | if (LocalCoords::kUnused_Type != localCoords.fType) { |
| 459 | SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType); |
| 460 | if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 461 | return nullptr; |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 462 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 463 | |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 464 | if (localCoords.hasLocalMatrix()) { |
Michael Ludwig | ef77604 | 2018-11-01 11:07:51 -0400 | [diff] [blame] | 465 | invert.postConcat(*localCoords.fMatrix); |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 466 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 470 | return Make(shaderCaps, color, coverage, inverted, SkMatrix::I()); |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 471 | } |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 472 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 473 | sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::MakeWithBones(const GrShaderCaps* shaderCaps, |
| 474 | const Color& color, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 475 | const Coverage& coverage, |
| 476 | const LocalCoords& localCoords, |
| 477 | const Bones& bones, |
| 478 | const SkMatrix& viewMatrix) { |
| 479 | uint32_t flags = 0; |
| 480 | if (Color::kPremulGrColorAttribute_Type == color.fType) { |
| 481 | flags |= kColorAttribute_GPFlag; |
| 482 | } else if (Color::kUnpremulSkColorAttribute_Type == color.fType) { |
| 483 | flags |= kColorAttribute_GPFlag | kColorAttributeIsSkColor_GPFlag; |
Brian Osman | 2a4c4df | 2018-12-20 14:06:54 -0500 | [diff] [blame] | 484 | } else if (Color::kPremulWideColorAttribute_Type == color.fType) { |
| 485 | flags |= kColorAttribute_GPFlag | kColorAttributeIsWide_GPFlag; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 486 | } |
Brian Osman | ded032c | 2019-01-07 19:14:13 +0000 | [diff] [blame] | 487 | flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverageAttribute_GPFlag : 0; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 488 | flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoordAttribute_GPFlag : 0; |
| 489 | flags |= kBonesAttribute_GPFlag; |
| 490 | |
| 491 | uint8_t inCoverage = coverage.fCoverage; |
| 492 | bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; |
| 493 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 494 | return DefaultGeoProc::Make(shaderCaps, |
| 495 | flags, |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 496 | color.fColor, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 497 | color.fColorSpaceXform, |
| 498 | viewMatrix, |
| 499 | localCoords.fMatrix ? *localCoords.fMatrix : SkMatrix::I(), |
| 500 | localCoordsWillBeRead, |
| 501 | inCoverage, |
| 502 | bones.fBones, |
| 503 | bones.fBoneCount); |
| 504 | } |