SkLayerDrawLooper.h revision 8a1c16ff38322f0210116fa7293eb8817c7e477e
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkLayerDrawLooper_DEFINED
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkLayerDrawLooper_DEFINED
38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDrawLooper.h"
58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comstruct SkPoint;
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkLayerDrawLooper : public SkDrawLooper {
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com            SkLayerDrawLooper();
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual ~SkLayerDrawLooper();
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Call for each layer you want to add (from top to bottom).
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        This returns a paint you can modify, but that ptr is only valid until
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the next call made to this object.
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPaint* addLayer(SkScalar dx, SkScalar dy);
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** Helper for addLayer() which passes (0, 0) for the offset parameters
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPaint* addLayer() {
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return this->addLayer(0, 0);
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // overrides from SkDrawLooper
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void init(SkCanvas*, SkPaint*);
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual bool next();
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void restore();
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // must be public for Registrar :(
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return SkNEW_ARGS(SkLayerDrawLooper, (buffer));
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkLayerDrawLooper(SkFlattenableReadBuffer&);
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    // overrides from SkFlattenable
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual void flatten(SkFlattenableWriteBuffer& );
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    virtual Factory getFactory() { return CreateProc; }
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    struct Rec {
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Rec*    fNext;
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPaint fPaint;
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPoint fOffset;
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        static Rec* Reverse(Rec*);
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Rec*    fRecs;
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int     fCount;
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    struct Iter {
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPaint     fSavedPaint;
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkPaint*    fPaint;
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        SkCanvas*   fCanvas;
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Rec*        fRec;
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Iter    fIter;
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    class MyRegistrar : public SkFlattenable::Registrar {
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    public:
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        MyRegistrar();
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    };
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    typedef SkDrawLooper INHERITED;
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
71