180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2012 Google Inc.
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #ifndef SkTwoPointConicalGradient_DEFINED
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru #define SkTwoPointConicalGradient_DEFINED
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkGradientShaderPriv.h"
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustruct TwoPtRadial {
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    enum {
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kDontDrawT  = 0x80000000
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    float   fCenterX, fCenterY;
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    float   fDCenterX, fDCenterY;
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    float   fRadius;
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    float   fDRadius;
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    float   fA;
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    float   fRadius2;
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    float   fRDR;
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void init(const SkPoint& center0, SkScalar rad0,
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru              const SkPoint& center1, SkScalar rad1);
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // used by setup and nextT
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    float   fRelX, fRelY, fIncX, fIncY;
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    float   fB, fDB;
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setup(SkScalar fx, SkScalar fy, SkScalar dfx, SkScalar dfy);
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkFixed nextT();
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool DontDrawT(SkFixed t) {
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return kDontDrawT == (uint32_t)t;
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkTwoPointConicalGradient : public SkGradientShaderBase {
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    TwoPtRadial fRec;
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void init();
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius,
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                              const SkPoint& end, SkScalar endRadius,
50779bf8a99dc7f03e5c43b26d4b85d7920ce89aeeDerek Sollenberger                              const Descriptor&);
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual void shadeSpan(int x, int y, SkPMColor* dstCParam,
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                           int count) SK_OVERRIDE;
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual bool setContext(const SkBitmap& device,
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            const SkPaint& paint,
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                            const SkMatrix& matrix) SK_OVERRIDE;
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual BitmapType asABitmap(SkBitmap* bitmap,
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                 SkMatrix* matrix,
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                                 TileMode* xy) const;
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual SkShader::GradientType asAGradient(GradientInfo* info) const  SK_OVERRIDE;
62d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) const SK_OVERRIDE;
63096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger    virtual bool isOpaque() const SK_OVERRIDE;
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkScalar getStartRadius() const { return fRadius1; }
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkScalar getDiffRadius() const { return fRadius2 - fRadius1; }
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
69d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger    SK_DEVELOPER_TO_STRING()
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient)
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprotected:
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkTwoPointConicalGradient(SkFlattenableReadBuffer& buffer);
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE;
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    typedef SkGradientShaderBase INHERITED;
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SkPoint fCenter1;
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SkPoint fCenter2;
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SkScalar fRadius1;
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const SkScalar fRadius2;
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
85