examples: Use pixman helper 25/278025/1
authorSeunghun Lee <shiin.lee@samsung.com>
Wed, 2 Mar 2022 09:14:12 +0000 (18:14 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 18 Jul 2022 05:07:52 +0000 (14:07 +0900)
Change-Id: Ia50a6369bf80c5c7cb0e5de254ca9a579d6dba9d

examples/meson.build
examples/tinyds.c

index 7a841e4..193b4a5 100644 (file)
@@ -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',
index 3925014..a4c1042 100644 (file)
@@ -1,3 +1,5 @@
+#include "pixman-helper.h"
+
 #include <assert.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -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)
 {