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