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 <climits>
27 #include <cstdint>
28
29 // Legacy flag
30 #if defined(SK_SUPPORT_GPU)
31 #if SK_SUPPORT_GPU && !defined(SK_GANESH)
32 # define SK_GANESH
33 #endif
34 #endif
35
36 #if defined(SK_GANESH) || defined(SK_GRAPHITE)
37 # if !defined(SK_ENABLE_SKSL)
38 # define SK_ENABLE_SKSL
39 # endif
40 #else
41 # undef SK_GL
42 # undef SK_VULKAN
43 # undef SK_METAL
44 # undef SK_DAWN
45 # undef SK_DIRECT3D
46 #endif
47
48 // If SK_R32_SHIFT is set, we'll use that to choose RGBA or BGRA.
49 // If not, we'll default to RGBA everywhere except BGRA on Windows.
50 #if defined(SK_R32_SHIFT)
51 static_assert(SK_R32_SHIFT == 0 || SK_R32_SHIFT == 16, "");
52 #elif defined(SK_BUILD_FOR_WIN)
53 #define SK_R32_SHIFT 16
54 #else
55 #define SK_R32_SHIFT 0
56 #endif
57
58 #if defined(SK_B32_SHIFT)
59 static_assert(SK_B32_SHIFT == (16-SK_R32_SHIFT), "");
60 #else
61 #define SK_B32_SHIFT (16-SK_R32_SHIFT)
62 #endif
63
64 #define SK_G32_SHIFT 8
65 #define SK_A32_SHIFT 24
66
67 /**
68 * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time.
69 */
70 #ifdef SK_CPU_BENDIAN
71 # define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
72 (SK_ ## C3 ## 32_SHIFT == 0 && \
73 SK_ ## C2 ## 32_SHIFT == 8 && \
74 SK_ ## C1 ## 32_SHIFT == 16 && \
75 SK_ ## C0 ## 32_SHIFT == 24)
76 #else
77 # define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
78 (SK_ ## C0 ## 32_SHIFT == 0 && \
79 SK_ ## C1 ## 32_SHIFT == 8 && \
80 SK_ ## C2 ## 32_SHIFT == 16 && \
81 SK_ ## C3 ## 32_SHIFT == 24)
82 #endif
83
84 #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN
85 #ifdef free
86 #undef free
87 #endif
88 #include <crtdbg.h>
89 #undef free
90 #endif
91
92 #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
93 #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 0
94 #endif
95
96 #if !defined(SK_GAMMA_EXPONENT)
97 #define SK_GAMMA_EXPONENT (0.0f) // SRGB
98 #endif
99
100 #ifndef GR_TEST_UTILS
101 # define GR_TEST_UTILS 0
102 #endif
103
104
105 #if defined(SK_HISTOGRAM_ENUMERATION) || \
106 defined(SK_HISTOGRAM_BOOLEAN) || \
107 defined(SK_HISTOGRAM_EXACT_LINEAR) || \
108 defined(SK_HISTOGRAM_MEMORY_KB)
109 # define SK_HISTOGRAMS_ENABLED 1
110 #else
111 # define SK_HISTOGRAMS_ENABLED 0
112 #endif
113
114 #ifndef SK_HISTOGRAM_BOOLEAN
115 # define SK_HISTOGRAM_BOOLEAN(name, sample)
116 #endif
117
118 #ifndef SK_HISTOGRAM_ENUMERATION
119 # define SK_HISTOGRAM_ENUMERATION(name, sample, enum_size)
120 #endif
121
122 #ifndef SK_HISTOGRAM_EXACT_LINEAR
123 # define SK_HISTOGRAM_EXACT_LINEAR(name, sample, value_max)
124 #endif
125
126 #ifndef SK_HISTOGRAM_MEMORY_KB
127 # define SK_HISTOGRAM_MEMORY_KB(name, sample)
128 #endif
129
130 #define SK_HISTOGRAM_PERCENTAGE(name, percent_as_int) \
131 SK_HISTOGRAM_EXACT_LINEAR(name, percent_as_int, 101)
132
133 // The top-level define SK_ENABLE_OPTIMIZE_SIZE can be used to remove several large features at once
134 #if defined(SK_ENABLE_OPTIMIZE_SIZE)
135 # define SK_FORCE_RASTER_PIPELINE_BLITTER
136 # define SK_DISABLE_SDF_TEXT
137 #endif
138
139 #ifndef SK_DISABLE_LEGACY_SHADERCONTEXT
140 # define SK_ENABLE_LEGACY_SHADERCONTEXT
141 #endif
142
143 #if defined(SK_BUILD_FOR_LIBFUZZER) || defined(SK_BUILD_FOR_AFL_FUZZ)
144 #if !defined(SK_BUILD_FOR_FUZZER)
145 #define SK_BUILD_FOR_FUZZER
146 #endif
147 #endif
148
149 /**
150 * Gr defines are set to 0 or 1, rather than being undefined or defined
151 */
152
153 #if !defined(GR_CACHE_STATS)
154 #if defined(SK_DEBUG) || defined(SK_DUMP_STATS)
155 #define GR_CACHE_STATS 1
156 #else
157 #define GR_CACHE_STATS 0
158 #endif
159 #endif
160
161 #if !defined(GR_GPU_STATS)
162 #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || GR_TEST_UTILS
163 #define GR_GPU_STATS 1
164 #else
165 #define GR_GPU_STATS 0
166 #endif
167 #endif
168
169 ////////////////////////////////////////////////////////////////////////////////
170
171 typedef uint32_t SkFourByteTag;
SkSetFourByteTag(char a,char b,char c,char d)172 static inline constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d) {
173 return (((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | (uint32_t)d);
174 }
175
176 ////////////////////////////////////////////////////////////////////////////////
177
178 /** 32 bit integer to hold a unicode value
179 */
180 typedef int32_t SkUnichar;
181
182 /** 16 bit unsigned integer to hold a glyph index
183 */
184 typedef uint16_t SkGlyphID;
185
186 /** 32 bit value to hold a millisecond duration
187 Note that SK_MSecMax is about 25 days.
188 */
189 typedef uint32_t SkMSec;
190
191 /** Maximum representable milliseconds; 24d 20h 31m 23.647s.
192 */
193 static constexpr SkMSec SK_MSecMax = INT32_MAX;
194
195 /** The generation IDs in Skia reserve 0 has an invalid marker.
196 */
197 static constexpr uint32_t SK_InvalidGenID = 0;
198
199 /** The unique IDs in Skia reserve 0 has an invalid marker.
200 */
201 static constexpr uint32_t SK_InvalidUniqueID = 0;
202
203
204 #endif
205