blob: 930af15ff8fe7fe67373fdd03e98673db8654fe2 [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
reed5e1ddb12015-12-21 08:52:45 -080038 static SkDrawLooper* Create(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
39 uint32_t flags = kNone_BlurFlag) {
halcanary385fe4d2015-08-26 13:07:48 -070040 return new SkBlurDrawLooper(color, sigma, dx, dy, flags);
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000041 }
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000042
reed@android.com8a1c16f2008-12-17 15:59:43 +000043 virtual ~SkBlurDrawLooper();
44
mtklein36352bf2015-03-25 18:17:31 -070045 SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const override;
commit-bot@chromium.org79fbb402014-03-12 09:42:01 +000046
mtklein36352bf2015-03-25 18:17:31 -070047 size_t contextSize() const override { return sizeof(BlurDrawLooperContext); }
reed@android.com8a1c16f2008-12-17 15:59:43 +000048
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +000049 SK_TO_STRING_OVERRIDE()
djsollen@google.comba28d032012-03-26 17:57:35 +000050 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper)
reed@android.com8a1c16f2008-12-17 15:59:43 +000051
52protected:
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000053 SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
54 uint32_t flags);
55
mtklein36352bf2015-03-25 18:17:31 -070056 void flatten(SkWriteBuffer&) const override;
reed@android.com8a1c16f2008-12-17 15:59:43 +000057
mtklein36352bf2015-03-25 18:17:31 -070058 bool asABlurShadow(BlurShadowRec*) const override;
reed@google.comdaaafa62014-04-29 15:20:16 +000059
reed@android.com8a1c16f2008-12-17 15:59:43 +000060private:
reed@android.com8a1c16f2008-12-17 15:59:43 +000061 SkMaskFilter* fBlur;
senorblanco@chromium.org4868e6b2011-02-18 19:03:01 +000062 SkColorFilter* fColorFilter;
reed@google.comdaaafa62014-04-29 15:20:16 +000063 SkScalar fDx, fDy, fSigma;
reed@android.com8a1c16f2008-12-17 15:59:43 +000064 SkColor fBlurColor;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000065 uint32_t fBlurFlags;
reed@android.com8a1c16f2008-12-17 15:59:43 +000066
67 enum State {
68 kBeforeEdge,
69 kAfterEdge,
70 kDone
71 };
commit-bot@chromium.org79fbb402014-03-12 09:42:01 +000072
73 class BlurDrawLooperContext : public SkDrawLooper::Context {
74 public:
75 explicit BlurDrawLooperContext(const SkBlurDrawLooper* looper);
76
mtklein36352bf2015-03-25 18:17:31 -070077 bool next(SkCanvas* canvas, SkPaint* paint) override;
commit-bot@chromium.org79fbb402014-03-12 09:42:01 +000078
79 private:
80 const SkBlurDrawLooper* fLooper;
81 State fState;
82 };
rmistry@google.comfbfcd562012-08-23 18:09:54 +000083
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000084 void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color, uint32_t flags);
reed@google.comdaaafa62014-04-29 15:20:16 +000085 void initEffects();
robertphillips@google.com7ce661d2013-08-27 16:14:03 +000086
reed@android.com8a1c16f2008-12-17 15:59:43 +000087 typedef SkDrawLooper INHERITED;
88};
89
90#endif