egl: definitions for EXT_image_dma_buf_import
[mesa.git] / src / egl / main / eglimage.h
1 /**************************************************************************
2 *
3 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
4 * Copyright 2010-2011 LunarG, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29
30 #ifndef EGLIMAGE_INCLUDED
31 #define EGLIMAGE_INCLUDED
32
33
34 #include "egltypedefs.h"
35 #include "egldisplay.h"
36
37 struct _egl_image_attrib_int
38 {
39 EGLint Value;
40 EGLBoolean IsPresent;
41 };
42
43 struct _egl_image_attribs
44 {
45 /* EGL_KHR_image_base */
46 EGLBoolean ImagePreserved;
47
48 /* EGL_KHR_gl_image */
49 EGLint GLTextureLevel;
50 EGLint GLTextureZOffset;
51
52 /* EGL_MESA_drm_image */
53 EGLint Width;
54 EGLint Height;
55 EGLint DRMBufferFormatMESA;
56 EGLint DRMBufferUseMESA;
57 EGLint DRMBufferStrideMESA;
58
59 /* EGL_WL_bind_wayland_display */
60 EGLint PlaneWL;
61
62 /* EGL_EXT_image_dma_buf_import */
63 struct _egl_image_attrib_int DMABufFourCC;
64 struct _egl_image_attrib_int DMABufPlaneFds[3];
65 struct _egl_image_attrib_int DMABufPlaneOffsets[3];
66 struct _egl_image_attrib_int DMABufPlanePitches[3];
67 struct _egl_image_attrib_int DMABufYuvColorSpaceHint;
68 struct _egl_image_attrib_int DMABufSampleRangeHint;
69 struct _egl_image_attrib_int DMABufChromaHorizontalSiting;
70 struct _egl_image_attrib_int DMABufChromaVerticalSiting;
71 };
72
73 /**
74 * "Base" class for device driver images.
75 */
76 struct _egl_image
77 {
78 /* An image is a display resource */
79 _EGLResource Resource;
80 };
81
82
83 PUBLIC EGLint
84 _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
85 const EGLint *attrib_list);
86
87
88 PUBLIC EGLBoolean
89 _eglInitImage(_EGLImage *img, _EGLDisplay *dpy);
90
91
92 /**
93 * Increment reference count for the image.
94 */
95 static INLINE _EGLImage *
96 _eglGetImage(_EGLImage *img)
97 {
98 if (img)
99 _eglGetResource(&img->Resource);
100 return img;
101 }
102
103
104 /**
105 * Decrement reference count for the image.
106 */
107 static INLINE EGLBoolean
108 _eglPutImage(_EGLImage *img)
109 {
110 return (img) ? _eglPutResource(&img->Resource) : EGL_FALSE;
111 }
112
113
114 /**
115 * Link an image to its display and return the handle of the link.
116 * The handle can be passed to client directly.
117 */
118 static INLINE EGLImageKHR
119 _eglLinkImage(_EGLImage *img)
120 {
121 _eglLinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);
122 return (EGLImageKHR) img;
123 }
124
125
126 /**
127 * Unlink a linked image from its display.
128 * Accessing an unlinked image should generate EGL_BAD_PARAMETER error.
129 */
130 static INLINE void
131 _eglUnlinkImage(_EGLImage *img)
132 {
133 _eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);
134 }
135
136
137 /**
138 * Lookup a handle to find the linked image.
139 * Return NULL if the handle has no corresponding linked image.
140 */
141 static INLINE _EGLImage *
142 _eglLookupImage(EGLImageKHR image, _EGLDisplay *dpy)
143 {
144 _EGLImage *img = (_EGLImage *) image;
145 if (!dpy || !_eglCheckResource((void *) img, _EGL_RESOURCE_IMAGE, dpy))
146 img = NULL;
147 return img;
148 }
149
150
151 /**
152 * Return the handle of a linked image, or EGL_NO_IMAGE_KHR.
153 */
154 static INLINE EGLImageKHR
155 _eglGetImageHandle(_EGLImage *img)
156 {
157 _EGLResource *res = (_EGLResource *) img;
158 return (res && _eglIsResourceLinked(res)) ?
159 (EGLImageKHR) img : EGL_NO_IMAGE_KHR;
160 }
161
162
163 #endif /* EGLIMAGE_INCLUDED */