1 #include "pixman-helper.h"
4 #include <drm_fourcc.h>
6 static void destroy_pixman_image(pixman_image_t *image, void *data);
7 static uint32_t convert_drm_format_to_pixman(uint32_t fmt);
10 pixman_image_from_buffer(struct ds_buffer *buffer,
11 enum ds_buffer_data_ptr_access_flag access_flag)
13 pixman_image_t *image;
19 ds_buffer_get_size(buffer, &width, &height);
21 if (!ds_buffer_begin_data_ptr_access(buffer,
22 access_flag, &data, &format, &stride))
25 format = convert_drm_format_to_pixman(format);
26 image = pixman_image_create_bits(format, width, height, data, stride);
28 ds_buffer_end_data_ptr_access(buffer);
32 pixman_image_set_destroy_function(image,
33 destroy_pixman_image, ds_buffer_lock(buffer));
39 pixman_image_fill_color(pixman_image_t *image, uint8_t r, uint8_t g, uint8_t b)
41 pixman_image_t *color_image;
44 color_rgb888(&color, r, g, b);
45 color_image = pixman_image_create_solid_fill(&color);
46 pixman_image_composite32(PIXMAN_OP_SRC,
51 pixman_image_get_width(image),
52 pixman_image_get_height(image));
53 pixman_image_unref(color_image);
57 color_rgb888(pixman_color_t *tmp, uint8_t r, uint8_t g, uint8_t b)
60 tmp->red = (r << 8) + r;
61 tmp->green = (g << 8) + g;
62 tmp->blue = (b << 8) +b;
68 convert_drm_format_to_pixman(uint32_t fmt)
71 case DRM_FORMAT_XRGB8888:
72 return PIXMAN_x8r8g8b8;
73 case DRM_FORMAT_ARGB8888:
74 return PIXMAN_a8r8g8b8;
76 assert(0 && "not reached");
81 destroy_pixman_image(pixman_image_t *image, void *data)
83 struct ds_buffer *buffer = data;
84 ds_buffer_end_data_ptr_access(buffer);
85 ds_buffer_unlock(buffer);