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 # 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 
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_HISTOGRAM_ENUMERATION) || \
90  defined(SK_HISTOGRAM_BOOLEAN) || \
91  defined(SK_HISTOGRAM_EXACT_LINEAR) || \
92  defined(SK_HISTOGRAM_MEMORY_KB)
93 # define SK_HISTOGRAMS_ENABLED 1
94 #else
95 # define SK_HISTOGRAMS_ENABLED 0
96 #endif
97 
98 #ifndef SK_HISTOGRAM_BOOLEAN
99 # define SK_HISTOGRAM_BOOLEAN(name, sample)
100 #endif
101 
102 #ifndef SK_HISTOGRAM_ENUMERATION
103 # define SK_HISTOGRAM_ENUMERATION(name, sample, enum_size)
104 #endif
105 
106 #ifndef SK_HISTOGRAM_EXACT_LINEAR
107 # define SK_HISTOGRAM_EXACT_LINEAR(name, sample, value_max)
108 #endif
109 
110 #ifndef SK_HISTOGRAM_MEMORY_KB
111 # define SK_HISTOGRAM_MEMORY_KB(name, sample)
112 #endif
113 
114 #define SK_HISTOGRAM_PERCENTAGE(name, percent_as_int) \
115  SK_HISTOGRAM_EXACT_LINEAR(name, percent_as_int, 101)
116 
117 // The top-level define SK_ENABLE_OPTIMIZE_SIZE can be used to remove several large features at once
118 #if defined(SK_ENABLE_OPTIMIZE_SIZE)
119  #if !defined(SK_FORCE_RASTER_PIPELINE_BLITTER)
120  #define SK_FORCE_RASTER_PIPELINE_BLITTER
121  #endif
122  #define SK_DISABLE_SDF_TEXT
123 #endif
124 
125 #ifndef SK_DISABLE_LEGACY_SHADERCONTEXT
126 # define SK_ENABLE_LEGACY_SHADERCONTEXT
127 #endif
128 
129 #if defined(SK_BUILD_FOR_LIBFUZZER) || defined(SK_BUILD_FOR_AFL_FUZZ)
130 #if !defined(SK_BUILD_FOR_FUZZER)
131  #define SK_BUILD_FOR_FUZZER
132 #endif
133 #endif
134 
140 #if !defined(GR_CACHE_STATS)
141  #if defined(SK_DEBUG) || defined(SK_DUMP_STATS)
142  #define GR_CACHE_STATS 1
143  #else
144  #define GR_CACHE_STATS 0
145  #endif
146 #endif
147 
148 #if !defined(GR_GPU_STATS)
149  #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || defined(GR_TEST_UTILS)
150  #define GR_GPU_STATS 1
151  #else
152  #define GR_GPU_STATS 0
153  #endif
154 #endif
155 
157 
158 typedef uint32_t SkFourByteTag;
159 static inline constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d) {
160  return (((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | (uint32_t)d);
161 }
162 
164 
167 typedef int32_t SkUnichar;
168 
171 typedef uint16_t SkGlyphID;
172 
176 typedef uint32_t SkMSec;
177 
180 static constexpr SkMSec SK_MSecMax = INT32_MAX;
181 
184 static constexpr uint32_t SK_InvalidGenID = 0;
185 
188 static constexpr uint32_t SK_InvalidUniqueID = 0;
189 
190 
191 #endif
static constexpr SkMSec SK_MSecMax
Maximum representable milliseconds; 24d 20h 31m 23.647s.
Definition: SkTypes.h:180
int32_t SkUnichar
32 bit integer to hold a unicode value
Definition: SkTypes.h:167
uint16_t SkGlyphID
16 bit unsigned integer to hold a glyph index
Definition: SkTypes.h:171
static constexpr uint32_t SK_InvalidUniqueID
The unique IDs in Skia reserve 0 has an invalid marker.
Definition: SkTypes.h:188
#define SK_R32_SHIFT
Definition: SkTypes.h:44
uint32_t SkFourByteTag
Definition: SkTypes.h:158
#define SK_B32_SHIFT
Definition: SkTypes.h:50
static constexpr uint32_t SK_InvalidGenID
The generation IDs in Skia reserve 0 has an invalid marker.
Definition: SkTypes.h:184
uint32_t SkMSec
32 bit value to hold a millisecond duration Note that SK_MSecMax is about 25 days.
Definition: SkTypes.h:176
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:159