SkBlurDrawLooper.h revision 91f489a65d436d36c7fe580af2775cd0cd13c8d2
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
15class SkMaskFilter;
16class SkColorFilter;
17
18/** \class SkBlurDrawLooper
19    This class draws a shadow of the object (possibly offset), and then draws
20    the original object in its original position.
21    should there be an option to just draw the shadow/blur layer? webkit?
22*/
23class SK_API SkBlurDrawLooper : public SkDrawLooper {
24public:
25    enum BlurFlags {
26        kNone_BlurFlag = 0x00,
27        /**
28            The blur layer's dx/dy/radius aren't affected by the canvas
29            transform.
30        */
31        kIgnoreTransform_BlurFlag   = 0x01,
32        kOverrideColor_BlurFlag     = 0x02,
33        kHighQuality_BlurFlag       = 0x04,
34        /** mask for all blur flags */
35        kAll_BlurFlag               = 0x07
36    };
37
38    SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color,
39                     uint32_t flags = kNone_BlurFlag);
40    virtual ~SkBlurDrawLooper();
41
42    // overrides from SkDrawLooper
43    virtual void init(SkCanvas*);
44    virtual bool next(SkCanvas*, SkPaint* paint);
45
46    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper)
47
48protected:
49    SkBlurDrawLooper(SkFlattenableReadBuffer&);
50    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
51
52private:
53    SkMaskFilter*   fBlur;
54    SkColorFilter*  fColorFilter;
55    SkScalar        fDx, fDy;
56    SkColor         fBlurColor;
57    uint32_t        fBlurFlags;
58
59    enum State {
60        kBeforeEdge,
61        kAfterEdge,
62        kDone
63    };
64    State   fState;
65
66    typedef SkDrawLooper INHERITED;
67};
68
69#endif
70