st/egl: track changes to drop wl_visual in wayland
[mesa.git] / src / gallium / state_trackers / egl / common / native_wayland_drm_bufmgr_helper.c
1 #include <stdint.h>
2 #include <string.h>
3
4 #include "native.h"
5 #include "util/u_inlines.h"
6 #include "state_tracker/drm_driver.h"
7
8 #ifdef HAVE_WAYLAND_BACKEND
9
10 #include <wayland-server.h>
11 #include <wayland-drm-server-protocol.h>
12
13 #include "native_wayland_drm_bufmgr_helper.h"
14
15 void *
16 egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name,
17 int32_t width, int32_t height,
18 uint32_t stride, uint32_t format)
19 {
20 struct native_display *ndpy = user_data;
21 struct pipe_resource templ;
22 struct winsys_handle wsh;
23 enum pipe_format pf;
24
25 switch (format) {
26 case WL_DRM_FORMAT_ARGB32:
27 case WL_DRM_FORMAT_PREMULTIPLIED_ARGB32:
28 pf = PIPE_FORMAT_B8G8R8A8_UNORM;
29 break;
30 case WL_DRM_FORMAT_XRGB32:
31 pf = PIPE_FORMAT_B8G8R8X8_UNORM;
32 break;
33 default:
34 pf = PIPE_FORMAT_NONE;
35 break;
36 }
37
38 if (pf == PIPE_FORMAT_NONE)
39 return NULL;
40
41 memset(&templ, 0, sizeof(templ));
42 templ.target = PIPE_TEXTURE_2D;
43 templ.format = pf;
44 templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
45 templ.width0 = width;
46 templ.height0 = height;
47 templ.depth0 = 1;
48 templ.array_size = 1;
49
50 memset(&wsh, 0, sizeof(wsh));
51 wsh.handle = name;
52 wsh.stride = stride;
53
54 return ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh);
55 }
56
57 void
58 egl_g3d_wl_drm_helper_unreference_buffer(void *user_data, void *buffer)
59 {
60 struct pipe_resource *resource = buffer;
61
62 pipe_resource_reference(&resource, NULL);
63 }
64
65 struct pipe_resource *
66 egl_g3d_wl_drm_common_wl_buffer_get_resource(struct native_display *ndpy,
67 struct wl_buffer *buffer)
68 {
69 return wayland_drm_buffer_get_buffer(buffer);
70 }
71
72 #endif