blob: e9688578891f3791c1d803f4fb56f9a23021070a [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2008 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
reed@android.com8a1c16f2008-12-17 15:59:43 +00009#ifndef SkBlurDrawLooper_DEFINED
10#define SkBlurDrawLooper_DEFINED
11
12#include "SkDrawLooper.h"
13#include "SkColor.h"
14
15class SkMaskFilter;
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000016class SkColorFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000017
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*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000023class SK_API SkBlurDrawLooper : public SkDrawLooper {
reed@android.com8a1c16f2008-12-17 15:59:43 +000024public:
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000025 enum BlurFlags {
26 kNone_BlurFlag = 0x00,
rmistry@google.comfbfcd562012-08-23 18:09:54 +000027 /**
28 The blur layer's dx/dy/radius aren't affected by the canvas
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000029 transform.
30 */
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000031 kIgnoreTransform_BlurFlag = 0x01,
32 kOverrideColor_BlurFlag = 0x02,
33 kHighQuality_BlurFlag = 0x04,
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000034 /** mask for all blur flags */
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +000035 kAll_BlurFlag = 0x07
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000036 };
37
rmistry@google.comfbfcd562012-08-23 18:09:54 +000038 SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color,
senorblanco@chromium.org038aff62010-12-06 23:45:58 +000039 uint32_t flags = kNone_BlurFlag);
reed@android.com8a1c16f2008-12-17 15:59:43 +000040 virtual ~SkBlurDrawLooper();
41
42 // overrides from SkDrawLooper
reed@google.com4e2b3d32011-04-07 14:18:59 +000043 virtual void init(SkCanvas*);
44 virtual bool next(SkCanvas*, SkPaint* paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +000045
robertphillips@google.com4991b8f2013-01-28 20:21:59 +000046 SK_DEVELOPER_TO_STRING()
djsollen@google.comba28d032012-03-26 17:57:35 +000047 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper)
reed@android.com8a1c16f2008-12-17 15:59:43 +000048
49protected:
50 SkBlurDrawLooper(SkFlattenableReadBuffer&);
djsollen@google.com54924242012-03-29 15:18:04 +000051 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
reed@android.com8a1c16f2008-12-17 15:59:43 +000052
53private:
reed@android.com8a1c16f2008-12-17 15:59:43 +000054 SkMaskFilter* fBlur;
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000055 SkColorFilter* fColorFilter;
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 SkScalar fDx, fDy;
57 SkColor fBlurColor;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000058 uint32_t fBlurFlags;
reed@android.com8a1c16f2008-12-17 15:59:43 +000059
60 enum State {
61 kBeforeEdge,
62 kAfterEdge,
63 kDone
64 };
65 State fState;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000066
reed@android.com8a1c16f2008-12-17 15:59:43 +000067 typedef SkDrawLooper INHERITED;
68};
69
70#endif