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;
79 struct shl_register_record *record;
80 const struct kmscon_font_ops *ops;
81 struct kmscon_font_attr attr;
82 unsigned int baseline;
86 struct kmscon_font_ops {
88 int (*init) (struct kmscon_font *out,
89 const struct kmscon_font_attr *attr);
90 void (*destroy) (struct kmscon_font *font);
91 int (*render) (struct kmscon_font *font,
92 uint32_t id, const uint32_t *ch, size_t len,
93 const struct kmscon_glyph **out);
94 int (*render_empty) (struct kmscon_font *font,
95 const struct kmscon_glyph **out);
96 int (*render_inval) (struct kmscon_font *font,
97 const struct kmscon_glyph **out);
100 int kmscon_font_register(const struct kmscon_font_ops *ops);
101 void kmscon_font_unregister(const char *name);
103 int kmscon_font_find(struct kmscon_font **out,
104 const struct kmscon_font_attr *attr,
105 const char *backend);
106 void kmscon_font_ref(struct kmscon_font *font);
107 void kmscon_font_unref(struct kmscon_font *font);
109 int kmscon_font_render(struct kmscon_font *font,
110 uint32_t id, const uint32_t *ch, size_t len,
111 const struct kmscon_glyph **out);
112 int kmscon_font_render_empty(struct kmscon_font *font,
113 const struct kmscon_glyph **out);
114 int kmscon_font_render_inval(struct kmscon_font *font,
115 const struct kmscon_glyph **out);
120 struct kmscon_text_ops;
124 const struct kmscon_text_ops *ops;
127 struct kmscon_font *font;
128 struct kmscon_font *bold_font;
129 struct uterm_display *disp;
135 struct kmscon_text_ops {
137 int (*init) (struct kmscon_text *txt);
138 void (*destroy) (struct kmscon_text *txt);
139 int (*set) (struct kmscon_text *txt);
140 void (*unset) (struct kmscon_text *txt);
141 int (*prepare) (struct kmscon_text *txt);
142 int (*draw) (struct kmscon_text *txt,
143 uint32_t id, const uint32_t *ch, size_t len,
145 unsigned int posx, unsigned int posy,
146 const struct tsm_screen_attr *attr);
147 int (*render) (struct kmscon_text *txt);
148 void (*abort) (struct kmscon_text *txt);
151 int kmscon_text_register(const struct kmscon_text_ops *ops);
152 void kmscon_text_unregister(const char *name);
154 int kmscon_text_new(struct kmscon_text **out, const char *backend);
155 void kmscon_text_ref(struct kmscon_text *txt);
156 void kmscon_text_unref(struct kmscon_text *txt);
158 int kmscon_text_set(struct kmscon_text *txt,
159 struct kmscon_font *font,
160 struct kmscon_font *bold_font,
161 struct uterm_display *disp);
162 void kmscon_text_unset(struct kmscon_text *txt);
163 unsigned int kmscon_text_get_cols(struct kmscon_text *txt);
164 unsigned int kmscon_text_get_rows(struct kmscon_text *txt);
166 int kmscon_text_prepare(struct kmscon_text *txt);
167 int kmscon_text_draw(struct kmscon_text *txt,
168 uint32_t id, const uint32_t *ch, size_t len,
170 unsigned int posx, unsigned int posy,
171 const struct tsm_screen_attr *attr);
172 int kmscon_text_render(struct kmscon_text *txt);
173 void kmscon_text_abort(struct kmscon_text *txt);
175 int kmscon_text_prepare_cb(struct tsm_screen *con, void *data);
176 int kmscon_text_draw_cb(struct tsm_screen *con,
177 uint32_t id, const uint32_t *ch, size_t len,
179 unsigned int posx, unsigned int posy,
180 const struct tsm_screen_attr *attr, void *data);
181 int kmscon_text_render_cb(struct tsm_screen *con, void *data);
183 /* modularized backends */
185 #ifdef BUILD_ENABLE_FONT_8X16
187 int kmscon_font_8x16_load(void);
188 void kmscon_font_8x16_unload(void);
192 static inline int kmscon_font_8x16_load(void)
197 static inline void kmscon_font_8x16_unload(void)
203 #ifdef BUILD_ENABLE_FONT_UNIFONT
205 int kmscon_font_unifont_load(void);
206 void kmscon_font_unifont_unload(void);
210 static inline int kmscon_font_unifont_load(void)
215 static inline void kmscon_font_unifont_unload(void)
221 #ifdef BUILD_ENABLE_FONT_FREETYPE2
223 int kmscon_font_freetype2_load(void);
224 void kmscon_font_freetype2_unload(void);
228 static inline int kmscon_font_freetype2_load(void)
233 static inline void kmscon_font_freetype2_unload(void)
239 #ifdef BUILD_ENABLE_FONT_PANGO
241 int kmscon_font_pango_load(void);
242 void kmscon_font_pango_unload(void);
246 static inline int kmscon_font_pango_load(void)
251 static inline void kmscon_font_pango_unload(void)
257 #ifdef BUILD_ENABLE_RENDERER_BBLIT
259 int kmscon_text_bblit_load(void);
260 void kmscon_text_bblit_unload(void);
264 static inline int kmscon_text_bblit_load(void)
269 static inline void kmscon_text_bblit_unload(void)
275 #ifdef BUILD_ENABLE_RENDERER_BBULK
277 int kmscon_text_bbulk_load(void);
278 void kmscon_text_bbulk_unload(void);
282 static inline int kmscon_text_bbulk_load(void)
287 static inline void kmscon_text_bbulk_unload(void)
293 #ifdef BUILD_ENABLE_RENDERER_GLTEX
295 int kmscon_text_gltex_load(void);
296 void kmscon_text_gltex_unload(void);
300 static inline int kmscon_text_gltex_load(void)
305 static inline void kmscon_text_gltex_unload(void)
311 static inline void kmscon_font_load_all(void)
313 kmscon_font_8x16_load();
314 kmscon_font_unifont_load();
315 kmscon_font_pango_load();
316 kmscon_font_freetype2_load();
319 static inline void kmscon_font_unload_all(void)
321 kmscon_font_freetype2_unload();
322 kmscon_font_pango_unload();
323 kmscon_font_unifont_unload();
324 kmscon_font_8x16_unload();
327 static inline void kmscon_text_load_all(void)
329 kmscon_text_bbulk_load();
330 kmscon_text_bblit_load();
331 kmscon_text_gltex_load();
334 static inline void kmscon_text_unload_all(void)
336 kmscon_text_gltex_unload();
337 kmscon_text_bblit_unload();
338 kmscon_text_bbulk_unload();
341 #endif /* KMSCON_TEXT_H */