2 * kmscon - Text Renderer
4 * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * The Text-Renderer subsystem provides a simple way to draw text into a
29 * framebuffer. The system is modular and several different backends are
30 * available that can be used.
31 * The system is split into:
32 * - Font renderer: The font renderer allows selecting fonts and rendering
33 * single glyphs into memory-buffers
34 * - Text renderer: The text renderer uses the font renderer to draw a whole
35 * console into a framebuffer.
43 #include "tsm_screen.h"
48 struct kmscon_font_attr;
51 struct kmscon_font_ops;
53 #define KMSCON_FONT_MAX_NAME 128
54 #define KMSCON_FONT_DEFAULT_NAME "monospace"
55 #define KMSCON_FONT_DEFAULT_PPI 72
57 struct kmscon_font_attr {
58 char name[KMSCON_FONT_MAX_NAME];
67 void kmscon_font_attr_normalize(struct kmscon_font_attr *attr);
68 bool kmscon_font_attr_match(const struct kmscon_font_attr *a1,
69 const struct kmscon_font_attr *a2);
72 struct uterm_video_buffer buf;
78 const struct kmscon_font_ops *ops;
79 struct kmscon_font_attr attr;
80 unsigned int baseline;
84 struct kmscon_font_ops {
86 int (*init) (struct kmscon_font *out,
87 const struct kmscon_font_attr *attr);
88 void (*destroy) (struct kmscon_font *font);
89 int (*render) (struct kmscon_font *font,
90 uint32_t id, const uint32_t *ch, size_t len,
91 const struct kmscon_glyph **out);
92 int (*render_empty) (struct kmscon_font *font,
93 const struct kmscon_glyph **out);
94 int (*render_inval) (struct kmscon_font *font,
95 const struct kmscon_glyph **out);
98 int kmscon_font_register(const struct kmscon_font_ops *ops);
99 void kmscon_font_unregister(const char *name);
101 int kmscon_font_find(struct kmscon_font **out,
102 const struct kmscon_font_attr *attr,
103 const char *backend);
104 void kmscon_font_ref(struct kmscon_font *font);
105 void kmscon_font_unref(struct kmscon_font *font);
107 int kmscon_font_render(struct kmscon_font *font,
108 uint32_t id, const uint32_t *ch, size_t len,
109 const struct kmscon_glyph **out);
110 int kmscon_font_render_empty(struct kmscon_font *font,
111 const struct kmscon_glyph **out);
112 int kmscon_font_render_inval(struct kmscon_font *font,
113 const struct kmscon_glyph **out);
118 struct kmscon_text_ops;
122 const struct kmscon_text_ops *ops;
125 struct kmscon_font *font;
126 struct uterm_screen *screen;
132 struct kmscon_text_ops {
134 int (*init) (struct kmscon_text *txt);
135 void (*destroy) (struct kmscon_text *txt);
136 int (*set) (struct kmscon_text *txt);
137 void (*unset) (struct kmscon_text *txt);
138 int (*prepare) (struct kmscon_text *txt);
139 int (*draw) (struct kmscon_text *txt,
140 uint32_t id, const uint32_t *ch, size_t len,
141 unsigned int posx, unsigned int posy,
142 const struct tsm_screen_attr *attr);
143 int (*render) (struct kmscon_text *txt);
144 void (*abort) (struct kmscon_text *txt);
147 int kmscon_text_register(const struct kmscon_text_ops *ops);
148 void kmscon_text_unregister(const char *name);
150 int kmscon_text_new(struct kmscon_text **out, const char *backend);
151 void kmscon_text_ref(struct kmscon_text *txt);
152 void kmscon_text_unref(struct kmscon_text *txt);
154 int kmscon_text_set(struct kmscon_text *txt,
155 struct kmscon_font *font,
156 struct uterm_screen *screen);
157 void kmscon_text_unset(struct kmscon_text *txt);
158 unsigned int kmscon_text_get_cols(struct kmscon_text *txt);
159 unsigned int kmscon_text_get_rows(struct kmscon_text *txt);
161 int kmscon_text_prepare(struct kmscon_text *txt);
162 int kmscon_text_draw(struct kmscon_text *txt,
163 uint32_t id, const uint32_t *ch, size_t len,
164 unsigned int posx, unsigned int posy,
165 const struct tsm_screen_attr *attr);
166 int kmscon_text_render(struct kmscon_text *txt);
167 void kmscon_text_abort(struct kmscon_text *txt);
169 int kmscon_text_prepare_cb(struct tsm_screen *con, void *data);
170 int kmscon_text_draw_cb(struct tsm_screen *con,
171 uint32_t id, const uint32_t *ch, size_t len,
172 unsigned int posx, unsigned int posy,
173 const struct tsm_screen_attr *attr, void *data);
174 int kmscon_text_render_cb(struct tsm_screen *con, void *data);
176 /* modularized backends */
178 #ifdef BUILD_ENABLE_FONT_8X16
180 int kmscon_font_8x16_load(void);
181 void kmscon_font_8x16_unload(void);
185 static inline int kmscon_font_8x16_load(void)
190 static inline void kmscon_font_8x16_unload(void)
196 #ifdef BUILD_ENABLE_FONT_UNIFONT
198 int kmscon_font_unifont_load(void);
199 void kmscon_font_unifont_unload(void);
203 static inline int kmscon_font_unifont_load(void)
208 static inline void kmscon_font_unifont_unload(void)
214 #ifdef BUILD_ENABLE_FONT_FREETYPE2
216 int kmscon_font_freetype2_load(void);
217 void kmscon_font_freetype2_unload(void);
221 static inline int kmscon_font_freetype2_load(void)
226 static inline void kmscon_font_freetype2_unload(void)
232 #ifdef BUILD_ENABLE_FONT_PANGO
234 int kmscon_font_pango_load(void);
235 void kmscon_font_pango_unload(void);
239 static inline int kmscon_font_pango_load(void)
244 static inline void kmscon_font_pango_unload(void)
250 #ifdef BUILD_ENABLE_RENDERER_BBLIT
252 int kmscon_text_bblit_load(void);
253 void kmscon_text_bblit_unload(void);
257 static inline int kmscon_text_bblit_load(void)
262 static inline void kmscon_text_bblit_unload(void)
268 #ifdef BUILD_ENABLE_RENDERER_BBULK
270 int kmscon_text_bbulk_load(void);
271 void kmscon_text_bbulk_unload(void);
275 static inline int kmscon_text_bbulk_load(void)
280 static inline void kmscon_text_bbulk_unload(void)
286 #ifdef BUILD_ENABLE_RENDERER_GLTEX
288 int kmscon_text_gltex_load(void);
289 void kmscon_text_gltex_unload(void);
293 static inline int kmscon_text_gltex_load(void)
298 static inline void kmscon_text_gltex_unload(void)
304 static inline void kmscon_font_load_all(void)
306 kmscon_font_8x16_load();
307 kmscon_font_unifont_load();
308 kmscon_font_pango_load();
309 kmscon_font_freetype2_load();
312 static inline void kmscon_font_unload_all(void)
314 kmscon_font_freetype2_unload();
315 kmscon_font_pango_unload();
316 kmscon_font_unifont_unload();
317 kmscon_font_8x16_unload();
320 static inline void kmscon_text_load_all(void)
322 kmscon_text_bbulk_load();
323 kmscon_text_bblit_load();
324 kmscon_text_gltex_load();
327 static inline void kmscon_text_unload_all(void)
329 kmscon_text_gltex_unload();
330 kmscon_text_bblit_unload();
331 kmscon_text_bbulk_unload();
334 #endif /* KMSCON_TEXT_H */