Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | /************************************************************************************************** |
| 9 | *** This file was autogenerated from GrTwoPointConicalGradientLayout.fp; do not modify. |
| 10 | **************************************************************************************************/ |
| 11 | #include "GrTwoPointConicalGradientLayout.h" |
| 12 | #include "glsl/GrGLSLFragmentProcessor.h" |
| 13 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 14 | #include "glsl/GrGLSLProgramBuilder.h" |
| 15 | #include "GrTexture.h" |
| 16 | #include "SkSLCPP.h" |
| 17 | #include "SkSLUtil.h" |
| 18 | class GrGLSLTwoPointConicalGradientLayout : public GrGLSLFragmentProcessor { |
| 19 | public: |
| 20 | GrGLSLTwoPointConicalGradientLayout() {} |
| 21 | void emitCode(EmitArgs& args) override { |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 22 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 23 | const GrTwoPointConicalGradientLayout& _outer = |
| 24 | args.fFp.cast<GrTwoPointConicalGradientLayout>(); |
| 25 | (void)_outer; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 26 | auto gradientMatrix = _outer.gradientMatrix; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 27 | (void)gradientMatrix; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 28 | auto type = _outer.type; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 29 | (void)type; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 30 | auto isRadiusIncreasing = _outer.isRadiusIncreasing; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 31 | (void)isRadiusIncreasing; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 32 | auto isFocalOnCircle = _outer.isFocalOnCircle; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 33 | (void)isFocalOnCircle; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 34 | auto isWellBehaved = _outer.isWellBehaved; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 35 | (void)isWellBehaved; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 36 | auto isSwapped = _outer.isSwapped; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 37 | (void)isSwapped; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 38 | auto isNativelyFocal = _outer.isNativelyFocal; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 39 | (void)isNativelyFocal; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 40 | auto focalParams = _outer.focalParams; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 41 | (void)focalParams; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 42 | focalParamsVar = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, |
| 43 | "focalParams"); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 44 | SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); |
| 45 | fragBuilder->codeAppendf( |
Michael Ludwig | bf6bf39 | 2018-09-19 16:46:07 -0400 | [diff] [blame] | 46 | "float2 p = %s;\nfloat t = -1.0;\nhalf v = 1.0;\n@switch (%d) {\n case 1:\n " |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 47 | " {\n half r0_2 = %s.y;\n t = float(r0_2) - p.y * p.y;\n " |
| 48 | " if (t >= 0.0) {\n t = p.x + sqrt(t);\n } else " |
| 49 | "{\n v = -1.0;\n }\n }\n break;\n case " |
| 50 | "0:\n {\n half r0 = %s.x;\n @if (%s) {\n " |
| 51 | " t = length(p) - float(r0);\n } else {\n t = " |
| 52 | "-length(p) - float(r0);\n ", |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 53 | sk_TransformedCoords2D_0.c_str(), (int)_outer.type, |
| 54 | args.fUniformHandler->getUniformCStr(focalParamsVar), |
| 55 | args.fUniformHandler->getUniformCStr(focalParamsVar), |
| 56 | (_outer.isRadiusIncreasing ? "true" : "false")); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 57 | fragBuilder->codeAppendf( |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 58 | " }\n }\n break;\n case 2:\n {\n half invR1 " |
| 59 | "= %s.x;\n half fx = %s.y;\n float x_t = -1.0;\n " |
| 60 | "@if (%s) {\n x_t = dot(p, p) / p.x;\n } else if (%s) " |
| 61 | "{\n x_t = length(p) - p.x * float(invR1);\n } else {\n " |
| 62 | " float temp = p.x * p.x - p.y * p.y;\n if (temp >= " |
| 63 | "0.0) {\n @if (%s || !%s) {\n x_t = " |
| 64 | "-sqrt(temp) - p.x * float(invR1)", |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 65 | args.fUniformHandler->getUniformCStr(focalParamsVar), |
| 66 | args.fUniformHandler->getUniformCStr(focalParamsVar), |
| 67 | (_outer.isFocalOnCircle ? "true" : "false"), |
| 68 | (_outer.isWellBehaved ? "true" : "false"), (_outer.isSwapped ? "true" : "false"), |
| 69 | (_outer.isRadiusIncreasing ? "true" : "false")); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 70 | fragBuilder->codeAppendf( |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 71 | ";\n } else {\n x_t = sqrt(temp) - p.x * " |
| 72 | "float(invR1);\n }\n }\n }\n " |
| 73 | " @if (!%s) {\n if (x_t <= 0.0) {\n v = -1.0;\n " |
| 74 | " }\n }\n @if (%s) {\n @if (%s) " |
| 75 | "{\n t = x_t;\n } else {\n t " |
| 76 | "= x_t + float(fx);\n }\n } else {\n @if " |
| 77 | "(%s) {\n ", |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 78 | (_outer.isWellBehaved ? "true" : "false"), |
| 79 | (_outer.isRadiusIncreasing ? "true" : "false"), |
| 80 | (_outer.isNativelyFocal ? "true" : "false"), |
| 81 | (_outer.isNativelyFocal ? "true" : "false")); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 82 | fragBuilder->codeAppendf( |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 83 | " t = -x_t;\n } else {\n t = -x_t + " |
Michael Ludwig | bf6bf39 | 2018-09-19 16:46:07 -0400 | [diff] [blame] | 84 | "float(fx);\n }\n }\n @if (%s) {\n " |
| 85 | " t = 1.0 - t;\n }\n }\n break;\n}\n%s = " |
| 86 | "half4(half(t), v, 0.0, 0.0);\n", |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 87 | (_outer.isSwapped ? "true" : "false"), args.fOutputColor); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | private: |
| 91 | void onSetData(const GrGLSLProgramDataManager& pdman, |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 92 | const GrFragmentProcessor& _proc) override { |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 93 | const GrTwoPointConicalGradientLayout& _outer = |
| 94 | _proc.cast<GrTwoPointConicalGradientLayout>(); |
| 95 | { |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 96 | const SkPoint& focalParamsValue = _outer.focalParams; |
| 97 | if (focalParamsPrev != focalParamsValue) { |
| 98 | focalParamsPrev = focalParamsValue; |
| 99 | pdman.set2f(focalParamsVar, focalParamsValue.fX, focalParamsValue.fY); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | } |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 103 | SkPoint focalParamsPrev = SkPoint::Make(SK_FloatNaN, SK_FloatNaN); |
| 104 | UniformHandle focalParamsVar; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 105 | }; |
| 106 | GrGLSLFragmentProcessor* GrTwoPointConicalGradientLayout::onCreateGLSLInstance() const { |
| 107 | return new GrGLSLTwoPointConicalGradientLayout(); |
| 108 | } |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 109 | void GrTwoPointConicalGradientLayout::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 110 | GrProcessorKeyBuilder* b) const { |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 111 | b->add32((int32_t)type); |
| 112 | b->add32((int32_t)isRadiusIncreasing); |
| 113 | b->add32((int32_t)isFocalOnCircle); |
| 114 | b->add32((int32_t)isWellBehaved); |
| 115 | b->add32((int32_t)isSwapped); |
| 116 | b->add32((int32_t)isNativelyFocal); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 117 | } |
| 118 | bool GrTwoPointConicalGradientLayout::onIsEqual(const GrFragmentProcessor& other) const { |
| 119 | const GrTwoPointConicalGradientLayout& that = other.cast<GrTwoPointConicalGradientLayout>(); |
| 120 | (void)that; |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 121 | if (gradientMatrix != that.gradientMatrix) return false; |
| 122 | if (type != that.type) return false; |
| 123 | if (isRadiusIncreasing != that.isRadiusIncreasing) return false; |
| 124 | if (isFocalOnCircle != that.isFocalOnCircle) return false; |
| 125 | if (isWellBehaved != that.isWellBehaved) return false; |
| 126 | if (isSwapped != that.isSwapped) return false; |
| 127 | if (isNativelyFocal != that.isNativelyFocal) return false; |
| 128 | if (focalParams != that.focalParams) return false; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 129 | return true; |
| 130 | } |
| 131 | GrTwoPointConicalGradientLayout::GrTwoPointConicalGradientLayout( |
| 132 | const GrTwoPointConicalGradientLayout& src) |
| 133 | : INHERITED(kGrTwoPointConicalGradientLayout_ClassID, src.optimizationFlags()) |
Ethan Nicholas | bcd51e8 | 2019-04-09 10:40:41 -0400 | [diff] [blame^] | 134 | , fCoordTransform0(src.fCoordTransform0) |
| 135 | , gradientMatrix(src.gradientMatrix) |
| 136 | , type(src.type) |
| 137 | , isRadiusIncreasing(src.isRadiusIncreasing) |
| 138 | , isFocalOnCircle(src.isFocalOnCircle) |
| 139 | , isWellBehaved(src.isWellBehaved) |
| 140 | , isSwapped(src.isSwapped) |
| 141 | , isNativelyFocal(src.isNativelyFocal) |
| 142 | , focalParams(src.focalParams) { |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 143 | this->addCoordTransform(&fCoordTransform0); |
| 144 | } |
| 145 | std::unique_ptr<GrFragmentProcessor> GrTwoPointConicalGradientLayout::clone() const { |
| 146 | return std::unique_ptr<GrFragmentProcessor>(new GrTwoPointConicalGradientLayout(*this)); |
| 147 | } |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 148 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrTwoPointConicalGradientLayout); |
| 149 | #if GR_TEST_UTILS |
| 150 | std::unique_ptr<GrFragmentProcessor> GrTwoPointConicalGradientLayout::TestCreate( |
| 151 | GrProcessorTestData* d) { |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 152 | SkScalar scale = GrGradientShader::RandomParams::kGradientScale; |
Michael Ludwig | 083bc15 | 2018-10-01 17:15:15 -0400 | [diff] [blame] | 153 | SkScalar offset = scale / 32.0f; |
| 154 | |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 155 | SkPoint center1 = {d->fRandom->nextRangeScalar(0.0f, scale), |
Michael Ludwig | 083bc15 | 2018-10-01 17:15:15 -0400 | [diff] [blame] | 156 | d->fRandom->nextRangeScalar(0.0f, scale)}; |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 157 | SkPoint center2 = {d->fRandom->nextRangeScalar(0.0f, scale), |
Michael Ludwig | 083bc15 | 2018-10-01 17:15:15 -0400 | [diff] [blame] | 158 | d->fRandom->nextRangeScalar(0.0f, scale)}; |
| 159 | SkScalar radius1 = d->fRandom->nextRangeScalar(0.0f, scale); |
| 160 | SkScalar radius2 = d->fRandom->nextRangeScalar(0.0f, scale); |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 161 | |
| 162 | constexpr int kTestTypeMask = (1 << 2) - 1, kTestNativelyFocalBit = (1 << 2), |
| 163 | kTestFocalOnCircleBit = (1 << 3), kTestSwappedBit = (1 << 4); |
| 164 | // We won't treat isWellDefined and isRadiusIncreasing specially because they |
| 165 | // should have high probability to be turned on and off as we're getting random |
| 166 | // radii and centers. |
| 167 | |
| 168 | int mask = d->fRandom->nextU(); |
| 169 | int type = mask & kTestTypeMask; |
| 170 | if (type == static_cast<int>(Type::kRadial)) { |
| 171 | center2 = center1; |
| 172 | // Make sure that the radii are different |
| 173 | if (SkScalarNearlyZero(radius1 - radius2)) { |
Michael Ludwig | 083bc15 | 2018-10-01 17:15:15 -0400 | [diff] [blame] | 174 | radius2 += offset; |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 175 | } |
| 176 | } else if (type == static_cast<int>(Type::kStrip)) { |
| 177 | radius1 = SkTMax(radius1, .1f); // Make sure that the radius is non-zero |
| 178 | radius2 = radius1; |
| 179 | // Make sure that the centers are different |
| 180 | if (SkScalarNearlyZero(SkPoint::Distance(center1, center2))) { |
Michael Ludwig | 083bc15 | 2018-10-01 17:15:15 -0400 | [diff] [blame] | 181 | center2.fX += offset; |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 182 | } |
| 183 | } else { // kFocal_Type |
| 184 | // Make sure that the centers are different |
| 185 | if (SkScalarNearlyZero(SkPoint::Distance(center1, center2))) { |
Michael Ludwig | 083bc15 | 2018-10-01 17:15:15 -0400 | [diff] [blame] | 186 | center2.fX += offset; |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | if (kTestNativelyFocalBit & mask) { |
| 190 | radius1 = 0; |
| 191 | } |
| 192 | if (kTestFocalOnCircleBit & mask) { |
| 193 | radius2 = radius1 + SkPoint::Distance(center1, center2); |
| 194 | } |
| 195 | if (kTestSwappedBit & mask) { |
| 196 | std::swap(radius1, radius2); |
| 197 | radius2 = 0; |
| 198 | } |
| 199 | |
| 200 | // Make sure that the radii are different |
| 201 | if (SkScalarNearlyZero(radius1 - radius2)) { |
Michael Ludwig | 083bc15 | 2018-10-01 17:15:15 -0400 | [diff] [blame] | 202 | radius2 += offset; |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
| 206 | if (SkScalarNearlyZero(radius1 - radius2) && |
| 207 | SkScalarNearlyZero(SkPoint::Distance(center1, center2))) { |
Michael Ludwig | 083bc15 | 2018-10-01 17:15:15 -0400 | [diff] [blame] | 208 | radius2 += offset; // make sure that we're not degenerated |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | GrGradientShader::RandomParams params(d->fRandom); |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 212 | auto shader = params.fUseColors4f |
| 213 | ? SkGradientShader::MakeTwoPointConical( |
| 214 | center1, radius1, center2, radius2, params.fColors4f, |
| 215 | params.fColorSpace, params.fStops, params.fColorCount, |
| 216 | params.fTileMode) |
| 217 | : SkGradientShader::MakeTwoPointConical( |
| 218 | center1, radius1, center2, radius2, params.fColors, |
| 219 | params.fStops, params.fColorCount, params.fTileMode); |
| 220 | GrTest::TestAsFPArgs asFPArgs(d); |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 221 | std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args()); |
| 222 | |
| 223 | GrAlwaysAssert(fp); |
| 224 | return fp; |
| 225 | } |
| 226 | #endif |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 227 | |
| 228 | // .fp files do not let you reference outside enum definitions, so we have to explicitly map |
| 229 | // between the two compatible enum defs |
| 230 | GrTwoPointConicalGradientLayout::Type convert_type(SkTwoPointConicalGradient::Type type) { |
| 231 | switch (type) { |
| 232 | case SkTwoPointConicalGradient::Type::kRadial: |
| 233 | return GrTwoPointConicalGradientLayout::Type::kRadial; |
| 234 | case SkTwoPointConicalGradient::Type::kStrip: |
| 235 | return GrTwoPointConicalGradientLayout::Type::kStrip; |
| 236 | case SkTwoPointConicalGradient::Type::kFocal: |
| 237 | return GrTwoPointConicalGradientLayout::Type::kFocal; |
| 238 | } |
| 239 | SkDEBUGFAIL("Should not be reachable"); |
| 240 | return GrTwoPointConicalGradientLayout::Type::kRadial; |
| 241 | } |
| 242 | |
| 243 | std::unique_ptr<GrFragmentProcessor> GrTwoPointConicalGradientLayout::Make( |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 244 | const SkTwoPointConicalGradient& grad, const GrFPArgs& args) { |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 245 | GrTwoPointConicalGradientLayout::Type grType = convert_type(grad.getType()); |
| 246 | |
| 247 | // The focalData struct is only valid if isFocal is true |
| 248 | const SkTwoPointConicalGradient::FocalData& focalData = grad.getFocalData(); |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 249 | bool isFocal = grType == Type::kFocal; |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 250 | |
| 251 | // Calculate optimization switches from gradient specification |
| 252 | bool isFocalOnCircle = isFocal && focalData.isFocalOnCircle(); |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 253 | bool isWellBehaved = isFocal && focalData.isWellBehaved(); |
| 254 | bool isSwapped = isFocal && focalData.isSwapped(); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 255 | bool isNativelyFocal = isFocal && focalData.isNativelyFocal(); |
| 256 | |
| 257 | // Type-specific calculations: isRadiusIncreasing, focalParams, and the gradient matrix. |
| 258 | // However, all types start with the total inverse local matrix calculated from the shader |
| 259 | // and args |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 260 | bool isRadiusIncreasing; |
| 261 | SkPoint focalParams; // really just a 2D tuple |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 262 | SkMatrix matrix; |
| 263 | |
| 264 | // Initialize the base matrix |
| 265 | if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) { |
| 266 | return nullptr; |
| 267 | } |
| 268 | |
| 269 | if (isFocal) { |
| 270 | isRadiusIncreasing = (1 - focalData.fFocalX) > 0; |
| 271 | |
| 272 | focalParams.set(1.0 / focalData.fR1, focalData.fFocalX); |
| 273 | |
| 274 | matrix.postConcat(grad.getGradientMatrix()); |
| 275 | } else if (grType == Type::kRadial) { |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 276 | SkScalar dr = grad.getDiffRadius(); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 277 | isRadiusIncreasing = dr >= 0; |
| 278 | |
| 279 | SkScalar r0 = grad.getStartRadius() / dr; |
| 280 | focalParams.set(r0, r0 * r0); |
| 281 | |
| 282 | // GPU radial matrix is different from the original matrix, since we map the diff radius |
| 283 | // to have |dr| = 1, so manually compute the final gradient matrix here. |
| 284 | |
| 285 | // Map center to (0, 0) |
| 286 | matrix.postTranslate(-grad.getStartCenter().fX, -grad.getStartCenter().fY); |
| 287 | |
| 288 | // scale |diffRadius| to 1 |
| 289 | matrix.postScale(1 / dr, 1 / dr); |
| 290 | } else { // kStrip |
| 291 | isRadiusIncreasing = false; // kStrip doesn't use this flag |
| 292 | |
| 293 | SkScalar r0 = grad.getStartRadius() / grad.getCenterX1(); |
| 294 | focalParams.set(r0, r0 * r0); |
| 295 | |
| 296 | matrix.postConcat(grad.getGradientMatrix()); |
| 297 | } |
| 298 | |
Mike Klein | d6ab77a | 2019-03-21 08:18:24 -0500 | [diff] [blame] | 299 | return std::unique_ptr<GrFragmentProcessor>(new GrTwoPointConicalGradientLayout( |
| 300 | matrix, grType, isRadiusIncreasing, isFocalOnCircle, isWellBehaved, isSwapped, |
| 301 | isNativelyFocal, focalParams)); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 302 | } |