xref: /aosp_15_r20/external/skia/include/core/SkTypes.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2006 The Android Open Source Project
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 SkTypes_DEFINED
9 #define SkTypes_DEFINED
10 
11 // All of these files should be independent of things users can set via the user config file.
12 // They should also be able to be included in any order.
13 // IWYU pragma: begin_exports
14 #include "include/private/base/SkFeatures.h"
15 
16 // Load and verify defines from the user config file.
17 #include "include/private/base/SkLoadUserConfig.h"
18 
19 // Any includes or defines below can be configured by the user config file.
20 #include "include/private/base/SkAPI.h"
21 #include "include/private/base/SkAssert.h"
22 #include "include/private/base/SkAttributes.h"
23 #include "include/private/base/SkDebug.h"
24 // IWYU pragma: end_exports
25 
26 #include <cstdint>
27 
28 #if !defined(SK_GANESH) && !defined(SK_GRAPHITE)
29 #  undef SK_GL
30 #  undef SK_VULKAN
31 #  undef SK_METAL
32 #  undef SK_DAWN
33 #  undef SK_DIRECT3D
34 #endif
35 
36 // If SK_R32_SHIFT is set, we'll use that to choose RGBA or BGRA.
37 // If not, we'll default to RGBA everywhere except BGRA on Windows.
38 #if defined(SK_R32_SHIFT)
39     static_assert(SK_R32_SHIFT == 0 || SK_R32_SHIFT == 16, "");
40 #elif defined(SK_BUILD_FOR_WIN)
41     #define SK_R32_SHIFT 16
42 #else
43     #define SK_R32_SHIFT 0
44 #endif
45 
46 #if defined(SK_B32_SHIFT)
47     static_assert(SK_B32_SHIFT == (16-SK_R32_SHIFT), "");
48 #else
49     #define SK_B32_SHIFT (16-SK_R32_SHIFT)
50 #endif
51 
52 #define SK_G32_SHIFT 8
53 #define SK_A32_SHIFT 24
54 
55 /**
56  * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time.
57  */
58 #ifdef SK_CPU_BENDIAN
59 #  define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3)     \
60         (SK_ ## C3 ## 32_SHIFT == 0  &&             \
61          SK_ ## C2 ## 32_SHIFT == 8  &&             \
62          SK_ ## C1 ## 32_SHIFT == 16 &&             \
63          SK_ ## C0 ## 32_SHIFT == 24)
64 #else
65 #  define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3)     \
66         (SK_ ## C0 ## 32_SHIFT == 0  &&             \
67          SK_ ## C1 ## 32_SHIFT == 8  &&             \
68          SK_ ## C2 ## 32_SHIFT == 16 &&             \
69          SK_ ## C3 ## 32_SHIFT == 24)
70 #endif
71 
72 #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN
73     #ifdef free
74         #undef free
75     #endif
76     #include <crtdbg.h>
77     #undef free
78 #endif
79 
80 #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
81     #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 0
82 #endif
83 
84 #if !defined(SK_GAMMA_EXPONENT)
85     #define SK_GAMMA_EXPONENT (0.0f)  // SRGB
86 #endif
87 
88 #if !defined(SK_GAMMA_CONTRAST)
89     // A value of 0.5 for SK_GAMMA_CONTRAST appears to be a good compromise.
90     // With lower values small text appears washed out (though correctly so).
91     // With higher values lcd fringing is worse and the smoothing effect of
92     // partial coverage is diminished.
93     #define SK_GAMMA_CONTRAST (0.5f)
94 #endif
95 
96 #if defined(SK_HISTOGRAM_ENUMERATION)  || \
97     defined(SK_HISTOGRAM_BOOLEAN)      || \
98     defined(SK_HISTOGRAM_EXACT_LINEAR) || \
99     defined(SK_HISTOGRAM_MEMORY_KB)    || \
100     defined(SK_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES)
101 #  define SK_HISTOGRAMS_ENABLED 1
102 #else
103 #  define SK_HISTOGRAMS_ENABLED 0
104 #endif
105 
106 #ifndef SK_HISTOGRAM_BOOLEAN
107 #  define SK_HISTOGRAM_BOOLEAN(name, sample)
108 #endif
109 
110 #ifndef SK_HISTOGRAM_ENUMERATION
111 #  define SK_HISTOGRAM_ENUMERATION(name, sampleEnum, enumSize)
112 #endif
113 
114 #ifndef SK_HISTOGRAM_EXACT_LINEAR
115 #  define SK_HISTOGRAM_EXACT_LINEAR(name, sample, valueMax)
116 #endif
117 
118 #ifndef SK_HISTOGRAM_MEMORY_KB
119 #  define SK_HISTOGRAM_MEMORY_KB(name, sample)
120 #endif
121 
122 #ifndef SK_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES
123 #  define SK_HISTOGRAM_CUSTOM_MICROSECONDS_TIMES(name, sampleUSec, minUSec, maxUSec, bucketCount)
124 #endif
125 
126 #define SK_HISTOGRAM_PERCENTAGE(name, percent_as_int) \
127     SK_HISTOGRAM_EXACT_LINEAR(name, percent_as_int, 101)
128 
129 // The top-level define SK_ENABLE_OPTIMIZE_SIZE can be used to remove several large features at once
130 #if defined(SK_ENABLE_OPTIMIZE_SIZE)
131     #if !defined(SK_FORCE_RASTER_PIPELINE_BLITTER)
132         #define SK_FORCE_RASTER_PIPELINE_BLITTER
133     #endif
134     #define SK_DISABLE_SDF_TEXT
135 #endif
136 
137 #ifndef SK_DISABLE_LEGACY_SHADERCONTEXT
138 #   define SK_ENABLE_LEGACY_SHADERCONTEXT
139 #endif
140 
141 #if defined(SK_BUILD_FOR_LIBFUZZER) || defined(SK_BUILD_FOR_AFL_FUZZ)
142 #if !defined(SK_BUILD_FOR_FUZZER)
143     #define SK_BUILD_FOR_FUZZER
144 #endif
145 #endif
146 
147 /**
148  *  These defines are set to 0 or 1, rather than being undefined or defined
149  *  TODO: consider updating these for consistency
150  */
151 
152 #if !defined(GR_CACHE_STATS)
153   #if defined(SK_DEBUG) || defined(SK_DUMP_STATS)
154       #define GR_CACHE_STATS  1
155   #else
156       #define GR_CACHE_STATS  0
157   #endif
158 #endif
159 
160 #if !defined(GR_GPU_STATS)
161   #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || defined(GPU_TEST_UTILS)
162       #define GR_GPU_STATS    1
163   #else
164       #define GR_GPU_STATS    0
165   #endif
166 #endif
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 
170 /** 32 bit integer to hold a unicode value
171 */
172 typedef int32_t SkUnichar;
173 
174 /** 16 bit unsigned integer to hold a glyph index
175 */
176 typedef uint16_t SkGlyphID;
177 
178 /** The generation IDs in Skia reserve 0 has an invalid marker.
179 */
180 static constexpr uint32_t SK_InvalidGenID = 0;
181 
182 /** The unique IDs in Skia reserve 0 has an invalid marker.
183 */
184 static constexpr uint32_t SK_InvalidUniqueID = 0;
185 
186 #endif
187