egl: handle EGL_IMAGE_EXTERNAL_FLUSH_EXT
[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 #include "c99_compat.h"
34
35 #include "egltypedefs.h"
36 #include "egldisplay.h"
37
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 struct _egl_image_attrib_int
44 {
45 EGLint Value;
46 EGLBoolean IsPresent;
47 };
48
49 #define DMA_BUF_MAX_PLANES 4
50
51 struct _egl_image_attribs
52 {
53 /* EGL_EXT_image_flush_external */
54 EGLBoolean ImageFlushExternal;
55
56 /* EGL_KHR_image_base */
57 EGLBoolean ImagePreserved;
58
59 /* EGL_KHR_gl_image */
60 EGLint GLTextureLevel;
61 EGLint GLTextureZOffset;
62
63 /* EGL_MESA_drm_image */
64 EGLint Width;
65 EGLint Height;
66 EGLint DRMBufferFormatMESA;
67 EGLint DRMBufferUseMESA;
68 EGLint DRMBufferStrideMESA;
69
70 /* EGL_WL_bind_wayland_display */
71 EGLint PlaneWL;
72
73 /* EGL_EXT_image_dma_buf_import and
74 * EGL_EXT_image_dma_buf_import_modifiers */
75 struct _egl_image_attrib_int DMABufFourCC;
76 struct _egl_image_attrib_int DMABufPlaneFds[DMA_BUF_MAX_PLANES];
77 struct _egl_image_attrib_int DMABufPlaneOffsets[DMA_BUF_MAX_PLANES];
78 struct _egl_image_attrib_int DMABufPlanePitches[DMA_BUF_MAX_PLANES];
79 struct _egl_image_attrib_int DMABufPlaneModifiersLo[DMA_BUF_MAX_PLANES];
80 struct _egl_image_attrib_int DMABufPlaneModifiersHi[DMA_BUF_MAX_PLANES];
81 struct _egl_image_attrib_int DMABufYuvColorSpaceHint;
82 struct _egl_image_attrib_int DMABufSampleRangeHint;
83 struct _egl_image_attrib_int DMABufChromaHorizontalSiting;
84 struct _egl_image_attrib_int DMABufChromaVerticalSiting;
85 };
86
87 /**
88 * "Base" class for device driver images.
89 */
90 struct _egl_image
91 {
92 /* An image is a display resource */
93 _EGLResource Resource;
94 };
95
96
97 EGLBoolean
98 _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *disp,
99 const EGLint *attrib_list);
100
101
102 static inline void
103 _eglInitImage(_EGLImage *img, _EGLDisplay *disp)
104 {
105 _eglInitResource(&img->Resource, sizeof(*img), disp);
106 }
107
108
109 /**
110 * Increment reference count for the image.
111 */
112 static inline _EGLImage *
113 _eglGetImage(_EGLImage *img)
114 {
115 if (img)
116 _eglGetResource(&img->Resource);
117 return img;
118 }
119
120
121 /**
122 * Decrement reference count for the image.
123 */
124 static inline EGLBoolean
125 _eglPutImage(_EGLImage *img)
126 {
127 return (img) ? _eglPutResource(&img->Resource) : EGL_FALSE;
128 }
129
130
131 /**
132 * Link an image to its display and return the handle of the link.
133 * The handle can be passed to client directly.
134 */
135 static inline EGLImage
136 _eglLinkImage(_EGLImage *img)
137 {
138 _eglLinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);
139 return (EGLImage) img;
140 }
141
142
143 /**
144 * Unlink a linked image from its display.
145 * Accessing an unlinked image should generate EGL_BAD_PARAMETER error.
146 */
147 static inline void
148 _eglUnlinkImage(_EGLImage *img)
149 {
150 _eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);
151 }
152
153
154 /**
155 * Lookup a handle to find the linked image.
156 * Return NULL if the handle has no corresponding linked image.
157 */
158 static inline _EGLImage *
159 _eglLookupImage(EGLImage image, _EGLDisplay *disp)
160 {
161 _EGLImage *img = (_EGLImage *) image;
162 if (!disp || !_eglCheckResource((void *) img, _EGL_RESOURCE_IMAGE, disp))
163 img = NULL;
164 return img;
165 }
166
167
168 /**
169 * Return the handle of a linked image, or EGL_NO_IMAGE_KHR.
170 */
171 static inline EGLImage
172 _eglGetImageHandle(_EGLImage *img)
173 {
174 _EGLResource *res = (_EGLResource *) img;
175 return (res && _eglIsResourceLinked(res)) ?
176 (EGLImage) img : EGL_NO_IMAGE_KHR;
177 }
178
179
180 #ifdef __cplusplus
181 }
182 #endif
183
184 #endif /* EGLIMAGE_INCLUDED */