2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkLayerDrawLooper_DEFINED
|
|
|
|
#define SkLayerDrawLooper_DEFINED
|
|
|
|
|
|
|
|
#include "SkDrawLooper.h"
|
|
|
|
|
|
|
|
struct SkPoint;
|
|
|
|
|
|
|
|
class SkLayerDrawLooper : public SkDrawLooper {
|
|
|
|
public:
|
|
|
|
SkLayerDrawLooper();
|
|
|
|
virtual ~SkLayerDrawLooper();
|
2011-04-08 02:41:54 +00:00
|
|
|
|
|
|
|
enum Bits {
|
|
|
|
kAlpha_Bit = 1 << 0, //!< use this layer's alpha
|
|
|
|
kColor_Bit = 1 << 1, //!< use this layer's color
|
|
|
|
kStyle_Bit = 1 << 2, //!< use this layer's Style/stroke settings
|
|
|
|
kTextSkewX_Bit = 1 << 3, //!< use this layer's textskewx
|
|
|
|
kPathEffect_Bit = 1 << 4, //!< use this layer's patheffect
|
|
|
|
kMaskFilter_Bit = 1 << 5, //!< use this layer's maskfilter
|
|
|
|
kShader_Bit = 1 << 6, //!< use this layer's shader
|
|
|
|
kColorFilter_Bit = 1 << 7, //!< use this layer's colorfilter
|
|
|
|
kXfermode_Bit = 1 << 8, //!< use this layer's xfermode
|
|
|
|
|
|
|
|
kEntirePaint_Bits = -1, //!< use this layer's paint entirely
|
|
|
|
};
|
|
|
|
typedef int32_t BitFlags;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-04-08 02:41:54 +00:00
|
|
|
/**
|
|
|
|
* Call for each layer you want to add (from top to bottom).
|
|
|
|
* This returns a paint you can modify, but that ptr is only valid until
|
|
|
|
* the next call made to this object.
|
|
|
|
*
|
|
|
|
* The optional bits parameter specifies which aspects of this paint
|
|
|
|
* should replace the paint that is passed to the draw call. If 0 is
|
|
|
|
* specified, then this layer's paint will be ignored.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2011-04-08 02:41:54 +00:00
|
|
|
SkPaint* addLayer(SkScalar dx, SkScalar dy, BitFlags = kEntirePaint_Bits);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-04-08 02:41:54 +00:00
|
|
|
/**
|
|
|
|
* Helper for addLayer() which passes (0, 0) for the offset parameters
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2011-04-08 02:41:54 +00:00
|
|
|
SkPaint* addLayer(BitFlags bits = kEntirePaint_Bits) {
|
|
|
|
return this->addLayer(0, 0, bits);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// overrides from SkDrawLooper
|
2011-04-07 14:18:59 +00:00
|
|
|
virtual void init(SkCanvas*);
|
|
|
|
virtual bool next(SkCanvas*, SkPaint* paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
// must be public for Registrar :(
|
|
|
|
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
|
|
|
|
return SkNEW_ARGS(SkLayerDrawLooper, (buffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkLayerDrawLooper(SkFlattenableReadBuffer&);
|
|
|
|
|
|
|
|
// overrides from SkFlattenable
|
|
|
|
virtual void flatten(SkFlattenableWriteBuffer& );
|
|
|
|
virtual Factory getFactory() { return CreateProc; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Rec {
|
|
|
|
Rec* fNext;
|
|
|
|
SkPaint fPaint;
|
|
|
|
SkPoint fOffset;
|
2011-04-08 02:41:54 +00:00
|
|
|
uint32_t fBits;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
static Rec* Reverse(Rec*);
|
|
|
|
};
|
|
|
|
Rec* fRecs;
|
|
|
|
int fCount;
|
2011-04-07 14:18:59 +00:00
|
|
|
|
|
|
|
// state-machine during the init/next cycle
|
|
|
|
Rec* fCurrRec;
|
2011-04-08 02:41:54 +00:00
|
|
|
|
|
|
|
static void ApplyBits(SkPaint* dst, const SkPaint& src, BitFlags bits);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
class MyRegistrar : public SkFlattenable::Registrar {
|
|
|
|
public:
|
|
|
|
MyRegistrar();
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef SkDrawLooper INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|