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
;
107 if (visual
->object
.interface
!= &wl_visual_interface
) {
108 /* FIXME: Define a real exception event instead of
109 * abusing this one */
110 wl_client_post_event(client
,
111 (struct wl_object
*) drm
->display
,
112 WL_DISPLAY_INVALID_OBJECT
, 0);
113 fprintf(stderr
, "invalid visual in create_buffer\n");
119 attribs
[5] = stride
/ 4;
120 buffer
->image
= drv
->API
.CreateImageKHR(drv
, drm
->edisp
,
123 (EGLClientBuffer
) (intptr_t) name
,
126 if (buffer
->image
== NULL
) {
127 /* FIXME: Define a real exception event instead of
128 * abusing this one */
129 wl_client_post_event(client
,
130 (struct wl_object
*) drm
->display
,
131 WL_DISPLAY_INVALID_OBJECT
, 0);
132 fprintf(stderr
, "failed to create image for name %d\n", name
);
136 buffer
->buffer
.resource
.object
.id
= id
;
137 buffer
->buffer
.resource
.object
.interface
= &wl_buffer_interface
;
138 buffer
->buffer
.resource
.object
.implementation
= (void (**)(void))
141 buffer
->buffer
.resource
.destroy
= destroy_buffer
;
143 wl_client_add_resource(client
, &buffer
->buffer
.resource
);
147 drm_authenticate(struct wl_client
*client
,
148 struct wl_drm
*drm
, uint32_t id
)
150 if (drm
->authenticate(drm
->edisp
, id
) < 0)
151 wl_client_post_event(client
,
152 (struct wl_object
*) drm
->display
,
153 WL_DISPLAY_INVALID_OBJECT
, 0);
155 wl_client_post_event(client
, &drm
->object
,
156 WL_DRM_AUTHENTICATED
);
159 const static struct wl_drm_interface drm_interface
= {
165 post_drm_device(struct wl_client
*client
,
166 struct wl_object
*global
,
169 struct wl_drm
*drm
= (struct wl_drm
*) global
;
171 wl_client_post_event(client
, global
, WL_DRM_DEVICE
, drm
->device_name
);
175 wayland_drm_init(struct wl_display
*display
, _EGLDisplay
*disp
,
176 authenticate_t authenticate
, char *device_name
)
180 drm
= malloc(sizeof *drm
);
182 drm
->display
= display
;
184 drm
->authenticate
= authenticate
;
185 drm
->device_name
= strdup(device_name
);
187 drm
->object
.interface
= &wl_drm_interface
;
188 drm
->object
.implementation
= (void (**)(void)) &drm_interface
;
189 wl_display_add_object(display
, &drm
->object
);
190 wl_display_add_global(display
, &drm
->object
, post_drm_device
);
196 wayland_drm_destroy(struct wl_drm
*drm
)
198 free(drm
->device_name
);
200 /* FIXME: need wl_display_del_{object,global} */