xref: /aosp_15_r20/external/skia/src/effects/colorfilters/SkWorkingFormatColorFilter.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2023 Google LLC
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 #ifndef SkWorkingFormatColorFilter_DEFINED
8 #define SkWorkingFormatColorFilter_DEFINED
9 
10 #include "include/core/SkColor.h"
11 #include "include/core/SkColorFilter.h"
12 #include "include/core/SkFlattenable.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/private/SkColorData.h"
15 #include "modules/skcms/skcms.h"
16 #include "src/effects/colorfilters/SkColorFilterBase.h"
17 
18 class SkColorSpace;
19 class SkReadBuffer;
20 class SkWriteBuffer;
21 enum SkAlphaType : int;
22 enum class SkBlendMode;
23 struct SkStageRec;
24 
25 class SkWorkingFormatColorFilter final : public SkColorFilterBase {
26 public:
27     SkWorkingFormatColorFilter(sk_sp<SkColorFilter> child,
28                                const skcms_TransferFunction* tf,
29                                const skcms_Matrix3x3* gamut,
30                                const SkAlphaType* at);
31 
32     sk_sp<SkColorSpace> workingFormat(const sk_sp<SkColorSpace>& dstCS, SkAlphaType* at) const;
33 
type()34     SkColorFilterBase::Type type() const override {
35         return SkColorFilterBase::Type::kWorkingFormat;
36     }
37 
38     bool appendStages(const SkStageRec& rec, bool shaderIsOpaque) const override;
39 
40     SkPMColor4f onFilterColor4f(const SkPMColor4f& origColor,
41                                 SkColorSpace* rawDstCS) const override;
42 
43     bool onIsAlphaUnchanged() const override;
44 
child()45     sk_sp<SkColorFilter> child() const { return fChild; }
46 
47 private:
48     friend void ::SkRegisterWorkingFormatColorFilterFlattenable();
49     SK_FLATTENABLE_HOOKS(SkWorkingFormatColorFilter)
50 
51     void flatten(SkWriteBuffer& buffer) const override;
52 
53     // We implement these so that callers can get this information, even after a filter is wrapped.
54     // That's important for Android, where *all* color filters work in sRGB. If the working format
55     // is ever important to a caller, we'll need to expand/alter the API. See: b/360020740
56     bool onAsAColorMode(SkColor*, SkBlendMode*) const override;
57     bool onAsAColorMatrix(float[20]) const override;
58 
59     sk_sp<SkColorFilter> fChild;
60     skcms_TransferFunction fTF;
61     bool fUseDstTF = true;
62     skcms_Matrix3x3 fGamut;
63     bool fUseDstGamut = true;
64     SkAlphaType fAT;
65     bool fUseDstAT = true;
66 };
67 
68 #endif
69