2 * Copyright © 2011 Kristian Høgsberg
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Kristian Høgsberg <krh@bitplanet.net>
26 * Benjamin Franzke <benjaminfranzke@googlemail.com>
34 #include <wayland-server.h>
35 #include "wayland-drm.h"
36 #include "wayland-drm-server-protocol.h"
38 #include "egldisplay.h"
39 #include "egldriver.h"
41 #include "egltypedefs.h"
44 struct wl_object object
;
45 struct wl_display
*display
;
50 authenticate_t authenticate
;
54 buffer_damage(struct wl_client
*client
, struct wl_buffer
*buffer
,
55 int32_t x
, int32_t y
, int32_t width
, int32_t height
)
60 destroy_buffer(struct wl_resource
*resource
, struct wl_client
*client
)
62 struct wl_drm_buffer
*buffer
= (struct wl_drm_buffer
*) resource
;
63 _EGLDriver
*drv
= buffer
->drm
->edisp
->Driver
;
65 drv
->API
.DestroyImageKHR(drv
, buffer
->drm
->edisp
, buffer
->image
);
70 buffer_destroy(struct wl_client
*client
, struct wl_buffer
*buffer
)
72 wl_resource_destroy(&buffer
->resource
, client
);
75 const static struct wl_buffer_interface buffer_interface
= {
81 drm_create_buffer(struct wl_client
*client
, struct wl_drm
*drm
,
82 uint32_t id
, uint32_t name
, int32_t width
, int32_t height
,
83 uint32_t stride
, struct wl_visual
*visual
)
85 struct wl_drm_buffer
*buffer
;
89 EGL_DRM_BUFFER_STRIDE_MESA
, 0,
90 EGL_DRM_BUFFER_FORMAT_MESA
, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA
,
93 _EGLDriver
*drv
= drm
->edisp
->Driver
;
95 buffer
= malloc(sizeof *buffer
);
97 wl_client_post_no_memory(client
);
102 buffer
->buffer
.compositor
= NULL
;
103 buffer
->buffer
.width
= width
;
104 buffer
->buffer
.height
= height
;
105 buffer
->buffer
.visual
= visual
;
106 buffer
->buffer
.attach
= NULL
;
108 if (visual
->object
.interface
!= &wl_visual_interface
) {
109 /* FIXME: Define a real exception event instead of
110 * abusing this one */
111 wl_client_post_event(client
,
112 (struct wl_object
*) drm
->display
,
113 WL_DISPLAY_INVALID_OBJECT
, 0);
114 fprintf(stderr
, "invalid visual in create_buffer\n");
120 attribs
[5] = stride
/ 4;
121 buffer
->image
= drv
->API
.CreateImageKHR(drv
, drm
->edisp
,
124 (EGLClientBuffer
) (intptr_t) name
,
127 if (buffer
->image
== NULL
) {
128 /* FIXME: Define a real exception event instead of
129 * abusing this one */
130 wl_client_post_event(client
,
131 (struct wl_object
*) drm
->display
,
132 WL_DISPLAY_INVALID_OBJECT
, 0);
133 fprintf(stderr
, "failed to create image for name %d\n", name
);
137 buffer
->buffer
.resource
.object
.id
= id
;
138 buffer
->buffer
.resource
.object
.interface
= &wl_buffer_interface
;
139 buffer
->buffer
.resource
.object
.implementation
= (void (**)(void))
142 buffer
->buffer
.resource
.destroy
= destroy_buffer
;
144 wl_client_add_resource(client
, &buffer
->buffer
.resource
);
148 drm_authenticate(struct wl_client
*client
,
149 struct wl_drm
*drm
, uint32_t id
)
151 if (drm
->authenticate(drm
->edisp
, id
) < 0)
152 wl_client_post_event(client
,
153 (struct wl_object
*) drm
->display
,
154 WL_DISPLAY_INVALID_OBJECT
, 0);
156 wl_client_post_event(client
, &drm
->object
,
157 WL_DRM_AUTHENTICATED
);
160 const static struct wl_drm_interface drm_interface
= {
166 post_drm_device(struct wl_client
*client
,
167 struct wl_object
*global
,
170 struct wl_drm
*drm
= (struct wl_drm
*) global
;
172 wl_client_post_event(client
, global
, WL_DRM_DEVICE
, drm
->device_name
);
176 wayland_drm_init(struct wl_display
*display
, _EGLDisplay
*disp
,
177 authenticate_t authenticate
, char *device_name
)
181 drm
= malloc(sizeof *drm
);
183 drm
->display
= display
;
185 drm
->authenticate
= authenticate
;
186 drm
->device_name
= strdup(device_name
);
188 drm
->object
.interface
= &wl_drm_interface
;
189 drm
->object
.implementation
= (void (**)(void)) &drm_interface
;
190 wl_display_add_object(display
, &drm
->object
);
191 wl_display_add_global(display
, &drm
->object
, post_drm_device
);
197 wayland_drm_destroy(struct wl_drm
*drm
)
199 free(drm
->device_name
);
201 /* FIXME: need wl_display_del_{object,global} */