blob: 670ac23d87541e148da29070e31cb71a028b20cf [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#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*, SkPaint*);
27 virtual bool next();
28 virtual void restore();
29
30 // must be public for Registrar :(
31 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
32 return SkNEW_ARGS(SkLayerDrawLooper, (buffer));
33 }
34
35protected:
36 SkLayerDrawLooper(SkFlattenableReadBuffer&);
37
38 // overrides from SkFlattenable
39 virtual void flatten(SkFlattenableWriteBuffer& );
40 virtual Factory getFactory() { return CreateProc; }
41
42private:
43 struct Rec {
44 Rec* fNext;
45 SkPaint fPaint;
46 SkPoint fOffset;
47
48 static Rec* Reverse(Rec*);
49 };
50 Rec* fRecs;
51 int fCount;
52
53 struct Iter {
54 SkPaint fSavedPaint;
55 SkPaint* fPaint;
56 SkCanvas* fCanvas;
57 Rec* fRec;
58 };
59 Iter fIter;
60
61 class MyRegistrar : public SkFlattenable::Registrar {
62 public:
63 MyRegistrar();
64 };
65
66 typedef SkDrawLooper INHERITED;
67};
68
69
70#endif