aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index d768f58..28c66e0 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
+#include <assert.h>
#include <xf86drmMode.h>
#include <xf86drm.h>
@@ -518,3 +519,95 @@ int create_directory_recursive(char *path) {
}
return 0;
}
+
+void setup_dma_buf_attrs(intptr_t *img_attr, uint32_t format, uint32_t width, uint32_t height, const int *fds, const uint32_t *offsets, const uint32_t *pitches, const uint64_t *modifiers, int num_planes, bool use_modifier) {
+ size_t img_attr_index = 0;
+
+ img_attr[img_attr_index++] = EGL_LINUX_DRM_FOURCC_EXT;
+ img_attr[img_attr_index++] = format;
+
+ img_attr[img_attr_index++] = EGL_WIDTH;
+ img_attr[img_attr_index++] = width;
+
+ img_attr[img_attr_index++] = EGL_HEIGHT;
+ img_attr[img_attr_index++] = height;
+
+ if(num_planes >= 1) {
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE0_FD_EXT;
+ img_attr[img_attr_index++] = fds[0];
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
+ img_attr[img_attr_index++] = offsets[0];
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
+ img_attr[img_attr_index++] = pitches[0];
+
+ if(use_modifier) {
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT;
+ img_attr[img_attr_index++] = modifiers[0] & 0xFFFFFFFFULL;
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
+ img_attr[img_attr_index++] = modifiers[0] >> 32ULL;
+ }
+ }
+
+ if(num_planes >= 2) {
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE1_FD_EXT;
+ img_attr[img_attr_index++] = fds[1];
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE1_OFFSET_EXT;
+ img_attr[img_attr_index++] = offsets[1];
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE1_PITCH_EXT;
+ img_attr[img_attr_index++] = pitches[1];
+
+ if(use_modifier) {
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT;
+ img_attr[img_attr_index++] = modifiers[1] & 0xFFFFFFFFULL;
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT;
+ img_attr[img_attr_index++] = modifiers[1] >> 32ULL;
+ }
+ }
+
+ if(num_planes >= 3) {
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE2_FD_EXT;
+ img_attr[img_attr_index++] = fds[2];
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE2_OFFSET_EXT;
+ img_attr[img_attr_index++] = offsets[2];
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE2_PITCH_EXT;
+ img_attr[img_attr_index++] = pitches[2];
+
+ if(use_modifier) {
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT;
+ img_attr[img_attr_index++] = modifiers[2] & 0xFFFFFFFFULL;
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT;
+ img_attr[img_attr_index++] = modifiers[2] >> 32ULL;
+ }
+ }
+
+ if(num_planes >= 4) {
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE3_FD_EXT;
+ img_attr[img_attr_index++] = fds[3];
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE3_OFFSET_EXT;
+ img_attr[img_attr_index++] = offsets[3];
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE3_PITCH_EXT;
+ img_attr[img_attr_index++] = pitches[3];
+
+ if(use_modifier) {
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT;
+ img_attr[img_attr_index++] = modifiers[3] & 0xFFFFFFFFULL;
+
+ img_attr[img_attr_index++] = EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT;
+ img_attr[img_attr_index++] = modifiers[3] >> 32ULL;
+ }
+ }
+
+ img_attr[img_attr_index++] = EGL_NONE;
+ assert(img_attr_index <= 44);
+}