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.
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 kmscon_console_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 kmscon_console_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 kmscon_console *con, void *data);
170 int kmscon_text_draw_cb(struct kmscon_console *con,
171 uint32_t id, const uint32_t *ch, size_t len,
172 unsigned int posx, unsigned int posy,
173 const struct kmscon_console_attr *attr, void *data);
174 int kmscon_text_render_cb(struct kmscon_console *con, void *data);
176 /* modularized backends */
178 #ifdef KMSCON_HAVE_UNIFONT
180 int kmscon_font_unifont_load(void);
181 void kmscon_font_unifont_unload(void);
185 static inline int kmscon_font_unifont_load(void)
190 static inline void kmscon_font_unifont_unload(void)
197 #ifdef KMSCON_HAVE_8X16
199 int kmscon_font_8x16_load(void);
200 void kmscon_font_8x16_unload(void);
204 static inline int kmscon_font_8x16_load(void)
209 static inline void kmscon_font_8x16_unload(void)
215 #ifdef KMSCON_HAVE_FREETYPE2
217 int kmscon_font_freetype2_load(void);
218 void kmscon_font_freetype2_unload(void);
222 static inline int kmscon_font_freetype2_load(void)
227 static inline void kmscon_font_freetype2_unload(void)
233 #ifdef KMSCON_HAVE_PANGO
235 int kmscon_font_pango_load(void);
236 void kmscon_font_pango_unload(void);
240 static inline int kmscon_font_pango_load(void)
245 static inline void kmscon_font_pango_unload(void)
251 #ifdef KMSCON_HAVE_BBLIT
253 int kmscon_text_bblit_load(void);
254 void kmscon_text_bblit_unload(void);
258 static inline int kmscon_text_bblit_load(void)
263 static inline void kmscon_text_bblit_unload(void)
269 #ifdef KMSCON_HAVE_BBULK
271 int kmscon_text_bbulk_load(void);
272 void kmscon_text_bbulk_unload(void);
276 static inline int kmscon_text_bbulk_load(void)
281 static inline void kmscon_text_bbulk_unload(void)
287 #ifdef KMSCON_HAVE_GLES2
289 int kmscon_text_gltex_load(void);
290 void kmscon_text_gltex_unload(void);
294 static inline int kmscon_text_gltex_load(void)
299 static inline void kmscon_text_gltex_unload(void)
305 #endif /* KMSCON_TEXT_H */