uvtd: vt: implement VT_GETMODE/SETMODE ioctl state-tracking
[platform/upstream/kmscon.git] / src / text_bblit.c
1 /*
2  * kmscon - Bit-Blitting Text Renderer Backend
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  * SECTION:text_bblit.c
28  * @short_description: Bit-Blitting Text Renderer Backend
29  * @include: text.h
30  *
31  * The bit-blitting renderer requires framebuffer access to the output device
32  * and simply blits the glyphs into the buffer.
33  */
34
35 #include <errno.h>
36 #include <stdbool.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include "shl_log.h"
40 #include "text.h"
41 #include "uterm_video.h"
42
43 #define LOG_SUBSYSTEM "text_bblit"
44
45 static int bblit_set(struct kmscon_text *txt)
46 {
47         unsigned int sw, sh, fw, fh;
48         struct uterm_mode *mode;
49
50         fw = txt->font->attr.width;
51         fh = txt->font->attr.height;
52         mode = uterm_display_get_current(txt->disp);
53         if (!mode)
54                 return -EINVAL;
55         sw = uterm_mode_get_width(mode);
56         sh = uterm_mode_get_height(mode);
57
58         txt->cols = sw / fw;
59         txt->rows = sh / fh;
60
61         return 0;
62 }
63
64 static int bblit_draw(struct kmscon_text *txt,
65                       uint32_t id, const uint32_t *ch, size_t len,
66                       unsigned int width,
67                       unsigned int posx, unsigned int posy,
68                       const struct tsm_screen_attr *attr)
69 {
70         const struct kmscon_glyph *glyph;
71         int ret;
72         struct kmscon_font *font;
73
74         if (!width)
75                 return 0;
76
77         if (attr->bold)
78                 font = txt->bold_font;
79         else
80                 font = txt->font;
81
82         if (!len) {
83                 ret = kmscon_font_render_empty(font, &glyph);
84         } else {
85                 ret = kmscon_font_render(font, id, ch, len, &glyph);
86         }
87
88         if (ret) {
89                 ret = kmscon_font_render_inval(font, &glyph);
90                 if (ret)
91                         return ret;
92         }
93
94         /* draw glyph */
95         if (attr->inverse) {
96                 ret = uterm_display_fake_blend(txt->disp, &glyph->buf,
97                                                posx * txt->font->attr.width,
98                                                posy * txt->font->attr.height,
99                                                attr->br, attr->bg, attr->bb,
100                                                attr->fr, attr->fg, attr->fb);
101         } else {
102                 ret = uterm_display_fake_blend(txt->disp, &glyph->buf,
103                                                posx * txt->font->attr.width,
104                                                posy * txt->font->attr.height,
105                                                attr->fr, attr->fg, attr->fb,
106                                                attr->br, attr->bg, attr->bb);
107         }
108
109         return ret;
110 }
111
112 struct kmscon_text_ops kmscon_text_bblit_ops = {
113         .name = "bblit",
114         .owner = NULL,
115         .init = NULL,
116         .destroy = NULL,
117         .set = bblit_set,
118         .unset = NULL,
119         .prepare = NULL,
120         .draw = bblit_draw,
121         .render = NULL,
122         .abort = NULL,
123 };