1From bdb5bbe994b91a7c64ca6103fbf2bbd590e6b8e5 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 2 Apr 2016 10:54:59 -0700
4Subject: [PATCH] implement buffer wrapping interface for dispmanx
5
6Courtesy: Zan Dobersek
7
8Signed-off-by: Khem Raj <raj.khem@gmail.com>
9---
10Upstream-Status: Pending
11
12 interface/khronos/ext/egl_wayland.c | 42 +++++++++++++++++++++++++++++
13 interface/wayland/dispmanx.xml      | 10 +++++++
14 2 files changed, 52 insertions(+)
15
16diff --git a/interface/khronos/ext/egl_wayland.c b/interface/khronos/ext/egl_wayland.c
17index 5730743..9ef89cd 100644
18--- a/interface/khronos/ext/egl_wayland.c
19+++ b/interface/khronos/ext/egl_wayland.c
20@@ -133,8 +133,50 @@ dispmanx_create_buffer(struct wl_client *client, struct wl_resource *resource,
21                                      buffer->handle);
22 }
23
24+static void
25+dispmanx_wrap_buffer(struct wl_client *client, struct wl_resource *resource,
26+                     uint32_t id, uint32_t handle, int32_t width, int32_t height,
27+                     uint32_t stride, uint32_t buffer_height, uint32_t format)
28+{
29+   struct wl_dispmanx_server_buffer *buffer;
30+   VC_IMAGE_TYPE_T vc_format = get_vc_format(format);
31+   uint32_t dummy;
32+
33+   if(vc_format == VC_IMAGE_MIN) {
34+      wl_resource_post_error(resource,
35+                             WL_DISPMANX_ERROR_INVALID_FORMAT,
36+                             "invalid format");
37+      return;
38+   }
39+
40+   buffer = calloc(1, sizeof *buffer);
41+   if (buffer == NULL) {
42+      wl_resource_post_no_memory(resource);
43+      return;
44+   }
45+
46+   buffer->handle = handle;
47+   buffer->width = width;
48+   buffer->height = height;
49+   buffer->format = format;
50+
51+   buffer->resource = wl_resource_create(resource->client, &wl_buffer_interface,
52+                                         1, id);
53+   if (!buffer->resource) {
54+      wl_resource_post_no_memory(resource);
55+      vc_dispmanx_resource_delete(buffer->handle);
56+      free(buffer);
57+      return;
58+   }
59+
60+   wl_resource_set_implementation(buffer->resource,
61+				       (void (**)(void)) &dispmanx_buffer_interface,
62+				       buffer, destroy_buffer);
63+}
64+
65 static const struct wl_dispmanx_interface dispmanx_interface = {
66    dispmanx_create_buffer,
67+   dispmanx_wrap_buffer,
68 };
69
70 static void
71diff --git a/interface/wayland/dispmanx.xml b/interface/wayland/dispmanx.xml
72index c18626d..11ed1ef 100644
73--- a/interface/wayland/dispmanx.xml
74+++ b/interface/wayland/dispmanx.xml
75@@ -118,6 +118,16 @@
76       <arg name="buffer" type="object" interface="wl_buffer"/>
77       <arg name="handle" type="uint"/>
78     </event>
79+
80+    <request name="wrap_buffer">
81+      <arg name="id" type="new_id" interface="wl_buffer"/>
82+      <arg name="handle" type="uint"/>
83+      <arg name="width" type="int"/>
84+      <arg name="height" type="int"/>
85+      <arg name="stride" type="uint"/>
86+      <arg name="buffer_height" type="uint"/>
87+      <arg name="format" type="uint"/>
88+    </request>
89   </interface>
90
91 </protocol>
92