-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctx.c
199 lines (167 loc) · 5.14 KB
/
ctx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* this file is the configuration and implementation of the ctx
* library, with adaptations to permit multipass SIMD builds.
*/
#include <stdint.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#if CTX_BABL
#include <babl/babl.h>
#endif
#include "local.conf"
#undef CTX_FORMATTER
#define CTX_FORMATTER 1
#define CTX_THREADS 1
#define CTX_DAMAGE_CONTROL 1// visualize damage in fb/sdl/wasm backends
#define CTX_MATH 1
#define CTX_32BIT_SEGMENTS 1
#define CTX_EXTRAS 0
#define CTX_GSTATE_PROTECT 1
#define CTX_FONT_SHAPE_CACHE 1
#define CTX_FONTS_FROM_FILE 1
//#define CTX_MAX_EDGES 255
//#define CTX_RASTERIZER_AA 15
#define CTX_MAX_TEXTURES 1024 // default: 32
#define CTX_RASTERIZER_BEZIER_FIXED_POINT 0
//
#define CTX_RASTERIZER_ALLOW_DIRECT 1
/* for misc storage with compressed/
variable size for each save|restore*/
#define CTX_MIN_JOURNAL_SIZE 1024 // default: 512 ~4kb
#define CTX_MAX_JOURNAL_SIZE 1024*1024*8 // default: 1024*1024*8 // 72mb
#define CTX_MIN_EDGE_LIST_SIZE 1024*16 // default: 1024*4
// when max is not set it is set to min
//#define CTX_PARSER_MAXLEN 1024*1024*64 // default: 1024*1024*16
#define CTX_HASH_COLS 6 // default: 6
#define CTX_HASH_ROWS 5 // default: 5
#define CTX_MAX_KEYDB 128 // default: 64
#define CTX_GET_CONTENTS 1
#define CTX_MAGIC 1
#define CTX_PROTOCOL_U8_COLOR 1
#include "stb_image.h"
typedef unsigned char stbtt_uint8;
typedef signed char stbtt_int8;
typedef unsigned short stbtt_uint16;
typedef signed short stbtt_int16;
typedef unsigned int stbtt_uint32;
typedef signed int stbtt_int32;
//#include "stb_truetype.h"
#ifdef CTX_SIMD_X86_64_V2
#define CTX_SIMD_SUFFIX(symbol) symbol##_x86_64_v2
#endif
#ifdef CTX_SIMD_X86_64_V3
#define CTX_SIMD_SUFFIX(symbol) symbol##_x86_64_v3
#endif
#ifdef CTX_SIMD_ARM_NEON
#define CTX_SIMD_SUFFIX(symbol) symbol##_arm_neon
#endif
#ifndef CTX_SIMD_SUFFIX
#if CTX_SDL
#include <SDL.h>
#endif
#if CTX_CAIRO
#include <cairo.h>
#endif
#define CSS_HAVE_FS 0
#define CTX_STATIC_FONT(font) \
ctx_load_font_ctx(ctx_font_##font##_name, \
ctx_font_##font, \
sizeof (ctx_font_##font))
//#define CTX_FONT0 CTX_STATIC_FONT("sans-ctx", ascii)
#if CTX_STATIC_FONTS
#include "Cousine-Regular.h"
//#include "Arimo-Regular.h"
#include "Roboto-Regular.h"
#if 0 // build more static fonts and uncomment these..
#include "Carlito-Regular.h"
#include "Carlito-Bold.h"
#include "Carlito-Italic.h"
#include "Carlito-BoldItalic.h"
#include "Cousine-Bold.h"
#include "Cousine-Italic.h"
#include "Cousine-BoldItalic.h"
#include "Arimo-Bold.h"
#include "Arimo-Italic.h"
#include "Arimo-BoldItalic.h"
#include "Tinos-Regular.h"
#include "Tinos-Bold.h"
#include "Tinos-Italic.h"
#include "Tinos-BoldItalic.h"
#endif
//#define CTX_FONT_0 CTX_STATIC_FONT(Arimo_Regular)
#define CTX_FONT_0 CTX_STATIC_FONT(Roboto_Regular)
#if 0
#define CTX_FONT_1 CTX_STATIC_FONT(Arimo_Bold)
#define CTX_FONT_2 CTX_STATIC_FONT(Arimo_Italic)
#define CTX_FONT_3 CTX_STATIC_FONT(Arimo_BoldItalic)
#define CTX_FONT_4 CTX_STATIC_FONT(Tinos_Regular)
#define CTX_FONT_5 CTX_STATIC_FONT(Tinos_Bold)
#define CTX_FONT_6 CTX_STATIC_FONT(Tinos_Italic)
#define CTX_FONT_7 CTX_STATIC_FONT(Tinos_BoldItalic)
#endif
#define CTX_FONT_8 CTX_STATIC_FONT(Cousine_Regular)
#if 0
#define CTX_FONT_9 CTX_STATIC_FONT(Cousine_Italic)
#define CTX_FONT_10 CTX_STATIC_FONT(Cousine_Bold)
#define CTX_FONT_11 CTX_STATIC_FONT(Cousine_BoldItalic)
#define CTX_FONT_12 CTX_STATIC_FONT(Carlito_Regular)
#define CTX_FONT_13 CTX_STATIC_FONT(Carlito_Bold)
#define CTX_FONT_14 CTX_STATIC_FONT(Carlito_Italic)
#define CTX_FONT_15 CTX_STATIC_FONT(Carlito_BoldItalic)
#endif
#endif
#define CTX_IMPLEMENTATION 1
#include "ctx.h"
#if CTX_SIMD
#if CTX_X86_64
#include <xmmintrin.h>
void ctx_simd_setup_x86_64_v2 (void);
void ctx_simd_setup_x86_64_v3 (void);
void ctx_simd_setup (void)
{
// this would also affect other code..
//_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
//_mm_setcsr(_mm_getcsr() | 0x8040);
switch (ctx_x86_64_level())
{
default:
case 0:
case 1: break;
case 2: ctx_simd_setup_x86_64_v2 ();break;
case 3: ctx_simd_setup_x86_64_v3 ();break;
}
}
#else // must be arm if we have SIMD enabled and are not x86_64
void ctx_simd_setup_arm_neon (void);
int ctx_arm_has_neon (int *armv);
void ctx_simd_setup (void)
{
if (ctx_arm_has_neon (NULL))
ctx_simd_setup_arm_neon ();
}
#endif
#endif
#if CTX_BABL
#include <babl/babl.h>
#else
#undef CTX_ENABLE_CM
#define CTX_ENABLE_CM 0
#endif
#if defined(CTX_SIMD_X86_64_V2)
#define CTX_SIMD_SUFFIX(symbol) symbol##_x86_64_v2
#elif defined(CTX_SIMD_X86_64_V3)
#define CTX_SIMD_SUFFIX(symbol) symbol##_x86_64_v3
#elif defined(CTX_SIMD_ARM_NEON)
#define CTX_SIMD_SUFFIX(symbol) symbol##_armv7l_neon
#else
#if CTX_STB_TT
#define STB_TRUETYPE_IMPLEMENTATION
#include "stb_truetype.h"
#endif
#if CTX_STB_IMAGE
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#endif
#endif
#endif
#include "ctx.h"