commit 2982c6d24ebd97cda8f0770e312b6fd6381e5b9e
Author: Kristian Høgsberg <krh@bitplanet.net>
Date:   Fri Dec 16 11:16:34 2011 -0500

    protocol: Move duplicated pixel format definitions to wl_buffer
    
    The mechanism by which a buffer factory interface (ie, an interface that
    creates buffers, such as wl_shm or wl_drm) negotiate pixel contents used to
    be private to the interface.  As such, wl_shm had its own pixel format
    and so did wl_drm.  The idea was to avoid imposing certain pixel formats or
    enumerations on such interfaces, indeed a buffer interface might not even
    use pixels (wl_svg, create a buffer from an svg streamed through an fd).
    
    Now, pixel buffer are the common case and there are only so many pixel formats,
    so it makes sense to define a common namespace for pixel formats, so
    pixel based buffer factory interface don't have to reinvent that wheel.
    The big shared enumeration doesn't imply that a buffer factory interface
    have to support all formats, it just provides a namespace to pick from.
    The wl_shm and wl_drm interfaces uses a format event, sent at bind time, to
    indicate the specific pixel formats they support.
    
    This patch also adds a format field to struct wl_buffer, which lets the
    compositor know the format of the buffer.  The compositor needs to know
    whether the buffer has an alpha channel, and in case of shm or scanout
    the exact pixel format.

diff --git a/protocol/wayland.xml b/protocol/wayland.xml
index b80f25e..c422d68 100644
--- a/protocol/wayland.xml
+++ b/protocol/wayland.xml
@@ -107,18 +107,13 @@
       <entry name="invalid_fd" value="2"/>
     </enum>
 
-    <enum name="format">
-      <entry name="argb32" value="0"/>
-      <entry name="premultiplied_argb32" value="1"/>
-      <entry name="xrgb32" value="2"/>
-    </enum>
-
     <!-- Transfer a shm buffer to the server.  The allocated buffer
          would include at least stride * height bytes starting at the
          beginning of fd.  The file descriptor is transferred over the
          socket using AF_UNIX magical features. width, height, stride
          and format describe the respective properties of the pixel
-         data contained in the buffer. -->
+         data contained in the buffer.  The format argument is one of
+         the wl_buffer format codes advertised in the format event. -->
     <request name="create_buffer">
       <arg name="id" type="new_id" interface="wl_buffer"/>
       <arg name="fd" type="fd"/>
@@ -138,6 +133,76 @@
        It has a size, visual and contents, but not a location on the
        screen. -->
   <interface name="wl_buffer" version="1">
+    <enum name="format">
+      <!-- These are the fourcc values defined by drm_fourcc.h (from
+           the Linux kernel).  They define a common namespace for
+           pixel formats and are used by the wl_shm interface.  The
+           wl_shm interface will announce which of the formats it
+           actually supports throught the wl_shm.format event.  Other
+           buffer factory interfaces (wl_drm, for example) can use the
+           format enumeration in a similar way or use their own
+           convention for communicating the type of buffer contents. -->
+      <entry name="other" value="0"/>
+      <entry name="c8" value="538982467"/>
+      <entry name="rgb332" value="943867730"/>
+      <entry name="bgr233" value="944916290"/>
+      <entry name="xrgb4444" value="842093144"/>
+      <entry name="xbgr4444" value="842089048"/>
+      <entry name="rgbx4444" value="842094674"/>
+      <entry name="bgrx4444" value="842094658"/>
+      <entry name="argb4444" value="842093121"/>
+      <entry name="abgr4444" value="842089025"/>
+      <entry name="rgba4444" value="842088786"/>
+      <entry name="bgra4444" value="842088770"/>
+      <entry name="xrgb1555" value="892424792"/>
+      <entry name="xbgr1555" value="892420696"/>
+      <entry name="rgbx5551" value="892426322"/>
+      <entry name="bgrx5551" value="892426306"/>
+      <entry name="argb1555" value="892424769"/>
+      <entry name="abgr1555" value="892420673"/>
+      <entry name="rgba5551" value="892420434"/>
+      <entry name="bgra5551" value="892420418"/>
+      <entry name="rgb565" value="909199186"/>
+      <entry name="bgr565" value="909199170"/>
+      <entry name="rgb888" value="875710290"/>
+      <entry name="bgr888" value="875710274"/>
+      <entry name="xrgb8888" value="875713112"/>
+      <entry name="xbgr8888" value="875709016"/>
+      <entry name="rgbx8888" value="875714642"/>
+      <entry name="bgrx8888" value="875714626"/>
+      <entry name="argb8888" value="875713089"/>
+      <entry name="abgr8888" value="875708993"/>
+      <entry name="rgba8888" value="875708754"/>
+      <entry name="bgra8888" value="875708738"/>
+      <entry name="xrgb2101010" value="808669784"/>
+      <entry name="xbgr2101010" value="808665688"/>
+      <entry name="rgbx1010102" value="808671314"/>
+      <entry name="bgrx1010102" value="808671298"/>
+      <entry name="argb2101010" value="808669761"/>
+      <entry name="abgr2101010" value="808665665"/>
+      <entry name="rgba1010102" value="808665426"/>
+      <entry name="bgra1010102" value="808665410"/>
+      <entry name="yuyv" value="1448695129"/>
+      <entry name="yvyu" value="1431918169"/>
+      <entry name="uyvy" value="1498831189"/>
+      <entry name="vyuy" value="1498765654"/>
+      <entry name="ayuv" value="1448433985"/>
+      <entry name="nv12" value="842094158"/>
+      <entry name="nv21" value="825382478"/>
+      <entry name="nv16" value="909203022"/>
+      <entry name="nv61" value="825644622"/>
+      <entry name="yuv410" value="961959257"/>
+      <entry name="yvu410" value="961893977"/>
+      <entry name="yuv411" value="825316697"/>
+      <entry name="yvu411" value="825316953"/>
+      <entry name="yuv420" value="842093913"/>
+      <entry name="yvu420" value="842094169"/>
+      <entry name="yuv422" value="909202777"/>
+      <entry name="yvu422" value="909203033"/>
+      <entry name="yuv444" value="875713881"/>
+      <entry name="yvu444" value="875714137"/>
+    </enum>
+
     <!-- Notify the server that the specified area of the buffers
          contents have changed.  To describe a more complicated area
          of damage, break down the region into rectangles and use this
