• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "SkColor.h"
9 #include "SkImageFilter.h"
10 #include "SkScalar.h"
11 
12 class SK_API SkDropShadowImageFilter : public SkImageFilter {
13 public:
14     enum ShadowMode {
15         kDrawShadowAndForeground_ShadowMode,
16         kDrawShadowOnly_ShadowMode,
17 
18         kLast_ShadowMode = kDrawShadowOnly_ShadowMode
19     };
20 
21     static const int kShadowModeCount = kLast_ShadowMode+1;
22 
23     static SkDropShadowImageFilter* Create(SkScalar dx, SkScalar dy,
24                                            SkScalar sigmaX, SkScalar sigmaY, SkColor color,
25                                            ShadowMode shadowMode,
26                                            SkImageFilter* input = NULL,
27                                            const CropRect* cropRect = NULL) {
28         return SkNEW_ARGS(SkDropShadowImageFilter, (dx, dy, sigmaX, sigmaY, color,
29                                                     shadowMode, input, cropRect));
30     }
31 
32     void computeFastBounds(const SkRect&, SkRect*) const override;
33     SK_TO_STRING_OVERRIDE()
34     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDropShadowImageFilter)
35 
36 protected:
37     SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkScalar sigmaX, SkScalar sigmaY, SkColor,
38                             ShadowMode shadowMode, SkImageFilter* input, const CropRect* cropRect);
39     void flatten(SkWriteBuffer&) const override;
40     bool onFilterImage(Proxy*, const SkBitmap& source, const Context&, SkBitmap* result, SkIPoint* loc) const override;
41     virtual bool onFilterBounds(const SkIRect& src, const SkMatrix&,
42                                 SkIRect* dst) const override;
43 
44 private:
45     SkScalar fDx, fDy, fSigmaX, fSigmaY;
46     SkColor fColor;
47     ShadowMode fShadowMode;
48     typedef SkImageFilter INHERITED;
49 };
50