1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**************************************************************************
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2010 LunarG, Inc.
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All Rights Reserved.
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Software"), to deal in the Software without restriction, including
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without limitation the rights to use, copy, modify, merge, publish,
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * distribute, sub license, and/or sell copies of the Software, and to
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * permit persons to whom the Software is furnished to do so, subject to
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the following conditions:
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * next paragraph) shall be included in all copies or substantial portions
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the Software.
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * DEALINGS IN THE SOFTWARE.
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **************************************************************************/
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef EGLSURFACE_INCLUDED
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define EGLSURFACE_INCLUDED
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "egltypedefs.h"
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "egldisplay.h"
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Base" class for device driver surfaces.
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct _egl_surface
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* A surface is a display resource */
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _EGLResource Resource;
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* The context that is currently bound to the surface */
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _EGLContext *CurrentContext;
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _EGLConfig *Config;
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLint Type; /* one of EGL_WINDOW_BIT, EGL_PIXMAP_BIT or EGL_PBUFFER_BIT */
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* attributes set by attribute list */
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLint Width, Height;
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLenum TextureFormat;
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLenum TextureTarget;
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLBoolean MipmapTexture;
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLBoolean LargestPbuffer;
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLenum RenderBuffer;
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLenum VGAlphaFormat;
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLenum VGColorspace;
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* attributes set by eglSurfaceAttrib */
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLint MipmapLevel;
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLenum MultisampleResolve;
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLenum SwapBehavior;
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLint HorizontalResolution, VerticalResolution;
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLint AspectRatio;
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLint SwapInterval;
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* True if the surface is bound to an OpenGL ES texture */
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLBoolean BoundToTexture;
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   EGLBoolean PostSubBufferSupportedNV;
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgPUBLIC EGLBoolean
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_eglInitSurface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                _EGLConfig *config, const EGLint *attrib_list);
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern EGLBoolean
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint *value);
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern EGLBoolean
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_eglSurfaceAttrib(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint attribute, EGLint value);
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgPUBLIC extern EGLBoolean
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_eglBindTexImage(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint buffer);
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern EGLBoolean
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_eglSwapInterval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval);
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Increment reference count for the surface.
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE _EGLSurface *
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_eglGetSurface(_EGLSurface *surf)
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (surf)
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _eglGetResource(&surf->Resource);
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return surf;
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Decrement reference count for the surface.
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE EGLBoolean
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_eglPutSurface(_EGLSurface *surf)
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return (surf) ? _eglPutResource(&surf->Resource) : EGL_FALSE;
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Link a surface to its display and return the handle of the link.
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The handle can be passed to client directly.
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE EGLSurface
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_eglLinkSurface(_EGLSurface *surf)
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return (EGLSurface) surf;
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Unlink a linked surface from its display.
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_eglUnlinkSurface(_EGLSurface *surf)
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Lookup a handle to find the linked surface.
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Return NULL if the handle has no corresponding linked surface.
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE _EGLSurface *
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _EGLSurface *surf = (_EGLSurface *) surface;
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!dpy || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, dpy))
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      surf = NULL;
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return surf;
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Return the handle of a linked surface, or EGL_NO_SURFACE.
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE EGLSurface
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_eglGetSurfaceHandle(_EGLSurface *surf)
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   _EGLResource *res = (_EGLResource *) surf;
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return (res && _eglIsResourceLinked(res)) ?
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      (EGLSurface) surf : EGL_NO_SURFACE;
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* EGLSURFACE_INCLUDED */
174