blob: bf25b5a33b400bef610c6f238b61434ca1986c69 [file] [log] [blame]
Marius Vladebd10e52019-11-16 19:22:48 +02001/*
2 * Copyright © 2019 Collabora, Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26#include "config.h"
27
28#include <assert.h>
29#include <stdint.h>
30#include <unistd.h>
31#include <sys/types.h>
32
33#include <libweston/libweston.h>
34#include "linux-dmabuf.h"
35#include "weston-direct-display-server-protocol.h"
36#include "libweston-internal.h"
37
38static void
39direct_display_enable(struct wl_client *client,
40 struct wl_resource *resource,
41 struct wl_resource *dmabuf_res)
42{
43 struct linux_dmabuf_buffer *dmabuf;
44
45 dmabuf = wl_resource_get_user_data(dmabuf_res);
46 assert(dmabuf);
47 dmabuf->direct_display = true;
48}
49
50static void
51direct_display_destroy(struct wl_client *client,
52 struct wl_resource *global_resource)
53{
54 wl_resource_destroy(global_resource);
55}
56
57static const struct weston_direct_display_v1_interface
58 weston_direct_display_interface_v1 = {
59 direct_display_enable,
60 direct_display_destroy,
61};
62
63static void
64bind_direct_display(struct wl_client *client, void *data,
65 uint32_t version, uint32_t id)
66{
67 struct wl_resource *resource;
68 struct weston_compositor *ec = data;
69
70 resource = wl_resource_create(client,
71 &weston_direct_display_v1_interface,
72 version, id);
73 if (!resource) {
74 wl_client_post_no_memory(client);
75 return;
76 }
77
78 wl_resource_set_implementation(resource,
79 &weston_direct_display_interface_v1,
80 ec, NULL);
81}
82
83WL_EXPORT int
84weston_direct_display_setup(struct weston_compositor *ec)
85{
86 if (!wl_global_create(ec->wl_display,
87 &weston_direct_display_v1_interface, 1,
88 ec, bind_direct_display))
89 return -1;
90
91 return 0;
92}