Debian Codegraph @

src/shaders/SkWorkingColorSpaceShader.h

raw
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 SkWorkingColorSpaceShader_DEFINED
8 #define SkWorkingColorSpaceShader_DEFINED
9
10 #include "include/core/SkColorSpace.h"
11 #include "include/core/SkFlattenable.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkShader.h"
14 #include "include/private/base/SkAssert.h"
15 #include "src/shaders/SkShaderBase.h"
16
17 #include <utility>
18
19 class SkReadBuffer;
20 class SkWriteBuffer;
21 struct SkStageRec;
22
23 class SkWorkingColorSpaceShader final : public SkShaderBase {
24 public:
25 // NOTE: `workInUnpremul` is not exposed to the public API yet as many shader implementations
26 // across CPU, Ganesh, and Graphite have to be updated to convert to unpremul.
27 static sk_sp<SkShader> Make(sk_sp<SkShader> shader,
28 sk_sp<SkColorSpace> inputCS,
29 sk_sp<SkColorSpace> outputCS,
30 bool workInUnpremul);
31
32 ShaderType type() const override { return ShaderType::kWorkingColorSpace; }
33
34 sk_sp<SkShader> shader() const { return fShader; }
35
36 std::tuple</*inputCS=*/sk_sp<SkColorSpace>,
37 /*outputCS=*/sk_sp<SkColorSpace>,
38 /*workingAT=*/SkAlphaType>
39 workingSpace(sk_sp<SkColorSpace> dstCS, SkAlphaType dstAT) const {
40 sk_sp<SkColorSpace> inputSpace = fInputSpace ? fInputSpace : dstCS;
41 sk_sp<SkColorSpace> outputSpace = fOutputSpace ? fOutputSpace : inputSpace;
42 return {inputSpace, outputSpace, fWorkInUnpremul ? kUnpremul_SkAlphaType : dstAT};
43 }
44
45 private:
46 SkWorkingColorSpaceShader(sk_sp<SkShader> shader,
47 sk_sp<SkColorSpace> inputCS,
48 sk_sp<SkColorSpace> outputCS,
49 bool workInUnpremul)
50 : fShader(std::move(shader))
51 , fInputSpace(std::move(inputCS))
52 , fOutputSpace(std::move(outputCS))
53 , fWorkInUnpremul(workInUnpremul) {
54 SkASSERT(fShader);
55 SkASSERT(fInputSpace || fOutputSpace || fWorkInUnpremul);
56 }
57
58 bool appendStages(const SkStageRec& rec, const SkShaders::MatrixRec&) const override;
59
60 friend void ::SkRegisterWorkingColorSpaceShaderFlattenable();
61 SK_FLATTENABLE_HOOKS(SkWorkingColorSpaceShader)
62
63 void flatten(SkWriteBuffer& buffer) const override;
64
65 sk_sp<SkShader> fShader;
66 sk_sp<SkColorSpace> fInputSpace;
67 sk_sp<SkColorSpace> fOutputSpace;
68 bool fWorkInUnpremul;
69 };
70
71 #endif