Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2014, 2015 Collabora, Ltd. |
| 3 | * |
Yong Bakos | 5336153 | 2017-01-23 06:17:44 -0800 | [diff] [blame] | 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: |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 11 | * |
Yong Bakos | 5336153 | 2017-01-23 06:17:44 -0800 | [diff] [blame] | 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. |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #ifndef WESTON_LINUX_DMABUF_H |
| 27 | #define WESTON_LINUX_DMABUF_H |
| 28 | |
| 29 | #include <stdint.h> |
| 30 | |
| 31 | #define MAX_DMABUF_PLANES 4 |
Varad Gautam | 41b4b8f | 2017-04-26 19:17:17 +0530 | [diff] [blame] | 32 | #ifndef DRM_FORMAT_MOD_INVALID |
| 33 | #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1) |
| 34 | #endif |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 35 | |
| 36 | struct linux_dmabuf_buffer; |
| 37 | typedef void (*dmabuf_user_data_destroy_func)( |
| 38 | struct linux_dmabuf_buffer *buffer); |
| 39 | |
Emmanuel Gil Peyrot | c399692 | 2015-11-24 19:28:24 +0000 | [diff] [blame] | 40 | struct dmabuf_attributes { |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 41 | int32_t width; |
| 42 | int32_t height; |
| 43 | uint32_t format; |
| 44 | uint32_t flags; /* enum zlinux_buffer_params_flags */ |
| 45 | int n_planes; |
Emmanuel Gil Peyrot | c399692 | 2015-11-24 19:28:24 +0000 | [diff] [blame] | 46 | int fd[MAX_DMABUF_PLANES]; |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 47 | uint32_t offset[MAX_DMABUF_PLANES]; |
| 48 | uint32_t stride[MAX_DMABUF_PLANES]; |
| 49 | uint64_t modifier[MAX_DMABUF_PLANES]; |
Emmanuel Gil Peyrot | c399692 | 2015-11-24 19:28:24 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct linux_dmabuf_buffer { |
| 53 | struct wl_resource *buffer_resource; |
| 54 | struct wl_resource *params_resource; |
| 55 | struct weston_compositor *compositor; |
| 56 | struct dmabuf_attributes attributes; |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 57 | |
| 58 | void *user_data; |
| 59 | dmabuf_user_data_destroy_func user_data_destroy_func; |
| 60 | |
| 61 | /* XXX: |
| 62 | * |
| 63 | * Add backend private data. This would be for the backend |
| 64 | * to do all additional imports it might ever use in advance. |
| 65 | * The basic principle, even if not implemented in drivers today, |
| 66 | * is that dmabufs are first attached, but the actual allocation |
| 67 | * is deferred to first use. This would allow the exporter and all |
| 68 | * attachers to agree on how to allocate. |
| 69 | * |
| 70 | * The DRM backend would use this to create drmFBs for each |
| 71 | * dmabuf_buffer, just in case at some point it would become |
| 72 | * feasible to scan it out directly. This would improve the |
| 73 | * possibilities to successfully scan out, avoiding compositing. |
| 74 | */ |
| 75 | }; |
| 76 | |
| 77 | int |
| 78 | linux_dmabuf_setup(struct weston_compositor *compositor); |
| 79 | |
| 80 | struct linux_dmabuf_buffer * |
| 81 | linux_dmabuf_buffer_get(struct wl_resource *resource); |
| 82 | |
| 83 | void |
| 84 | linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer, |
| 85 | void *data, |
| 86 | dmabuf_user_data_destroy_func func); |
| 87 | void * |
| 88 | linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer); |
| 89 | |
| 90 | void |
| 91 | linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer, |
| 92 | const char *msg); |
| 93 | |
| 94 | #endif /* WESTON_LINUX_DMABUF_H */ |