native_wayland_drm_bufmgr_helper.c revision 58dc1b28d1ef4d1931c52b079d304f2e1546329d
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 15void * 16egl_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_ARGB8888: 27 pf = PIPE_FORMAT_B8G8R8A8_UNORM; 28 break; 29 case WL_DRM_FORMAT_XRGB8888: 30 pf = PIPE_FORMAT_B8G8R8X8_UNORM; 31 break; 32 default: 33 pf = PIPE_FORMAT_NONE; 34 break; 35 } 36 37 if (pf == PIPE_FORMAT_NONE) 38 return NULL; 39 40 memset(&templ, 0, sizeof(templ)); 41 templ.target = PIPE_TEXTURE_2D; 42 templ.format = pf; 43 templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; 44 templ.width0 = width; 45 templ.height0 = height; 46 templ.depth0 = 1; 47 templ.array_size = 1; 48 49 memset(&wsh, 0, sizeof(wsh)); 50 wsh.handle = name; 51 wsh.stride = stride; 52 53 return ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh); 54} 55 56void 57egl_g3d_wl_drm_helper_unreference_buffer(void *user_data, void *buffer) 58{ 59 struct pipe_resource *resource = buffer; 60 61 pipe_resource_reference(&resource, NULL); 62} 63 64struct pipe_resource * 65egl_g3d_wl_drm_common_wl_buffer_get_resource(struct native_display *ndpy, 66 struct wl_buffer *buffer) 67{ 68 return wayland_drm_buffer_get_buffer(buffer); 69} 70 71#endif 72