reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | #ifndef SkLayerDrawLooper_DEFINED |
| 2 | #define SkLayerDrawLooper_DEFINED |
| 3 | |
| 4 | #include "SkDrawLooper.h" |
| 5 | |
| 6 | struct SkPoint; |
| 7 | |
| 8 | class SkLayerDrawLooper : public SkDrawLooper { |
| 9 | public: |
| 10 | SkLayerDrawLooper(); |
| 11 | virtual ~SkLayerDrawLooper(); |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame^] | 12 | |
| 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame^] | 28 | /** |
| 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 36 | */ |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame^] | 37 | SkPaint* addLayer(SkScalar dx, SkScalar dy, BitFlags = kEntirePaint_Bits); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame^] | 39 | /** |
| 40 | * Helper for addLayer() which passes (0, 0) for the offset parameters |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | */ |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame^] | 42 | SkPaint* addLayer(BitFlags bits = kEntirePaint_Bits) { |
| 43 | return this->addLayer(0, 0, bits); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | // overrides from SkDrawLooper |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 47 | virtual void init(SkCanvas*); |
| 48 | virtual bool next(SkCanvas*, SkPaint* paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | |
| 50 | // must be public for Registrar :( |
| 51 | static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { |
| 52 | return SkNEW_ARGS(SkLayerDrawLooper, (buffer)); |
| 53 | } |
| 54 | |
| 55 | protected: |
| 56 | SkLayerDrawLooper(SkFlattenableReadBuffer&); |
| 57 | |
| 58 | // overrides from SkFlattenable |
| 59 | virtual void flatten(SkFlattenableWriteBuffer& ); |
| 60 | virtual Factory getFactory() { return CreateProc; } |
| 61 | |
| 62 | private: |
| 63 | struct Rec { |
| 64 | Rec* fNext; |
| 65 | SkPaint fPaint; |
| 66 | SkPoint fOffset; |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame^] | 67 | uint32_t fBits; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 68 | |
| 69 | static Rec* Reverse(Rec*); |
| 70 | }; |
| 71 | Rec* fRecs; |
| 72 | int fCount; |
reed@google.com | 4e2b3d3 | 2011-04-07 14:18:59 +0000 | [diff] [blame] | 73 | |
| 74 | // state-machine during the init/next cycle |
| 75 | Rec* fCurrRec; |
mike@reedtribe.org | 0e2810b | 2011-04-08 02:41:54 +0000 | [diff] [blame^] | 76 | |
| 77 | static void ApplyBits(SkPaint* dst, const SkPaint& src, BitFlags bits); |
| 78 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 79 | class MyRegistrar : public SkFlattenable::Registrar { |
| 80 | public: |
| 81 | MyRegistrar(); |
| 82 | }; |
| 83 | |
| 84 | typedef SkDrawLooper INHERITED; |
| 85 | }; |
| 86 | |
| 87 | |
| 88 | #endif |