Debian Codegraph @

src/gpu/graphite/precompile/PrecompileImageShader.h

raw
1 /*
2 * Copyright 2025 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
8 #ifndef skgpu_graphite_precompile_PrecompileImageShader_DEFINED
9 #define skgpu_graphite_precompile_PrecompileImageShader_DEFINED
10
11 #include "include/gpu/graphite/precompile/PrecompileShader.h"
12 #include "src/core/SkColorSpacePriv.h"
13 #include "src/gpu/graphite/ResourceTypes.h"
14
15 namespace skgpu::graphite {
16
17 class PrecompileImageShader final : public PrecompileShader {
18 public:
19 PrecompileImageShader(SkEnumBitMask<PrecompileShaders::ImageShaderFlags> flags,
20 SkSpan<const SkColorInfo> colorInfos,
21 SkSpan<const SkTileMode> tileModes,
22 bool raw);
23
24 void setImmutableSamplerInfo(const ImmutableSamplerInfo& samplerInfo);
25
26 private:
27 friend class PrecompileYUVImageShader; // for NonAlphaOnlyDefaultColorInfos
28
29 // In addition to the tile mode options provided by the client, we can precompile two additional
30 // sampling/tiling variants: hardware-tiled and cubic sampling (which always uses the most
31 // generic tiling shader).
32 inline static constexpr int kExtraNumSamplingTilingCombos = 2;
33 inline static constexpr int kCubicSampled = 1;
34 inline static constexpr int kHWTiled = 0;
35
36 // These color info objects are defined assuming an sRGB destination.
37 // Most specialized color space transform shader, no actual color space handling.
38 static SkColorInfo DefaultColorInfoPremul() {
39 return { kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB() };
40 }
41 // sRGB-to-sRGB specialized color space transform shader.
42 static SkColorInfo DefaultColorInfoSRGB() {
43 return { kRGBA_8888_SkColorType, kPremul_SkAlphaType,
44 sk_srgb_singleton()->makeColorSpin() };
45 }
46 // Most general color space transform shader.
47 static SkColorInfo DefaultColorInfoGeneral() {
48 return { kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGBLinear() };
49 }
50 // Alpha-only, most general color space transform shader.
51 static SkColorInfo DefaultColorInfoAlphaOnly() {
52 return { kAlpha_8_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGBLinear() };
53 }
54
55 // A fixed list of SkColorInfos that will trigger each possible combination of alpha-only
56 // handling and color space transform variants, when drawn to an sRGB destination.
57 static std::vector<SkColorInfo> DefaultColorInfos() {
58 return { DefaultColorInfoPremul(), DefaultColorInfoSRGB(), DefaultColorInfoGeneral(),
59 DefaultColorInfoAlphaOnly() };
60 }
61 // A fixed list of SkColorInfos that will trigger each color space transform shader variant when
62 // drawn to an sRGB destination.
63 static std::vector<SkColorInfo> NonAlphaOnlyDefaultColorInfos() {
64 return { DefaultColorInfoPremul(), DefaultColorInfoSRGB(), DefaultColorInfoGeneral() };
65 }
66 // A fixed list of SkColorInfos that will trigger each color space transform shader variant
67 // possible from a raw image draw. The general shader is still required if the image is
68 // alpha-only, because the read swizzle is implemented as a gamut transformation.
69 static std::vector<SkColorInfo> RawImageDefaultColorInfos() {
70 return { DefaultColorInfoPremul(), DefaultColorInfoAlphaOnly() };
71 }
72
73 const int fNumExtraSamplingTilingCombos;
74
75 const std::vector<SkColorInfo> fColorInfos;
76 const std::vector<SkTileMode> fTileModes;
77
78 // If true, use the destination ColorInfo from the KeyContext provided to addToKey.
79 // This is true if and only if the client has provided a list of color infos. Otherwise, we
80 // always use an sRGB destination (as per the default SkColorInfo lists defined above) and
81 // the source's alphaType.
82 const bool fUseDstColorInfo;
83
84 // Whether this precompiles raw image shaders.
85 const bool fRaw;
86 ImmutableSamplerInfo fImmutableSamplerInfo;
87
88 int numIntrinsicCombinations() const override;
89
90 void addToKey(const KeyContext& keyContext, int desiredCombination) const override;
91 };
92
93 } // namespace skgpu::graphite
94
95 #endif // skgpu_graphite_precompile_PrecompileImageShader_DEFINED