SkLayerDrawLooper.h revision 4e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7b
1#ifndef SkLayerDrawLooper_DEFINED
2#define SkLayerDrawLooper_DEFINED
3
4#include "SkDrawLooper.h"
5
6struct SkPoint;
7
8class SkLayerDrawLooper : public SkDrawLooper {
9public:
10            SkLayerDrawLooper();
11    virtual ~SkLayerDrawLooper();
12
13    /** Call for each layer you want to add (from top to bottom).
14        This returns a paint you can modify, but that ptr is only valid until
15        the next call made to this object.
16     */
17    SkPaint* addLayer(SkScalar dx, SkScalar dy);
18
19    /** Helper for addLayer() which passes (0, 0) for the offset parameters
20     */
21    SkPaint* addLayer() {
22        return this->addLayer(0, 0);
23    }
24
25    // overrides from SkDrawLooper
26    virtual void init(SkCanvas*);
27    virtual bool next(SkCanvas*, SkPaint* paint);
28
29    // must be public for Registrar :(
30    static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
31        return SkNEW_ARGS(SkLayerDrawLooper, (buffer));
32    }
33
34protected:
35    SkLayerDrawLooper(SkFlattenableReadBuffer&);
36
37    // overrides from SkFlattenable
38    virtual void flatten(SkFlattenableWriteBuffer& );
39    virtual Factory getFactory() { return CreateProc; }
40
41private:
42    struct Rec {
43        Rec*    fNext;
44        SkPaint fPaint;
45        SkPoint fOffset;
46
47        static Rec* Reverse(Rec*);
48    };
49    Rec*    fRecs;
50    int     fCount;
51
52    // state-machine during the init/next cycle
53    Rec* fCurrRec;
54
55    class MyRegistrar : public SkFlattenable::Registrar {
56    public:
57        MyRegistrar();
58    };
59
60    typedef SkDrawLooper INHERITED;
61};
62
63
64#endif
65