senorblanco@chromium.org | 4a9a612 | 2012-12-04 14:18:50 +0000 | [diff] [blame] | 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: |
senorblanco@chromium.org | 4a9a612 | 2012-12-04 14:18:50 +0000 | [diff] [blame] | 17 | virtual ~SkMergeImageFilter(); |
| 18 | |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 19 | static SkMergeImageFilter* Create(SkImageFilter* first, SkImageFilter* second, |
| 20 | SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode, |
senorblanco | 5e5f948 | 2014-08-26 12:27:12 -0700 | [diff] [blame^] | 21 | const CropRect* cropRect = NULL, |
| 22 | uint32_t uniqueID = 0) { |
senorblanco | 9ea3d57 | 2014-07-08 09:16:22 -0700 | [diff] [blame] | 23 | SkImageFilter* inputs[2] = { first, second }; |
| 24 | SkXfermode::Mode modes[2] = { mode, mode }; |
senorblanco | 5e5f948 | 2014-08-26 12:27:12 -0700 | [diff] [blame^] | 25 | return SkNEW_ARGS(SkMergeImageFilter, (inputs, 2, modes, cropRect, uniqueID)); |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 26 | } |
| 27 | static SkMergeImageFilter* Create(SkImageFilter* filters[], int count, |
| 28 | const SkXfermode::Mode modes[] = NULL, |
senorblanco | 5e5f948 | 2014-08-26 12:27:12 -0700 | [diff] [blame^] | 29 | const CropRect* cropRect = NULL, |
| 30 | uint32_t uniqueID = 0) { |
| 31 | return SkNEW_ARGS(SkMergeImageFilter, (filters, count, modes, cropRect, uniqueID)); |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 32 | } |
| 33 | |
senorblanco@chromium.org | 4a9a612 | 2012-12-04 14:18:50 +0000 | [diff] [blame] | 34 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMergeImageFilter) |
| 35 | |
| 36 | protected: |
commit-bot@chromium.org | cac5fd5 | 2014-03-10 10:51:58 +0000 | [diff] [blame] | 37 | SkMergeImageFilter(SkImageFilter* filters[], int count, |
senorblanco | 9ea3d57 | 2014-07-08 09:16:22 -0700 | [diff] [blame] | 38 | const SkXfermode::Mode modes[], |
senorblanco | 5e5f948 | 2014-08-26 12:27:12 -0700 | [diff] [blame^] | 39 | const CropRect* cropRect, |
| 40 | uint32_t uniqueID); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 41 | #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
commit-bot@chromium.org | bd0be25 | 2014-05-15 15:40:41 +0000 | [diff] [blame] | 42 | explicit SkMergeImageFilter(SkReadBuffer& buffer); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 43 | #endif |
commit-bot@chromium.org | bd0be25 | 2014-05-15 15:40:41 +0000 | [diff] [blame] | 44 | virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
| 45 | |
| 46 | virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
| 47 | SkBitmap* result, SkIPoint* loc) const SK_OVERRIDE; |
| 48 | |
senorblanco@chromium.org | 4a9a612 | 2012-12-04 14:18:50 +0000 | [diff] [blame] | 49 | private: |
| 50 | uint8_t* fModes; // SkXfermode::Mode |
| 51 | |
| 52 | // private storage, to avoid dynamically allocating storage for our copy |
| 53 | // of the modes (unless the count is so large we can't fit). |
| 54 | intptr_t fStorage[16]; |
| 55 | |
| 56 | void initAllocModes(); |
| 57 | void initModes(const SkXfermode::Mode []); |
| 58 | |
| 59 | typedef SkImageFilter INHERITED; |
| 60 | }; |
| 61 | |
| 62 | #endif |