diff --git a/src/wayland-server.h b/src/wayland-server.h
index 8019c56..18ea551 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -131,6 +131,7 @@ struct wl_shm_callbacks {
 struct wl_buffer {
 	struct wl_resource resource;
 	int32_t width, height;
+	uint32_t format;
 	uint32_t busy_count;
 	void *user_data;
 };
@@ -253,9 +254,6 @@ wl_shm_buffer_get_data(struct wl_buffer *buffer);
 int32_t
 wl_shm_buffer_get_stride(struct wl_buffer *buffer);
 
-uint32_t
-wl_shm_buffer_get_format(struct wl_buffer *buffer);
-
 struct wl_buffer *
 wl_shm_buffer_create(struct wl_shm *shm, int width, int height,
 		     int stride, uint32_t visual, void *data);
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index c6020ae..0e4dc0a 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -41,7 +41,6 @@ struct wl_shm_buffer {
 	struct wl_buffer buffer;
 	struct wl_shm *shm;
 	int32_t stride;
-	uint32_t format;
 	void *data;
 };
 
@@ -92,7 +91,7 @@ wl_shm_buffer_init(struct wl_shm *shm, struct wl_client *client, uint32_t id,
 
 	buffer->buffer.width = width;
 	buffer->buffer.height = height;
-	buffer->format = format;
+	buffer->buffer.format = format;
 	buffer->stride = stride;
 	buffer->data = data;
 
@@ -123,9 +122,8 @@ shm_create_buffer(struct wl_client *client, struct wl_resource *resource,
 
 
 	switch (format) {
-	case WL_SHM_FORMAT_ARGB32:
-	case WL_SHM_FORMAT_PREMULTIPLIED_ARGB32:
-	case WL_SHM_FORMAT_XRGB32:
+	case WL_BUFFER_FORMAT_ARGB8888:
+	case WL_BUFFER_FORMAT_XRGB8888:
 		break;
 	default:
 		wl_resource_post_error(resource,
@@ -179,10 +177,10 @@ bind_shm(struct wl_client *client,
 	resource = wl_client_add_object(client, &wl_shm_interface,
 					&shm_interface, id, data);
 
-	wl_resource_post_event(resource, WL_SHM_FORMAT, WL_SHM_FORMAT_ARGB32);
 	wl_resource_post_event(resource, WL_SHM_FORMAT,
-			       WL_SHM_FORMAT_PREMULTIPLIED_ARGB32);
-	wl_resource_post_event(resource, WL_SHM_FORMAT, WL_SHM_FORMAT_XRGB32);
+			       WL_BUFFER_FORMAT_ARGB8888);
+	wl_resource_post_event(resource, WL_SHM_FORMAT,
+			       WL_BUFFER_FORMAT_XRGB8888);
 }
 
 WL_EXPORT struct wl_shm *
@@ -243,11 +241,3 @@ wl_shm_buffer_get_data(struct wl_buffer *buffer_base)
 
 	return buffer->data;
 }
-
-WL_EXPORT uint32_t
-wl_shm_buffer_get_format(struct wl_buffer *buffer_base)
-{
-	struct wl_shm_buffer *buffer = (struct wl_shm_buffer *) buffer_base;
-
-	return buffer->format;
-}
