2 * Mesa 3-D graphics library
5 * Copyright (C) 2011 Benjamin Franzke <benjaminfranzke@googlemail.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 #include "util/u_memory.h"
27 #include "util/u_inlines.h"
29 #include "pipe/p_compiler.h"
30 #include "pipe/p_screen.h"
31 #include "pipe/p_context.h"
32 #include "pipe/p_state.h"
34 #include "sw/wayland/wayland_sw_winsys.h"
38 #include "native_wayland.h"
40 #include <wayland-client.h>
41 #include "wayland-egl-priv.h"
43 #include <sys/types.h>
47 struct wayland_shm_display
{
48 struct wayland_display base
;
50 const struct native_event_handler
*event_handler
;
51 struct wl_shm
*wl_shm
;
54 static INLINE
struct wayland_shm_display
*
55 wayland_shm_display(const struct native_display
*ndpy
)
57 return (struct wayland_shm_display
*) ndpy
;
62 wayland_shm_display_destroy(struct native_display
*ndpy
)
64 struct wayland_shm_display
*shmdpy
= wayland_shm_display(ndpy
);
66 if (shmdpy
->base
.config
)
67 FREE(shmdpy
->base
.config
);
68 if (shmdpy
->base
.own_dpy
)
69 wl_display_destroy(shmdpy
->base
.dpy
);
77 static struct wl_buffer
*
78 wayland_create_shm_buffer(struct wayland_display
*display
,
79 struct wayland_surface
*surface
,
80 enum native_attachment attachment
)
82 struct wayland_shm_display
*shmdpy
= (struct wayland_shm_display
*) display
;
83 struct pipe_screen
*screen
= shmdpy
->base
.base
.screen
;
84 struct pipe_resource
*resource
;
85 struct winsys_handle wsh
;
87 struct wl_visual
*visual
;
89 resource
= resource_surface_get_single_resource(surface
->rsurf
, attachment
);
90 resource_surface_get_size(surface
->rsurf
, &width
, &height
);
92 screen
->resource_get_handle(screen
, resource
, &wsh
);
94 pipe_resource_reference(&resource
, NULL
);
96 switch (surface
->type
) {
97 case WL_WINDOW_SURFACE
:
98 visual
= surface
->win
->visual
;
100 case WL_PIXMAP_SURFACE
:
101 visual
= surface
->pix
->visual
;
107 return wl_shm_create_buffer(shmdpy
->wl_shm
, wsh
.fd
,
113 wayland_shm_display_init_screen(struct native_display
*ndpy
)
115 struct wayland_shm_display
*shmdpy
= wayland_shm_display(ndpy
);
116 struct sw_winsys
*winsys
= NULL
;
119 id
= wl_display_get_global(shmdpy
->base
.dpy
, "wl_shm", 1);
121 wl_display_iterate(shmdpy
->base
.dpy
, WL_DISPLAY_READABLE
);
122 id
= wl_display_get_global(shmdpy
->base
.dpy
, "wl_shm", 1);
126 shmdpy
->wl_shm
= wl_shm_create(shmdpy
->base
.dpy
, id
, 1);
130 winsys
= wayland_create_sw_winsys(shmdpy
->base
.dpy
);
134 shmdpy
->base
.base
.screen
=
135 shmdpy
->event_handler
->new_sw_screen(&shmdpy
->base
.base
, winsys
);
137 if (!shmdpy
->base
.base
.screen
) {
138 _eglLog(_EGL_WARNING
, "failed to create shm screen");
145 struct wayland_display
*
146 wayland_create_shm_display(struct wl_display
*dpy
,
147 const struct native_event_handler
*event_handler
)
149 struct wayland_shm_display
*shmdpy
;
151 shmdpy
= CALLOC_STRUCT(wayland_shm_display
);
155 shmdpy
->event_handler
= event_handler
;
157 shmdpy
->base
.dpy
= dpy
;
158 if (!shmdpy
->base
.dpy
) {
159 wayland_shm_display_destroy(&shmdpy
->base
.base
);
163 shmdpy
->base
.base
.init_screen
= wayland_shm_display_init_screen
;
164 shmdpy
->base
.base
.destroy
= wayland_shm_display_destroy
;
165 shmdpy
->base
.create_buffer
= wayland_create_shm_buffer
;
167 return &shmdpy
->base
;
170 /* vim: set sw=3 ts=8 sts=3 expandtab: */