eglsurface.h revision 01e04c3f
13464ebd5Sriastradh/**************************************************************************
23464ebd5Sriastradh *
3af69d88dSmrg * Copyright 2008 VMware, Inc.
43464ebd5Sriastradh * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
53464ebd5Sriastradh * Copyright 2010 LunarG, Inc.
63464ebd5Sriastradh * All Rights Reserved.
73464ebd5Sriastradh *
83464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
93464ebd5Sriastradh * copy of this software and associated documentation files (the
103464ebd5Sriastradh * "Software"), to deal in the Software without restriction, including
113464ebd5Sriastradh * without limitation the rights to use, copy, modify, merge, publish,
123464ebd5Sriastradh * distribute, sub license, and/or sell copies of the Software, and to
133464ebd5Sriastradh * permit persons to whom the Software is furnished to do so, subject to
143464ebd5Sriastradh * the following conditions:
153464ebd5Sriastradh *
163464ebd5Sriastradh * The above copyright notice and this permission notice (including the
173464ebd5Sriastradh * next paragraph) shall be included in all copies or substantial portions
183464ebd5Sriastradh * of the Software.
193464ebd5Sriastradh *
203464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
213464ebd5Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
223464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
233464ebd5Sriastradh * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243464ebd5Sriastradh * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
253464ebd5Sriastradh * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
263464ebd5Sriastradh * DEALINGS IN THE SOFTWARE.
273464ebd5Sriastradh *
283464ebd5Sriastradh **************************************************************************/
293464ebd5Sriastradh
303464ebd5Sriastradh
314a49301eSmrg#ifndef EGLSURFACE_INCLUDED
324a49301eSmrg#define EGLSURFACE_INCLUDED
334a49301eSmrg
3401e04c3fSmrg#include "c99_compat.h"
354a49301eSmrg
364a49301eSmrg#include "egltypedefs.h"
37cdc920a0Smrg#include "egldisplay.h"
384a49301eSmrg
394a49301eSmrg
4001e04c3fSmrg#ifdef __cplusplus
4101e04c3fSmrgextern "C" {
4201e04c3fSmrg#endif
4301e04c3fSmrg
4401e04c3fSmrgstruct _egl_xy
4501e04c3fSmrg{
4601e04c3fSmrg   EGLint x;
4701e04c3fSmrg   EGLint y;
4801e04c3fSmrg};
4901e04c3fSmrg
5001e04c3fSmrgstruct _egl_hdr_metadata
5101e04c3fSmrg{
5201e04c3fSmrg   struct _egl_xy display_primary_r;
5301e04c3fSmrg   struct _egl_xy display_primary_g;
5401e04c3fSmrg   struct _egl_xy display_primary_b;
5501e04c3fSmrg   struct _egl_xy white_point;
5601e04c3fSmrg   EGLint max_luminance;
5701e04c3fSmrg   EGLint min_luminance;
5801e04c3fSmrg   EGLint max_cll;
5901e04c3fSmrg   EGLint max_fall;
6001e04c3fSmrg};
6101e04c3fSmrg
624a49301eSmrg/**
634a49301eSmrg * "Base" class for device driver surfaces.
644a49301eSmrg */
654a49301eSmrgstruct _egl_surface
664a49301eSmrg{
67cdc920a0Smrg   /* A surface is a display resource */
68cdc920a0Smrg   _EGLResource Resource;
694a49301eSmrg
70cdc920a0Smrg   /* The context that is currently bound to the surface */
71cdc920a0Smrg   _EGLContext *CurrentContext;
724a49301eSmrg
734a49301eSmrg   _EGLConfig *Config;
744a49301eSmrg
754a49301eSmrg   EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */
764a49301eSmrg
7701e04c3fSmrg   /* The native surface is lost. The EGL spec requires certain functions
7801e04c3fSmrg    * to generate EGL_BAD_NATIVE_WINDOW when given this surface.
7901e04c3fSmrg    */
8001e04c3fSmrg   EGLBoolean Lost;
8101e04c3fSmrg
82cdc920a0Smrg   /* attributes set by attribute list */
83cdc920a0Smrg   EGLint Width, Height;
84cdc920a0Smrg   EGLenum TextureFormat;
85cdc920a0Smrg   EGLenum TextureTarget;
86cdc920a0Smrg   EGLBoolean MipmapTexture;
87cdc920a0Smrg   EGLBoolean LargestPbuffer;
8801e04c3fSmrg
8901e04c3fSmrg   /**
9001e04c3fSmrg    * Value of EGL_RENDER_BUFFER selected at creation.
9101e04c3fSmrg    *
9201e04c3fSmrg    * The user may select, for window surfaces, the EGL_RENDER_BUFFER through
9301e04c3fSmrg    * the attribute list of eglCreateWindowSurface(). The EGL spec allows the
9401e04c3fSmrg    * implementation to ignore request, though; hence why we maintain both
9501e04c3fSmrg    * RequestedRenderBuffer and ActiveRenderBuffer. For pbuffer and pixmap
9601e04c3fSmrg    * surfaces, the EGL spec hard-codes the EGL_RENDER_BUFFER value and the
9701e04c3fSmrg    * user must not provide it in the attribute list.
9801e04c3fSmrg    *
9901e04c3fSmrg    * Normally, the attribute is immutable and after surface creation.
10001e04c3fSmrg    * However, EGL_KHR_mutable_render_buffer allows the user to change it in
10101e04c3fSmrg    * window surfaces via eglSurfaceAttrib, in which case
10201e04c3fSmrg    * eglQuerySurface(EGL_RENDER_BUFFER) will immediately afterwards return
10301e04c3fSmrg    * the requested value but the actual render buffer used by the context
10401e04c3fSmrg    * does not change until completion of the next eglSwapBuffers call.
10501e04c3fSmrg    *
10601e04c3fSmrg    * From the EGL_KHR_mutable_render_buffer spec (v12):
10701e04c3fSmrg    *
10801e04c3fSmrg    *    Querying EGL_RENDER_BUFFER returns the buffer which client API
10901e04c3fSmrg    *    rendering is requested to use. For a window surface, this is the
11001e04c3fSmrg    *    attribute value specified when the surface was created or last set
11101e04c3fSmrg    *    via eglSurfaceAttrib.
11201e04c3fSmrg    *
11301e04c3fSmrg    * eglQueryContext(EGL_RENDER_BUFFER) ignores this.
11401e04c3fSmrg    */
11501e04c3fSmrg   EGLenum RequestedRenderBuffer;
11601e04c3fSmrg
11701e04c3fSmrg   /**
11801e04c3fSmrg    * The EGL_RENDER_BUFFER in use by the context.
11901e04c3fSmrg    *
12001e04c3fSmrg    * This is valid only when bound as the draw surface.  This may differ from
12101e04c3fSmrg    * the RequestedRenderBuffer.
12201e04c3fSmrg    *
12301e04c3fSmrg    * Refer to eglQueryContext(EGL_RENDER_BUFFER) in the EGL spec.
12401e04c3fSmrg    * eglQuerySurface(EGL_RENDER_BUFFER) ignores this.
12501e04c3fSmrg    *
12601e04c3fSmrg    * If a window surface is bound as the draw surface and has a pending,
12701e04c3fSmrg    * user-requested change to EGL_RENDER_BUFFER, then the next eglSwapBuffers
12801e04c3fSmrg    * will flush the pending change. (The flush of EGL_RENDER_BUFFER state may
12901e04c3fSmrg    * occur without the implicit glFlush induced by eglSwapBuffers). The spec
13001e04c3fSmrg    * requires that the flush occur at that time and nowhere else. During the
13101e04c3fSmrg    * state-flush, we copy RequestedRenderBuffer to ActiveRenderBuffer.
13201e04c3fSmrg    *
13301e04c3fSmrg    * From the EGL_KHR_mutable_render_buffer spec (v12):
13401e04c3fSmrg    *
13501e04c3fSmrg    *    If [...] there is a pending change to the EGL_RENDER_BUFFER
13601e04c3fSmrg    *    attribute, eglSwapBuffers performs an implicit flush operation on the
13701e04c3fSmrg    *    context and effects the attribute change.
13801e04c3fSmrg    */
13901e04c3fSmrg   EGLenum ActiveRenderBuffer;
14001e04c3fSmrg
141cdc920a0Smrg   EGLenum VGAlphaFormat;
142cdc920a0Smrg   EGLenum VGColorspace;
14301e04c3fSmrg   EGLenum GLColorspace;
144cdc920a0Smrg
145cdc920a0Smrg   /* attributes set by eglSurfaceAttrib */
146cdc920a0Smrg   EGLint MipmapLevel;
147cdc920a0Smrg   EGLenum MultisampleResolve;
148cdc920a0Smrg   EGLenum SwapBehavior;
1494a49301eSmrg
1504a49301eSmrg   EGLint HorizontalResolution, VerticalResolution;
1514a49301eSmrg   EGLint AspectRatio;
152cdc920a0Smrg
153cdc920a0Smrg   EGLint SwapInterval;
154cdc920a0Smrg
15501e04c3fSmrg   /* EGL_KHR_partial_update
15601e04c3fSmrg    * True if the damage region is already set
15701e04c3fSmrg    * between frame boundaries.
15801e04c3fSmrg    */
15901e04c3fSmrg   EGLBoolean SetDamageRegionCalled;
16001e04c3fSmrg
16101e04c3fSmrg   /* EGL_KHR_partial_update
16201e04c3fSmrg    * True if the buffer age is read by the client
16301e04c3fSmrg    * between frame boundaries.
16401e04c3fSmrg    */
16501e04c3fSmrg   EGLBoolean BufferAgeRead;
16601e04c3fSmrg
167cdc920a0Smrg   /* True if the surface is bound to an OpenGL ES texture */
168cdc920a0Smrg   EGLBoolean BoundToTexture;
169af69d88dSmrg
170af69d88dSmrg   EGLBoolean PostSubBufferSupportedNV;
17101e04c3fSmrg
17201e04c3fSmrg   struct _egl_hdr_metadata HdrMetadata;
1734a49301eSmrg};
1744a49301eSmrg
1754a49301eSmrg
17601e04c3fSmrgextern EGLBoolean
177cdc920a0Smrg_eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
1784a49301eSmrg                _EGLConfig *config, const EGLint *attrib_list);
1794a49301eSmrg
1804a49301eSmrg
1814a49301eSmrgextern EGLBoolean
1824a49301eSmrg_eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint *value);
1834a49301eSmrg
1844a49301eSmrg
1854a49301eSmrgextern EGLBoolean
1864a49301eSmrg_eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint value);
1874a49301eSmrg
1884a49301eSmrg
18901e04c3fSmrgextern EGLBoolean
1904a49301eSmrg_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer);
1914a49301eSmrg
19201e04c3fSmrgextern EGLBoolean
193af69d88dSmrg_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
194af69d88dSmrg
1954a49301eSmrg
1964a49301eSmrgextern EGLBoolean
1974a49301eSmrg_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval);
1984a49301eSmrg
19901e04c3fSmrgextern EGLBoolean
20001e04c3fSmrg_eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf);
20101e04c3fSmrg
20201e04c3fSmrgextern EGLBoolean
20301e04c3fSmrg_eglSurfaceInSharedBufferMode(_EGLSurface *surf);
2044a49301eSmrg
2053464ebd5Sriastradh/**
2063464ebd5Sriastradh * Increment reference count for the surface.
2073464ebd5Sriastradh */
20801e04c3fSmrgstatic inline _EGLSurface *
2093464ebd5Sriastradh_eglGetSurface(_EGLSurface *surf)
2103464ebd5Sriastradh{
2113464ebd5Sriastradh   if (surf)
2123464ebd5Sriastradh      _eglGetResource(&surf->Resource);
2133464ebd5Sriastradh   return surf;
2143464ebd5Sriastradh}
2154a49301eSmrg
2164a49301eSmrg
2174a49301eSmrg/**
2183464ebd5Sriastradh * Decrement reference count for the surface.
2194a49301eSmrg */
22001e04c3fSmrgstatic inline EGLBoolean
2213464ebd5Sriastradh_eglPutSurface(_EGLSurface *surf)
2224a49301eSmrg{
2233464ebd5Sriastradh   return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE;
224cdc920a0Smrg}
225cdc920a0Smrg
226cdc920a0Smrg
227cdc920a0Smrg/**
2283464ebd5Sriastradh * Link a surface to its display and return the handle of the link.
229cdc920a0Smrg * The handle can be passed to client directly.
230cdc920a0Smrg */
23101e04c3fSmrgstatic inline EGLSurface
2323464ebd5Sriastradh_eglLinkSurface(_EGLSurface *surf)
233cdc920a0Smrg{
2343464ebd5Sriastradh   _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
235cdc920a0Smrg   return (EGLSurface) surf;
236cdc920a0Smrg}
237cdc920a0Smrg
238cdc920a0Smrg
239cdc920a0Smrg/**
240cdc920a0Smrg * Unlink a linked surface from its display.
241cdc920a0Smrg * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
242cdc920a0Smrg */
24301e04c3fSmrgstatic inline void
244cdc920a0Smrg_eglUnlinkSurface(_EGLSurface *surf)
245cdc920a0Smrg{
246cdc920a0Smrg   _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
247cdc920a0Smrg}
248cdc920a0Smrg
249cdc920a0Smrg
250cdc920a0Smrg/**
251cdc920a0Smrg * Lookup a handle to find the linked surface.
252cdc920a0Smrg * Return NULL if the handle has no corresponding linked surface.
253cdc920a0Smrg */
25401e04c3fSmrgstatic inline _EGLSurface *
255cdc920a0Smrg_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
256cdc920a0Smrg{
257cdc920a0Smrg   _EGLSurface *surf = (_EGLSurface *) surface;
258cdc920a0Smrg   if (!dpy || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, dpy))
259cdc920a0Smrg      surf = NULL;
260cdc920a0Smrg   return surf;
261cdc920a0Smrg}
262cdc920a0Smrg
263cdc920a0Smrg
264cdc920a0Smrg/**
265cdc920a0Smrg * Return the handle of a linked surface, or EGL_NO_SURFACE.
266cdc920a0Smrg */
26701e04c3fSmrgstatic inline EGLSurface
268cdc920a0Smrg_eglGetSurfaceHandle(_EGLSurface *surf)
269cdc920a0Smrg{
270cdc920a0Smrg   _EGLResource *res = (_EGLResource *) surf;
271cdc920a0Smrg   return (res && _eglIsResourceLinked(res)) ?
272cdc920a0Smrg      (EGLSurface) surf : EGL_NO_SURFACE;
273cdc920a0Smrg}
274cdc920a0Smrg
275cdc920a0Smrg
27601e04c3fSmrg#ifdef __cplusplus
27701e04c3fSmrg}
27801e04c3fSmrg#endif
27901e04c3fSmrg
2804a49301eSmrg#endif /* EGLSURFACE_INCLUDED */
281