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
40extern "C" {
41#endif
42
43struct _egl_image_attrib_int
44{
45   EGLint Value;
46   EGLBoolean IsPresent;
47};
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 */
69   struct _egl_image_attrib_int DMABufFourCC;
70   struct _egl_image_attrib_int DMABufPlaneFds[3];
71   struct _egl_image_attrib_int DMABufPlaneOffsets[3];
72   struct _egl_image_attrib_int DMABufPlanePitches[3];
73   struct _egl_image_attrib_int DMABufYuvColorSpaceHint;
74   struct _egl_image_attrib_int DMABufSampleRangeHint;
75   struct _egl_image_attrib_int DMABufChromaHorizontalSiting;
76   struct _egl_image_attrib_int DMABufChromaVerticalSiting;
77};
78
79/**
80 * "Base" class for device driver images.
81 */
82struct _egl_image
83{
84   /* An image is a display resource */
85   _EGLResource Resource;
86};
87
88
89extern EGLint
90_eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
91                         const EGLint *attrib_list);
92
93
94extern EGLBoolean
95_eglInitImage(_EGLImage *img, _EGLDisplay *dpy);
96
97
98/**
99 * Increment reference count for the image.
100 */
101static inline _EGLImage *
102_eglGetImage(_EGLImage *img)
103{
104   if (img)
105      _eglGetResource(&img->Resource);
106   return img;
107}
108
109
110/**
111 * Decrement reference count for the image.
112 */
113static inline EGLBoolean
114_eglPutImage(_EGLImage *img)
115{
116   return (img) ? _eglPutResource(&img->Resource) : EGL_FALSE;
117}
118
119
120/**
121 * Link an image to its display and return the handle of the link.
122 * The handle can be passed to client directly.
123 */
124static inline EGLImage
125_eglLinkImage(_EGLImage *img)
126{
127   _eglLinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);
128   return (EGLImage) img;
129}
130
131
132/**
133 * Unlink a linked image from its display.
134 * Accessing an unlinked image should generate EGL_BAD_PARAMETER error.
135 */
136static inline void
137_eglUnlinkImage(_EGLImage *img)
138{
139   _eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);
140}
141
142
143/**
144 * Lookup a handle to find the linked image.
145 * Return NULL if the handle has no corresponding linked image.
146 */
147static inline _EGLImage *
148_eglLookupImage(EGLImage image, _EGLDisplay *dpy)
149{
150   _EGLImage *img = (_EGLImage *) image;
151   if (!dpy || !_eglCheckResource((void *) img, _EGL_RESOURCE_IMAGE, dpy))
152      img = NULL;
153   return img;
154}
155
156
157/**
158 * Return the handle of a linked image, or EGL_NO_IMAGE_KHR.
159 */
160static inline EGLImage
161_eglGetImageHandle(_EGLImage *img)
162{
163   _EGLResource *res = (_EGLResource *) img;
164   return (res && _eglIsResourceLinked(res)) ?
165      (EGLImage) img : EGL_NO_IMAGE_KHR;
166}
167
168
169#ifdef __cplusplus
170}
171#endif
172
173#endif /* EGLIMAGE_INCLUDED */
174