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 | |
| 14 | struct TwoPtRadial { |
| 15 | enum { |
| 16 | kDontDrawT = 0x80000000 |
| 17 | }; |
| 18 | |
| 19 | float fCenterX, fCenterY; |
| 20 | float fDCenterX, fDCenterY; |
| 21 | float fRadius; |
| 22 | float fDRadius; |
| 23 | float fA; |
| 24 | float fRadius2; |
| 25 | float fRDR; |
| 26 | |
| 27 | void init(const SkPoint& center0, SkScalar rad0, |
| 28 | const SkPoint& center1, SkScalar rad1); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 29 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 30 | // used by setup and nextT |
| 31 | float fRelX, fRelY, fIncX, fIncY; |
| 32 | float fB, fDB; |
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 | void setup(SkScalar fx, SkScalar fy, SkScalar dfx, SkScalar dfy); |
| 35 | SkFixed nextT(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 36 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 37 | static bool DontDrawT(SkFixed t) { |
| 38 | return kDontDrawT == (uint32_t)t; |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | |
| 43 | class SkTwoPointConicalGradient : public SkGradientShaderBase { |
| 44 | TwoPtRadial fRec; |
| 45 | void init(); |
| 46 | |
| 47 | public: |
| 48 | SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius, |
| 49 | const SkPoint& end, SkScalar endRadius, |
reed@google.com | 437d6eb | 2013-05-23 19:03:05 +0000 | [diff] [blame] | 50 | const Descriptor&); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 51 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 52 | virtual void shadeSpan(int x, int y, SkPMColor* dstCParam, |
| 53 | int count) SK_OVERRIDE; |
| 54 | virtual bool setContext(const SkBitmap& device, |
| 55 | const SkPaint& paint, |
| 56 | const SkMatrix& matrix) SK_OVERRIDE; |
| 57 | |
| 58 | virtual BitmapType asABitmap(SkBitmap* bitmap, |
| 59 | SkMatrix* matrix, |
| 60 | TileMode* xy) const; |
| 61 | virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE; |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 62 | virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) const SK_OVERRIDE; |
commit-bot@chromium.org | 3fbab82 | 2013-03-20 00:49:57 +0000 | [diff] [blame] | 63 | virtual bool isOpaque() const SK_OVERRIDE; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 64 | |
rileya@google.com | 1c6d64b | 2012-07-27 15:49:05 +0000 | [diff] [blame] | 65 | SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); } |
| 66 | SkScalar getStartRadius() const { return fRadius1; } |
| 67 | SkScalar getDiffRadius() const { return fRadius2 - fRadius1; } |
commit-bot@chromium.org | 2af1a2d | 2014-04-04 13:50:50 +0000 | [diff] [blame^] | 68 | const SkPoint& getStartCenter() const { return fCenter1; } |
| 69 | const SkPoint& getEndCenter() const { return fCenter2; } |
| 70 | SkScalar getEndRadius() const { return fRadius2; } |
rileya@google.com | 1c6d64b | 2012-07-27 15:49:05 +0000 | [diff] [blame] | 71 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 72 | SK_TO_STRING_OVERRIDE() |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 73 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient) |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 74 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 75 | protected: |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 76 | SkTwoPointConicalGradient(SkReadBuffer& buffer); |
| 77 | virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 78 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 79 | private: |
| 80 | typedef SkGradientShaderBase INHERITED; |
| 81 | const SkPoint fCenter1; |
| 82 | const SkPoint fCenter2; |
| 83 | const SkScalar fRadius1; |
| 84 | const SkScalar fRadius2; |
| 85 | }; |
| 86 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 87 | #endif |