Skia
2D Graphics Library
SkDrawLooper.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2011 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkDrawLooper_DEFINED
11 #define SkDrawLooper_DEFINED
12 
14 #include "include/core/SkColor.h"
16 #include "include/core/SkPoint.h"
17 #include <functional> // std::function
18 
19 #ifndef SK_SUPPORT_LEGACY_DRAWLOOPER
20 #error "SkDrawLooper is unsupported"
21 #endif
22 
23 class SkArenaAlloc;
24 class SkCanvas;
25 class SkMatrix;
26 class SkPaint;
27 struct SkRect;
28 
32 class SK_API SkDrawLooper : public SkFlattenable {
33 public:
40  class SK_API Context {
41  public:
42  Context() {}
43  virtual ~Context() {}
44 
45  struct Info {
46  SkVector fTranslate;
48 
49  void applyToCTM(SkMatrix* ctm) const;
50  void applyToCanvas(SkCanvas*) const;
51  };
52 
67  virtual bool next(Info*, SkPaint*) = 0;
68 
69  private:
70  Context(const Context&) = delete;
71  Context& operator=(const Context&) = delete;
72  };
73 
78  virtual Context* makeContext(SkArenaAlloc*) const = 0;
79 
90  bool canComputeFastBounds(const SkPaint& paint) const;
91  void computeFastBounds(const SkPaint& paint, const SkRect& src, SkRect* dst) const;
92 
93  struct BlurShadowRec {
95  SkVector fOffset;
98  };
108  virtual bool asABlurShadow(BlurShadowRec*) const;
109 
111  return kSkDrawLooper_Type;
112  }
113 
115  return kSkDrawLooper_Type;
116  }
117 
118  static sk_sp<SkDrawLooper> Deserialize(const void* data, size_t size,
119  const SkDeserialProcs* procs = nullptr) {
120  return sk_sp<SkDrawLooper>(static_cast<SkDrawLooper*>(
122  kSkDrawLooper_Type, data, size, procs).release()));
123  }
124 
125  void apply(SkCanvas* canvas, const SkPaint& paint,
126  std::function<void(SkCanvas*, const SkPaint&)>);
127 
128 protected:
130 
131 private:
132  using INHERITED = SkFlattenable;
133 };
134 
135 #endif
SkBlurStyle
Definition: SkBlurTypes.h:11
Types, consts, functions, and macros for colors.
uint32_t SkColor
32-bit ARGB color value, unpremultiplied.
Definition: SkColor.h:37
float SkScalar
Definition: SkScalar.h:14
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
Holds state during a draw.
Definition: SkDrawLooper.h:40
virtual bool next(Info *, SkPaint *)=0
Called in a loop on objects returned by SkDrawLooper::createContext().
Context()
Definition: SkDrawLooper.h:42
virtual ~Context()
Definition: SkDrawLooper.h:43
DEPRECATED: No longer supported in Skia.
Definition: SkDrawLooper.h:32
virtual bool asABlurShadow(BlurShadowRec *) const
If this looper can be interpreted as having two layers, such that.
bool canComputeFastBounds(const SkPaint &paint) const
The fast bounds functions are used to enable the paint to be culled early in the drawing pipeline.
static sk_sp< SkDrawLooper > Deserialize(const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
Definition: SkDrawLooper.h:118
void computeFastBounds(const SkPaint &paint, const SkRect &src, SkRect *dst) const
static SkFlattenable::Type GetFlattenableType()
Definition: SkDrawLooper.h:110
SkFlattenable::Type getFlattenableType() const override
Definition: SkDrawLooper.h:114
virtual Context * makeContext(SkArenaAlloc *) const =0
Called right before something is being drawn.
void apply(SkCanvas *canvas, const SkPaint &paint, std::function< void(SkCanvas *, const SkPaint &)>)
SkDrawLooper()
Definition: SkDrawLooper.h:129
SkFlattenable is the base class for objects that need to be flattened into a data stream for either t...
Definition: SkFlattenable.h:28
static sk_sp< SkFlattenable > Deserialize(Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
SkFlattenable()
Definition: SkFlattenable.h:43
Type
Definition: SkFlattenable.h:30
@ kSkDrawLooper_Type
Definition: SkFlattenable.h:34
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
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: SkSerialProcs.h:97
Definition: SkDrawLooper.h:93
SkVector fOffset
Definition: SkDrawLooper.h:95
SkBlurStyle fStyle
Definition: SkDrawLooper.h:97
SkScalar fSigma
Definition: SkDrawLooper.h:94
SkColor fColor
Definition: SkDrawLooper.h:96
Definition: SkDrawLooper.h:45
void applyToCanvas(SkCanvas *) const
bool fApplyPostCTM
Definition: SkDrawLooper.h:47
void applyToCTM(SkMatrix *ctm) const
SkVector fTranslate
Definition: SkDrawLooper.h:46
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582