1 /**************************************************************************
3 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
4 * Copyright 2010-2011 LunarG, Inc.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
27 **************************************************************************/
30 #ifndef EGLIMAGE_INCLUDED
31 #define EGLIMAGE_INCLUDED
33 #include "c99_compat.h"
35 #include "egltypedefs.h"
36 #include "egldisplay.h"
43 struct _egl_image_attrib_int
49 #define DMA_BUF_MAX_PLANES 3
51 struct _egl_image_attribs
53 /* EGL_KHR_image_base */
54 EGLBoolean ImagePreserved
;
56 /* EGL_KHR_gl_image */
57 EGLint GLTextureLevel
;
58 EGLint GLTextureZOffset
;
60 /* EGL_MESA_drm_image */
63 EGLint DRMBufferFormatMESA
;
64 EGLint DRMBufferUseMESA
;
65 EGLint DRMBufferStrideMESA
;
67 /* EGL_WL_bind_wayland_display */
70 /* EGL_EXT_image_dma_buf_import */
71 struct _egl_image_attrib_int DMABufFourCC
;
72 struct _egl_image_attrib_int DMABufPlaneFds
[DMA_BUF_MAX_PLANES
];
73 struct _egl_image_attrib_int DMABufPlaneOffsets
[DMA_BUF_MAX_PLANES
];
74 struct _egl_image_attrib_int DMABufPlanePitches
[DMA_BUF_MAX_PLANES
];
75 struct _egl_image_attrib_int DMABufYuvColorSpaceHint
;
76 struct _egl_image_attrib_int DMABufSampleRangeHint
;
77 struct _egl_image_attrib_int DMABufChromaHorizontalSiting
;
78 struct _egl_image_attrib_int DMABufChromaVerticalSiting
;
82 * "Base" class for device driver images.
86 /* An image is a display resource */
87 _EGLResource Resource
;
92 _eglParseImageAttribList(_EGLImageAttribs
*attrs
, _EGLDisplay
*dpy
,
93 const EGLint
*attrib_list
);
97 _eglInitImage(_EGLImage
*img
, _EGLDisplay
*dpy
);
101 * Increment reference count for the image.
103 static inline _EGLImage
*
104 _eglGetImage(_EGLImage
*img
)
107 _eglGetResource(&img
->Resource
);
113 * Decrement reference count for the image.
115 static inline EGLBoolean
116 _eglPutImage(_EGLImage
*img
)
118 return (img
) ? _eglPutResource(&img
->Resource
) : EGL_FALSE
;
123 * Link an image to its display and return the handle of the link.
124 * The handle can be passed to client directly.
126 static inline EGLImage
127 _eglLinkImage(_EGLImage
*img
)
129 _eglLinkResource(&img
->Resource
, _EGL_RESOURCE_IMAGE
);
130 return (EGLImage
) img
;
135 * Unlink a linked image from its display.
136 * Accessing an unlinked image should generate EGL_BAD_PARAMETER error.
139 _eglUnlinkImage(_EGLImage
*img
)
141 _eglUnlinkResource(&img
->Resource
, _EGL_RESOURCE_IMAGE
);
146 * Lookup a handle to find the linked image.
147 * Return NULL if the handle has no corresponding linked image.
149 static inline _EGLImage
*
150 _eglLookupImage(EGLImage image
, _EGLDisplay
*dpy
)
152 _EGLImage
*img
= (_EGLImage
*) image
;
153 if (!dpy
|| !_eglCheckResource((void *) img
, _EGL_RESOURCE_IMAGE
, dpy
))
160 * Return the handle of a linked image, or EGL_NO_IMAGE_KHR.
162 static inline EGLImage
163 _eglGetImageHandle(_EGLImage
*img
)
165 _EGLResource
*res
= (_EGLResource
*) img
;
166 return (res
&& _eglIsResourceLinked(res
)) ?
167 (EGLImage
) img
: EGL_NO_IMAGE_KHR
;
175 #endif /* EGLIMAGE_INCLUDED */