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"
|
2016-11-18 22:19:54 +00:00
|
|
|
#include "SkBlendMode.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:
|
2017-03-22 16:05:03 +00:00
|
|
|
~SkLayerDrawLooper() override;
|
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);
|
2016-11-18 22:19:54 +00:00
|
|
|
* Any SkBlendMode will work. Two common choices are:
|
|
|
|
* kSrc: to use the layer's color, ignoring the draw's
|
|
|
|
* kDst: to just keep the draw's color, ignoring the layer's
|
2011-04-12 18:32:06 +00:00
|
|
|
*/
|
2011-04-15 15:42:24 +00:00
|
|
|
struct SK_API LayerInfo {
|
2016-11-03 18:45:31 +00:00
|
|
|
BitFlags fPaintBits;
|
|
|
|
SkBlendMode fColorMode;
|
|
|
|
SkVector fOffset;
|
|
|
|
bool fPostTranslate; //!< applies to fOffset
|
2011-04-12 18:32:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
};
|
|
|
|
|
2017-02-08 20:12:19 +00:00
|
|
|
SkDrawLooper::Context* makeContext(SkCanvas*, SkArenaAlloc*) const override;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool asABlurShadow(BlurShadowRec* rec) const 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-03-26 01:17:31 +00:00
|
|
|
Factory getFactory() const override { return CreateProc; }
|
2016-04-03 16:11:13 +00:00
|
|
|
static sk_sp<SkFlattenable> CreateProc(SkReadBuffer& buffer);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2017-03-30 16:41:48 +00:00
|
|
|
sk_sp<SkDrawLooper> onMakeColorSpace(SkColorSpaceXformer*) const override;
|
|
|
|
|
2014-04-15 15:48:36 +00:00
|
|
|
SkLayerDrawLooper();
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void flatten(SkWriteBuffer&) const 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;
|
|
|
|
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-03-26 01:17:31 +00:00
|
|
|
bool next(SkCanvas*, SkPaint* paint) 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
|
|
|
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.
|
|
|
|
*/
|
2016-03-21 20:25:16 +00:00
|
|
|
sk_sp<SkDrawLooper> detach();
|
2014-02-14 10:06:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Rec* fRecs;
|
|
|
|
Rec* fTopRec;
|
|
|
|
int fCount;
|
|
|
|
};
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|