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