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