blob: 682a9dc1190751019426586258dc33907e462a55 [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();
mike@reedtribe.org0e2810b2011-04-08 02:41:54 +000012
13 enum Bits {
14 kAlpha_Bit = 1 << 0, //!< use this layer's alpha
15 kColor_Bit = 1 << 1, //!< use this layer's color
16 kStyle_Bit = 1 << 2, //!< use this layer's Style/stroke settings
17 kTextSkewX_Bit = 1 << 3, //!< use this layer's textskewx
18 kPathEffect_Bit = 1 << 4, //!< use this layer's patheffect
19 kMaskFilter_Bit = 1 << 5, //!< use this layer's maskfilter
20 kShader_Bit = 1 << 6, //!< use this layer's shader
21 kColorFilter_Bit = 1 << 7, //!< use this layer's colorfilter
22 kXfermode_Bit = 1 << 8, //!< use this layer's xfermode
23
24 kEntirePaint_Bits = -1, //!< use this layer's paint entirely
25 };
26 typedef int32_t BitFlags;
reed@android.com8a1c16f2008-12-17 15:59:43 +000027
mike@reedtribe.org0e2810b2011-04-08 02:41:54 +000028 /**
29 * Call for each layer you want to add (from top to bottom).
30 * This returns a paint you can modify, but that ptr is only valid until
31 * the next call made to this object.
32 *
33 * The optional bits parameter specifies which aspects of this paint
34 * should replace the paint that is passed to the draw call. If 0 is
35 * specified, then this layer's paint will be ignored.
reed@android.com8a1c16f2008-12-17 15:59:43 +000036 */
mike@reedtribe.org0e2810b2011-04-08 02:41:54 +000037 SkPaint* addLayer(SkScalar dx, SkScalar dy, BitFlags = kEntirePaint_Bits);
reed@android.com8a1c16f2008-12-17 15:59:43 +000038
mike@reedtribe.org0e2810b2011-04-08 02:41:54 +000039 /**
40 * Helper for addLayer() which passes (0, 0) for the offset parameters
reed@android.com8a1c16f2008-12-17 15:59:43 +000041 */
mike@reedtribe.org0e2810b2011-04-08 02:41:54 +000042 SkPaint* addLayer(BitFlags bits = kEntirePaint_Bits) {
43 return this->addLayer(0, 0, bits);
reed@android.com8a1c16f2008-12-17 15:59:43 +000044 }
45
46 // overrides from SkDrawLooper
reed@google.com4e2b3d32011-04-07 14:18:59 +000047 virtual void init(SkCanvas*);
48 virtual bool next(SkCanvas*, SkPaint* paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +000049
50 // must be public for Registrar :(
51 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
52 return SkNEW_ARGS(SkLayerDrawLooper, (buffer));
53 }
54
55protected:
56 SkLayerDrawLooper(SkFlattenableReadBuffer&);
57
58 // overrides from SkFlattenable
59 virtual void flatten(SkFlattenableWriteBuffer& );
60 virtual Factory getFactory() { return CreateProc; }
61
62private:
63 struct Rec {
64 Rec* fNext;
65 SkPaint fPaint;
66 SkPoint fOffset;
mike@reedtribe.org0e2810b2011-04-08 02:41:54 +000067 uint32_t fBits;
reed@android.com8a1c16f2008-12-17 15:59:43 +000068
69 static Rec* Reverse(Rec*);
70 };
71 Rec* fRecs;
72 int fCount;
reed@google.com4e2b3d32011-04-07 14:18:59 +000073
74 // state-machine during the init/next cycle
75 Rec* fCurrRec;
mike@reedtribe.org0e2810b2011-04-08 02:41:54 +000076
77 static void ApplyBits(SkPaint* dst, const SkPaint& src, BitFlags bits);
78
reed@android.com8a1c16f2008-12-17 15:59:43 +000079 class MyRegistrar : public SkFlattenable::Registrar {
80 public:
81 MyRegistrar();
82 };
83
84 typedef SkDrawLooper INHERITED;
85};
86
87
88#endif