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 Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 42 | GrColor 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 | |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 57 | GrColor 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() |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 71 | : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), fCoverage(0xff) {} |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 72 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 73 | void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 74 | const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 75 | GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
Chris Dalton | 6028361 | 2018-02-14 13:38:14 -0700 | [diff] [blame] | 76 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 77 | GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 78 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 79 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 80 | // emit attributes |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 81 | varyingHandler->emitAttributes(gp); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 82 | |
| 83 | // Setup pass through color |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 84 | if (gp.hasVertexColor()) { |
Chris Dalton | 2737288 | 2017-12-08 13:34:21 -0700 | [diff] [blame] | 85 | GrGLSLVarying varying(kHalf4_GrSLType); |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 86 | varyingHandler->addVarying("color", &varying); |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 87 | |
| 88 | // 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] | 89 | vertBuilder->codeAppendf("half4 color = %s;", gp.fInColor.name()); |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 90 | |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 91 | // 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] | 92 | if (gp.fFlags & kColorAttributeIsSkColor_GPFlag) { |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 93 | vertBuilder->codeAppend("color = color.bgra;"); |
| 94 | |
| 95 | if (gp.fColorSpaceXform) { |
| 96 | fColorSpaceHelper.emitCode(uniformHandler, gp.fColorSpaceXform.get(), |
| 97 | kVertex_GrShaderFlag); |
| 98 | SkString xformedColor; |
| 99 | vertBuilder->appendColorGamutXform(&xformedColor, "color", |
| 100 | &fColorSpaceHelper); |
| 101 | vertBuilder->codeAppendf("color = %s;", xformedColor.c_str()); |
| 102 | } |
| 103 | |
| 104 | vertBuilder->codeAppend("color = half4(color.rgb * color.a, color.a);"); |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 107 | vertBuilder->codeAppendf("%s = color;\n", varying.vsOut()); |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 108 | fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, varying.fsIn()); |
Brian Salomon | bfd5183 | 2017-01-04 13:22:08 -0500 | [diff] [blame] | 109 | } else { |
| 110 | this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, |
| 111 | &fColorUniform); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 114 | // Setup bone transforms |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 115 | // NOTE: This code path is currently unused. Benchmarks have found that for all |
| 116 | // reasonable cases of skinned vertices, the overhead involved in copying and uploading |
| 117 | // bone data makes performing the transformations on the CPU faster than doing so on |
| 118 | // the GPU. This is being kept here in case that changes. |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 119 | const char* transformedPositionName = gp.fInPosition.name(); |
| 120 | if (gp.hasBones()) { |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 121 | // Set up the uniform for the bones. |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 122 | const char* vertBonesUniformName; |
| 123 | fBonesUniform = uniformHandler->addUniformArray(kVertex_GrShaderFlag, |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 124 | kFloat2_GrSLType, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 125 | "Bones", |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 126 | kMaxBones * kNumVec2sPerBone, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 127 | &vertBonesUniformName); |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 128 | |
| 129 | // Set up the bone application function. |
| 130 | SkString applyBoneFunctionName; |
| 131 | this->emitApplyBoneFunction(vertBuilder, |
| 132 | vertBonesUniformName, |
| 133 | &applyBoneFunctionName); |
| 134 | |
| 135 | // Apply the world transform to the position first. |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 136 | vertBuilder->codeAppendf( |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 137 | "float2 worldPosition = %s(0, %s);" |
| 138 | "float2 transformedPosition = float2(0, 0);" |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 139 | "for (int i = 0; i < 4; i++) {", |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 140 | applyBoneFunctionName.c_str(), |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 141 | gp.fInPosition.name()); |
| 142 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 143 | // If the GPU supports unsigned integers, then we can read the index. Otherwise, |
| 144 | // we have to estimate it given the float representation. |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 145 | if (args.fShaderCaps->unsignedSupport()) { |
| 146 | vertBuilder->codeAppendf( |
| 147 | " byte index = %s[i];", |
| 148 | gp.fInBoneIndices.name()); |
| 149 | } else { |
| 150 | vertBuilder->codeAppendf( |
| 151 | " byte index = byte(floor(%s[i] * 255 + 0.5));", |
| 152 | gp.fInBoneIndices.name()); |
| 153 | } |
| 154 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 155 | // Get the weight and apply the transformation. |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 156 | vertBuilder->codeAppendf( |
| 157 | " float weight = %s[i];" |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 158 | " transformedPosition += %s(index, worldPosition) * weight;" |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 159 | "}", |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 160 | gp.fInBoneWeights.name(), |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 161 | applyBoneFunctionName.c_str()); |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 162 | transformedPositionName = "transformedPosition"; |
| 163 | } |
| 164 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 165 | // Setup position |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 166 | this->writeOutputPosition(vertBuilder, |
| 167 | uniformHandler, |
| 168 | gpArgs, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 169 | transformedPositionName, |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 170 | gp.viewMatrix(), |
| 171 | &fViewMatrixUniform); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 172 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 173 | if (gp.fInLocalCoords.isInitialized()) { |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 174 | // emit transforms with explicit local coords |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 175 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 176 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 177 | uniformHandler, |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 178 | gp.fInLocalCoords.asShaderVar(), |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 179 | gp.localMatrix(), |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 180 | args.fFPCoordTransformHandler); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 181 | } else { |
| 182 | // emit transforms with position |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 183 | this->emitTransforms(vertBuilder, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 184 | varyingHandler, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 185 | uniformHandler, |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 186 | gp.fInPosition.asShaderVar(), |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 187 | gp.localMatrix(), |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 188 | args.fFPCoordTransformHandler); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 189 | } |
| 190 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 191 | // Setup coverage as pass through |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 192 | if (gp.hasVertexCoverage()) { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 193 | fragBuilder->codeAppendf("half alpha = 1.0;"); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 194 | varyingHandler->addPassThroughAttribute(gp.fInCoverage, "alpha"); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 195 | fragBuilder->codeAppendf("%s = half4(alpha);", args.fOutputCoverage); |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 196 | } else if (gp.coverage() == 0xff) { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 197 | fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage); |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 198 | } else { |
| 199 | const char* fragCoverage; |
| 200 | fCoverageUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 201 | kHalf_GrSLType, |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 202 | "Coverage", |
| 203 | &fragCoverage); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 204 | fragBuilder->codeAppendf("%s = half4(%s);", args.fOutputCoverage, fragCoverage); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 205 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 206 | } |
| 207 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 208 | static inline void GenKey(const GrGeometryProcessor& gp, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 209 | const GrShaderCaps&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 210 | GrProcessorKeyBuilder* b) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 211 | const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 212 | uint32_t key = def.fFlags; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 213 | key |= (def.coverage() == 0xff) ? 0x20 : 0; |
| 214 | key |= (def.localCoordsWillBeRead() && def.localMatrix().hasPerspective()) ? 0x40 : 0x0; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 215 | key |= ComputePosKey(def.viewMatrix()) << 20; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 216 | b->add32(key); |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 217 | b->add32(GrColorSpaceXform::XformKey(def.fColorSpaceXform.get())); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 218 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 219 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 220 | void setData(const GrGLSLProgramDataManager& pdman, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 221 | const GrPrimitiveProcessor& gp, |
| 222 | FPCoordTransformIter&& transformIter) override { |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 223 | const DefaultGeoProc& dgp = gp.cast<DefaultGeoProc>(); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 224 | |
| 225 | if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp.viewMatrix())) { |
| 226 | fViewMatrix = dgp.viewMatrix(); |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 227 | float viewMatrix[3 * 3]; |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 228 | GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
joshualitt | 5559ca2 | 2015-05-21 15:50:36 -0700 | [diff] [blame] | 229 | pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 230 | } |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 231 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 232 | if (dgp.color() != fColor && !dgp.hasVertexColor()) { |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 233 | float c[4]; |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 234 | GrColorToRGBAFloat(dgp.color(), c); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 235 | pdman.set4fv(fColorUniform, 1, c); |
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. |
| 259 | static const GrShaderVar gApplyBoneArgs[] = { |
| 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; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 284 | GrColor fColor; |
| 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, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 306 | GrColor 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 Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 324 | fInPosition = {"inPosition", kFloat2_GrVertexAttribType}; |
| 325 | int cnt = 1; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 326 | if (fFlags & kColorAttribute_GPFlag) { |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 327 | fInColor = {"inColor", kUByte4_norm_GrVertexAttribType}; |
| 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 Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 331 | fInLocalCoords = {"inLocalCoord", kFloat2_GrVertexAttribType}; |
| 332 | ++cnt; |
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 Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 335 | fInCoverage = {"inCoverage", kHalf_GrVertexAttribType}; |
| 336 | ++cnt; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 337 | } |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 338 | if (fFlags & kBonesAttribute_GPFlag) { |
| 339 | SkASSERT(bones && (boneCount > 0)); |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 340 | // GLSL 1.10 and 1.20 don't support integer attributes. |
| 341 | GrVertexAttribType indicesAttribType = |
| 342 | shaderCaps->unsignedSupport() ? kByte4_GrVertexAttribType : |
| 343 | kUByte4_norm_GrVertexAttribType; |
| 344 | fInBoneIndices = {"inBoneIndices", indicesAttribType}; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 345 | ++cnt; |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 346 | fInBoneWeights = {"inBoneWeights", kUByte4_norm_GrVertexAttribType}; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 347 | ++cnt; |
| 348 | } |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 349 | this->setVertexAttributeCnt(cnt); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 350 | } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 351 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 352 | const Attribute& onVertexAttribute(int i) const override { |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 353 | return IthInitializedAttribute(i, |
| 354 | fInPosition, |
| 355 | fInColor, |
| 356 | fInLocalCoords, |
| 357 | fInCoverage, |
| 358 | fInBoneIndices, |
| 359 | fInBoneWeights); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | Attribute fInPosition; |
| 363 | Attribute fInColor; |
| 364 | Attribute fInLocalCoords; |
| 365 | Attribute fInCoverage; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 366 | Attribute fInBoneIndices; |
| 367 | Attribute fInBoneWeights; |
joshualitt | 88c23fc | 2015-05-13 14:18:07 -0700 | [diff] [blame] | 368 | GrColor fColor; |
joshualitt | e578a95 | 2015-05-14 10:09:13 -0700 | [diff] [blame] | 369 | SkMatrix fViewMatrix; |
joshualitt | e3ababe | 2015-05-15 07:56:07 -0700 | [diff] [blame] | 370 | SkMatrix fLocalMatrix; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 371 | uint8_t fCoverage; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 372 | uint32_t fFlags; |
bsalomon | 7765a47 | 2015-07-08 11:26:37 -0700 | [diff] [blame] | 373 | bool fLocalCoordsWillBeRead; |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 374 | sk_sp<GrColorSpaceXform> fColorSpaceXform; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 375 | const float* fBones; |
| 376 | int fBoneCount; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 377 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 378 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 379 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 380 | typedef GrGeometryProcessor INHERITED; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 381 | }; |
| 382 | |
| 383 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); |
| 384 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 385 | #if GR_TEST_UTILS |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 386 | static constexpr int kNumFloatsPerBone = 6; |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 387 | static constexpr int kTestBoneCount = 4; |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame^] | 388 | static constexpr float kTestBones[kTestBoneCount * kNumFloatsPerBone] = { |
| 389 | 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, |
| 390 | 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, |
| 391 | 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, |
| 392 | 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 393 | }; |
| 394 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 395 | sk_sp<GrGeometryProcessor> DefaultGeoProc::TestCreate(GrProcessorTestData* d) { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 396 | uint32_t flags = 0; |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 397 | if (d->fRandom->nextBool()) { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 398 | flags |= kColorAttribute_GPFlag; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 399 | } |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 400 | if (d->fRandom->nextBool()) { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 401 | flags |= kColorAttributeIsSkColor_GPFlag; |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 402 | } |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 403 | if (d->fRandom->nextBool()) { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 404 | flags |= kCoverageAttribute_GPFlag; |
| 405 | } |
| 406 | if (d->fRandom->nextBool()) { |
| 407 | flags |= kLocalCoordAttribute_GPFlag; |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 408 | } |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 409 | if (d->fRandom->nextBool()) { |
| 410 | flags |= kBonesAttribute_GPFlag; |
| 411 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 412 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 413 | return DefaultGeoProc::Make(d->caps()->shaderCaps(), |
| 414 | flags, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 415 | GrRandomColor(d->fRandom), |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 416 | GrTest::TestColorXform(d->fRandom), |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 417 | GrTest::TestMatrix(d->fRandom), |
| 418 | GrTest::TestMatrix(d->fRandom), |
| 419 | d->fRandom->nextBool(), |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 420 | GrRandomCoverage(d->fRandom), |
| 421 | kTestBones, |
| 422 | kTestBoneCount); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 423 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 424 | #endif |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 425 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 426 | sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::Make(const GrShaderCaps* shaderCaps, |
| 427 | const Color& color, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 428 | const Coverage& coverage, |
| 429 | const LocalCoords& localCoords, |
| 430 | const SkMatrix& viewMatrix) { |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 431 | uint32_t flags = 0; |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 432 | if (Color::kPremulGrColorAttribute_Type == color.fType) { |
| 433 | flags |= kColorAttribute_GPFlag; |
| 434 | } else if (Color::kUnpremulSkColorAttribute_Type == color.fType) { |
| 435 | flags |= kColorAttribute_GPFlag | kColorAttributeIsSkColor_GPFlag; |
| 436 | } |
| 437 | flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverageAttribute_GPFlag : 0; |
| 438 | flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoordAttribute_GPFlag : 0; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 439 | |
| 440 | uint8_t inCoverage = coverage.fCoverage; |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 441 | bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 442 | |
| 443 | GrColor inColor = color.fColor; |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 444 | return DefaultGeoProc::Make(shaderCaps, |
| 445 | flags, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 446 | inColor, |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 447 | color.fColorSpaceXform, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 448 | viewMatrix, |
| 449 | localCoords.fMatrix ? *localCoords.fMatrix : SkMatrix::I(), |
| 450 | localCoordsWillBeRead, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 451 | inCoverage, |
| 452 | nullptr, |
| 453 | 0); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 454 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 455 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 456 | sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::MakeForDeviceSpace( |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 457 | const GrShaderCaps* shaderCaps, |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 458 | const Color& color, |
| 459 | const Coverage& coverage, |
| 460 | const LocalCoords& localCoords, |
| 461 | const SkMatrix& viewMatrix) { |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 462 | SkMatrix invert = SkMatrix::I(); |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 463 | if (LocalCoords::kUnused_Type != localCoords.fType) { |
| 464 | SkASSERT(LocalCoords::kUsePosition_Type == localCoords.fType); |
| 465 | if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 466 | return nullptr; |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 467 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 468 | |
joshualitt | df0c557 | 2015-08-03 11:35:28 -0700 | [diff] [blame] | 469 | if (localCoords.hasLocalMatrix()) { |
| 470 | invert.preConcat(*localCoords.fMatrix); |
| 471 | } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 475 | return Make(shaderCaps, color, coverage, inverted, SkMatrix::I()); |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 476 | } |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 477 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 478 | sk_sp<GrGeometryProcessor> GrDefaultGeoProcFactory::MakeWithBones(const GrShaderCaps* shaderCaps, |
| 479 | const Color& color, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 480 | const Coverage& coverage, |
| 481 | const LocalCoords& localCoords, |
| 482 | const Bones& bones, |
| 483 | const SkMatrix& viewMatrix) { |
| 484 | uint32_t flags = 0; |
| 485 | if (Color::kPremulGrColorAttribute_Type == color.fType) { |
| 486 | flags |= kColorAttribute_GPFlag; |
| 487 | } else if (Color::kUnpremulSkColorAttribute_Type == color.fType) { |
| 488 | flags |= kColorAttribute_GPFlag | kColorAttributeIsSkColor_GPFlag; |
| 489 | } |
| 490 | flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverageAttribute_GPFlag : 0; |
| 491 | flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoordAttribute_GPFlag : 0; |
| 492 | flags |= kBonesAttribute_GPFlag; |
| 493 | |
| 494 | uint8_t inCoverage = coverage.fCoverage; |
| 495 | bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; |
| 496 | |
| 497 | GrColor inColor = color.fColor; |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 498 | return DefaultGeoProc::Make(shaderCaps, |
| 499 | flags, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 500 | inColor, |
| 501 | color.fColorSpaceXform, |
| 502 | viewMatrix, |
| 503 | localCoords.fMatrix ? *localCoords.fMatrix : SkMatrix::I(), |
| 504 | localCoordsWillBeRead, |
| 505 | inCoverage, |
| 506 | bones.fBones, |
| 507 | bones.fBoneCount); |
| 508 | } |