2 * kmscon - Bit-Blitting Bulk Text Renderer Backend
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.
27 * SECTION:text_bbulk.c
28 * @short_description: Bit-Blitting Bulk Text Renderer Backend
31 * Similar to the bblit renderer but assembles an array of blit-requests and
32 * pushes all of them at once to the video device.
40 #include "static_misc.h"
45 #define LOG_SUBSYSTEM "text_bbulk"
48 struct uterm_video_blend_req *reqs;
51 #define FONT_WIDTH(txt) ((txt)->font->attr.width)
52 #define FONT_HEIGHT(txt) ((txt)->font->attr.height)
54 #define SCREEN_WIDTH(txt) uterm_screen_width((txt)->screen)
55 #define SCREEN_HEIGHT(txt) uterm_screen_height((txt)->screen)
57 static int bbulk_init(struct kmscon_text *txt)
61 bb = malloc(sizeof(*bb));
69 static void bbulk_destroy(struct kmscon_text *txt)
71 struct bbulk *bb = txt->data;
76 static int bbulk_set(struct kmscon_text *txt)
78 struct bbulk *bb = txt->data;
79 unsigned int sw, sh, i, j;
80 struct uterm_video_blend_req *req;
82 memset(bb, 0, sizeof(*bb));
84 sw = SCREEN_WIDTH(txt);
85 sh = SCREEN_HEIGHT(txt);
87 txt->cols = sw / FONT_WIDTH(txt);
88 txt->rows = sh / FONT_HEIGHT(txt);
90 bb->reqs = malloc(sizeof(*bb->reqs) * txt->cols * txt->rows);
93 memset(bb->reqs, 0, sizeof(*bb->reqs) * txt->cols * txt->rows);
95 for (i = 0; i < txt->rows; ++i) {
96 for (j = 0; j < txt->cols; ++j) {
97 req = &bb->reqs[i * txt->cols + j];
98 req->x = j * FONT_WIDTH(txt);
99 req->y = i * FONT_HEIGHT(txt);
106 static void bbulk_unset(struct kmscon_text *txt)
108 struct bbulk *bb = txt->data;
114 static int bbulk_draw(struct kmscon_text *txt, kmscon_symbol_t ch,
115 unsigned int posx, unsigned int posy,
116 const struct font_char_attr *attr)
118 struct bbulk *bb = txt->data;
119 const struct kmscon_glyph *glyph;
121 struct uterm_video_blend_req *req;
123 if (ch == 0 || ch == ' ') {
124 ret = kmscon_font_render_empty(txt->font, &glyph);
126 ret = kmscon_font_render(txt->font, ch, &glyph);
130 ret = kmscon_font_render_inval(txt->font, &glyph);
135 req = &bb->reqs[posy * txt->cols + posx];
136 req->buf = &glyph->buf;
156 static int bbulk_render(struct kmscon_text *txt)
158 struct bbulk *bb = txt->data;
160 return uterm_screen_blendv(txt->screen, bb->reqs,
161 txt->cols * txt->rows);
164 static const struct kmscon_text_ops kmscon_text_bbulk_ops = {
167 .destroy = bbulk_destroy,
169 .unset = bbulk_unset,
172 .render = bbulk_render,
176 int kmscon_text_bbulk_load(void)
180 ret = kmscon_text_register(&kmscon_text_bbulk_ops);
182 log_error("cannot register bbulk renderer");
189 void kmscon_text_bbulk_unload(void)
191 kmscon_text_unregister(kmscon_text_bbulk_ops.name);