blob: 6f96ff633d803e932bd8418a9ceb6698dd03e108 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkBlurDrawLooper_DEFINED
18#define SkBlurDrawLooper_DEFINED
19
20#include "SkDrawLooper.h"
21#include "SkColor.h"
22
23class SkMaskFilter;
24
25/** \class SkBlurDrawLooper
26 This class draws a shadow of the object (possibly offset), and then draws
27 the original object in its original position.
28 should there be an option to just draw the shadow/blur layer? webkit?
29*/
30class SkBlurDrawLooper : public SkDrawLooper {
31public:
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000032 enum BlurFlags {
33 kNone_BlurFlag = 0x00,
34 /**
35 The blur layer's dx/dy/radius aren't affected by the canvas
36 transform.
37 */
38 kIgnoreTransform_BlurFlag = 0x01,
39 /** mask for all blur flags */
40 kAll_BlurFlag = 0x01
41 };
42
43 SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color,
44 uint32_t flags = kNone_BlurFlag);
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 virtual ~SkBlurDrawLooper();
46
47 // overrides from SkDrawLooper
48 virtual void init(SkCanvas*, SkPaint*);
49 virtual bool next();
50 virtual void restore();
51
52 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
53 return SkNEW_ARGS(SkBlurDrawLooper, (buffer));
54 }
55
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000056
reed@android.com8a1c16f2008-12-17 15:59:43 +000057protected:
58 SkBlurDrawLooper(SkFlattenableReadBuffer&);
59 // overrides from SkFlattenable
60 virtual void flatten(SkFlattenableWriteBuffer& );
61 virtual Factory getFactory() { return CreateProc; }
62
63private:
64 SkCanvas* fCanvas;
65 SkPaint* fPaint;
66 SkMaskFilter* fBlur;
67 SkScalar fDx, fDy;
68 SkColor fBlurColor;
69 SkColor fSavedColor; // remember the original
70 int fSaveCount;
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000071 uint32_t fBlurFlags;
reed@android.com8a1c16f2008-12-17 15:59:43 +000072
73 enum State {
74 kBeforeEdge,
75 kAfterEdge,
76 kDone
77 };
78 State fState;
79
80 typedef SkDrawLooper INHERITED;
81};
82
83#endif