1848b8605Smrg/**************************************************************************
2848b8605Smrg *
3848b8605Smrg * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
4848b8605Smrg * Copyright 2010-2011 LunarG, Inc.
5848b8605Smrg * All Rights Reserved.
6848b8605Smrg *
7848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
8848b8605Smrg * copy of this software and associated documentation files (the
9848b8605Smrg * "Software"), to deal in the Software without restriction, including
10848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish,
11848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to
12848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to
13848b8605Smrg * the following conditions:
14848b8605Smrg *
15848b8605Smrg * The above copyright notice and this permission notice (including the
16848b8605Smrg * next paragraph) shall be included in all copies or substantial portions
17848b8605Smrg * of the Software.
18848b8605Smrg *
19848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23848b8605Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24848b8605Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25848b8605Smrg * DEALINGS IN THE SOFTWARE.
26848b8605Smrg *
27848b8605Smrg **************************************************************************/
28848b8605Smrg
29848b8605Smrg
30848b8605Smrg#ifndef EGLIMAGE_INCLUDED
31848b8605Smrg#define EGLIMAGE_INCLUDED
32848b8605Smrg
33b8e80941Smrg#include "c99_compat.h"
34848b8605Smrg
35848b8605Smrg#include "egltypedefs.h"
36848b8605Smrg#include "egldisplay.h"
37848b8605Smrg
38b8e80941Smrg
39b8e80941Smrg#ifdef __cplusplus
40b8e80941Smrgextern "C" {
41b8e80941Smrg#endif
42b8e80941Smrg
43848b8605Smrgstruct _egl_image_attrib_int
44848b8605Smrg{
45848b8605Smrg   EGLint Value;
46848b8605Smrg   EGLBoolean IsPresent;
47848b8605Smrg};
48848b8605Smrg
49b8e80941Smrg#define DMA_BUF_MAX_PLANES 4
50b8e80941Smrg
51848b8605Smrgstruct _egl_image_attribs
52848b8605Smrg{
53848b8605Smrg   /* EGL_KHR_image_base */
54848b8605Smrg   EGLBoolean ImagePreserved;
55848b8605Smrg
56848b8605Smrg   /* EGL_KHR_gl_image */
57848b8605Smrg   EGLint GLTextureLevel;
58848b8605Smrg   EGLint GLTextureZOffset;
59848b8605Smrg
60848b8605Smrg   /* EGL_MESA_drm_image */
61848b8605Smrg   EGLint Width;
62848b8605Smrg   EGLint Height;
63848b8605Smrg   EGLint DRMBufferFormatMESA;
64848b8605Smrg   EGLint DRMBufferUseMESA;
65848b8605Smrg   EGLint DRMBufferStrideMESA;
66848b8605Smrg
67848b8605Smrg   /* EGL_WL_bind_wayland_display */
68848b8605Smrg   EGLint PlaneWL;
69848b8605Smrg
70b8e80941Smrg   /* EGL_EXT_image_dma_buf_import and
71b8e80941Smrg    * EGL_EXT_image_dma_buf_import_modifiers */
72848b8605Smrg   struct _egl_image_attrib_int DMABufFourCC;
73b8e80941Smrg   struct _egl_image_attrib_int DMABufPlaneFds[DMA_BUF_MAX_PLANES];
74b8e80941Smrg   struct _egl_image_attrib_int DMABufPlaneOffsets[DMA_BUF_MAX_PLANES];
75b8e80941Smrg   struct _egl_image_attrib_int DMABufPlanePitches[DMA_BUF_MAX_PLANES];
76b8e80941Smrg   struct _egl_image_attrib_int DMABufPlaneModifiersLo[DMA_BUF_MAX_PLANES];
77b8e80941Smrg   struct _egl_image_attrib_int DMABufPlaneModifiersHi[DMA_BUF_MAX_PLANES];
78848b8605Smrg   struct _egl_image_attrib_int DMABufYuvColorSpaceHint;
79848b8605Smrg   struct _egl_image_attrib_int DMABufSampleRangeHint;
80848b8605Smrg   struct _egl_image_attrib_int DMABufChromaHorizontalSiting;
81848b8605Smrg   struct _egl_image_attrib_int DMABufChromaVerticalSiting;
82848b8605Smrg};
83848b8605Smrg
84848b8605Smrg/**
85848b8605Smrg * "Base" class for device driver images.
86848b8605Smrg */
87848b8605Smrgstruct _egl_image
88848b8605Smrg{
89848b8605Smrg   /* An image is a display resource */
90848b8605Smrg   _EGLResource Resource;
91848b8605Smrg};
92848b8605Smrg
93848b8605Smrg
94b8e80941SmrgEGLBoolean
95b8e80941Smrg_eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *disp,
96848b8605Smrg                         const EGLint *attrib_list);
97848b8605Smrg
98848b8605Smrg
99b8e80941Smrgstatic inline void
100b8e80941Smrg_eglInitImage(_EGLImage *img, _EGLDisplay *disp)
101b8e80941Smrg{
102b8e80941Smrg   _eglInitResource(&img->Resource, sizeof(*img), disp);
103b8e80941Smrg}
104848b8605Smrg
105848b8605Smrg
106848b8605Smrg/**
107848b8605Smrg * Increment reference count for the image.
108848b8605Smrg */
109b8e80941Smrgstatic inline _EGLImage *
110848b8605Smrg_eglGetImage(_EGLImage *img)
111848b8605Smrg{
112848b8605Smrg   if (img)
113848b8605Smrg      _eglGetResource(&img->Resource);
114848b8605Smrg   return img;
115848b8605Smrg}
116848b8605Smrg
117848b8605Smrg
118848b8605Smrg/**
119848b8605Smrg * Decrement reference count for the image.
120848b8605Smrg */
121b8e80941Smrgstatic inline EGLBoolean
122848b8605Smrg_eglPutImage(_EGLImage *img)
123848b8605Smrg{
124848b8605Smrg   return (img) ? _eglPutResource(&img->Resource) : EGL_FALSE;
125848b8605Smrg}
126848b8605Smrg
127848b8605Smrg
128848b8605Smrg/**
129848b8605Smrg * Link an image to its display and return the handle of the link.
130848b8605Smrg * The handle can be passed to client directly.
131848b8605Smrg */
132b8e80941Smrgstatic inline EGLImage
133848b8605Smrg_eglLinkImage(_EGLImage *img)
134848b8605Smrg{
135848b8605Smrg   _eglLinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);
136b8e80941Smrg   return (EGLImage) img;
137848b8605Smrg}
138848b8605Smrg
139848b8605Smrg
140848b8605Smrg/**
141848b8605Smrg * Unlink a linked image from its display.
142848b8605Smrg * Accessing an unlinked image should generate EGL_BAD_PARAMETER error.
143848b8605Smrg */
144b8e80941Smrgstatic inline void
145848b8605Smrg_eglUnlinkImage(_EGLImage *img)
146848b8605Smrg{
147848b8605Smrg   _eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);
148848b8605Smrg}
149848b8605Smrg
150848b8605Smrg
151848b8605Smrg/**
152848b8605Smrg * Lookup a handle to find the linked image.
153848b8605Smrg * Return NULL if the handle has no corresponding linked image.
154848b8605Smrg */
155b8e80941Smrgstatic inline _EGLImage *
156b8e80941Smrg_eglLookupImage(EGLImage image, _EGLDisplay *disp)
157848b8605Smrg{
158848b8605Smrg   _EGLImage *img = (_EGLImage *) image;
159b8e80941Smrg   if (!disp || !_eglCheckResource((void *) img, _EGL_RESOURCE_IMAGE, disp))
160848b8605Smrg      img = NULL;
161848b8605Smrg   return img;
162848b8605Smrg}
163848b8605Smrg
164848b8605Smrg
165848b8605Smrg/**
166848b8605Smrg * Return the handle of a linked image, or EGL_NO_IMAGE_KHR.
167848b8605Smrg */
168b8e80941Smrgstatic inline EGLImage
169848b8605Smrg_eglGetImageHandle(_EGLImage *img)
170848b8605Smrg{
171848b8605Smrg   _EGLResource *res = (_EGLResource *) img;
172848b8605Smrg   return (res && _eglIsResourceLinked(res)) ?
173b8e80941Smrg      (EGLImage) img : EGL_NO_IMAGE_KHR;
174848b8605Smrg}
175848b8605Smrg
176848b8605Smrg
177b8e80941Smrg#ifdef __cplusplus
178b8e80941Smrg}
179b8e80941Smrg#endif
180b8e80941Smrg
181848b8605Smrg#endif /* EGLIMAGE_INCLUDED */
182