blob: 846048c858cd2d3e50565a426b8bb8b3a0573314 [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
reed@google.com4e2b3d32011-04-07 14:18:59 +000051 virtual void init(SkCanvas*);
52 virtual bool next(SkCanvas*, SkPaint* paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +000053
54 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
55 return SkNEW_ARGS(SkBlurDrawLooper, (buffer));
56 }
57
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000058
reed@android.com8a1c16f2008-12-17 15:59:43 +000059protected:
60 SkBlurDrawLooper(SkFlattenableReadBuffer&);
61 // overrides from SkFlattenable
62 virtual void flatten(SkFlattenableWriteBuffer& );
63 virtual Factory getFactory() { return CreateProc; }
64
65private:
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 SkMaskFilter* fBlur;
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000067 SkColorFilter* fColorFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000068 SkScalar fDx, fDy;
69 SkColor fBlurColor;
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000070 uint32_t fBlurFlags;
reed@android.com8a1c16f2008-12-17 15:59:43 +000071
72 enum State {
73 kBeforeEdge,
74 kAfterEdge,
75 kDone
76 };
77 State fState;
78
79 typedef SkDrawLooper INHERITED;
80};
81
82#endif