From 6ae5ddc0e73d9de6984cbfc567d15565323975e9 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Tue, 4 Sep 2012 17:58:37 +0200 Subject: [PATCH] text: add bbulk renderer The bbulk renderer is very similar to the bblit renderer but it assembles a request-buffer of all characters and then pushes these requests via a vector-call to the video hardware. This turns out to increase performance slightly as we do not call into the video subsystem for every characters but only once. This renderer can reduce performance when used with partial-redraws (which are not implemented, yet), so we keep the bblit renderer around. Signed-off-by: David Herrmann --- Makefile.am | 5 ++ configure.ac | 23 ++++++ src/main.c | 3 + src/text.h | 18 +++++ src/text_bbulk.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 241 insertions(+) create mode 100644 src/text_bbulk.c diff --git a/Makefile.am b/Makefile.am index e91a646..563da68 100644 --- a/Makefile.am +++ b/Makefile.am @@ -173,6 +173,11 @@ libkmscon_core_la_SOURCES += \ src/text_bblit.c endif +if KMSCON_HAVE_BBULK +libkmscon_core_la_SOURCES += \ + src/text_bbulk.c +endif + if KMSCON_HAVE_GLES2 libkmscon_core_la_SOURCES += \ src/text_gltex.c diff --git a/configure.ac b/configure.ac index 7846c55..09b4c2a 100644 --- a/configure.ac +++ b/configure.ac @@ -160,6 +160,12 @@ AC_ARG_ENABLE([bblit], [disable bblit rendering backend])]) AC_MSG_RESULT([ok]) +AC_MSG_CHECKING([whether to use bbulk rendering backend]) +AC_ARG_ENABLE([bbulk], + [AS_HELP_STRING([--disable-bbulk], + [disable bbulk rendering backend])]) +AC_MSG_RESULT([ok]) + AC_MSG_CHECKING([whether to build with debugging on]) AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug], @@ -496,6 +502,22 @@ fi AM_CONDITIONAL([KMSCON_HAVE_BBLIT], [test x$bblit_enabled = xyes]) +# +# BBulk Rendering backend +# + +bbulk_enabled=no +if test ! x$enable_bbulk = xno ; then + bbulk_enabled=yes +fi + +if test x$bbulk_enabled = xyes ; then + AC_DEFINE([KMSCON_HAVE_BBULK], [1], + [Use bbulk rendering backend]) +fi + +AM_CONDITIONAL([KMSCON_HAVE_BBULK], [test x$bbulk_enabled = xyes]) + # # OpenGL Texture rendering backend # This is not really an option but automatically enabled if OpenGLES2 support @@ -567,6 +589,7 @@ AC_MSG_NOTICE([Build configuration: rendering backends: bblit: $bblit_enabled + bbulk: $bbulk_enabled gltex: $gltex_enabled Run "make" to start compilation process]) diff --git a/src/main.c b/src/main.c index 1bdbe35..9355a75 100644 --- a/src/main.c +++ b/src/main.c @@ -574,6 +574,7 @@ int main(int argc, char **argv) kmscon_font_pango_load(); kmscon_font_freetype2_load(); kmscon_text_bblit_load(); + kmscon_text_bbulk_load(); kmscon_text_gltex_load(); memset(&app, 0, sizeof(app)); @@ -605,6 +606,7 @@ int main(int argc, char **argv) destroy_app(&app); kmscon_text_gltex_unload(); + kmscon_text_bbulk_unload(); kmscon_text_bblit_unload(); kmscon_font_freetype2_unload(); kmscon_font_pango_unload(); @@ -617,6 +619,7 @@ int main(int argc, char **argv) err_unload: kmscon_text_gltex_unload(); + kmscon_text_bbulk_unload(); kmscon_text_bblit_unload(); kmscon_font_freetype2_unload(); kmscon_font_pango_unload(); diff --git a/src/text.h b/src/text.h index 1de85cf..23c77b6 100644 --- a/src/text.h +++ b/src/text.h @@ -271,6 +271,24 @@ static inline void kmscon_text_bblit_unload(void) #endif +#ifdef KMSCON_HAVE_BBULK + +int kmscon_text_bbulk_load(void); +void kmscon_text_bbulk_unload(void); + +#else + +static inline int kmscon_text_bbulk_load(void) +{ + return -EOPNOTSUPP; +} + +static inline void kmscon_text_bbulk_unload(void) +{ +} + +#endif + #ifdef KMSCON_HAVE_GLES2 int kmscon_text_gltex_load(void); diff --git a/src/text_bbulk.c b/src/text_bbulk.c new file mode 100644 index 0000000..aaf5201 --- /dev/null +++ b/src/text_bbulk.c @@ -0,0 +1,192 @@ +/* + * kmscon - Bit-Blitting Bulk Text Renderer Backend + * + * Copyright (c) 2012 David Herrmann + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * SECTION:text_bbulk.c + * @short_description: Bit-Blitting Bulk Text Renderer Backend + * @include: text.h + * + * Similar to the bblit renderer but assembles an array of blit-requests and + * pushes all of them at once to the video device. + */ + +#include +#include +#include +#include +#include "log.h" +#include "static_misc.h" +#include "text.h" +#include "unicode.h" +#include "uterm.h" + +#define LOG_SUBSYSTEM "text_bbulk" + +struct bbulk { + struct uterm_video_blend_req *reqs; +}; + +#define FONT_WIDTH(txt) ((txt)->font->attr.width) +#define FONT_HEIGHT(txt) ((txt)->font->attr.height) + +#define SCREEN_WIDTH(txt) uterm_screen_width((txt)->screen) +#define SCREEN_HEIGHT(txt) uterm_screen_height((txt)->screen) + +static int bbulk_init(struct kmscon_text *txt) +{ + struct bbulk *bb; + + bb = malloc(sizeof(*bb)); + if (!bb) + return -ENOMEM; + + txt->data = bb; + return 0; +} + +static void bbulk_destroy(struct kmscon_text *txt) +{ + struct bbulk *bb = txt->data; + + free(bb); +} + +static int bbulk_set(struct kmscon_text *txt) +{ + struct bbulk *bb = txt->data; + unsigned int sw, sh, i, j; + struct uterm_video_blend_req *req; + + memset(bb, 0, sizeof(*bb)); + + sw = SCREEN_WIDTH(txt); + sh = SCREEN_HEIGHT(txt); + + txt->cols = sw / FONT_WIDTH(txt); + txt->rows = sh / FONT_HEIGHT(txt); + + bb->reqs = malloc(sizeof(*bb->reqs) * txt->cols * txt->rows); + if (!bb->reqs) + return -ENOMEM; + memset(bb->reqs, 0, sizeof(*bb->reqs) * txt->cols * txt->rows); + + for (i = 0; i < txt->rows; ++i) { + for (j = 0; j < txt->cols; ++j) { + req = &bb->reqs[i * txt->cols + j]; + req->x = j * FONT_WIDTH(txt); + req->y = i * FONT_HEIGHT(txt); + } + } + + return 0; +} + +static void bbulk_unset(struct kmscon_text *txt) +{ + struct bbulk *bb = txt->data; + + free(bb->reqs); + bb->reqs = NULL; +} + +static int bbulk_draw(struct kmscon_text *txt, kmscon_symbol_t ch, + unsigned int posx, unsigned int posy, + const struct font_char_attr *attr) +{ + struct bbulk *bb = txt->data; + const struct kmscon_glyph *glyph; + int ret; + struct uterm_video_blend_req *req; + + if (ch == 0 || ch == ' ') { + ret = kmscon_font_render_empty(txt->font, &glyph); + } else { + ret = kmscon_font_render(txt->font, ch, &glyph); + } + + if (ret) { + ret = kmscon_font_render_inval(txt->font, &glyph); + if (ret) + return ret; + } + + req = &bb->reqs[posy * txt->cols + posx]; + req->buf = &glyph->buf; + if (attr->inverse) { + req->fr = attr->br; + req->fg = attr->bg; + req->fb = attr->bb; + req->br = attr->fr; + req->bg = attr->fg; + req->bb = attr->fb; + } else { + req->fr = attr->fr; + req->fg = attr->fg; + req->fb = attr->fb; + req->br = attr->br; + req->bg = attr->bg; + req->bb = attr->bb; + } + + return 0; +} + +static int bbulk_render(struct kmscon_text *txt) +{ + struct bbulk *bb = txt->data; + + return uterm_screen_blendv(txt->screen, bb->reqs, + txt->cols * txt->rows); +} + +static const struct kmscon_text_ops kmscon_text_bbulk_ops = { + .name = "bbulk", + .init = bbulk_init, + .destroy = bbulk_destroy, + .set = bbulk_set, + .unset = bbulk_unset, + .prepare = NULL, + .draw = bbulk_draw, + .render = bbulk_render, + .abort = NULL, +}; + +int kmscon_text_bbulk_load(void) +{ + int ret; + + ret = kmscon_text_register(&kmscon_text_bbulk_ops); + if (ret) { + log_error("cannot register bbulk renderer"); + return ret; + } + + return 0; +} + +void kmscon_text_bbulk_unload(void) +{ + kmscon_text_unregister(kmscon_text_bbulk_ops.name); +}