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