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 { |
| 18 | kDontDrawT = 0x80000000 |
| 19 | }; |
| 20 | |
| 21 | float fCenterX, fCenterY; |
| 22 | float fDCenterX, fDCenterY; |
| 23 | float fRadius; |
| 24 | float fDRadius; |
| 25 | float fA; |
| 26 | float fRadius2; |
| 27 | float fRDR; |
commit-bot@chromium.org | 44d83c1 | 2014-04-21 13:10:25 +0000 | [diff] [blame] | 28 | bool fFlipped; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 29 | |
| 30 | void init(const SkPoint& center0, SkScalar rad0, |
commit-bot@chromium.org | 44d83c1 | 2014-04-21 13:10:25 +0000 | [diff] [blame] | 31 | const SkPoint& center1, SkScalar rad1, |
| 32 | bool flipped); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 33 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 34 | static bool DontDrawT(SkFixed t) { |
| 35 | return kDontDrawT == (uint32_t)t; |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | |
| 40 | class SkTwoPointConicalGradient : public SkGradientShaderBase { |
| 41 | TwoPtRadial fRec; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 42 | public: |
| 43 | SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius, |
| 44 | const SkPoint& end, SkScalar endRadius, |
reed | addf2ed | 2014-08-11 08:28:24 -0700 | [diff] [blame] | 45 | bool flippedGrad, const Descriptor&); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 46 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 47 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 48 | size_t contextSize() const override; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 49 | |
| 50 | class TwoPointConicalGradientContext : public SkGradientShaderBase::GradientShaderBaseContext { |
| 51 | public: |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 52 | TwoPointConicalGradientContext(const SkTwoPointConicalGradient&, const ContextRec&); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 53 | ~TwoPointConicalGradientContext() {} |
| 54 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 55 | 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] | 56 | |
| 57 | private: |
| 58 | typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED; |
| 59 | }; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 60 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 61 | SkShader::GradientType asAGradient(GradientInfo* info) const override; |
bsalomon | c21b09e | 2015-08-28 18:46:56 -0700 | [diff] [blame^] | 62 | #if SK_SUPPORT_GPU |
| 63 | const GrFragmentProcessor* asFragmentProcessor(GrContext*, |
| 64 | const SkMatrix&, |
| 65 | const SkMatrix*, |
| 66 | SkFilterQuality, |
| 67 | GrProcessorDataManager*) const override; |
| 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 |