2 * Copyright © 2012 Collabora, Ltd.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 #include <EGL/eglext.h>
29 #include <cutils/native_handle.h>
30 #include <hardware/gralloc.h>
33 #include <wayland-server.h>
34 #include "wayland-android-server-protocol.h"
35 #include "server_wlegl_private.h"
36 #include "server_wlegl_handle.h"
37 #include "server_wlegl_buffer.h"
39 static inline server_wlegl
*
40 server_wlegl_from(struct wl_resource
*resource
)
42 return reinterpret_cast<server_wlegl
*>(resource
->data
);
46 server_wlegl_create_handle(struct wl_client
*client
,
47 struct wl_resource
*resource
,
50 struct wl_array
*ints
)
52 server_wlegl
*wlegl
= server_wlegl_from(resource
);
53 server_wlegl_handle
*handle
;
56 wl_resource_post_error(resource
,
57 ANDROID_WLEGL_ERROR_BAD_VALUE
,
58 "num_fds is negative: %d", num_fds
);
62 handle
= server_wlegl_handle_create(id
);
63 wl_array_copy(&handle
->ints
, ints
);
64 handle
->num_fds
= num_fds
;
65 wl_client_add_resource(client
, &handle
->resource
);
69 server_wlegl_create_buffer(struct wl_client
*client
,
70 struct wl_resource
*resource
,
77 struct wl_resource
*hnd
)
79 server_wlegl
*wlegl
= server_wlegl_from(resource
);
80 server_wlegl_handle
*handle
= server_wlegl_handle_from(hnd
);
81 server_wlegl_buffer
*buffer
;
82 buffer_handle_t native
;
84 if (width
< 1 || height
< 1) {
85 wl_resource_post_error(resource
,
86 ANDROID_WLEGL_ERROR_BAD_VALUE
,
87 "bad width (%d) or height (%d)",
92 native
= server_wlegl_handle_to_native(handle
);
94 wl_resource_post_error(resource
,
95 ANDROID_WLEGL_ERROR_BAD_HANDLE
,
100 buffer
= server_wlegl_buffer_create(id
, width
, height
, stride
,
101 format
, usage
, native
, wlegl
);
103 native_handle_close((native_handle_t
*)native
);
104 native_handle_delete((native_handle_t
*)native
);
105 wl_resource_post_error(resource
,
106 ANDROID_WLEGL_ERROR_BAD_HANDLE
,
107 "invalid native handle");
111 wl_client_add_resource(client
, &buffer
->base
.resource
);
114 static const struct android_wlegl_interface server_wlegl_impl
= {
115 server_wlegl_create_handle
,
116 server_wlegl_create_buffer
,
120 server_wlegl_bind(struct wl_client
*client
, void *data
,
121 uint32_t version
, uint32_t id
)
123 server_wlegl
*wlegl
= reinterpret_cast<server_wlegl
*>(data
);
124 struct wl_resource
*resource
;
126 resource
= wl_client_add_object(client
, &android_wlegl_interface
,
127 &server_wlegl_impl
, id
, wlegl
);
131 server_wlegl_create(struct wl_display
*display
, gralloc_module_t
*gralloc
)
133 struct server_wlegl
*wlegl
;
136 wlegl
= new server_wlegl
;
138 wlegl
->display
= display
;
139 wlegl
->global
= wl_display_add_global(display
,
140 &android_wlegl_interface
,
141 wlegl
, server_wlegl_bind
);
142 wlegl
->gralloc
= (const gralloc_module_t
*)gralloc
;
148 server_wlegl_destroy(server_wlegl
*wlegl
)
150 /* FIXME: server_wlegl_buffer objects may exist */
152 /* no way to release wlegl->gralloc */
154 /* FIXME: remove global_ */
156 /* Better to leak than expose dtor segfaults, the server
157 * supposedly exits soon after. */
158 //LOGW("server_wlegl object leaked on UnbindWaylandDisplayWL");