rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | |
Matt Sarett | 6cc6ae75 | 2017-04-18 18:29:12 -0400 | [diff] [blame] | 8 | #include "SkColorSpaceXformer.h" |
Florin Malita | d4e9ec8 | 2017-10-25 18:00:26 -0400 | [diff] [blame] | 9 | #include "SkReadBuffer.h" |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 10 | #include "SkSweepGradient.h" |
Herb Derby | 7eb8698 | 2017-05-02 19:04:39 -0400 | [diff] [blame] | 11 | #include "SkPM4fPriv.h" |
| 12 | #include "SkRasterPipeline.h" |
Florin Malita | d4e9ec8 | 2017-10-25 18:00:26 -0400 | [diff] [blame] | 13 | #include "SkWriteBuffer.h" |
Herb Derby | 7eb8698 | 2017-05-02 19:04:39 -0400 | [diff] [blame] | 14 | |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 15 | SkSweepGradient::SkSweepGradient(const SkPoint& center, SkScalar t0, SkScalar t1, |
| 16 | const Descriptor& desc) |
| 17 | : SkGradientShaderBase(desc, SkMatrix::MakeTrans(-center.x(), -center.y())) |
| 18 | , fCenter(center) |
| 19 | , fTBias(-t0) |
| 20 | , fTScale(1 / (t1 - t0)) |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 21 | { |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 22 | SkASSERT(t0 < t1); |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 23 | } |
| 24 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 25 | SkShader::GradientType SkSweepGradient::asAGradient(GradientInfo* info) const { |
| 26 | if (info) { |
| 27 | commonAsAGradient(info); |
| 28 | info->fPoint[0] = fCenter; |
| 29 | } |
| 30 | return kSweep_GradientType; |
| 31 | } |
| 32 | |
Florin Malita | 545630b | 2017-08-02 10:42:41 -0400 | [diff] [blame] | 33 | static std::tuple<SkScalar, SkScalar> angles_from_t_coeff(SkScalar tBias, SkScalar tScale) { |
| 34 | return std::make_tuple(-tBias * 360, (1 / tScale - tBias) * 360); |
| 35 | } |
| 36 | |
reed | 60c9b58 | 2016-04-03 09:11:13 -0700 | [diff] [blame] | 37 | sk_sp<SkFlattenable> SkSweepGradient::CreateProc(SkReadBuffer& buffer) { |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 38 | DescriptorScope desc; |
| 39 | if (!desc.unflatten(buffer)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 40 | return nullptr; |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 41 | } |
| 42 | const SkPoint center = buffer.readPoint(); |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 43 | |
| 44 | SkScalar startAngle = 0, |
| 45 | endAngle = 360; |
| 46 | if (!buffer.isVersionLT(SkReadBuffer::kTileInfoInSweepGradient_Version)) { |
| 47 | const auto tBias = buffer.readScalar(), |
| 48 | tScale = buffer.readScalar(); |
Florin Malita | 545630b | 2017-08-02 10:42:41 -0400 | [diff] [blame] | 49 | std::tie(startAngle, endAngle) = angles_from_t_coeff(tBias, tScale); |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 50 | } |
| 51 | |
brianosman | e25d71c | 2016-09-28 11:27:28 -0700 | [diff] [blame] | 52 | return SkGradientShader::MakeSweep(center.x(), center.y(), desc.fColors, |
| 53 | std::move(desc.fColorSpace), desc.fPos, desc.fCount, |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 54 | desc.fTileMode, startAngle, endAngle, |
brianosman | e25d71c | 2016-09-28 11:27:28 -0700 | [diff] [blame] | 55 | desc.fGradFlags, desc.fLocalMatrix); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 56 | } |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 57 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 58 | void SkSweepGradient::flatten(SkWriteBuffer& buffer) const { |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 59 | this->INHERITED::flatten(buffer); |
| 60 | buffer.writePoint(fCenter); |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 61 | buffer.writeScalar(fTBias); |
| 62 | buffer.writeScalar(fTScale); |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 63 | } |
| 64 | |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 65 | ///////////////////////////////////////////////////////////////////// |
| 66 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 67 | #if SK_SUPPORT_GPU |
| 68 | |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 69 | #include "SkGr.h" |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 70 | #include "GrShaderCaps.h" |
egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 71 | #include "gl/GrGLContext.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 72 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 73 | |
rileya@google.com | 98e8b6d | 2012-07-31 20:38:06 +0000 | [diff] [blame] | 74 | class GrSweepGradient : public GrGradientEffect { |
| 75 | public: |
fmenozzi | 55d318d | 2016-08-09 08:05:57 -0700 | [diff] [blame] | 76 | class GLSLSweepProcessor; |
| 77 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 78 | static std::unique_ptr<GrFragmentProcessor> Make(const CreateArgs& args, SkScalar tBias, |
| 79 | SkScalar tScale) { |
Brian Osman | 5911a7c | 2017-10-25 12:52:31 -0400 | [diff] [blame] | 80 | return GrGradientEffect::AdjustFP(std::unique_ptr<GrSweepGradient>( |
| 81 | new GrSweepGradient(args, tBias, tScale)), |
| 82 | args); |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 83 | } |
Brian Salomon | 6af2701 | 2017-06-09 08:21:42 -0400 | [diff] [blame] | 84 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 85 | const char* name() const override { return "Sweep Gradient"; } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 86 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 87 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
| 88 | return std::unique_ptr<GrFragmentProcessor>(new GrSweepGradient(*this)); |
Brian Salomon | f8480b9 | 2017-07-27 15:45:59 -0400 | [diff] [blame] | 89 | } |
| 90 | |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 91 | private: |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 92 | explicit GrSweepGradient(const CreateArgs& args, SkScalar tBias, SkScalar tScale) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 93 | : INHERITED(kGrSweepGradient_ClassID, args, args.fShader->colorsAreOpaque()) |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 94 | , fTBias(tBias) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 95 | , fTScale(tScale) {} |
Brian Salomon | f8480b9 | 2017-07-27 15:45:59 -0400 | [diff] [blame] | 96 | |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 97 | explicit GrSweepGradient(const GrSweepGradient& that) |
| 98 | : INHERITED(that) |
| 99 | , fTBias(that.fTBias) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 100 | , fTScale(that.fTScale) {} |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 101 | |
fmenozzi | 55d318d | 2016-08-09 08:05:57 -0700 | [diff] [blame] | 102 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 103 | |
Florin Malita | e657dc8 | 2017-11-03 08:46:18 -0400 | [diff] [blame] | 104 | bool onIsEqual(const GrFragmentProcessor& base) const override { |
| 105 | const GrSweepGradient& fp = base.cast<GrSweepGradient>(); |
| 106 | return INHERITED::onIsEqual(base) |
| 107 | && fTBias == fp.fTBias |
| 108 | && fTScale == fp.fTScale; |
| 109 | } |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 110 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 111 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
rileya@google.com | 98e8b6d | 2012-07-31 20:38:06 +0000 | [diff] [blame] | 112 | |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 113 | SkScalar fTBias; |
| 114 | SkScalar fTScale; |
| 115 | |
rileya@google.com | 98e8b6d | 2012-07-31 20:38:06 +0000 | [diff] [blame] | 116 | typedef GrGradientEffect INHERITED; |
| 117 | }; |
| 118 | |
| 119 | ///////////////////////////////////////////////////////////////////// |
| 120 | |
fmenozzi | 55d318d | 2016-08-09 08:05:57 -0700 | [diff] [blame] | 121 | class GrSweepGradient::GLSLSweepProcessor : public GrGradientEffect::GLSLProcessor { |
| 122 | public: |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 123 | GLSLSweepProcessor(const GrProcessor&) |
| 124 | : fCachedTBias(SK_FloatNaN) |
| 125 | , fCachedTScale(SK_FloatNaN) {} |
fmenozzi | 55d318d | 2016-08-09 08:05:57 -0700 | [diff] [blame] | 126 | |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 127 | void emitCode(EmitArgs&) override; |
fmenozzi | 55d318d | 2016-08-09 08:05:57 -0700 | [diff] [blame] | 128 | |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 129 | protected: |
| 130 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 131 | const GrFragmentProcessor& processor) override { |
| 132 | INHERITED::onSetData(pdman, processor); |
| 133 | const GrSweepGradient& data = processor.cast<GrSweepGradient>(); |
fmenozzi | 55d318d | 2016-08-09 08:05:57 -0700 | [diff] [blame] | 134 | |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 135 | if (fCachedTBias != data.fTBias || fCachedTScale != data.fTScale) { |
| 136 | fCachedTBias = data.fTBias; |
| 137 | fCachedTScale = data.fTScale; |
| 138 | pdman.set2f(fTBiasScaleUni, fCachedTBias, fCachedTScale); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | private: |
| 143 | UniformHandle fTBiasScaleUni; |
| 144 | |
| 145 | // Uploaded uniform values. |
| 146 | float fCachedTBias, |
| 147 | fCachedTScale; |
| 148 | |
| 149 | typedef GrGradientEffect::GLSLProcessor INHERITED; |
fmenozzi | 55d318d | 2016-08-09 08:05:57 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | ///////////////////////////////////////////////////////////////////// |
| 153 | |
| 154 | GrGLSLFragmentProcessor* GrSweepGradient::onCreateGLSLInstance() const { |
| 155 | return new GrSweepGradient::GLSLSweepProcessor(*this); |
| 156 | } |
| 157 | |
fmenozzi | 55d318d | 2016-08-09 08:05:57 -0700 | [diff] [blame] | 158 | ///////////////////////////////////////////////////////////////////// |
| 159 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 160 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSweepGradient); |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 161 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 162 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 163 | std::unique_ptr<GrFragmentProcessor> GrSweepGradient::TestCreate(GrProcessorTestData* d) { |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 164 | SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 165 | |
Brian Osman | 3f74860 | 2016-10-03 18:29:03 -0400 | [diff] [blame] | 166 | RandomGradientParams params(d->fRandom); |
Brian Osman | a219653 | 2016-10-17 12:48:13 -0400 | [diff] [blame] | 167 | auto shader = params.fUseColors4f ? |
| 168 | SkGradientShader::MakeSweep(center.fX, center.fY, params.fColors4f, params.fColorSpace, |
| 169 | params.fStops, params.fColorCount) : |
| 170 | SkGradientShader::MakeSweep(center.fX, center.fY, params.fColors, |
| 171 | params.fStops, params.fColorCount); |
Brian Osman | 9f532a3 | 2016-10-19 11:12:09 -0400 | [diff] [blame] | 172 | GrTest::TestAsFPArgs asFPArgs(d); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 173 | std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args()); |
bsalomon | c21b09e | 2015-08-28 18:46:56 -0700 | [diff] [blame] | 174 | GrAlwaysAssert(fp); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 175 | return fp; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 176 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 177 | #endif |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 178 | |
| 179 | ///////////////////////////////////////////////////////////////////// |
| 180 | |
fmenozzi | 55d318d | 2016-08-09 08:05:57 -0700 | [diff] [blame] | 181 | void GrSweepGradient::GLSLSweepProcessor::emitCode(EmitArgs& args) { |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame] | 182 | const GrSweepGradient& ge = args.fFp.cast<GrSweepGradient>(); |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 183 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 184 | this->emitUniforms(uniformHandler, ge); |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 185 | fTBiasScaleUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, |
| 186 | "SweepFSParams"); |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 187 | const char* tBiasScaleV = uniformHandler->getUniformCStr(fTBiasScaleUni); |
| 188 | |
| 189 | const SkString coords2D = args.fFragBuilder->ensureCoords2D(args.fTransformedCoords[0]); |
| 190 | |
| 191 | // On some devices they incorrectly implement atan2(y,x) as atan(y/x). In actuality it is |
| 192 | // atan2(y,x) = 2 * atan(y / (sqrt(x^2 + y^2) + x)). So to work around this we pass in |
| 193 | // (sqrt(x^2 + y^2) + x) as the second parameter to atan2 in these cases. We let the device |
| 194 | // handle the undefined behavior of the second paramenter being 0 instead of doing the |
| 195 | // divide ourselves and using atan instead. |
| 196 | const SkString atan = args.fShaderCaps->atan2ImplementedAsAtanYOverX() |
| 197 | ? SkStringPrintf("2.0 * atan(- %s.y, length(%s) - %s.x)", |
| 198 | coords2D.c_str(), coords2D.c_str(), coords2D.c_str()) |
| 199 | : SkStringPrintf("atan(- %s.y, - %s.x)", coords2D.c_str(), coords2D.c_str()); |
| 200 | |
commit-bot@chromium.org | 54318d3 | 2014-02-14 17:27:04 +0000 | [diff] [blame] | 201 | // 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi] |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 202 | const SkString t = SkStringPrintf("((%s * 0.1591549430918 + 0.5 + %s[0]) * %s[1])", |
| 203 | atan.c_str(), tBiasScaleV, tBiasScaleV); |
| 204 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 205 | this->emitColor(args.fFragBuilder, |
| 206 | args.fUniformHandler, |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 207 | args.fShaderCaps, |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 208 | ge, t.c_str(), |
| 209 | args.fOutputColor, |
| 210 | args.fInputColor, |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 211 | args.fTexSamplers); |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | ///////////////////////////////////////////////////////////////////// |
| 215 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 216 | std::unique_ptr<GrFragmentProcessor> SkSweepGradient::asFragmentProcessor( |
| 217 | const AsFPArgs& args) const { |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 218 | SkMatrix matrix; |
bsalomon@google.com | f94b3a4 | 2012-10-31 18:09:01 +0000 | [diff] [blame] | 219 | if (!this->getLocalMatrix().invert(&matrix)) { |
bsalomon | c21b09e | 2015-08-28 18:46:56 -0700 | [diff] [blame] | 220 | return nullptr; |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 221 | } |
brianosman | 839345d | 2016-07-22 11:04:53 -0700 | [diff] [blame] | 222 | if (args.fLocalMatrix) { |
commit-bot@chromium.org | 96fb748 | 2014-05-09 20:28:11 +0000 | [diff] [blame] | 223 | SkMatrix inv; |
brianosman | 839345d | 2016-07-22 11:04:53 -0700 | [diff] [blame] | 224 | if (!args.fLocalMatrix->invert(&inv)) { |
bsalomon | c21b09e | 2015-08-28 18:46:56 -0700 | [diff] [blame] | 225 | return nullptr; |
commit-bot@chromium.org | 96fb748 | 2014-05-09 20:28:11 +0000 | [diff] [blame] | 226 | } |
| 227 | matrix.postConcat(inv); |
| 228 | } |
bsalomon@google.com | f94b3a4 | 2012-10-31 18:09:01 +0000 | [diff] [blame] | 229 | matrix.postConcat(fPtsToUnit); |
mtklein | 3f3b3d0 | 2014-12-01 11:47:08 -0800 | [diff] [blame] | 230 | |
Brian Osman | 5911a7c | 2017-10-25 12:52:31 -0400 | [diff] [blame] | 231 | return GrSweepGradient::Make( |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 232 | GrGradientEffect::CreateArgs(args.fContext, this, &matrix, fTileMode, |
Brian Salomon | 4cbb6e6 | 2017-10-25 15:12:19 -0400 | [diff] [blame] | 233 | args.fDstColorSpaceInfo->colorSpace()), |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 234 | fTBias, fTScale); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | #endif |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 238 | |
Matt Sarett | 6cc6ae75 | 2017-04-18 18:29:12 -0400 | [diff] [blame] | 239 | sk_sp<SkShader> SkSweepGradient::onMakeColorSpace(SkColorSpaceXformer* xformer) const { |
Florin Malita | 39d71de | 2017-10-31 11:33:49 -0400 | [diff] [blame] | 240 | const AutoXformColors xformedColors(*this, xformer); |
Florin Malita | 545630b | 2017-08-02 10:42:41 -0400 | [diff] [blame] | 241 | |
| 242 | SkScalar startAngle, endAngle; |
| 243 | std::tie(startAngle, endAngle) = angles_from_t_coeff(fTBias, fTScale); |
| 244 | |
Florin Malita | 39d71de | 2017-10-31 11:33:49 -0400 | [diff] [blame] | 245 | return SkGradientShader::MakeSweep(fCenter.fX, fCenter.fY, xformedColors.fColors.get(), |
| 246 | fOrigPos, fColorCount, fTileMode, startAngle, endAngle, |
Florin Malita | 545630b | 2017-08-02 10:42:41 -0400 | [diff] [blame] | 247 | fGradFlags, &this->getLocalMatrix()); |
Matt Sarett | 6cc6ae75 | 2017-04-18 18:29:12 -0400 | [diff] [blame] | 248 | } |
| 249 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 250 | #ifndef SK_IGNORE_TO_STRING |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 251 | void SkSweepGradient::toString(SkString* str) const { |
| 252 | str->append("SkSweepGradient: ("); |
| 253 | |
| 254 | str->append("center: ("); |
| 255 | str->appendScalar(fCenter.fX); |
| 256 | str->append(", "); |
| 257 | str->appendScalar(fCenter.fY); |
| 258 | str->append(") "); |
| 259 | |
| 260 | this->INHERITED::toString(str); |
| 261 | |
| 262 | str->append(")"); |
| 263 | } |
Herb Derby | 7eb8698 | 2017-05-02 19:04:39 -0400 | [diff] [blame] | 264 | |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 265 | void SkSweepGradient::appendGradientStages(SkArenaAlloc* alloc, SkRasterPipeline* p, |
Florin Malita | 50b2084 | 2017-07-29 19:08:28 -0400 | [diff] [blame] | 266 | SkRasterPipeline*) const { |
Mike Klein | 5c7960b | 2017-05-11 10:59:22 -0400 | [diff] [blame] | 267 | p->append(SkRasterPipeline::xy_to_unit_angle); |
Florin Malita | 5a9a981 | 2017-08-01 16:38:08 -0400 | [diff] [blame] | 268 | p->append_matrix(alloc, SkMatrix::Concat(SkMatrix::MakeScale(fTScale, 1), |
| 269 | SkMatrix::MakeTrans(fTBias , 0))); |
Herb Derby | 7eb8698 | 2017-05-02 19:04:39 -0400 | [diff] [blame] | 270 | } |
| 271 | |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 272 | #endif |