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 | |
| 9 | #ifndef SkTwoPointConicalGradient_DEFINED |
| 10 | #define SkTwoPointConicalGradient_DEFINED |
| 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); |
| 29 | |
| 30 | // used by setup and nextT |
| 31 | float fRelX, fRelY, fIncX, fIncY; |
| 32 | float fB, fDB; |
| 33 | |
| 34 | void setup(SkScalar fx, SkScalar fy, SkScalar dfx, SkScalar dfy); |
| 35 | SkFixed nextT(); |
| 36 | |
| 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, |
| 50 | const SkColor colors[], const SkScalar pos[], |
| 51 | int colorCount, SkShader::TileMode mode, |
| 52 | SkUnitMapper* mapper); |
| 53 | |
| 54 | virtual void shadeSpan(int x, int y, SkPMColor* dstCParam, |
| 55 | int count) SK_OVERRIDE; |
| 56 | virtual bool setContext(const SkBitmap& device, |
| 57 | const SkPaint& paint, |
| 58 | const SkMatrix& matrix) SK_OVERRIDE; |
| 59 | |
| 60 | virtual BitmapType asABitmap(SkBitmap* bitmap, |
| 61 | SkMatrix* matrix, |
| 62 | TileMode* xy) const; |
| 63 | virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE; |
| 64 | virtual GrCustomStage* asNewCustomStage(GrContext* context, |
| 65 | GrSamplerState* sampler) const SK_OVERRIDE; |
| 66 | |
| 67 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient) |
| 68 | |
| 69 | protected: |
| 70 | SkTwoPointConicalGradient(SkFlattenableReadBuffer& buffer); |
| 71 | virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; |
| 72 | |
| 73 | private: |
| 74 | typedef SkGradientShaderBase INHERITED; |
| 75 | const SkPoint fCenter1; |
| 76 | const SkPoint fCenter2; |
| 77 | const SkScalar fRadius1; |
| 78 | const SkScalar fRadius2; |
| 79 | }; |
| 80 | |
| 81 | #endif |
| 82 | |