Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkBlurDrawLooper.h
1 /*
2  * Copyright 2008 The Android Open Source Project
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 
9 #ifndef SkBlurDrawLooper_DEFINED
10 #define SkBlurDrawLooper_DEFINED
11 
12 #include "SkDrawLooper.h"
13 #include "SkColor.h"
14 
15 class SkMaskFilter;
16 class SkColorFilter;
17 
23 class SK_API SkBlurDrawLooper : public SkDrawLooper {
24 public:
25  enum BlurFlags {
26  kNone_BlurFlag = 0x00,
31  kIgnoreTransform_BlurFlag = 0x01,
32  kOverrideColor_BlurFlag = 0x02,
33  kHighQuality_BlurFlag = 0x04,
35  kAll_BlurFlag = 0x07
36  };
37 
38  static sk_sp<SkDrawLooper> Make(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
39  uint32_t flags = kNone_BlurFlag) {
40  return sk_sp<SkDrawLooper>(new SkBlurDrawLooper(color, sigma, dx, dy, flags));
41  }
42 #ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
43  static SkDrawLooper* Create(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
44  uint32_t flags = kNone_BlurFlag) {
45  return Make(color, sigma, dx, dy, flags).release();
46  }
47 #endif
48 
49  SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const override;
50 
51  size_t contextSize() const override { return sizeof(BlurDrawLooperContext); }
52 
53  SK_TO_STRING_OVERRIDE()
54  SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper)
55 
56 protected:
57  SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
58  uint32_t flags);
59 
60  void flatten(SkWriteBuffer&) const override;
61 
62  bool asABlurShadow(BlurShadowRec*) const override;
63 
64 private:
65  sk_sp<SkMaskFilter> fBlur;
66  sk_sp<SkColorFilter> fColorFilter;
67  SkScalar fDx, fDy, fSigma;
68  SkColor fBlurColor;
69  uint32_t fBlurFlags;
70 
71  enum State {
72  kBeforeEdge,
73  kAfterEdge,
74  kDone
75  };
76 
78  public:
79  explicit BlurDrawLooperContext(const SkBlurDrawLooper* looper);
80 
81  bool next(SkCanvas* canvas, SkPaint* paint) override;
82 
83  private:
84  const SkBlurDrawLooper* fLooper;
85  State fState;
86  };
87 
88  void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color, uint32_t flags);
89  void initEffects();
90 
91  typedef SkDrawLooper INHERITED;
92 };
93 
94 #endif
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:58
ColorFilters are optional objects in the drawing pipeline.
Definition: SkColorFilter.h:29
This class draws a shadow of the object (possibly offset), and then draws the original object in its ...
Definition: SkBlurDrawLooper.h:23
Definition: SkBlurDrawLooper.h:77
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:46
SkFlattenable is the base class for objects that need to be flattened into a data stream for either t...
Definition: SkFlattenable.h:70
BlurFlags
Definition: SkBlurDrawLooper.h:25
SkMaskFilter is the base class for object that perform transformations on an alpha-channel mask befor...
Definition: SkMaskFilter.h:44
Holds state during a draw.
Definition: SkDrawLooper.h:39
virtual Context * createContext(SkCanvas *, void *storage) const =0
Called right before something is being drawn.
uint32_t SkColor
32 bit ARGB color value, not premultiplied.
Definition: SkColor.h:28
size_t contextSize() const override
Returns the number of bytes needed to store subclasses of Context (belonging to the corresponding SkD...
Definition: SkBlurDrawLooper.h:51
Subclasses of SkDrawLooper can be attached to a SkPaint.
Definition: SkDrawLooper.h:31
Definition: SkWriteBuffer.h:26
Types and macros for colors.