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// TODO(dominikg): Worth making it truly immutable (i.e. set values in constructor)? 15// Should only be initialized once via init(). Immutable afterwards. 16struct 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; 28 bool fFlipped; 29 30 void init(const SkPoint& center0, SkScalar rad0, 31 const SkPoint& center1, SkScalar rad1, 32 bool flipped); 33 34 static bool DontDrawT(SkFixed t) { 35 return kDontDrawT == (uint32_t)t; 36 } 37}; 38 39 40class SkTwoPointConicalGradient : public SkGradientShaderBase { 41 TwoPtRadial fRec; 42public: 43 SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius, 44 const SkPoint& end, SkScalar endRadius, 45 bool flippedGrad, const Descriptor&); 46 47 48 size_t contextSize() const override; 49 50 class TwoPointConicalGradientContext : public SkGradientShaderBase::GradientShaderBaseContext { 51 public: 52 TwoPointConicalGradientContext(const SkTwoPointConicalGradient&, const ContextRec&); 53 ~TwoPointConicalGradientContext() {} 54 55 void shadeSpan(int x, int y, SkPMColor dstC[], int count) override; 56 57 private: 58 typedef SkGradientShaderBase::GradientShaderBaseContext INHERITED; 59 }; 60 61 virtual BitmapType asABitmap(SkBitmap* bitmap, 62 SkMatrix* matrix, 63 TileMode* xy) const override; 64 SkShader::GradientType asAGradient(GradientInfo* info) const override; 65 virtual bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, const SkMatrix*, 66 GrColor*, GrFragmentProcessor**) const override; 67 bool isOpaque() const override; 68 69 SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); } 70 SkScalar getStartRadius() const { return fRadius1; } 71 SkScalar getDiffRadius() const { return fRadius2 - fRadius1; } 72 const SkPoint& getStartCenter() const { return fCenter1; } 73 const SkPoint& getEndCenter() const { return fCenter2; } 74 SkScalar getEndRadius() const { return fRadius2; } 75 bool isFlippedGrad() const { return fFlippedGrad; } 76 77 SK_TO_STRING_OVERRIDE() 78 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient) 79 80protected: 81 SkTwoPointConicalGradient(SkReadBuffer& buffer); 82 void flatten(SkWriteBuffer& buffer) const override; 83 Context* onCreateContext(const ContextRec&, void* storage) const override; 84 85private: 86 SkPoint fCenter1; 87 SkPoint fCenter2; 88 SkScalar fRadius1; 89 SkScalar fRadius2; 90 bool fFlippedGrad; 91 92 friend class SkGradientShader; 93 typedef SkGradientShaderBase INHERITED; 94}; 95 96#endif 97