text: add owner field to text-ops
[platform/upstream/kmscon.git] / src / text.h
1 /*
2  * kmscon - Text Renderer
3  *
4  * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
5  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
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.
24  */
25
26 /*
27  * Text Renderer
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  */
32
33 #ifndef KMSCON_TEXT_H
34 #define KMSCON_TEXT_H
35
36 #include <errno.h>
37 #include <stdlib.h>
38 #include "font.h"
39 #include "kmscon_module.h"
40 #include "tsm_screen.h"
41 #include "uterm.h"
42
43 /* text renderer */
44
45 struct kmscon_text;
46 struct kmscon_text_ops;
47
48 struct kmscon_text {
49         unsigned long ref;
50         struct shl_register_record *record;
51         const struct kmscon_text_ops *ops;
52         void *data;
53
54         struct kmscon_font *font;
55         struct kmscon_font *bold_font;
56         struct uterm_display *disp;
57         unsigned int cols;
58         unsigned int rows;
59         bool rendering;
60 };
61
62 struct kmscon_text_ops {
63         const char *name;
64         struct kmscon_module *owner;
65         int (*init) (struct kmscon_text *txt);
66         void (*destroy) (struct kmscon_text *txt);
67         int (*set) (struct kmscon_text *txt);
68         void (*unset) (struct kmscon_text *txt);
69         int (*prepare) (struct kmscon_text *txt);
70         int (*draw) (struct kmscon_text *txt,
71                      uint32_t id, const uint32_t *ch, size_t len,
72                      unsigned int width,
73                      unsigned int posx, unsigned int posy,
74                      const struct tsm_screen_attr *attr);
75         int (*render) (struct kmscon_text *txt);
76         void (*abort) (struct kmscon_text *txt);
77 };
78
79 int kmscon_text_register(const struct kmscon_text_ops *ops);
80 void kmscon_text_unregister(const char *name);
81
82 int kmscon_text_new(struct kmscon_text **out, const char *backend);
83 void kmscon_text_ref(struct kmscon_text *txt);
84 void kmscon_text_unref(struct kmscon_text *txt);
85
86 int kmscon_text_set(struct kmscon_text *txt,
87                     struct kmscon_font *font,
88                     struct kmscon_font *bold_font,
89                     struct uterm_display *disp);
90 void kmscon_text_unset(struct kmscon_text *txt);
91 unsigned int kmscon_text_get_cols(struct kmscon_text *txt);
92 unsigned int kmscon_text_get_rows(struct kmscon_text *txt);
93
94 int kmscon_text_prepare(struct kmscon_text *txt);
95 int kmscon_text_draw(struct kmscon_text *txt,
96                      uint32_t id, const uint32_t *ch, size_t len,
97                      unsigned int width,
98                      unsigned int posx, unsigned int posy,
99                      const struct tsm_screen_attr *attr);
100 int kmscon_text_render(struct kmscon_text *txt);
101 void kmscon_text_abort(struct kmscon_text *txt);
102
103 int kmscon_text_prepare_cb(struct tsm_screen *con, void *data);
104 int kmscon_text_draw_cb(struct tsm_screen *con,
105                         uint32_t id, const uint32_t *ch, size_t len,
106                         unsigned int width,
107                         unsigned int posx, unsigned int posy,
108                         const struct tsm_screen_attr *attr, void *data);
109 int kmscon_text_render_cb(struct tsm_screen *con, void *data);
110
111 /* modularized backends */
112
113 extern struct kmscon_text_ops kmscon_text_bblit_ops;
114 extern struct kmscon_text_ops kmscon_text_bbulk_ops;
115 extern struct kmscon_text_ops kmscon_text_gltex_ops;
116
117 #ifdef BUILD_ENABLE_RENDERER_BBLIT
118
119 int kmscon_text_bblit_load(void);
120 void kmscon_text_bblit_unload(void);
121
122 #else
123
124 static inline int kmscon_text_bblit_load(void)
125 {
126         return -EOPNOTSUPP;
127 }
128
129 static inline void kmscon_text_bblit_unload(void)
130 {
131 }
132
133 #endif
134
135 #ifdef BUILD_ENABLE_RENDERER_BBULK
136
137 int kmscon_text_bbulk_load(void);
138 void kmscon_text_bbulk_unload(void);
139
140 #else
141
142 static inline int kmscon_text_bbulk_load(void)
143 {
144         return -EOPNOTSUPP;
145 }
146
147 static inline void kmscon_text_bbulk_unload(void)
148 {
149 }
150
151 #endif
152
153 #ifdef BUILD_ENABLE_RENDERER_GLTEX
154
155 int kmscon_text_gltex_load(void);
156 void kmscon_text_gltex_unload(void);
157
158 #else
159
160 static inline int kmscon_text_gltex_load(void)
161 {
162         return -EOPNOTSUPP;
163 }
164
165 static inline void kmscon_text_gltex_unload(void)
166 {
167 }
168
169 #endif
170
171 static inline void kmscon_text_load_all(void)
172 {
173         kmscon_text_bbulk_load();
174         kmscon_text_bblit_load();
175         kmscon_text_gltex_load();
176 }
177
178 static inline void kmscon_text_unload_all(void)
179 {
180         kmscon_text_gltex_unload();
181         kmscon_text_bblit_unload();
182         kmscon_text_bbulk_unload();
183 }
184
185 #endif /* KMSCON_TEXT_H */