1 /*
2  * Copyright 2012 The Android Open Source Project
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 #ifndef SkMergeImageFilter_DEFINED
9 #define SkMergeImageFilter_DEFINED
10 
11 #include "SkImageFilter.h"
12 
13 #include "SkXfermode.h"
14 
15 class SK_API SkMergeImageFilter : public SkImageFilter {
16 public:
17     virtual ~SkMergeImageFilter();
18 
19     static SkImageFilter* Create(SkImageFilter* first, SkImageFilter* second,
20                                  SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
21                                  const CropRect* cropRect = NULL) {
22         SkImageFilter* inputs[2] = { first, second };
23         SkXfermode::Mode modes[2] = { mode, mode };
24         return new SkMergeImageFilter(inputs, 2, modes, cropRect);
25     }
26 
27     static SkImageFilter* Create(SkImageFilter* filters[], int count,
28                                  const SkXfermode::Mode modes[] = NULL,
29                                 const CropRect* cropRect = NULL) {
30         return new SkMergeImageFilter(filters, count, modes, cropRect);
31     }
32 
33     SK_TO_STRING_OVERRIDE()
34     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMergeImageFilter)
35 
36 protected:
37     void flatten(SkWriteBuffer&) const override;
38     bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, SkBitmap* result,
39                                  SkIPoint* loc) const override;
40 
41 private:
42     SkMergeImageFilter(SkImageFilter* filters[], int count, const SkXfermode::Mode modes[],
43                        const CropRect* cropRect);
44 
45     uint8_t*    fModes; // SkXfermode::Mode
46 
47     // private storage, to avoid dynamically allocating storage for our copy
48     // of the modes (unless the count is so large we can't fit).
49     intptr_t    fStorage[16];
50 
51     void initAllocModes();
52     void initModes(const SkXfermode::Mode []);
53 
54     typedef SkImageFilter INHERITED;
55 };
56 
57 #endif
58