junov@chromium.org | f44fcdc | 2013-08-07 20:00:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
robertphillips | 0a291c7 | 2016-03-23 05:00:01 -0700 | [diff] [blame] | 8 | #ifndef SkDropShadowImageFilter_DEFINED |
| 9 | #define SkDropShadowImageFilter_DEFINED |
| 10 | |
junov@chromium.org | f44fcdc | 2013-08-07 20:00:55 +0000 | [diff] [blame] | 11 | #include "SkColor.h" |
| 12 | #include "SkImageFilter.h" |
| 13 | #include "SkScalar.h" |
| 14 | |
| 15 | class SK_API SkDropShadowImageFilter : public SkImageFilter { |
| 16 | public: |
sugoi | 234f036 | 2014-10-23 13:59:52 -0700 | [diff] [blame] | 17 | enum ShadowMode { |
| 18 | kDrawShadowAndForeground_ShadowMode, |
robertphillips | f3f5bad | 2014-12-19 13:49:15 -0800 | [diff] [blame] | 19 | kDrawShadowOnly_ShadowMode, |
| 20 | |
| 21 | kLast_ShadowMode = kDrawShadowOnly_ShadowMode |
sugoi | 234f036 | 2014-10-23 13:59:52 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
robertphillips | f3f5bad | 2014-12-19 13:49:15 -0800 | [diff] [blame] | 24 | static const int kShadowModeCount = kLast_ShadowMode+1; |
| 25 | |
robertphillips | c416912 | 2016-04-06 08:40:59 -0700 | [diff] [blame^] | 26 | static sk_sp<SkImageFilter> Make(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY, |
| 27 | SkColor color, ShadowMode shadowMode, |
| 28 | sk_sp<SkImageFilter> input, |
| 29 | const CropRect* cropRect = nullptr) { |
| 30 | return sk_sp<SkImageFilter>(new SkDropShadowImageFilter(dx, dy, sigmaX, sigmaY, |
| 31 | color, shadowMode, |
| 32 | std::move(input), |
| 33 | cropRect)); |
sugoi | 234f036 | 2014-10-23 13:59:52 -0700 | [diff] [blame] | 34 | } |
| 35 | |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 36 | SkRect computeFastBounds(const SkRect&) const override; |
robertphillips | f3f5bad | 2014-12-19 13:49:15 -0800 | [diff] [blame] | 37 | SK_TO_STRING_OVERRIDE() |
junov@chromium.org | f44fcdc | 2013-08-07 20:00:55 +0000 | [diff] [blame] | 38 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDropShadowImageFilter) |
| 39 | |
robertphillips | c416912 | 2016-04-06 08:40:59 -0700 | [diff] [blame^] | 40 | #ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR |
| 41 | static SkImageFilter* Create(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY, |
| 42 | SkColor color, ShadowMode shadowMode, |
| 43 | SkImageFilter* input = nullptr, |
| 44 | const CropRect* cropRect = nullptr) { |
| 45 | return Make(dx, dy, sigmaX, sigmaY, color, shadowMode, |
| 46 | sk_ref_sp<SkImageFilter>(input), cropRect).release(); |
| 47 | } |
| 48 | #endif |
| 49 | |
junov@chromium.org | f44fcdc | 2013-08-07 20:00:55 +0000 | [diff] [blame] | 50 | protected: |
schenney | 95376a0 | 2015-10-06 12:59:55 -0700 | [diff] [blame] | 51 | void flatten(SkWriteBuffer&) const override; |
robertphillips | 2302de9 | 2016-03-24 07:26:32 -0700 | [diff] [blame] | 52 | sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, |
| 53 | SkIPoint* offset) const override; |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 54 | SkIRect onFilterNodeBounds(const SkIRect& src, const SkMatrix&, MapDirection) const override; |
reed | 80a6dca | 2015-10-06 11:12:23 -0700 | [diff] [blame] | 55 | |
schenney | 95376a0 | 2015-10-06 12:59:55 -0700 | [diff] [blame] | 56 | private: |
reed | 5ea95df | 2015-10-06 14:05:32 -0700 | [diff] [blame] | 57 | SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY, SkColor, |
robertphillips | c416912 | 2016-04-06 08:40:59 -0700 | [diff] [blame^] | 58 | ShadowMode shadowMode, sk_sp<SkImageFilter> input, |
| 59 | const CropRect* cropRect); |
reed | 5ea95df | 2015-10-06 14:05:32 -0700 | [diff] [blame] | 60 | |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 61 | SkScalar fDx, fDy, fSigmaX, fSigmaY; |
junov@chromium.org | f44fcdc | 2013-08-07 20:00:55 +0000 | [diff] [blame] | 62 | SkColor fColor; |
sugoi | 234f036 | 2014-10-23 13:59:52 -0700 | [diff] [blame] | 63 | ShadowMode fShadowMode; |
reed | 5ea95df | 2015-10-06 14:05:32 -0700 | [diff] [blame] | 64 | |
junov@chromium.org | f44fcdc | 2013-08-07 20:00:55 +0000 | [diff] [blame] | 65 | typedef SkImageFilter INHERITED; |
| 66 | }; |
robertphillips | 0a291c7 | 2016-03-23 05:00:01 -0700 | [diff] [blame] | 67 | |
| 68 | #endif |