From efacbd2b7543333547793715b0e411bd5dc8130f Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 2 Mar 2022 18:14:12 +0900 Subject: [PATCH] examples: Use pixman helper Change-Id: I22a63f7af7c9b054d2be52f1e6dbbe92291ee96d --- examples/meson.build | 20 +++++++----- examples/tinyds.c | 91 +++------------------------------------------------- 2 files changed, 17 insertions(+), 94 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 7a841e4..193b4a5 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -10,14 +10,18 @@ executable('wl-backend', install : true) executable('tinyds', - 'tinyds.c', - dependencies: [ - common_deps, - dependency('pixman-1', required: true), - dependency('libdrm', required: true), - ], - install_dir: libds_bindir, - install : true) + [ + 'tinyds.c', + 'pixman-helper.c' + ], + dependencies: [ + common_deps, + dependency('pixman-1', required: true), + dependency('libdrm', required: true), + ], + install_dir: libds_bindir, + install : true +) if features.get('tdm-backend') executable('tdm-backend', diff --git a/examples/tinyds.c b/examples/tinyds.c index 3925014..a4c1042 100644 --- a/examples/tinyds.c +++ b/examples/tinyds.c @@ -1,3 +1,5 @@ +#include "pixman-helper.h" + #include #include #include @@ -361,10 +363,6 @@ draw_server_with_damage(struct tinyds_server *server) } } -static void image_fill_color(pixman_image_t *image, - uint8_t r, uint8_t g, uint8_t b); -static pixman_image_t *image_from_buffer(struct ds_buffer *buffer, - enum ds_buffer_data_ptr_access_flag access_flag); static void view_send_frame_done(struct tinyds_view *view); static void @@ -381,14 +379,14 @@ draw_output(struct tinyds_output *output) if (!output_buffer) return; - output_image = image_from_buffer(output_buffer, + output_image = pixman_image_from_buffer(output_buffer, DS_BUFFER_DATA_PTR_ACCESS_WRITE); if (!output_image) { ds_buffer_unlock(output_buffer); return; } - image_fill_color(output_image, 80, 80, 80); + pixman_image_fill_color(output_image, 80, 80, 80); wl_list_for_each(view, &output->server->views, link) { if (!view->mapped) @@ -419,7 +417,7 @@ draw_view(struct tinyds_view *view, pixman_image_t *dst_image) if (!buffer) return; - src_image = image_from_buffer(buffer, + src_image = pixman_image_from_buffer(buffer, DS_BUFFER_DATA_PTR_ACCESS_READ); pixman_image_composite32(PIXMAN_OP_OVER, src_image, @@ -433,85 +431,6 @@ draw_view(struct tinyds_view *view, pixman_image_t *dst_image) view_send_frame_done(view); } -static pixman_color_t * -color_rgb888(pixman_color_t *tmp, uint8_t r, uint8_t g, uint8_t b) -{ - tmp->alpha = 65535; - tmp->red = (r << 8) + r; - tmp->green = (g << 8) + g; - tmp->blue = (b << 8) +b; - - return tmp; -} - -static void -image_fill_color(pixman_image_t *image, uint8_t r, uint8_t g, uint8_t b) -{ - pixman_image_t *color_image; - pixman_color_t color; - - color_rgb888(&color, r, g, b); - color_image = pixman_image_create_solid_fill(&color); - pixman_image_composite32(PIXMAN_OP_SRC, - color_image, - NULL, - image, - 0, 0, 0, 0, 0, 0, - pixman_image_get_width(image), - pixman_image_get_height(image)); - pixman_image_unref(color_image); -} - -static void -destroy_pixman_image(pixman_image_t *image TINYDS_UNUSED, void *data) -{ - struct ds_buffer *buffer = data; - ds_buffer_end_data_ptr_access(buffer); - ds_buffer_unlock(buffer); -} - -static uint32_t -convert_drm_format_to_pixman(uint32_t fmt) -{ - switch (fmt) { - case DRM_FORMAT_XRGB8888: - return PIXMAN_x8r8g8b8; - case DRM_FORMAT_ARGB8888: - return PIXMAN_a8r8g8b8; - default: - assert(0 && "not reached"); - } -} - -static pixman_image_t * -image_from_buffer(struct ds_buffer *buffer, - enum ds_buffer_data_ptr_access_flag access_flag) -{ - pixman_image_t *image; - void *data; - uint32_t format; - size_t stride; - int width, height; - - ds_buffer_get_size(buffer, &width, &height); - - if (!ds_buffer_begin_data_ptr_access(buffer, - access_flag, &data, &format, &stride)) - return NULL; - - format = convert_drm_format_to_pixman(format); - image = pixman_image_create_bits(format, width, height, data, stride); - if (!image) { - ds_buffer_end_data_ptr_access(buffer); - return NULL; - } - - pixman_image_set_destroy_function(image, - destroy_pixman_image, ds_buffer_lock(buffer)); - - return image; -} - static void view_send_frame_done(struct tinyds_view *view) { -- 2.7.4