blob: d35d70d7dd37e95d3aecee4895e0dd710e5cd3e7 [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
reed@google.com4e2b3d32011-04-07 14:18:59 +000026 virtual void init(SkCanvas*);
27 virtual bool next(SkCanvas*, SkPaint* paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +000028
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;
reed@google.com4e2b3d32011-04-07 14:18:59 +000051
52 // state-machine during the init/next cycle
53 Rec* fCurrRec;
reed@android.com8a1c16f2008-12-17 15:59:43 +000054
55 class MyRegistrar : public SkFlattenable::Registrar {
56 public:
57 MyRegistrar();
58 };
59
60 typedef SkDrawLooper INHERITED;
61};
62
63
64#endif