eglsurface.h revision 848b8605
1848b8605Smrg/**************************************************************************
2848b8605Smrg *
3848b8605Smrg * Copyright 2008 VMware, Inc.
4848b8605Smrg * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5848b8605Smrg * Copyright 2010 LunarG, Inc.
6848b8605Smrg * All Rights Reserved.
7848b8605Smrg *
8848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
9848b8605Smrg * copy of this software and associated documentation files (the
10848b8605Smrg * "Software"), to deal in the Software without restriction, including
11848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish,
12848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to
13848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to
14848b8605Smrg * the following conditions:
15848b8605Smrg *
16848b8605Smrg * The above copyright notice and this permission notice (including the
17848b8605Smrg * next paragraph) shall be included in all copies or substantial portions
18848b8605Smrg * of the Software.
19848b8605Smrg *
20848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24848b8605Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25848b8605Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26848b8605Smrg * DEALINGS IN THE SOFTWARE.
27848b8605Smrg *
28848b8605Smrg **************************************************************************/
29848b8605Smrg
30848b8605Smrg
31848b8605Smrg#ifndef EGLSURFACE_INCLUDED
32848b8605Smrg#define EGLSURFACE_INCLUDED
33848b8605Smrg
34848b8605Smrg
35848b8605Smrg#include "egltypedefs.h"
36848b8605Smrg#include "egldisplay.h"
37848b8605Smrg
38848b8605Smrg
39848b8605Smrg/**
40848b8605Smrg * "Base" class for device driver surfaces.
41848b8605Smrg */
42848b8605Smrgstruct _egl_surface
43848b8605Smrg{
44848b8605Smrg   /* A surface is a display resource */
45848b8605Smrg   _EGLResource Resource;
46848b8605Smrg
47848b8605Smrg   /* The context that is currently bound to the surface */
48848b8605Smrg   _EGLContext *CurrentContext;
49848b8605Smrg
50848b8605Smrg   _EGLConfig *Config;
51848b8605Smrg
52848b8605Smrg   EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */
53848b8605Smrg
54848b8605Smrg   /* attributes set by attribute list */
55848b8605Smrg   EGLint Width, Height;
56848b8605Smrg   EGLenum TextureFormat;
57848b8605Smrg   EGLenum TextureTarget;
58848b8605Smrg   EGLBoolean MipmapTexture;
59848b8605Smrg   EGLBoolean LargestPbuffer;
60848b8605Smrg   EGLenum RenderBuffer;
61848b8605Smrg   EGLenum VGAlphaFormat;
62848b8605Smrg   EGLenum VGColorspace;
63848b8605Smrg
64848b8605Smrg   /* attributes set by eglSurfaceAttrib */
65848b8605Smrg   EGLint MipmapLevel;
66848b8605Smrg   EGLenum MultisampleResolve;
67848b8605Smrg   EGLenum SwapBehavior;
68848b8605Smrg
69848b8605Smrg   EGLint HorizontalResolution, VerticalResolution;
70848b8605Smrg   EGLint AspectRatio;
71848b8605Smrg
72848b8605Smrg   EGLint SwapInterval;
73848b8605Smrg
74848b8605Smrg   /* True if the surface is bound to an OpenGL ES texture */
75848b8605Smrg   EGLBoolean BoundToTexture;
76848b8605Smrg
77848b8605Smrg   EGLBoolean PostSubBufferSupportedNV;
78848b8605Smrg};
79848b8605Smrg
80848b8605Smrg
81848b8605SmrgPUBLIC EGLBoolean
82848b8605Smrg_eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
83848b8605Smrg                _EGLConfig *config, const EGLint *attrib_list);
84848b8605Smrg
85848b8605Smrg
86848b8605Smrgextern EGLBoolean
87848b8605Smrg_eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint *value);
88848b8605Smrg
89848b8605Smrg
90848b8605Smrgextern EGLBoolean
91848b8605Smrg_eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint value);
92848b8605Smrg
93848b8605Smrg
94848b8605SmrgPUBLIC extern EGLBoolean
95848b8605Smrg_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer);
96848b8605Smrg
97848b8605SmrgPUBLIC extern EGLBoolean
98848b8605Smrg_eglReleaseTexImage(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint buffer);
99848b8605Smrg
100848b8605Smrg
101848b8605Smrgextern EGLBoolean
102848b8605Smrg_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval);
103848b8605Smrg
104848b8605Smrg
105848b8605Smrg/**
106848b8605Smrg * Increment reference count for the surface.
107848b8605Smrg */
108848b8605Smrgstatic INLINE _EGLSurface *
109848b8605Smrg_eglGetSurface(_EGLSurface *surf)
110848b8605Smrg{
111848b8605Smrg   if (surf)
112848b8605Smrg      _eglGetResource(&surf->Resource);
113848b8605Smrg   return surf;
114848b8605Smrg}
115848b8605Smrg
116848b8605Smrg
117848b8605Smrg/**
118848b8605Smrg * Decrement reference count for the surface.
119848b8605Smrg */
120848b8605Smrgstatic INLINE EGLBoolean
121848b8605Smrg_eglPutSurface(_EGLSurface *surf)
122848b8605Smrg{
123848b8605Smrg   return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE;
124848b8605Smrg}
125848b8605Smrg
126848b8605Smrg
127848b8605Smrg/**
128848b8605Smrg * Link a surface to its display and return the handle of the link.
129848b8605Smrg * The handle can be passed to client directly.
130848b8605Smrg */
131848b8605Smrgstatic INLINE EGLSurface
132848b8605Smrg_eglLinkSurface(_EGLSurface *surf)
133848b8605Smrg{
134848b8605Smrg   _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
135848b8605Smrg   return (EGLSurface) surf;
136848b8605Smrg}
137848b8605Smrg
138848b8605Smrg
139848b8605Smrg/**
140848b8605Smrg * Unlink a linked surface from its display.
141848b8605Smrg * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
142848b8605Smrg */
143848b8605Smrgstatic INLINE void
144848b8605Smrg_eglUnlinkSurface(_EGLSurface *surf)
145848b8605Smrg{
146848b8605Smrg   _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
147848b8605Smrg}
148848b8605Smrg
149848b8605Smrg
150848b8605Smrg/**
151848b8605Smrg * Lookup a handle to find the linked surface.
152848b8605Smrg * Return NULL if the handle has no corresponding linked surface.
153848b8605Smrg */
154848b8605Smrgstatic INLINE _EGLSurface *
155848b8605Smrg_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
156848b8605Smrg{
157848b8605Smrg   _EGLSurface *surf = (_EGLSurface *) surface;
158848b8605Smrg   if (!dpy || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, dpy))
159848b8605Smrg      surf = NULL;
160848b8605Smrg   return surf;
161848b8605Smrg}
162848b8605Smrg
163848b8605Smrg
164848b8605Smrg/**
165848b8605Smrg * Return the handle of a linked surface, or EGL_NO_SURFACE.
166848b8605Smrg */
167848b8605Smrgstatic INLINE EGLSurface
168848b8605Smrg_eglGetSurfaceHandle(_EGLSurface *surf)
169848b8605Smrg{
170848b8605Smrg   _EGLResource *res = (_EGLResource *) surf;
171848b8605Smrg   return (res && _eglIsResourceLinked(res)) ?
172848b8605Smrg      (EGLSurface) surf : EGL_NO_SURFACE;
173848b8605Smrg}
174848b8605Smrg
175848b8605Smrg
176848b8605Smrg#endif /* EGLSURFACE_INCLUDED */
177