Skia
2D Graphics Library
SkLayerDrawLooper.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkLayerDrawLooper_DEFINED
9 #define SkLayerDrawLooper_DEFINED
10 
13 #include "include/core/SkPaint.h"
14 #include "include/core/SkPoint.h"
15 
16 #ifndef SK_SUPPORT_LEGACY_DRAWLOOPER
17 #error "SkDrawLooper is unsupported"
18 #endif
19 
23 class SK_API SkLayerDrawLooper : public SkDrawLooper {
24 public:
25  ~SkLayerDrawLooper() override;
26 
34  enum Bits {
35  kStyle_Bit = 1 << 0,
36  kPathEffect_Bit = 1 << 2,
37  kMaskFilter_Bit = 1 << 3,
38  kShader_Bit = 1 << 4,
39  kColorFilter_Bit = 1 << 5,
40  kXfermode_Bit = 1 << 6,
41 
42  // unsupported kTextSkewX_Bit = 1 << 1,
43 
50  kEntirePaint_Bits = -1
51 
52  };
53  typedef int32_t BitFlags;
54 
66  struct SK_API LayerInfo {
69  SkVector fOffset;
71 
80  };
81 
82  SkDrawLooper::Context* makeContext(SkArenaAlloc*) const override;
83 
84  bool asABlurShadow(BlurShadowRec* rec) const override;
85 
86 protected:
88 
89  void flatten(SkWriteBuffer&) const override;
90 
91 private:
93 
94  struct Rec {
95  Rec* fNext;
96  SkPaint fPaint;
97  LayerInfo fInfo;
98  };
99  Rec* fRecs;
100  int fCount;
101 
102  // state-machine during the init/next cycle
103  class LayerDrawLooperContext : public SkDrawLooper::Context {
104  public:
105  explicit LayerDrawLooperContext(const SkLayerDrawLooper* looper);
106 
107  protected:
108  bool next(Info*, SkPaint* paint) override;
109 
110  private:
111  Rec* fCurrRec;
112 
113  static void ApplyInfo(SkPaint* dst, const SkPaint& src, const LayerInfo&);
114  };
115 
116  using INHERITED = SkDrawLooper;
117 
118 public:
119  class SK_API Builder {
120  public:
122 
124 
131 
135  void addLayer(SkScalar dx, SkScalar dy);
136 
140  void addLayer() { this->addLayer(0, 0); }
141 
144 
150 
151  private:
152  Builder(const Builder&) = delete;
153  Builder& operator=(const Builder&) = delete;
154 
155  Rec* fRecs;
156  Rec* fTopRec;
157  int fCount;
158  };
159 };
160 
161 #endif
SkBlendMode
Blends are operators that take in two colors (source, destination) and return a new color.
Definition: SkBlendMode.h:38
#define SK_FLATTENABLE_HOOKS(type)
Definition: SkFlattenable.h:108
float SkScalar
Definition: SkScalar.h:14
Holds state during a draw.
Definition: SkDrawLooper.h:40
DEPRECATED: No longer supported in Skia.
Definition: SkDrawLooper.h:32
SkDrawLooper()
Definition: SkDrawLooper.h:129
Definition: SkLayerDrawLooper.h:119
void addLayer(SkScalar dx, SkScalar dy)
This layer will draw with the original paint, at the specified offset.
SkPaint * addLayerOnTop(const LayerInfo &)
Similar to addLayer, but adds a layer to the top.
sk_sp< SkDrawLooper > detach()
Pass list of layers on to newly built looper and return it.
SkPaint * addLayer(const LayerInfo &)
Call for each layer you want to add (from top to bottom).
void addLayer()
This layer will with the original paint and no offset.
Definition: SkLayerDrawLooper.h:140
DEPRECATED: No longer supported by Skia.
Definition: SkLayerDrawLooper.h:23
void flatten(SkWriteBuffer &) const override
Override this if your subclass needs to record data that it will need to recreate itself from its Cre...
~SkLayerDrawLooper() override
Bits
Bits specifies which aspects of the layer's paint should replace the corresponding aspects on the dra...
Definition: SkLayerDrawLooper.h:34
int32_t BitFlags
Definition: SkLayerDrawLooper.h:53
SkDrawLooper::Context * makeContext(SkArenaAlloc *) const override
Called right before something is being drawn.
bool asABlurShadow(BlurShadowRec *rec) const override
If this looper can be interpreted as having two layers, such that.
SkPaint controls options applied when drawing.
Definition: SkPaint.h:44
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
Definition: SkDrawLooper.h:93
Info for how to apply the layer's paint and offset.
Definition: SkLayerDrawLooper.h:66
SkBlendMode fColorMode
Definition: SkLayerDrawLooper.h:68
bool fPostTranslate
applies to fOffset
Definition: SkLayerDrawLooper.h:70
SkVector fOffset
Definition: SkLayerDrawLooper.h:69
BitFlags fPaintBits
Definition: SkLayerDrawLooper.h:67
LayerInfo()
Initial the LayerInfo.