diff options
author | David Herrmann <dh.herrmann@googlemail.com> | 2013-01-24 14:42:54 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@googlemail.com> | 2013-01-24 14:42:54 +0100 |
commit | f289349ef9a0a14566c50d666e698c4c97912e76 (patch) | |
tree | fa2befe8545be7dad0d52cc11e4a9bd937ba42bd /src | |
parent | ae25adc34fd835569e28b713408e0fea1bfdd3d1 (diff) |
uterm: rename drm-dumb backend into drm2d module
This moves all the drm-dumb code into a new module that is now called
drm2d (which was already used internally before).
No conceptual changes, just renames and moves.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/kmscon_conf.c | 2 | ||||
-rw-r--r-- | src/kmscon_main.c | 6 | ||||
-rw-r--r-- | src/uterm_drm2d_internal.h | 66 | ||||
-rw-r--r-- | src/uterm_drm2d_render.c | 223 | ||||
-rw-r--r-- | src/uterm_drm2d_video.c (renamed from src/uterm_video_dumb.c) | 219 | ||||
-rw-r--r-- | src/uterm_video.c | 2 | ||||
-rw-r--r-- | src/uterm_video.h | 6 | ||||
-rw-r--r-- | src/uterm_video_internal.h | 2 |
8 files changed, 311 insertions, 215 deletions
diff --git a/src/kmscon_conf.c b/src/kmscon_conf.c index f88b696..d0f98df 100644 --- a/src/kmscon_conf.c +++ b/src/kmscon_conf.c @@ -448,7 +448,7 @@ static int aftercheck_drm(struct conf_option *opt, int argc, char **argv, * remove this check. */ if (conf->drm) { if (!uterm_video_available(UTERM_VIDEO_DRM) && - !uterm_video_available(UTERM_VIDEO_DUMB)) { + !uterm_video_available(UTERM_VIDEO_DRM2D)) { log_info("no DRM runtime support available; disabling --drm"); conf->drm = false; } diff --git a/src/kmscon_main.c b/src/kmscon_main.c index 927ca4d..b223b35 100644 --- a/src/kmscon_main.c +++ b/src/kmscon_main.c @@ -357,7 +357,7 @@ static int app_seat_add_video(struct app_seat *seat, if (seat->conf->hwaccel) mode = UTERM_VIDEO_DRM; else - mode = UTERM_VIDEO_DUMB; + mode = UTERM_VIDEO_DRM2D; } else { mode = UTERM_VIDEO_FBDEV; } @@ -365,10 +365,10 @@ static int app_seat_add_video(struct app_seat *seat, ret = uterm_video_new(&vid->video, seat->app->eloop, node, mode); if (ret) { if (mode == UTERM_VIDEO_DRM) { - log_info("cannot create drm device %s on seat %s (%d); trying dumb drm mode", + log_info("cannot create drm device %s on seat %s (%d); trying drm2d mode", vid->node, seat->name, ret); ret = uterm_video_new(&vid->video, seat->app->eloop, - node, UTERM_VIDEO_DUMB); + node, UTERM_VIDEO_DRM2D); if (ret) goto err_node; } else { diff --git a/src/uterm_drm2d_internal.h b/src/uterm_drm2d_internal.h new file mode 100644 index 0000000..e2bcabe --- /dev/null +++ b/src/uterm_drm2d_internal.h @@ -0,0 +1,66 @@ +/* + * uterm - Linux User-Space Terminal drm2d module + * + * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@googlemail.com> + * + * 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. + */ + +/* Internal definitions */ + +#ifndef UTERM_DRM2D_INTERNAL_H +#define UTERM_DRM2D_INTERNAL_H + +#include <inttypes.h> +#include <limits.h> +#include <stdbool.h> +#include <stdlib.h> +#include "uterm_video.h" + +struct uterm_drm2d_rb { + uint32_t fb; + uint32_t handle; + uint32_t stride; + uint64_t size; + void *map; +}; + +struct uterm_drm2d_display { + int current_rb; + struct uterm_drm2d_rb rb[2]; +}; + +struct uterm_drm2d_video { + int fd; + struct ev_fd *efd; +}; + +int uterm_drm2d_display_blit(struct uterm_display *disp, + const struct uterm_video_buffer *buf, + unsigned int x, unsigned int y); +int uterm_drm2d_display_fake_blendv(struct uterm_display *disp, + const struct uterm_video_blend_req *req, + size_t num); +int uterm_drm2d_display_fill(struct uterm_display *disp, + uint8_t r, uint8_t g, uint8_t b, + unsigned int x, unsigned int y, + unsigned int width, unsigned int height); + +#endif /* UTERM_DRM2D_INTERNAL_H */ diff --git a/src/uterm_drm2d_render.c b/src/uterm_drm2d_render.c new file mode 100644 index 0000000..6e50bd2 --- /dev/null +++ b/src/uterm_drm2d_render.c @@ -0,0 +1,223 @@ +/* + * uterm - Linux User-Space Terminal drm2d module + * + * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@googlemail.com> + * + * 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. + */ + +/* + * DRM2D Video backend rendering functions + */ + +#include <errno.h> +#include <fcntl.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> +#include <unistd.h> +#include <xf86drm.h> +#include <xf86drmMode.h> +#include "eloop.h" +#include "log.h" +#include "uterm_drm_shared_internal.h" +#include "uterm_drm2d_internal.h" +#include "uterm_video.h" +#include "uterm_video_internal.h" + +#define LOG_SUBSYSTEM "uterm_drm2d_render" + +int uterm_drm2d_display_blit(struct uterm_display *disp, + const struct uterm_video_buffer *buf, + unsigned int x, unsigned int y) +{ + unsigned int tmp; + uint8_t *dst, *src; + unsigned int width, height; + unsigned int sw, sh; + struct uterm_drm2d_rb *rb; + struct uterm_drm2d_display *d2d = uterm_drm_display_get_data(disp); + + if (!buf || buf->format != UTERM_FORMAT_XRGB32) + return -EINVAL; + + rb = &d2d->rb[d2d->current_rb ^ 1]; + sw = uterm_drm_mode_get_width(disp->current_mode); + sh = uterm_drm_mode_get_height(disp->current_mode); + + tmp = x + buf->width; + if (tmp < x || x >= sw) + return -EINVAL; + if (tmp > sw) + width = sw - x; + else + width = buf->width; + + tmp = y + buf->height; + if (tmp < y || y >= sh) + return -EINVAL; + if (tmp > sh) + height = sh - y; + else + height = buf->height; + + dst = rb->map; + dst = &dst[y * rb->stride + x * 4]; + src = buf->data; + + while (height--) { + memcpy(dst, src, 4 * width); + dst += rb->stride; + src += buf->stride; + } + + return 0; +} + +int uterm_drm2d_display_fake_blendv(struct uterm_display *disp, + const struct uterm_video_blend_req *req, + size_t num) +{ + unsigned int tmp; + uint8_t *dst, *src; + unsigned int width, height, i, j; + unsigned int sw, sh; + uint_fast32_t r, g, b, out; + struct uterm_drm2d_rb *rb; + struct uterm_drm2d_display *d2d = uterm_drm_display_get_data(disp); + + if (!req) + return -EINVAL; + + rb = &d2d->rb[d2d->current_rb ^ 1]; + sw = uterm_drm_mode_get_width(disp->current_mode); + sh = uterm_drm_mode_get_height(disp->current_mode); + + for (j = 0; j < num; ++j, ++req) { + if (!req->buf) + continue; + + if (req->buf->format != UTERM_FORMAT_GREY) + return -EOPNOTSUPP; + + tmp = req->x + req->buf->width; + if (tmp < req->x || req->x >= sw) + return -EINVAL; + if (tmp > sw) + width = sw - req->x; + else + width = req->buf->width; + + tmp = req->y + req->buf->height; + if (tmp < req->y || req->y >= sh) + return -EINVAL; + if (tmp > sh) + height = sh - req->y; + else + height = req->buf->height; + + dst = rb->map; + dst = &dst[req->y * rb->stride + req->x * 4]; + src = req->buf->data; + + while (height--) { + for (i = 0; i < width; ++i) { + /* Division by 255 (t /= 255) is done with: + * t += 0x80 + * t = (t + (t >> 8)) >> 8 + * This speeds up the computation by ~20% as the + * division is not needed. */ + if (src[i] == 0) { + r = req->br; + g = req->bg; + b = req->bb; + out = (r << 16) | (g << 8) | b; + } else if (src[i] == 255) { + r = req->fr; + g = req->fg; + b = req->fb; + out = (r << 16) | (g << 8) | b; + } else { + r = req->fr * src[i] + + req->br * (255 - src[i]); + r += 0x80; + r = (r + (r >> 8)) >> 8; + + g = req->fg * src[i] + + req->bg * (255 - src[i]); + g += 0x80; + g = (g + (g >> 8)) >> 8; + + b = req->fb * src[i] + + req->bb * (255 - src[i]); + b += 0x80; + b = (b + (b >> 8)) >> 8; + out = (r << 16) | (g << 8) | b; + } + + ((uint32_t*)dst)[i] = out; + } + dst += rb->stride; + src += req->buf->stride; + } + } + + return 0; +} + +int uterm_drm2d_display_fill(struct uterm_display *disp, + uint8_t r, uint8_t g, uint8_t b, + unsigned int x, unsigned int y, + unsigned int width, unsigned int height) +{ + unsigned int tmp, i; + uint8_t *dst; + unsigned int sw, sh; + struct uterm_drm2d_rb *rb; + struct uterm_drm2d_display *d2d = uterm_drm_display_get_data(disp); + + rb = &d2d->rb[d2d->current_rb ^ 1]; + sw = uterm_drm_mode_get_width(disp->current_mode); + sh = uterm_drm_mode_get_height(disp->current_mode); + + tmp = x + width; + if (tmp < x || x >= sw) + return -EINVAL; + if (tmp > sw) + width = sw - x; + tmp = y + height; + if (tmp < y || y >= sh) + return -EINVAL; + if (tmp > sh) + height = sh - y; + + dst = rb->map; + dst = &dst[y * rb->stride + x * 4]; + + while (height--) { + for (i = 0; i < width; ++i) + ((uint32_t*)dst)[i] = (r << 16) | (g << 8) | b; + dst += rb->stride; + } + + return 0; +} diff --git a/src/uterm_video_dumb.c b/src/uterm_drm2d_video.c index d4ebe07..021d290 100644 --- a/src/uterm_video_dumb.c +++ b/src/uterm_drm2d_video.c @@ -1,5 +1,5 @@ /* - * uterm - Linux User-Space Terminal + * uterm - Linux User-Space Terminal drm2d module * * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@googlemail.com> * @@ -40,28 +40,11 @@ #include "eloop.h" #include "log.h" #include "uterm_drm_shared_internal.h" +#include "uterm_drm2d_internal.h" #include "uterm_video.h" #include "uterm_video_internal.h" -#define LOG_SUBSYSTEM "video_dumb" - -struct uterm_drm2d_rb { - uint32_t fb; - uint32_t handle; - uint32_t stride; - uint64_t size; - void *map; -}; - -struct uterm_drm2d_display { - int current_rb; - struct uterm_drm2d_rb rb[2]; -}; - -struct uterm_drm2d_video { - int fd; - struct ev_fd *efd; -}; +#define LOG_SUBSYSTEM "video_drm2d" static int display_init(struct uterm_display *disp) { @@ -287,183 +270,7 @@ static int display_swap(struct uterm_display *disp, bool immediate) return 0; } -static int display_blit(struct uterm_display *disp, - const struct uterm_video_buffer *buf, - unsigned int x, unsigned int y) -{ - unsigned int tmp; - uint8_t *dst, *src; - unsigned int width, height; - unsigned int sw, sh; - struct uterm_drm2d_rb *rb; - struct uterm_drm2d_display *d2d = uterm_drm_display_get_data(disp); - - if (!buf || buf->format != UTERM_FORMAT_XRGB32) - return -EINVAL; - - rb = &d2d->rb[d2d->current_rb ^ 1]; - sw = uterm_drm_mode_get_width(disp->current_mode); - sh = uterm_drm_mode_get_height(disp->current_mode); - - tmp = x + buf->width; - if (tmp < x || x >= sw) - return -EINVAL; - if (tmp > sw) - width = sw - x; - else - width = buf->width; - - tmp = y + buf->height; - if (tmp < y || y >= sh) - return -EINVAL; - if (tmp > sh) - height = sh - y; - else - height = buf->height; - - dst = rb->map; - dst = &dst[y * rb->stride + x * 4]; - src = buf->data; - - while (height--) { - memcpy(dst, src, 4 * width); - dst += rb->stride; - src += buf->stride; - } - - return 0; -} - -static int display_fake_blendv(struct uterm_display *disp, - const struct uterm_video_blend_req *req, - size_t num) -{ - unsigned int tmp; - uint8_t *dst, *src; - unsigned int width, height, i, j; - unsigned int sw, sh; - uint_fast32_t r, g, b, out; - struct uterm_drm2d_rb *rb; - struct uterm_drm2d_display *d2d = uterm_drm_display_get_data(disp); - - if (!req) - return -EINVAL; - - rb = &d2d->rb[d2d->current_rb ^ 1]; - sw = uterm_drm_mode_get_width(disp->current_mode); - sh = uterm_drm_mode_get_height(disp->current_mode); - - for (j = 0; j < num; ++j, ++req) { - if (!req->buf) - continue; - - if (req->buf->format != UTERM_FORMAT_GREY) - return -EOPNOTSUPP; - - tmp = req->x + req->buf->width; - if (tmp < req->x || req->x >= sw) - return -EINVAL; - if (tmp > sw) - width = sw - req->x; - else - width = req->buf->width; - - tmp = req->y + req->buf->height; - if (tmp < req->y || req->y >= sh) - return -EINVAL; - if (tmp > sh) - height = sh - req->y; - else - height = req->buf->height; - - dst = rb->map; - dst = &dst[req->y * rb->stride + req->x * 4]; - src = req->buf->data; - - while (height--) { - for (i = 0; i < width; ++i) { - /* Division by 255 (t /= 255) is done with: - * t += 0x80 - * t = (t + (t >> 8)) >> 8 - * This speeds up the computation by ~20% as the - * division is not needed. */ - if (src[i] == 0) { - r = req->br; - g = req->bg; - b = req->bb; - out = (r << 16) | (g << 8) | b; - } else if (src[i] == 255) { - r = req->fr; - g = req->fg; - b = req->fb; - out = (r << 16) | (g << 8) | b; - } else { - r = req->fr * src[i] + - req->br * (255 - src[i]); - r += 0x80; - r = (r + (r >> 8)) >> 8; - - g = req->fg * src[i] + - req->bg * (255 - src[i]); - g += 0x80; - g = (g + (g >> 8)) >> 8; - - b = req->fb * src[i] + - req->bb * (255 - src[i]); - b += 0x80; - b = (b + (b >> 8)) >> 8; - out = (r << 16) | (g << 8) | b; - } - - ((uint32_t*)dst)[i] = out; - } - dst += rb->stride; - src += req->buf->stride; - } - } - - return 0; -} - -static int display_fill(struct uterm_display *disp, - uint8_t r, uint8_t g, uint8_t b, - unsigned int x, unsigned int y, - unsigned int width, unsigned int height) -{ - unsigned int tmp, i; - uint8_t *dst; - unsigned int sw, sh; - struct uterm_drm2d_rb *rb; - struct uterm_drm2d_display *d2d = uterm_drm_display_get_data(disp); - - rb = &d2d->rb[d2d->current_rb ^ 1]; - sw = uterm_drm_mode_get_width(disp->current_mode); - sh = uterm_drm_mode_get_height(disp->current_mode); - - tmp = x + width; - if (tmp < x || x >= sw) - return -EINVAL; - if (tmp > sw) - width = sw - x; - tmp = y + height; - if (tmp < y || y >= sh) - return -EINVAL; - if (tmp > sh) - height = sh - y; - - dst = rb->map; - dst = &dst[y * rb->stride + x * 4]; - - while (height--) { - for (i = 0; i < width; ++i) - ((uint32_t*)dst)[i] = (r << 16) | (g << 8) | b; - dst += rb->stride; - } - - return 0; -} - -static const struct display_ops dumb_display_ops = { +static const struct display_ops drm2d_display_ops = { .init = display_init, .destroy = display_destroy, .activate = display_activate, @@ -472,9 +279,9 @@ static const struct display_ops dumb_display_ops = { .use = display_use, .get_buffers = display_get_buffers, .swap = display_swap, - .blit = display_blit, - .fake_blendv = display_fake_blendv, - .fill = display_fill, + .blit = uterm_drm2d_display_blit, + .fake_blendv = uterm_drm2d_display_fake_blendv, + .fill = uterm_drm2d_display_fill, }; static void show_displays(struct uterm_video *video) @@ -539,7 +346,7 @@ static void video_destroy(struct uterm_video *video) static int video_poll(struct uterm_video *video) { - return uterm_drm_video_poll(video, &dumb_display_ops); + return uterm_drm_video_poll(video, &drm2d_display_ops); } static void video_sleep(struct uterm_video *video) @@ -552,7 +359,7 @@ static int video_wake_up(struct uterm_video *video) { int ret; - ret = uterm_drm_video_wake_up(video, &dumb_display_ops); + ret = uterm_drm_video_wake_up(video, &drm2d_display_ops); if (ret) return ret; @@ -560,7 +367,7 @@ static int video_wake_up(struct uterm_video *video) return 0; } -static const struct video_ops dumb_video_ops = { +static const struct video_ops drm2d_video_ops = { .init = video_init, .destroy = video_destroy, .segfault = NULL, /* TODO: reset all saved CRTCs on segfault */ @@ -569,8 +376,8 @@ static const struct video_ops dumb_video_ops = { .wake_up = video_wake_up, }; -static const struct uterm_video_module dumb_module = { - .ops = &dumb_video_ops, +static const struct uterm_video_module drm2d_module = { + .ops = &drm2d_video_ops, }; -const struct uterm_video_module *UTERM_VIDEO_DUMB = &dumb_module; +const struct uterm_video_module *UTERM_VIDEO_DRM2D = &drm2d_module; diff --git a/src/uterm_video.c b/src/uterm_video.c index fc440d0..259199c 100644 --- a/src/uterm_video.c +++ b/src/uterm_video.c @@ -64,7 +64,7 @@ bool uterm_video_available(const struct uterm_video_module *mod) if (!mod) return false; - if (mod == UTERM_VIDEO_DUMB || mod == UTERM_VIDEO_DRM) + if (mod == UTERM_VIDEO_DRM2D || mod == UTERM_VIDEO_DRM) return video_drm_available(); return true; diff --git a/src/uterm_video.h b/src/uterm_video.h index 607fc14..3aaff8b 100644 --- a/src/uterm_video.h +++ b/src/uterm_video.h @@ -214,10 +214,10 @@ extern const struct uterm_video_module *UTERM_VIDEO_FBDEV; #define UTERM_VIDEO_FBDEV NULL #endif -#ifdef BUILD_ENABLE_VIDEO_DUMB -extern const struct uterm_video_module *UTERM_VIDEO_DUMB; +#ifdef BUILD_ENABLE_VIDEO_DRM2D +extern const struct uterm_video_module *UTERM_VIDEO_DRM2D; #else -#define UTERM_VIDEO_DUMB NULL +#define UTERM_VIDEO_DRM2D NULL #endif #ifdef BUILD_ENABLE_VIDEO_DRM diff --git a/src/uterm_video_internal.h b/src/uterm_video_internal.h index 712a552..801316a 100644 --- a/src/uterm_video_internal.h +++ b/src/uterm_video_internal.h @@ -180,7 +180,7 @@ static inline bool video_need_hotplug(const struct uterm_video *video) .action = (act), \ }) -#if defined(BUILD_ENABLE_VIDEO_DRM) || defined(BUILD_ENABLE_VIDEO_DUMB) +#if defined(BUILD_ENABLE_VIDEO_DRM) || defined(BUILD_ENABLE_VIDEO_DRM2D) #include <xf86drm.h> |