2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2012-10-12 14:41:39 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkLayerDrawLooper_DEFINED
|
|
|
|
#define SkLayerDrawLooper_DEFINED
|
|
|
|
|
|
|
|
#include "SkDrawLooper.h"
|
2013-05-14 20:11:23 +00:00
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPoint.h"
|
2011-04-12 18:32:06 +00:00
|
|
|
#include "SkXfermode.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-04-15 15:42:24 +00:00
|
|
|
class SK_API SkLayerDrawLooper : public SkDrawLooper {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2012-06-27 14:03:26 +00:00
|
|
|
SK_DECLARE_INST_COUNT(SkLayerDrawLooper)
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual ~SkLayerDrawLooper();
|
2011-04-08 02:41:54 +00:00
|
|
|
|
2011-04-12 18:32:06 +00:00
|
|
|
/**
|
|
|
|
* Bits specifies which aspects of the layer's paint should replace the
|
|
|
|
* corresponding aspects on the draw's paint.
|
|
|
|
* kEntirePaint_Bits means use the layer's paint completely.
|
2014-02-28 15:38:22 +00:00
|
|
|
* 0 means ignore the layer's paint... except for fColorMode, which is
|
|
|
|
* always applied.
|
2011-04-12 18:32:06 +00:00
|
|
|
*/
|
2011-04-08 02:41:54 +00:00
|
|
|
enum Bits {
|
2011-04-12 18:32:06 +00:00
|
|
|
kStyle_Bit = 1 << 0, //!< use this layer's Style/stroke settings
|
|
|
|
kTextSkewX_Bit = 1 << 1, //!< use this layer's textskewx
|
|
|
|
kPathEffect_Bit = 1 << 2, //!< use this layer's patheffect
|
|
|
|
kMaskFilter_Bit = 1 << 3, //!< use this layer's maskfilter
|
|
|
|
kShader_Bit = 1 << 4, //!< use this layer's shader
|
|
|
|
kColorFilter_Bit = 1 << 5, //!< use this layer's colorfilter
|
|
|
|
kXfermode_Bit = 1 << 6, //!< use this layer's xfermode
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-11-21 16:42:10 +00:00
|
|
|
/**
|
|
|
|
* Use the layer's paint entirely, with these exceptions:
|
|
|
|
* - We never override the draw's paint's text_encoding, since that is
|
|
|
|
* used to interpret the text/len parameters in draw[Pos]Text.
|
2014-02-28 15:38:22 +00:00
|
|
|
* - Color is always computed using the LayerInfo's fColorMode.
|
2011-11-21 16:42:10 +00:00
|
|
|
*/
|
2012-06-01 13:15:47 +00:00
|
|
|
kEntirePaint_Bits = -1
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-04-08 02:41:54 +00:00
|
|
|
};
|
|
|
|
typedef int32_t BitFlags;
|
2011-04-12 18:32:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Info for how to apply the layer's paint and offset.
|
|
|
|
*
|
|
|
|
* fColorMode controls how we compute the final color for the layer:
|
|
|
|
* The layer's paint's color is treated as the SRC
|
|
|
|
* The draw's paint's color is treated as the DST
|
|
|
|
* final-color = Mode(layers-color, draws-color);
|
|
|
|
* Any SkXfermode::Mode will work. Two common choices are:
|
|
|
|
* kSrc_Mode: to use the layer's color, ignoring the draw's
|
|
|
|
* kDst_Mode: to just keep the draw's color, ignoring the layer's
|
|
|
|
*/
|
2011-04-15 15:42:24 +00:00
|
|
|
struct SK_API LayerInfo {
|
2011-04-12 18:32:06 +00:00
|
|
|
BitFlags fPaintBits;
|
|
|
|
SkXfermode::Mode fColorMode;
|
|
|
|
SkVector fOffset;
|
|
|
|
bool fPostTranslate; //!< applies to fOffset
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initial the LayerInfo. Defaults to settings that will draw the
|
|
|
|
* layer with no changes: e.g.
|
|
|
|
* fPaintBits == 0
|
|
|
|
* fColorMode == kDst_Mode
|
|
|
|
* fOffset == (0, 0)
|
|
|
|
*/
|
|
|
|
LayerInfo();
|
|
|
|
};
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const SK_OVERRIDE;
|
2014-03-12 09:42:01 +00:00
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
size_t contextSize() const SK_OVERRIDE { return sizeof(LayerDrawLooperContext); }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
bool asABlurShadow(BlurShadowRec* rec) const SK_OVERRIDE;
|
2014-04-29 15:20:16 +00:00
|
|
|
|
2014-03-13 18:02:17 +00:00
|
|
|
SK_TO_STRING_OVERRIDE()
|
2014-02-14 10:06:42 +00:00
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
Factory getFactory() const SK_OVERRIDE { return CreateProc; }
|
2014-02-14 10:06:42 +00:00
|
|
|
static SkFlattenable* CreateProc(SkReadBuffer& buffer);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2014-04-15 15:48:36 +00:00
|
|
|
SkLayerDrawLooper();
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void flatten(SkWriteBuffer&) const SK_OVERRIDE;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
struct Rec {
|
|
|
|
Rec* fNext;
|
|
|
|
SkPaint fPaint;
|
2011-04-12 18:32:06 +00:00
|
|
|
LayerInfo fInfo;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
Rec* fRecs;
|
2013-05-22 12:35:50 +00:00
|
|
|
Rec* fTopRec;
|
2008-12-17 15:59:43 +00:00
|
|
|
int fCount;
|
2011-04-07 14:18:59 +00:00
|
|
|
|
|
|
|
// state-machine during the init/next cycle
|
2014-03-12 09:42:01 +00:00
|
|
|
class LayerDrawLooperContext : public SkDrawLooper::Context {
|
|
|
|
public:
|
|
|
|
explicit LayerDrawLooperContext(const SkLayerDrawLooper* looper);
|
|
|
|
|
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
bool next(SkCanvas*, SkPaint* paint) SK_OVERRIDE;
|
2011-04-08 02:41:54 +00:00
|
|
|
|
2014-03-12 09:42:01 +00:00
|
|
|
private:
|
|
|
|
Rec* fCurrRec;
|
|
|
|
|
|
|
|
static void ApplyInfo(SkPaint* dst, const SkPaint& src, const LayerInfo&);
|
|
|
|
};
|
2011-04-08 02:41:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
class MyRegistrar : public SkFlattenable::Registrar {
|
|
|
|
public:
|
|
|
|
MyRegistrar();
|
|
|
|
};
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
typedef SkDrawLooper INHERITED;
|
2014-02-14 10:06:42 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
class SK_API Builder {
|
|
|
|
public:
|
|
|
|
Builder();
|
|
|
|
~Builder();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 addLayer().
|
|
|
|
*/
|
|
|
|
SkPaint* addLayer(const LayerInfo&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This layer will draw with the original paint, at the specified offset
|
|
|
|
*/
|
|
|
|
void addLayer(SkScalar dx, SkScalar dy);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This layer will with the original paint and no offset.
|
|
|
|
*/
|
|
|
|
void addLayer() { this->addLayer(0, 0); }
|
|
|
|
|
|
|
|
/// Similar to addLayer, but adds a layer to the top.
|
|
|
|
SkPaint* addLayerOnTop(const LayerInfo&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pass list of layers on to newly built looper and return it. This will
|
|
|
|
* also reset the builder, so it can be used to build another looper.
|
|
|
|
*/
|
|
|
|
SkLayerDrawLooper* detachLooper();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Rec* fRecs;
|
|
|
|
Rec* fTopRec;
|
|
|
|
int fCount;
|
|
|
|
};
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|