Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkLayerDrawLooper.h
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 
11 #include "SkDrawLooper.h"
12 #include "SkPaint.h"
13 #include "SkPoint.h"
14 #include "SkBlendMode.h"
15 
16 class SK_API SkLayerDrawLooper : public SkDrawLooper {
17 public:
18  ~SkLayerDrawLooper() override;
19 
27  enum Bits {
28  kStyle_Bit = 1 << 0,
29  kTextSkewX_Bit = 1 << 1,
30  kPathEffect_Bit = 1 << 2,
31  kMaskFilter_Bit = 1 << 3,
32  kShader_Bit = 1 << 4,
33  kColorFilter_Bit = 1 << 5,
34  kXfermode_Bit = 1 << 6,
35 
42  kEntirePaint_Bits = -1
43 
44  };
45  typedef int32_t BitFlags;
46 
58  struct SK_API LayerInfo {
59  BitFlags fPaintBits;
60  SkBlendMode fColorMode;
61  SkVector fOffset;
63 
71  LayerInfo();
72  };
73 
74  SkDrawLooper::Context* makeContext(SkCanvas*, SkArenaAlloc*) const override;
75 
76  bool asABlurShadow(BlurShadowRec* rec) const override;
77 
78  SK_TO_STRING_OVERRIDE()
79 
80  Factory getFactory() const override { return CreateProc; }
81  static sk_sp<SkFlattenable> CreateProc(SkReadBuffer& buffer);
82 
83 protected:
84  sk_sp<SkDrawLooper> onMakeColorSpace(SkColorSpaceXformer*) const override;
85 
87 
88  void flatten(SkWriteBuffer&) const override;
89 
90 private:
91  struct Rec {
92  Rec* fNext;
93  SkPaint fPaint;
94  LayerInfo fInfo;
95  };
96  Rec* fRecs;
97  int fCount;
98 
99  // state-machine during the init/next cycle
101  public:
102  explicit LayerDrawLooperContext(const SkLayerDrawLooper* looper);
103 
104  protected:
105  bool next(SkCanvas*, SkPaint* paint) override;
106 
107  private:
108  Rec* fCurrRec;
109 
110  static void ApplyInfo(SkPaint* dst, const SkPaint& src, const LayerInfo&);
111  };
112 
113  typedef SkDrawLooper INHERITED;
114 
115 public:
116  class SK_API Builder {
117  public:
118  Builder();
119  ~Builder();
120 
126  SkPaint* addLayer(const LayerInfo&);
127 
131  void addLayer(SkScalar dx, SkScalar dy);
132 
136  void addLayer() { this->addLayer(0, 0); }
137 
139  SkPaint* addLayerOnTop(const LayerInfo&);
140 
145  sk_sp<SkDrawLooper> detach();
146 
147  private:
148  Rec* fRecs;
149  Rec* fTopRec;
150  int fCount;
151  };
152 };
153 
154 #endif
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:59
Definition: SkLayerDrawLooper.h:116
Definition: SkPoint.h:156
Definition: SkLayerDrawLooper.h:16
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:45
Bits
Bits specifies which aspects of the layer's paint should replace the corresponding aspects on the dra...
Definition: SkLayerDrawLooper.h:27
SkFlattenable is the base class for objects that need to be flattened into a data stream for either t...
Definition: SkFlattenable.h:70
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:246
Definition: SkLayerDrawLooper.h:100
Info for how to apply the layer's paint and offset.
Definition: SkLayerDrawLooper.h:58
Holds state during a draw.
Definition: SkDrawLooper.h:41
void addLayer()
This layer will with the original paint and no offset.
Definition: SkLayerDrawLooper.h:136
Subclasses of SkDrawLooper can be attached to a SkPaint.
Definition: SkDrawLooper.h:33
Definition: SkWriteBuffer.h:27
Definition: SkDrawLooper.h:82
bool fPostTranslate
applies to fOffset
Definition: SkLayerDrawLooper.h:62
Definition: SkLayerDrawLooper.h:91