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