dmabuf: implement linux_dmabuf extension

v2 changes:
- implement the revised protocol
- add basic sanity checks when creating buffer and check for support
- add way to attach user data to the dmabuf for renderer use
- bump max number of planes to 4 to follow DRM AddFb2 ioctl
- improve errors handling
- use separate linux_dmabuf_buffer fields for the different wl_resource
  types
- as SERVER_ERROR code is no more, use a wl_display "generic" error for
  emergency-disconneting a client we fail to process
- more documentation
- change y-invert from per-plane boolean to per-buffer flag

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
diff --git a/src/compositor.c b/src/compositor.c
index 0268afc..cbef4dc 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -4672,6 +4672,34 @@
 	}
 }
 
+/** Import dmabuf buffer into current renderer
+ *
+ * \param compositor
+ * \param buffer the dmabuf buffer to import
+ * \return true on usable buffers, false otherwise
+ *
+ * This function tests that the linux_dmabuf_buffer is usable
+ * for the current renderer. Returns false on unusable buffers. Usually
+ * usability is tested by importing the dmabufs for composition.
+ *
+ * This hook is also used for detecting if the renderer supports
+ * dmabufs at all. If the renderer hook is NULL, dmabufs are not
+ * supported.
+ * */
+WL_EXPORT bool
+weston_compositor_import_dmabuf(struct weston_compositor *compositor,
+				struct linux_dmabuf_buffer *buffer)
+{
+	struct weston_renderer *renderer;
+
+	renderer = compositor->renderer;
+
+	if (renderer->import_dmabuf == NULL)
+		return false;
+
+	return renderer->import_dmabuf(compositor, buffer);
+}
+
 WL_EXPORT void
 weston_version(int *major, int *minor, int *micro)
 {