xref: /aosp_15_r20/external/skia/src/core/SkKnownRuntimeEffects.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2024 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 SkKnownRuntimeEffects_DEFINED
9 #define SkKnownRuntimeEffects_DEFINED
10 
11 #include "include/core/SkTypes.h"
12 #include <cstdint>
13 
14 class SkRuntimeEffect;
15 
16 namespace SkKnownRuntimeEffects {
17 
18 // We allocate the keys in blocks in the order:
19 //     Skia builtins
20 //     Skia known runtime effects
21 //     Android known runtime effects
22 //     Chrome known runtime effects
23 //     unknown runtime effects (on a first come, first served basis -> unstable)
24 //
25 // WARNING: If any of these values are changed, UniqueKeys that have stably-keyed effects
26 // will need to be invalidated.
27 // TODO(b/238759147): add a revision number that can drive the invalidation.
28 static constexpr int kSkiaBuiltInReservedCnt = 500;
29 static constexpr int kSkiaKnownRuntimeEffectsReservedCnt = 500;
30 static constexpr int kAndroidKnownRuntimeEffectsReservedCnt = 100;
31 static constexpr int kChromeKnownRuntimeEffectsReservedCnt = 100;
32 
33 static constexpr int kSkiaKnownRuntimeEffectsStart = kSkiaBuiltInReservedCnt;
34 static constexpr int kSkiaKnownRuntimeEffectsEnd = kSkiaKnownRuntimeEffectsStart +
35                                                    kSkiaKnownRuntimeEffectsReservedCnt;
36 
37 static constexpr int kAndroidKnownRuntimeEffectsStart = kSkiaKnownRuntimeEffectsEnd;
38 static constexpr int kAndroidKnownRuntimeEffectsEnd = kAndroidKnownRuntimeEffectsStart +
39                                                       kAndroidKnownRuntimeEffectsReservedCnt;
40 
41 static constexpr int kChromeKnownRuntimeEffectsStart = kAndroidKnownRuntimeEffectsEnd;
42 static constexpr int kChromeKnownRuntimeEffectsEnd = kChromeKnownRuntimeEffectsStart +
43                                                      kChromeKnownRuntimeEffectsReservedCnt;
44 
45 static constexpr int kUnknownRuntimeEffectIDStart = kChromeKnownRuntimeEffectsEnd;
46 
47 // All six 1DBlur* stable keys must be consecutive after 1DBlurBase and
48 // there is no 1DBlur24 bc for large kernels we bin by a multiple of eight.
49 // Similarly, all six 2DBlur* stable keys must be consecutive after 2DBlurBase and
50 // there is no 2DBlur24 bc for large kernels we bin by a multiple of eight.
51 // As for the macros:
52 //   M(X) is for standard entries
53 //   M1(X) is for helper values that should be skipped in a switch statement
54 //   M2(X,Y) is for entries that have an initializer (Y)
55 #define SK_ALL_STABLEKEYS(M, M1, M2) \
56     M2(Invalid, Start)      \
57     M1(1DBlurBase)          \
58     M2(1DBlur4, 1DBlurBase) \
59     M(1DBlur8)              \
60     M(1DBlur12)             \
61     M(1DBlur16)             \
62     M(1DBlur20)             \
63     M(1DBlur28)             \
64     M1(2DBlurBase)          \
65     M2(2DBlur4, 2DBlurBase) \
66     M(2DBlur8)              \
67     M(2DBlur12)             \
68     M(2DBlur16)             \
69     M(2DBlur20)             \
70     M(2DBlur28)             \
71     M(Blend)                \
72     M(Decal)                \
73     M(Displacement)         \
74     M(Lighting)             \
75     M(LinearMorphology)     \
76     M(Magnifier)            \
77     M(MatrixConvUniforms)   \
78     M(MatrixConvTexSm)      \
79     M(MatrixConvTexLg)      \
80     M(Normal)               \
81     M(SparseMorphology)     \
82     M(Arithmetic)           \
83     M(HighContrast)         \
84     M(Lerp)                 \
85     M(Luma)                 \
86     M(Overdraw)
87 
88 // WARNING: If any of the existing values are changed, UniqueKeys that have stably-keyed effects
89 // will need to be invalidated. (Adding new values to the end of the enum should be fine though.)
90 // TODO(b/238759147): add a revision number that can drive the invalidation
91 enum class StableKey : uint32_t {
92     kStart =   kSkiaKnownRuntimeEffectsStart,
93 
94 #define M(type) k##type,
95 #define M1(type) k##type,
96 #define M2(type, initializer) k##type = k##initializer,
97     SK_ALL_STABLEKEYS(M, M1, M2)
98 #undef M2
99 #undef M1
100 #undef M
101 
102     kLast =    kOverdraw,
103 };
104 
105 static const int kStableKeyCnt = static_cast<int>(StableKey::kLast) -
106                                  static_cast<int>(StableKey::kStart) + 1;
107 
108 static_assert(static_cast<int>(StableKey::kLast) < kSkiaKnownRuntimeEffectsEnd);
109 
110 const SkRuntimeEffect* GetKnownRuntimeEffect(StableKey);
111 
112 static_assert(static_cast<int>(StableKey::kInvalid)  == static_cast<int>(StableKey::kStart));
113 
114 static_assert(static_cast<int>(StableKey::k1DBlur4)  == static_cast<int>(StableKey::k1DBlurBase));
115 static_assert(static_cast<int>(StableKey::k1DBlur8)  == static_cast<int>(StableKey::k1DBlurBase)+1);
116 static_assert(static_cast<int>(StableKey::k1DBlur12) == static_cast<int>(StableKey::k1DBlurBase)+2);
117 static_assert(static_cast<int>(StableKey::k1DBlur16) == static_cast<int>(StableKey::k1DBlurBase)+3);
118 static_assert(static_cast<int>(StableKey::k1DBlur20) == static_cast<int>(StableKey::k1DBlurBase)+4);
119 static_assert(static_cast<int>(StableKey::k1DBlur28) == static_cast<int>(StableKey::k1DBlurBase)+5);
120 
121 static_assert(static_cast<int>(StableKey::k2DBlur4)  == static_cast<int>(StableKey::k2DBlurBase));
122 static_assert(static_cast<int>(StableKey::k2DBlur8)  == static_cast<int>(StableKey::k2DBlurBase)+1);
123 static_assert(static_cast<int>(StableKey::k2DBlur12) == static_cast<int>(StableKey::k2DBlurBase)+2);
124 static_assert(static_cast<int>(StableKey::k2DBlur16) == static_cast<int>(StableKey::k2DBlurBase)+3);
125 static_assert(static_cast<int>(StableKey::k2DBlur20) == static_cast<int>(StableKey::k2DBlurBase)+4);
126 static_assert(static_cast<int>(StableKey::k2DBlur28) == static_cast<int>(StableKey::k2DBlurBase)+5);
127 
128 } // namespace SkKnownRuntimeEffects
129 
130 #endif // SkKnownRuntimeEffects_DEFINED
131