reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2008 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | #ifndef SkBlurDrawLooper_DEFINED |
| 10 | #define SkBlurDrawLooper_DEFINED |
| 11 | |
| 12 | #include "SkDrawLooper.h" |
| 13 | #include "SkColor.h" |
| 14 | |
| 15 | class SkMaskFilter; |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 16 | class SkColorFilter; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 17 | |
| 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.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 23 | class SK_API SkBlurDrawLooper : public SkDrawLooper { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | public: |
senorblanco@chromium.org | 038aff6 | 2010-12-06 23:45:58 +0000 | [diff] [blame] | 25 | enum BlurFlags { |
| 26 | kNone_BlurFlag = 0x00, |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 27 | /** |
| 28 | The blur layer's dx/dy/radius aren't affected by the canvas |
senorblanco@chromium.org | 038aff6 | 2010-12-06 23:45:58 +0000 | [diff] [blame] | 29 | transform. |
| 30 | */ |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 31 | kIgnoreTransform_BlurFlag = 0x01, |
| 32 | kOverrideColor_BlurFlag = 0x02, |
| 33 | kHighQuality_BlurFlag = 0x04, |
senorblanco@chromium.org | 038aff6 | 2010-12-06 23:45:58 +0000 | [diff] [blame] | 34 | /** mask for all blur flags */ |
senorblanco@chromium.org | 91f489a | 2012-11-29 17:09:27 +0000 | [diff] [blame] | 35 | kAll_BlurFlag = 0x07 |
senorblanco@chromium.org | 038aff6 | 2010-12-06 23:45:58 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
reed | 2d6ba66 | 2015-12-20 20:08:42 -0800 | [diff] [blame^] | 38 | static SkBlurDrawLooper* Create(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy, |
| 39 | uint32_t flags = kNone_BlurFlag) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 40 | return new SkBlurDrawLooper(color, sigma, dx, dy, flags); |
commit-bot@chromium.org | 73cb153 | 2014-04-15 15:48:36 +0000 | [diff] [blame] | 41 | } |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 42 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | virtual ~SkBlurDrawLooper(); |
| 44 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 45 | SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const override; |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 46 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 47 | size_t contextSize() const override { return sizeof(BlurDrawLooperContext); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 49 | SK_TO_STRING_OVERRIDE() |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 50 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | |
| 52 | protected: |
commit-bot@chromium.org | 73cb153 | 2014-04-15 15:48:36 +0000 | [diff] [blame] | 53 | SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy, |
| 54 | uint32_t flags); |
| 55 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 56 | void flatten(SkWriteBuffer&) const override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 58 | bool asABlurShadow(BlurShadowRec*) const override; |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 59 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 60 | private: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | SkMaskFilter* fBlur; |
senorblanco@chromium.org | 4868e6b | 2011-02-18 19:03:01 +0000 | [diff] [blame] | 62 | SkColorFilter* fColorFilter; |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 63 | SkScalar fDx, fDy, fSigma; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | SkColor fBlurColor; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 65 | uint32_t fBlurFlags; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | |
| 67 | enum State { |
| 68 | kBeforeEdge, |
| 69 | kAfterEdge, |
| 70 | kDone |
| 71 | }; |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 72 | |
| 73 | class BlurDrawLooperContext : public SkDrawLooper::Context { |
| 74 | public: |
| 75 | explicit BlurDrawLooperContext(const SkBlurDrawLooper* looper); |
| 76 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 77 | bool next(SkCanvas* canvas, SkPaint* paint) override; |
commit-bot@chromium.org | 79fbb40 | 2014-03-12 09:42:01 +0000 | [diff] [blame] | 78 | |
| 79 | private: |
| 80 | const SkBlurDrawLooper* fLooper; |
| 81 | State fState; |
| 82 | }; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 83 | |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 84 | void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color, uint32_t flags); |
reed@google.com | daaafa6 | 2014-04-29 15:20:16 +0000 | [diff] [blame] | 85 | void initEffects(); |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 86 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 87 | typedef SkDrawLooper INHERITED; |
| 88 | }; |
| 89 | |
| 90 | #endif |