16c432337818ff15e553c957d466a67e54684f97brileya@google.com
26c432337818ff15e553c957d466a67e54684f97brileya@google.com/*
36c432337818ff15e553c957d466a67e54684f97brileya@google.com * Copyright 2012 Google Inc.
46c432337818ff15e553c957d466a67e54684f97brileya@google.com *
56c432337818ff15e553c957d466a67e54684f97brileya@google.com * Use of this source code is governed by a BSD-style license that can be
66c432337818ff15e553c957d466a67e54684f97brileya@google.com * found in the LICENSE file.
76c432337818ff15e553c957d466a67e54684f97brileya@google.com */
86c432337818ff15e553c957d466a67e54684f97brileya@google.com
96c432337818ff15e553c957d466a67e54684f97brileya@google.com #ifndef SkTwoPointConicalGradient_DEFINED
106c432337818ff15e553c957d466a67e54684f97brileya@google.com #define SkTwoPointConicalGradient_DEFINED
116c432337818ff15e553c957d466a67e54684f97brileya@google.com
126c432337818ff15e553c957d466a67e54684f97brileya@google.com#include "SkGradientShaderPriv.h"
136c432337818ff15e553c957d466a67e54684f97brileya@google.com
146c432337818ff15e553c957d466a67e54684f97brileya@google.comstruct TwoPtRadial {
156c432337818ff15e553c957d466a67e54684f97brileya@google.com    enum {
166c432337818ff15e553c957d466a67e54684f97brileya@google.com        kDontDrawT  = 0x80000000
176c432337818ff15e553c957d466a67e54684f97brileya@google.com    };
186c432337818ff15e553c957d466a67e54684f97brileya@google.com
196c432337818ff15e553c957d466a67e54684f97brileya@google.com    float   fCenterX, fCenterY;
206c432337818ff15e553c957d466a67e54684f97brileya@google.com    float   fDCenterX, fDCenterY;
216c432337818ff15e553c957d466a67e54684f97brileya@google.com    float   fRadius;
226c432337818ff15e553c957d466a67e54684f97brileya@google.com    float   fDRadius;
236c432337818ff15e553c957d466a67e54684f97brileya@google.com    float   fA;
246c432337818ff15e553c957d466a67e54684f97brileya@google.com    float   fRadius2;
256c432337818ff15e553c957d466a67e54684f97brileya@google.com    float   fRDR;
266c432337818ff15e553c957d466a67e54684f97brileya@google.com
276c432337818ff15e553c957d466a67e54684f97brileya@google.com    void init(const SkPoint& center0, SkScalar rad0,
286c432337818ff15e553c957d466a67e54684f97brileya@google.com              const SkPoint& center1, SkScalar rad1);
29935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com
306c432337818ff15e553c957d466a67e54684f97brileya@google.com    // used by setup and nextT
316c432337818ff15e553c957d466a67e54684f97brileya@google.com    float   fRelX, fRelY, fIncX, fIncY;
326c432337818ff15e553c957d466a67e54684f97brileya@google.com    float   fB, fDB;
33935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com
346c432337818ff15e553c957d466a67e54684f97brileya@google.com    void setup(SkScalar fx, SkScalar fy, SkScalar dfx, SkScalar dfy);
356c432337818ff15e553c957d466a67e54684f97brileya@google.com    SkFixed nextT();
36935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com
376c432337818ff15e553c957d466a67e54684f97brileya@google.com    static bool DontDrawT(SkFixed t) {
386c432337818ff15e553c957d466a67e54684f97brileya@google.com        return kDontDrawT == (uint32_t)t;
396c432337818ff15e553c957d466a67e54684f97brileya@google.com    }
406c432337818ff15e553c957d466a67e54684f97brileya@google.com};
416c432337818ff15e553c957d466a67e54684f97brileya@google.com
426c432337818ff15e553c957d466a67e54684f97brileya@google.com
436c432337818ff15e553c957d466a67e54684f97brileya@google.comclass SkTwoPointConicalGradient : public SkGradientShaderBase {
446c432337818ff15e553c957d466a67e54684f97brileya@google.com    TwoPtRadial fRec;
456c432337818ff15e553c957d466a67e54684f97brileya@google.com    void init();
466c432337818ff15e553c957d466a67e54684f97brileya@google.com
476c432337818ff15e553c957d466a67e54684f97brileya@google.compublic:
486c432337818ff15e553c957d466a67e54684f97brileya@google.com    SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius,
496c432337818ff15e553c957d466a67e54684f97brileya@google.com                              const SkPoint& end, SkScalar endRadius,
5052d6fb7020e41328b86785a5ea12d42f44f36b8creed@google.com                              const Descriptor&);
51935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com
526c432337818ff15e553c957d466a67e54684f97brileya@google.com    virtual void shadeSpan(int x, int y, SkPMColor* dstCParam,
536c432337818ff15e553c957d466a67e54684f97brileya@google.com                           int count) SK_OVERRIDE;
546c432337818ff15e553c957d466a67e54684f97brileya@google.com    virtual bool setContext(const SkBitmap& device,
556c432337818ff15e553c957d466a67e54684f97brileya@google.com                            const SkPaint& paint,
566c432337818ff15e553c957d466a67e54684f97brileya@google.com                            const SkMatrix& matrix) SK_OVERRIDE;
576c432337818ff15e553c957d466a67e54684f97brileya@google.com
586c432337818ff15e553c957d466a67e54684f97brileya@google.com    virtual BitmapType asABitmap(SkBitmap* bitmap,
596c432337818ff15e553c957d466a67e54684f97brileya@google.com                                 SkMatrix* matrix,
606c432337818ff15e553c957d466a67e54684f97brileya@google.com                                 TileMode* xy) const;
616c432337818ff15e553c957d466a67e54684f97brileya@google.com    virtual SkShader::GradientType asAGradient(GradientInfo* info) const  SK_OVERRIDE;
6238b58f31a3070ea9254d55894a59528270ac67ddbsalomon@google.com    virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) const SK_OVERRIDE;
63f999f59dac04f742f6c45c2c029d563538e97620commit-bot@chromium.org    virtual bool isOpaque() const SK_OVERRIDE;
646c432337818ff15e553c957d466a67e54684f97brileya@google.com
6524a508e688b595f3381afc9a0e9d069e483fa360rileya@google.com    SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
6624a508e688b595f3381afc9a0e9d069e483fa360rileya@google.com    SkScalar getStartRadius() const { return fRadius1; }
6724a508e688b595f3381afc9a0e9d069e483fa360rileya@google.com    SkScalar getDiffRadius() const { return fRadius2 - fRadius1; }
6824a508e688b595f3381afc9a0e9d069e483fa360rileya@google.com
69bc0c7b3fc892adc21eeac2d56b02a525ee811fdbrobertphillips@google.com    SK_DEVELOPER_TO_STRING()
706c432337818ff15e553c957d466a67e54684f97brileya@google.com    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTwoPointConicalGradient)
71935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com
726c432337818ff15e553c957d466a67e54684f97brileya@google.comprotected:
736c432337818ff15e553c957d466a67e54684f97brileya@google.com    SkTwoPointConicalGradient(SkFlattenableReadBuffer& buffer);
746c432337818ff15e553c957d466a67e54684f97brileya@google.com    virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE;
75935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com
766c432337818ff15e553c957d466a67e54684f97brileya@google.comprivate:
776c432337818ff15e553c957d466a67e54684f97brileya@google.com    typedef SkGradientShaderBase INHERITED;
786c432337818ff15e553c957d466a67e54684f97brileya@google.com    const SkPoint fCenter1;
796c432337818ff15e553c957d466a67e54684f97brileya@google.com    const SkPoint fCenter2;
806c432337818ff15e553c957d466a67e54684f97brileya@google.com    const SkScalar fRadius1;
816c432337818ff15e553c957d466a67e54684f97brileya@google.com    const SkScalar fRadius2;
826c432337818ff15e553c957d466a67e54684f97brileya@google.com};
836c432337818ff15e553c957d466a67e54684f97brileya@google.com
846c432337818ff15e553c957d466a67e54684f97brileya@google.com#endif
85