/**************************************************************************1*2* Copyright 2009-2010 Chia-I Wu <[email protected]>3* Copyright 2010-2011 LunarG, Inc.4* All Rights Reserved.5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the8* "Software"), to deal in the Software without restriction, including9* without limitation the rights to use, copy, modify, merge, publish,10* distribute, sub license, and/or sell copies of the Software, and to11* permit persons to whom the Software is furnished to do so, subject to12* the following conditions:13*14* The above copyright notice and this permission notice (including the15* next paragraph) shall be included in all copies or substantial portions16* of the Software.17*18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR19* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,20* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL21* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER22* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING23* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER24* DEALINGS IN THE SOFTWARE.25*26**************************************************************************/272829#ifndef EGLIMAGE_INCLUDED30#define EGLIMAGE_INCLUDED3132#include "c99_compat.h"3334#include "egltypedefs.h"35#include "egldisplay.h"363738#ifdef __cplusplus39extern "C" {40#endif4142struct _egl_image_attrib_int43{44EGLint Value;45EGLBoolean IsPresent;46};4748#define DMA_BUF_MAX_PLANES 44950struct _egl_image_attribs51{52/* EGL_KHR_image_base */53EGLBoolean ImagePreserved;5455/* EGL_KHR_gl_image */56EGLint GLTextureLevel;57EGLint GLTextureZOffset;5859/* EGL_MESA_drm_image */60EGLint Width;61EGLint Height;62EGLint DRMBufferFormatMESA;63EGLint DRMBufferUseMESA;64EGLint DRMBufferStrideMESA;6566/* EGL_WL_bind_wayland_display */67EGLint PlaneWL;6869/* EGL_EXT_image_dma_buf_import and70* EGL_EXT_image_dma_buf_import_modifiers */71struct _egl_image_attrib_int DMABufFourCC;72struct _egl_image_attrib_int DMABufPlaneFds[DMA_BUF_MAX_PLANES];73struct _egl_image_attrib_int DMABufPlaneOffsets[DMA_BUF_MAX_PLANES];74struct _egl_image_attrib_int DMABufPlanePitches[DMA_BUF_MAX_PLANES];75struct _egl_image_attrib_int DMABufPlaneModifiersLo[DMA_BUF_MAX_PLANES];76struct _egl_image_attrib_int DMABufPlaneModifiersHi[DMA_BUF_MAX_PLANES];77struct _egl_image_attrib_int DMABufYuvColorSpaceHint;78struct _egl_image_attrib_int DMABufSampleRangeHint;79struct _egl_image_attrib_int DMABufChromaHorizontalSiting;80struct _egl_image_attrib_int DMABufChromaVerticalSiting;8182/* EGL_EXT_protected_surface */83EGLBoolean ProtectedContent;84};8586/**87* "Base" class for device driver images.88*/89struct _egl_image90{91/* An image is a display resource */92_EGLResource Resource;93};949596EGLBoolean97_eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *disp,98const EGLint *attrib_list);99100101static inline void102_eglInitImage(_EGLImage *img, _EGLDisplay *disp)103{104_eglInitResource(&img->Resource, sizeof(*img), disp);105}106107108/**109* Increment reference count for the image.110*/111static inline _EGLImage *112_eglGetImage(_EGLImage *img)113{114if (img)115_eglGetResource(&img->Resource);116return img;117}118119120/**121* Decrement reference count for the image.122*/123static inline EGLBoolean124_eglPutImage(_EGLImage *img)125{126return (img) ? _eglPutResource(&img->Resource) : EGL_FALSE;127}128129130/**131* Link an image to its display and return the handle of the link.132* The handle can be passed to client directly.133*/134static inline EGLImage135_eglLinkImage(_EGLImage *img)136{137_eglLinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);138return (EGLImage) img;139}140141142/**143* Unlink a linked image from its display.144* Accessing an unlinked image should generate EGL_BAD_PARAMETER error.145*/146static inline void147_eglUnlinkImage(_EGLImage *img)148{149_eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);150}151152153/**154* Lookup a handle to find the linked image.155* Return NULL if the handle has no corresponding linked image.156*/157static inline _EGLImage *158_eglLookupImage(EGLImage image, _EGLDisplay *disp)159{160_EGLImage *img = (_EGLImage *) image;161if (!disp || !_eglCheckResource((void *) img, _EGL_RESOURCE_IMAGE, disp))162img = NULL;163return img;164}165166167/**168* Return the handle of a linked image, or EGL_NO_IMAGE_KHR.169*/170static inline EGLImage171_eglGetImageHandle(_EGLImage *img)172{173_EGLResource *res = (_EGLResource *) img;174return (res && _eglIsResourceLinked(res)) ?175(EGLImage) img : EGL_NO_IMAGE_KHR;176}177178179#ifdef __cplusplus180}181#endif182183#endif /* EGLIMAGE_INCLUDED */184185186