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
|
|
|
|
Revert "Reland "remove toString""
This reverts commit 92e37b6d79f12ccfaaf7671413316952d182267d.
Reason for revert: toString still used by flutter
Original change's description:
> Reland "remove toString"
>
> This reverts commit 32a4910e57b1fdd3c8671de1ee85e05ca21d079f.
>
> Reason for revert: SkMatrix::toString use has been removed from flutter and has been picked up in fuchsia
>
> Original change's description:
> > Revert "remove toString"
> >
> > This reverts commit 5191880cbf3ee4d122b0d11b4945fbab0784fda7.
> >
> > Reason for revert: broke flutter
> >
> > Original change's description:
> > > remove toString
> > >
> > > toString may have been used by obsolete debugger only
> > > find out if that is so
> > >
> > > R=​brianosman@google.com,bsalomon@google.com
> > >
> > > Docs-Preview: https://skia.org/?cl=119894
> > > Bug:830651
> > > Change-Id: I737f19b7d3fbc869bea2f443fa3b5ed7c1393ffd
> > > Reviewed-on: https://skia-review.googlesource.com/119894
> > > Commit-Queue: Cary Clark <caryclark@google.com>
> > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> >
> > TBR=bsalomon@google.com,brianosman@google.com,caryclark@google.com,caryclark@skia.org
> >
> > Change-Id: I9f81de6c3615ee0608bcea9081b77239b4b8816c
> > No-Presubmit: true
> > No-Tree-Checks: true
> > No-Try: true
> > Bug: 830651
> > Reviewed-on: https://skia-review.googlesource.com/129340
> > Reviewed-by: Cary Clark <caryclark@google.com>
> > Commit-Queue: Cary Clark <caryclark@google.com>
>
> TBR=bsalomon@google.com,brianosman@google.com,caryclark@google.com,caryclark@skia.org
>
> # Not skipping CQ checks because original CL landed > 1 day ago.
>
> Bug: 830651
> Change-Id: Ida8725b6051132d8c46faf99358a8fcc1bcabf34
> Reviewed-on: https://skia-review.googlesource.com/129623
> Reviewed-by: Cary Clark <caryclark@skia.org>
> Reviewed-by: Cary Clark <caryclark@google.com>
> Commit-Queue: Cary Clark <caryclark@google.com>
TBR=bsalomon@google.com,brianosman@google.com,caryclark@google.com,caryclark@skia.org
Change-Id: Iafc59ffc1b3db67c520ba31bf12d68e1b46c0ea2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 830651
Reviewed-on: https://skia-review.googlesource.com/131082
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Cary Clark <caryclark@google.com>
2018-05-31 12:27:33 +00:00
|
|
|
void toString(SkString* str) const override;
|
|
|
|
|
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
|