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.
27 #include "server_wlegl_handle.h"
28 #include "wayland-android-server-protocol.h"
31 add_fd(struct wl_client
*client
, struct wl_resource
*resource
, int32_t fd
)
33 server_wlegl_handle
*handle
= server_wlegl_handle_from(resource
);
35 if (handle
->fds
.size
>= handle
->num_fds
* sizeof(int)) {
37 wl_resource_post_error(&handle
->resource
,
38 ANDROID_WLEGL_HANDLE_ERROR_TOO_MANY_FDS
,
39 "too many file descriptors");
43 int *ptr
= (int *)wl_array_add(&handle
->fds
, sizeof(int));
48 destroy(struct wl_client
*client
, struct wl_resource
*resource
)
50 wl_resource_destroy(resource
);
53 static const struct android_wlegl_handle_interface server_handle_impl
= {
59 server_wlegl_handle_dtor(struct wl_resource
*resource
)
61 server_wlegl_handle
*handle
= server_wlegl_handle_from(resource
);
63 int *fd
= (int *)handle
->fds
.data
;
64 int *end
= (int *)((char *)handle
->fds
.data
+ handle
->fds
.size
);
66 for (; fd
< end
; ++fd
)
69 wl_array_release(&handle
->fds
);
70 wl_array_release(&handle
->ints
);
76 server_wlegl_handle_create(uint32_t id
)
78 server_wlegl_handle
*handle
= new server_wlegl_handle
;
80 memset(handle
, 0, sizeof(*handle
));
82 handle
->resource
.object
.id
= id
;
83 handle
->resource
.object
.interface
= &android_wlegl_handle_interface
;
84 handle
->resource
.object
.implementation
=
85 (void (**)(void))&server_handle_impl
;
87 handle
->resource
.destroy
= server_wlegl_handle_dtor
;
88 handle
->resource
.data
= handle
;
90 wl_array_init(&handle
->ints
);
91 wl_array_init(&handle
->fds
);
97 server_wlegl_handle_to_native(server_wlegl_handle
*handle
)
99 native_handle_t
*native
;
100 int numFds
= handle
->fds
.size
/ sizeof(int);
101 int numInts
= handle
->ints
.size
/ sizeof(int32_t);
103 if (numFds
!= handle
->num_fds
)
106 native
= native_handle_create(numFds
, numInts
);
108 memcpy(&native
->data
[0], handle
->fds
.data
, handle
->fds
.size
);
109 memcpy(&native
->data
[numFds
], handle
->ints
.data
, handle
->ints
.size
);
110 /* ownership of fds passed to native_handle_t */
111 handle
->fds
.size
= 0;
113 return (buffer_handle_t
) native
;