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