rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
commit-bot@chromium.org | aa64fbf | 2014-04-03 14:59:19 +0000 | [diff] [blame] | 9 | #ifndef SkTwoPointConicalGradient_DEFINED |
| 10 | #define SkTwoPointConicalGradient_DEFINED |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 11 | |
| 12 | #include "SkGradientShaderPriv.h" |
| 13 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 14 | // TODO(dominikg): Worth making it truly immutable (i.e. set values in constructor)? |
| 15 | // Should only be initialized once via init(). Immutable afterwards. |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 16 | struct TwoPtRadial { |
| 17 | enum { |
benjaminwagner | 7ea5cb1 | 2016-02-24 06:51:52 -0800 | [diff] [blame^] | 18 | // This value is outside the range SK_FixedMin to SK_FixedMax. |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 19 | kDontDrawT = 0x80000000 |
| 20 | }; |
| 21 | |
| 22 | float fCenterX, fCenterY; |
| 23 | float fDCenterX, fDCenterY; |
| 24 | float fRadius; |
| 25 | float fDRadius; |
| 26 | float fA; |
| 27 | float fRadius2; |
| 28 | float fRDR; |
commit-bot@chromium.org | 44d83c1 | 2014-04-21 13:10:25 +0000 | [diff] [blame] | 29 | bool fFlipped; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 30 | |
| 31 | void init(const SkPoint& center0, SkScalar rad0, |
commit-bot@chromium.org | 44d83c1 | 2014-04-21 13:10:25 +0000 | [diff] [blame] | 32 | const SkPoint& center1, SkScalar rad1, |
| 33 | bool flipped); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 34 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 35 | static bool DontDrawT(SkFixed t) { |
| 36 | return kDontDrawT == (uint32_t)t; |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | |
| 41 | class SkTwoPointConicalGradient : public SkGradientShaderBase { |
| 42 | TwoPtRadial fRec; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 43 | public: |
| 44 | SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius, |
| 45 | const SkPoint& end, SkScalar endRadius, |
reed | addf2ed | 2014-08-11 08:28:24 -0700 | [diff] [blame] | 46 | bool flippedGrad, const Descriptor&); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 47 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 48 | |
fmalita | 8d9f2e4 | 2016-02-22 10:39:41 -0800 | [diff] [blame] | 49 | size_t contextSize(const ContextRec&) const override; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 50 | |
| 51 | class TwoPointConicalGradientContext : public SkGradientShaderBase::GradientShaderBaseContext { |
| 52 | public: |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 53 | TwoPointConicalGradientContext(const SkTwoPointConicalGradient&, const ContextRec&); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 54 | ~TwoPointConicalGradientContext() {} |
| 55 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 56 | void shadeSpan(int x, int y, SkPMColor dstC[], int count) override; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 57 | |
| 58 | private: |
| 59 | typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED; |
| 60 | }; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 61 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 62 | SkShader::GradientType asAGradient(GradientInfo* info) const override; |
bsalomon | c21b09e | 2015-08-28 18:46:56 -0700 | [diff] [blame] | 63 | #if SK_SUPPORT_GPU |
| 64 | const GrFragmentProcessor* asFragmentProcessor(GrContext*, |
| 65 | const SkMatrix&, |
| 66 | const SkMatrix*, |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 67 | SkFilterQuality) const override; |
bsalomon | c21b09e | 2015-08-28 18:46:56 -0700 | [diff] [blame] | 68 | #endif |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 69 | bool isOpaque() const override; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 70 | |
rileya@google.com | 1c6d64b | 2012-07-27 15:49:05 +0000 | [diff] [blame] | 71 | SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); } |
| 72 | SkScalar getStartRadius() const { return fRadius1; } |
| 73 | SkScalar getDiffRadius() const { return fRadius2 - fRadius1; } |
commit-bot@chromium.org | 2af1a2d | 2014-04-04 13:50:50 +0000 | [diff] [blame] | 74 | const SkPoint& getStartCenter() const { return fCenter1; } |
| 75 | const SkPoint& getEndCenter() const { return fCenter2; } |
| 76 | SkScalar getEndRadius() const { return fRadius2; } |
commit-bot@chromium.org | 44d83c1 | 2014-04-21 13:10:25 +0000 | [diff] [blame] | 77 | bool isFlippedGrad() const { return fFlippedGrad; } |
rileya@google.com | 1c6d64b | 2012-07-27 15:49:05 +0000 | [diff] [blame] | 78 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 79 | SK_TO_STRING_OVERRIDE() |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 80 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient) |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 81 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 82 | protected: |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 83 | SkTwoPointConicalGradient(SkReadBuffer& buffer); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 84 | void flatten(SkWriteBuffer& buffer) const override; |
| 85 | Context* onCreateContext(const ContextRec&, void* storage) const override; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 86 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 87 | private: |
commit-bot@chromium.org | 44d83c1 | 2014-04-21 13:10:25 +0000 | [diff] [blame] | 88 | SkPoint fCenter1; |
| 89 | SkPoint fCenter2; |
| 90 | SkScalar fRadius1; |
| 91 | SkScalar fRadius2; |
| 92 | bool fFlippedGrad; |
skia.committer@gmail.com | d3b28e8 | 2014-04-22 03:05:17 +0000 | [diff] [blame] | 93 | |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 94 | friend class SkGradientShader; |
commit-bot@chromium.org | 53783b0 | 2014-04-17 21:09:49 +0000 | [diff] [blame] | 95 | typedef SkGradientShaderBase INHERITED; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 98 | #endif |