mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	shm: Add API for renderers to register additional pixel formats
This commit is contained in:
		
							parent
							
								
									dbeb5134fa
								
							
						
					
					
						commit
						d9883a6be1
					
				
					 4 changed files with 58 additions and 13 deletions
				
			
		| 
						 | 
					@ -29,6 +29,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define WL_HIDE_DEPRECATED 1
 | 
					#define WL_HIDE_DEPRECATED 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "wayland-server.h"
 | 
				
			||||||
#include "wayland-util.h"
 | 
					#include "wayland-util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
 | 
					#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
 | 
				
			||||||
| 
						 | 
					@ -176,4 +177,7 @@ extern wl_log_func_t wl_log_handler;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void wl_log(const char *fmt, ...);
 | 
					void wl_log(const char *fmt, ...);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct wl_array *
 | 
				
			||||||
 | 
					wl_display_get_additional_shm_formats(struct wl_display *display);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -92,6 +92,8 @@ struct wl_display {
 | 
				
			||||||
	struct wl_list client_list;
 | 
						struct wl_list client_list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct wl_signal destroy_signal;
 | 
						struct wl_signal destroy_signal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct wl_array additional_shm_formats;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wl_global {
 | 
					struct wl_global {
 | 
				
			||||||
| 
						 | 
					@ -711,6 +713,8 @@ wl_display_create(void)
 | 
				
			||||||
	display->id = 1;
 | 
						display->id = 1;
 | 
				
			||||||
	display->serial = 0;
 | 
						display->serial = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						wl_array_init(&display->additional_shm_formats);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!wl_global_create(display, &wl_display_interface, 1,
 | 
						if (!wl_global_create(display, &wl_display_interface, 1,
 | 
				
			||||||
			      display, bind_display)) {
 | 
								      display, bind_display)) {
 | 
				
			||||||
		wl_event_loop_destroy(display->loop);
 | 
							wl_event_loop_destroy(display->loop);
 | 
				
			||||||
| 
						 | 
					@ -1168,3 +1172,18 @@ wl_display_remove_global(struct wl_display *display, struct wl_global *global)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	wl_global_destroy(global);
 | 
						wl_global_destroy(global);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					WL_EXPORT void
 | 
				
			||||||
 | 
					wl_display_add_shm_format(struct wl_display *display, uint32_t format)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						uint32_t *p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						p = wl_array_add(&display->additional_shm_formats, sizeof *p);
 | 
				
			||||||
 | 
						*p = format;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct wl_array *
 | 
				
			||||||
 | 
					wl_display_get_additional_shm_formats(struct wl_display *display)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return &display->additional_shm_formats;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -321,6 +321,9 @@ wl_shm_buffer_get_height(struct wl_shm_buffer *buffer);
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
wl_display_init_shm(struct wl_display *display);
 | 
					wl_display_init_shm(struct wl_display *display);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					wl_display_add_shm_format(struct wl_display *display, uint32_t format);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wl_shm_buffer *
 | 
					struct wl_shm_buffer *
 | 
				
			||||||
wl_shm_buffer_create(struct wl_client *client,
 | 
					wl_shm_buffer_create(struct wl_client *client,
 | 
				
			||||||
		     uint32_t id, int32_t width, int32_t height,
 | 
							     uint32_t id, int32_t width, int32_t height,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,6 +83,27 @@ static const struct wl_buffer_interface shm_buffer_interface = {
 | 
				
			||||||
	shm_buffer_destroy
 | 
						shm_buffer_destroy
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					format_is_supported(struct wl_client *client, uint32_t format)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct wl_display *display = wl_client_get_display(client);
 | 
				
			||||||
 | 
						struct wl_array *formats;
 | 
				
			||||||
 | 
						uint32_t *p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch (format) {
 | 
				
			||||||
 | 
						case WL_SHM_FORMAT_ARGB8888:
 | 
				
			||||||
 | 
						case WL_SHM_FORMAT_XRGB8888:
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							formats = wl_display_get_additional_shm_formats(display);
 | 
				
			||||||
 | 
							wl_array_for_each(p, formats)
 | 
				
			||||||
 | 
								if(*p == format)
 | 
				
			||||||
 | 
									return 1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
 | 
					shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
 | 
				
			||||||
		       uint32_t id, int32_t offset,
 | 
							       uint32_t id, int32_t offset,
 | 
				
			||||||
| 
						 | 
					@ -92,14 +113,10 @@ shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
 | 
				
			||||||
	struct wl_shm_pool *pool = wl_resource_get_user_data(resource);
 | 
						struct wl_shm_pool *pool = wl_resource_get_user_data(resource);
 | 
				
			||||||
	struct wl_shm_buffer *buffer;
 | 
						struct wl_shm_buffer *buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (format) {
 | 
						if (!format_is_supported(client, format)) {
 | 
				
			||||||
	case WL_SHM_FORMAT_ARGB8888:
 | 
					 | 
				
			||||||
	case WL_SHM_FORMAT_XRGB8888:
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
		wl_resource_post_error(resource,
 | 
							wl_resource_post_error(resource,
 | 
				
			||||||
				       WL_SHM_ERROR_INVALID_FORMAT,
 | 
									       WL_SHM_ERROR_INVALID_FORMAT,
 | 
				
			||||||
				       "invalid format");
 | 
									       "invalid format 0x%x", format);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -242,6 +259,9 @@ bind_shm(struct wl_client *client,
 | 
				
			||||||
	 void *data, uint32_t version, uint32_t id)
 | 
						 void *data, uint32_t version, uint32_t id)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct wl_resource *resource;
 | 
						struct wl_resource *resource;
 | 
				
			||||||
 | 
						struct wl_display *display = wl_client_get_display(client);
 | 
				
			||||||
 | 
						struct wl_array *additional_formats;
 | 
				
			||||||
 | 
						uint32_t *p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	resource = wl_resource_create(client, &wl_shm_interface, 1, id);
 | 
						resource = wl_resource_create(client, &wl_shm_interface, 1, id);
 | 
				
			||||||
	if (!resource) {
 | 
						if (!resource) {
 | 
				
			||||||
| 
						 | 
					@ -253,6 +273,10 @@ bind_shm(struct wl_client *client,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_shm_send_format(resource, WL_SHM_FORMAT_ARGB8888);
 | 
						wl_shm_send_format(resource, WL_SHM_FORMAT_ARGB8888);
 | 
				
			||||||
	wl_shm_send_format(resource, WL_SHM_FORMAT_XRGB8888);
 | 
						wl_shm_send_format(resource, WL_SHM_FORMAT_XRGB8888);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						additional_formats = wl_display_get_additional_shm_formats(display);
 | 
				
			||||||
 | 
						wl_array_for_each(p, additional_formats)
 | 
				
			||||||
 | 
							wl_shm_send_format(resource, *p);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WL_EXPORT int
 | 
					WL_EXPORT int
 | 
				
			||||||
| 
						 | 
					@ -271,13 +295,8 @@ wl_shm_buffer_create(struct wl_client *client,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct wl_shm_buffer *buffer;
 | 
						struct wl_shm_buffer *buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (format) {
 | 
						if (!format_is_supported(client, format))
 | 
				
			||||||
	case WL_SHM_FORMAT_ARGB8888:
 | 
					 | 
				
			||||||
	case WL_SHM_FORMAT_XRGB8888:
 | 
					 | 
				
			||||||
		break;
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	buffer = malloc(sizeof *buffer + stride * height);
 | 
						buffer = malloc(sizeof *buffer + stride * height);
 | 
				
			||||||
	if (buffer == NULL)
 | 
						if (buffer == NULL)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue