2 * Copyright 2013 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkXfermodeImageFilter_DEFINED
9 #define SkXfermodeImageFilter_DEFINED
11 #include "SkImageFilter.h"
16 * This filter takes an xfermode, and uses it to composite the foreground
17 * over the background. If foreground or background is NULL, the input
18 * bitmap (src) is used instead.
20 class SK_API SkXfermodeImageFilter {
22 static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> background,
23 sk_sp<SkImageFilter> foreground,
24 const SkImageFilter::CropRect* cropRect);
25 static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> background) {
26 return Make(std::move(mode), std::move(background), nullptr, nullptr);
29 static sk_sp<SkImageFilter> MakeArithmetic(float k1, float k2, float k3, float k4,
31 sk_sp<SkImageFilter> background,
32 sk_sp<SkImageFilter> foreground,
33 const SkImageFilter::CropRect* cropRect);
34 static sk_sp<SkImageFilter> MakeArithmetic(float k1, float k2, float k3, float k4,
36 sk_sp<SkImageFilter> background) {
37 return MakeArithmetic(k1, k2, k3, k4, enforcePMColor, std::move(background),
41 #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
42 static SkImageFilter* Create(SkXfermode* mode, SkImageFilter* background,
43 SkImageFilter* foreground = NULL,
44 const SkImageFilter::CropRect* cropRect = NULL) {
45 return Make(sk_ref_sp(mode),
46 sk_ref_sp(background),
47 sk_ref_sp(foreground),
51 #ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
52 static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, SkImageFilter* background,
53 SkImageFilter* foreground,
54 const SkImageFilter::CropRect* cropRect) {
55 return Make(std::move(mode),
56 sk_ref_sp(background),
57 sk_ref_sp(foreground),
60 static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, SkImageFilter* background) {
61 return Make(std::move(mode), sk_ref_sp(background));
65 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP();
68 SkXfermodeImageFilter(); // can't instantiate