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 "SkBlendMode.h"
12 #include "SkImageFilter.h"
13 
14 class SK_API SkMergeImageFilter : public SkImageFilter {
15 public:
16     ~SkMergeImageFilter() override;
17 
18     static sk_sp<SkImageFilter> Make(sk_sp<SkImageFilter> first, sk_sp<SkImageFilter> second,
19                                      SkBlendMode, const CropRect* cropRect = nullptr);
20     static sk_sp<SkImageFilter> MakeN(sk_sp<SkImageFilter>[], int count, const SkBlendMode[],
21                                      const CropRect* cropRect = nullptr);
22 
23     SK_TO_STRING_OVERRIDE()
24     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMergeImageFilter)
25 
26 protected:
27     void flatten(SkWriteBuffer&) const override;
28     sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
29                                         SkIPoint* offset) const override;
onCanHandleComplexCTM()30     bool onCanHandleComplexCTM() const override { return true; }
31 
32 private:
33     SkMergeImageFilter(sk_sp<SkImageFilter> filters[], int count, const SkBlendMode modes[],
34                        const CropRect* cropRect);
35 
36     uint8_t*    fModes; // SkBlendMode
37 
38     // private storage, to avoid dynamically allocating storage for our copy
39     // of the modes (unless the count is so large we can't fit).
40     intptr_t    fStorage[16];
41 
42     void initAllocModes();
43     void initModes(const SkBlendMode[]);
44 
45     typedef SkImageFilter INHERITED;
46 };
47 
48 #endif
49