This repository has been archived by the owner on Apr 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathegl_util.c
79 lines (71 loc) · 2.7 KB
/
egl_util.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* egl_util.c - help utility for egl
*
* Copyright (C) 2014 Intel Corporation
* Author: Zhao, Halley<[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include "egl_util.h"
#include <libdrm/drm_fourcc.h>
#include <assert.h>
EGLImageKHR createEglImageFromDrmBuffer(EGLDisplay eglDisplay, EGLContext eglContext, uint32_t drmName, int width, int height, int pitch)
{
EGLImageKHR eglImage = EGL_NO_IMAGE_KHR;
EGLint attribs[] = {
EGL_WIDTH, width,
EGL_HEIGHT, height,
EGL_DRM_BUFFER_STRIDE_MESA, pitch/4,
EGL_DRM_BUFFER_FORMAT_MESA,
EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
EGL_DRM_BUFFER_USE_MESA,
EGL_DRM_BUFFER_USE_SHARE_MESA,
EGL_NONE
};
eglImage = eglCreateImageKHR(eglDisplay, eglContext, EGL_DRM_BUFFER_MESA,
(EGLClientBuffer)(intptr_t)drmName, attribs);
return eglImage;
}
EGLImageKHR createEglImageFromDmaBuf(EGLDisplay eglDisplay, EGLContext eglContext, uint32_t dmaBuf, int width, int height, int pitch)
{
EGLImageKHR eglImage = EGL_NO_IMAGE_KHR;
EGLint attribs[] = {
EGL_WIDTH, width,
EGL_HEIGHT, height,
EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_XRGB8888,
EGL_DMA_BUF_PLANE0_FD_EXT, dmaBuf,
EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
EGL_DMA_BUF_PLANE0_PITCH_EXT, pitch,
EGL_NONE
};
eglImage = eglCreateImageKHR(eglDisplay, EGL_NO_CONTEXT,
EGL_LINUX_DMA_BUF_EXT, NULL, attribs);
assert(eglImage != EGL_NO_IMAGE_KHR);
return eglImage;
}
EGLImageKHR createEglImageFromHandle(EGLDisplay eglDisplay, EGLContext eglContext, int isDmabuf, uint32_t handle, int width, int height, int pitch)
{
EGLImageKHR eglImage = EGL_NO_IMAGE_KHR;
if (isDmabuf)
eglImage = createEglImageFromDmaBuf(eglDisplay, eglContext, handle, width, height, pitch);
else
eglImage = createEglImageFromDrmBuffer(eglDisplay, eglContext, handle, width, height, pitch);
return eglImage;
}