1 /* 2 * Copyright © 2014, 2015 Collabora, Ltd. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files (the 6 * "Software"), to deal in the Software without restriction, including 7 * without limitation the rights to use, copy, modify, merge, publish, 8 * distribute, sublicense, and/or sell copies of the Software, and to 9 * permit persons to whom the Software is furnished to do so, subject to 10 * the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the 13 * next paragraph) shall be included in all copies or substantial 14 * portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 * SOFTWARE. 24 */ 25 26 #ifndef WESTON_LINUX_DMABUF_H 27 #define WESTON_LINUX_DMABUF_H 28 29 #include <stdint.h> 30 31 #include "buffer_handle.h" 32 33 #define MAX_DMABUF_PLANES 4 34 #ifndef DRM_FORMAT_MOD_INVALID 35 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1) 36 #endif 37 #ifndef DRM_FORMAT_MOD_LINEAR 38 #define DRM_FORMAT_MOD_LINEAR 0 39 #endif 40 41 struct linux_dmabuf_buffer; 42 typedef void (*dmabuf_user_data_destroy_func)( 43 struct linux_dmabuf_buffer *buffer); 44 45 struct dmabuf_attributes { 46 int32_t width; 47 int32_t height; 48 uint32_t format; 49 uint32_t flags; /* enum zlinux_buffer_params_flags */ 50 BufferHandle *buffer_handle; 51 int n_planes; 52 int fd[MAX_DMABUF_PLANES]; 53 uint32_t offset[MAX_DMABUF_PLANES]; 54 uint32_t stride[MAX_DMABUF_PLANES]; 55 uint64_t modifier[MAX_DMABUF_PLANES]; 56 }; 57 58 struct linux_dmabuf_buffer { 59 struct wl_resource *buffer_resource; 60 struct wl_resource *params_resource; 61 struct weston_compositor *compositor; 62 struct dmabuf_attributes attributes; 63 64 void *user_data; 65 dmabuf_user_data_destroy_func user_data_destroy_func; 66 67 /* XXX: 68 * 69 * Add backend private data. This would be for the backend 70 * to do all additional imports it might ever use in advance. 71 * The basic principle, even if not implemented in drivers today, 72 * is that dmabufs are first attached, but the actual allocation 73 * is deferred to first use. This would allow the exporter and all 74 * attachers to agree on how to allocate. 75 * 76 * The DRM backend would use this to create drmFBs for each 77 * dmabuf_buffer, just in case at some point it would become 78 * feasible to scan it out directly. This would improve the 79 * possibilities to successfully scan out, avoiding compositing. 80 */ 81 82 /**< marked as scan-out capable, avoids any composition */ 83 bool direct_display; 84 }; 85 86 int 87 linux_dmabuf_setup(struct weston_compositor *compositor); 88 89 int 90 weston_direct_display_setup(struct weston_compositor *compositor); 91 92 struct linux_dmabuf_buffer * 93 linux_dmabuf_buffer_get(struct wl_resource *resource); 94 95 void 96 linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer, 97 void *data, 98 dmabuf_user_data_destroy_func func); 99 void * 100 linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer); 101 102 void 103 linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer, 104 const char *msg); 105 106 #endif /* WESTON_LINUX_DMABUF_H */ 107