blob: 101d24ebb41529621cdc5949005ecb91b86680a0 [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;
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000024class SkColorFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000025
26/** \class SkBlurDrawLooper
27 This class draws a shadow of the object (possibly offset), and then draws
28 the original object in its original position.
29 should there be an option to just draw the shadow/blur layer? webkit?
30*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000031class SK_API SkBlurDrawLooper : public SkDrawLooper {
reed@android.com8a1c16f2008-12-17 15:59:43 +000032public:
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000033 enum BlurFlags {
34 kNone_BlurFlag = 0x00,
35 /**
36 The blur layer's dx/dy/radius aren't affected by the canvas
37 transform.
38 */
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000039 kIgnoreTransform_BlurFlag = 0x01,
40 kOverrideColor_BlurFlag = 0x02,
41 kHighQuality_BlurFlag = 0x04,
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000042 /** mask for all blur flags */
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000043 kAll_BlurFlag = 0x07
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000044 };
45
46 SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color,
47 uint32_t flags = kNone_BlurFlag);
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 virtual ~SkBlurDrawLooper();
49
50 // overrides from SkDrawLooper
51 virtual void init(SkCanvas*, SkPaint*);
52 virtual bool next();
53 virtual void restore();
54
55 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
56 return SkNEW_ARGS(SkBlurDrawLooper, (buffer));
57 }
58
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000059
reed@android.com8a1c16f2008-12-17 15:59:43 +000060protected:
61 SkBlurDrawLooper(SkFlattenableReadBuffer&);
62 // overrides from SkFlattenable
63 virtual void flatten(SkFlattenableWriteBuffer& );
64 virtual Factory getFactory() { return CreateProc; }
65
66private:
67 SkCanvas* fCanvas;
68 SkPaint* fPaint;
69 SkMaskFilter* fBlur;
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000070 SkColorFilter* fColorFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000071 SkScalar fDx, fDy;
72 SkColor fBlurColor;
73 SkColor fSavedColor; // remember the original
74 int fSaveCount;
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000075 uint32_t fBlurFlags;
reed@android.com8a1c16f2008-12-17 15:59:43 +000076
77 enum State {
78 kBeforeEdge,
79 kAfterEdge,
80 kDone
81 };
82 State fState;
83
84 typedef SkDrawLooper INHERITED;
85};
86
87#endif