1f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu/**************************************************************************
2f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
3f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * Copyright 2010-2011 LunarG, Inc.
6f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * All Rights Reserved.
7f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
8f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * Permission is hereby granted, free of charge, to any person obtaining a
9f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * copy of this software and associated documentation files (the
10f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * "Software"), to deal in the Software without restriction, including
11f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * without limitation the rights to use, copy, modify, merge, publish,
12f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * distribute, sub license, and/or sell copies of the Software, and to
13f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * permit persons to whom the Software is furnished to do so, subject to
14f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * the following conditions:
15f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
16f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * The above copyright notice and this permission notice (including the
17f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * next paragraph) shall be included in all copies or substantial portions
18f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * of the Software.
19f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
20f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu * DEALINGS IN THE SOFTWARE.
27f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu *
28f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu **************************************************************************/
29f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu
30f2001df508fda599a18b3586d2775e970a3db13aChia-I Wu
31adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#ifndef EGLCONTEXT_INCLUDED
32adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#define EGLCONTEXT_INCLUDED
33adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
34adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
35adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#include "egltypedefs.h"
36ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu#include "egldisplay.h"
37adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
38adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
39adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul/**
40adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul * "Base" class for device driver contexts.
41adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul */
42adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paulstruct _egl_context
43adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul{
44ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu   /* A context is a display resource */
45ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu   _EGLResource Resource;
46adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
4707ee01365a8bddf6f50821ecd585784498a25ff0Chia-I Wu   /* The bound status of the context */
4807ee01365a8bddf6f50821ecd585784498a25ff0Chia-I Wu   _EGLThreadInfo *Binding;
49adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   _EGLSurface *DrawSurface;
50adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul   _EGLSurface *ReadSurface;
51adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
5207ee01365a8bddf6f50821ecd585784498a25ff0Chia-I Wu   _EGLConfig *Config;
53d5078b94323241a6482f54797756116b1c864327Brian Paul
54d5078b94323241a6482f54797756116b1c864327Brian Paul   EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */
553fd79dd9886f05f45f3dc94c028a38dd75b8ee1bIan Romanick   EGLint ClientMajorVersion;
563fd79dd9886f05f45f3dc94c028a38dd75b8ee1bIan Romanick   EGLint ClientMinorVersion;
5763beb3df98147f34fd0965cb0afbb97444206d0cIan Romanick   EGLint Flags;
5863beb3df98147f34fd0965cb0afbb97444206d0cIan Romanick   EGLint Profile;
5963beb3df98147f34fd0965cb0afbb97444206d0cIan Romanick   EGLint ResetNotificationStrategy;
60d845f2754bb8c0677323a5922cb90f9ea42bdb1fChia-I Wu
61d845f2754bb8c0677323a5922cb90f9ea42bdb1fChia-I Wu   /* The real render buffer when a window surface is bound */
62d845f2754bb8c0677323a5922cb90f9ea42bdb1fChia-I Wu   EGLint WindowRenderBuffer;
63adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul};
64adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
65adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
66897cb8950ae14ffe7029b1daf16113ff62ce0dfeChia-I WuPUBLIC EGLBoolean
67d69242be55091e53b0ae2cfa6282790ce1862f29Chia-I Wu_eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy,
68cca31340b5a9c0b941946753a31236c7201ca87cChia-I Wu                _EGLConfig *config, const EGLint *attrib_list);
69adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
70adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
71adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paulextern EGLBoolean
722f2cf461c57974abd89e4917945cc8ae6a67a72eChia-I Wu_eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value);
73adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
74adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul
75897cb8950ae14ffe7029b1daf16113ff62ce0dfeChia-I WuPUBLIC EGLBoolean
76d19afc57fe49816f3f3290410e0124d326577be2Chia-I Wu_eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,
77d19afc57fe49816f3f3290410e0124d326577be2Chia-I Wu                _EGLContext **old_ctx,
78d19afc57fe49816f3f3290410e0124d326577be2Chia-I Wu                _EGLSurface **old_draw, _EGLSurface **old_read);
79959481ad70b033a254f4d7d0a94dfdfab6b94c15Chia-I Wu
80959481ad70b033a254f4d7d0a94dfdfab6b94c15Chia-I Wu
8107ee01365a8bddf6f50821ecd585784498a25ff0Chia-I Wu/**
82dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu * Increment reference count for the context.
83dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu */
84dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wustatic INLINE _EGLContext *
85dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu_eglGetContext(_EGLContext *ctx)
86dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu{
87dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu   if (ctx)
88dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu      _eglGetResource(&ctx->Resource);
89dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu   return ctx;
90dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu}
91dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu
92dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu
93dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu/**
94dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu * Decrement reference count for the context.
95dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu */
96dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wustatic INLINE EGLBoolean
97dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu_eglPutContext(_EGLContext *ctx)
98dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu{
99dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu   return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE;
100dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu}
101dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu
102dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu
103dc4f845c37a8446de19036e24fd397a0aa864c02Chia-I Wu/**
1044ce33ec606292d92eff5afad6f50e1acc7109729Chia-I Wu * Link a context to its display and return the handle of the link.
105ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu * The handle can be passed to client directly.
106ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu */
107ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wustatic INLINE EGLContext
1084ce33ec606292d92eff5afad6f50e1acc7109729Chia-I Wu_eglLinkContext(_EGLContext *ctx)
1095e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu{
1104ce33ec606292d92eff5afad6f50e1acc7109729Chia-I Wu   _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
111ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu   return (EGLContext) ctx;
1125e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu}
1135e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu
1145e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu
115ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu/**
116ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu * Unlink a linked context from its display.
117ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
118ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu */
119ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wustatic INLINE void
120ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu_eglUnlinkContext(_EGLContext *ctx)
121ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu{
122ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu   _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
123ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu}
1245e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu
1255e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu
1265e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu/**
1275e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu * Lookup a handle to find the linked context.
1285e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu * Return NULL if the handle has no corresponding linked context.
1295e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu */
1305e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wustatic INLINE _EGLContext *
1315e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu_eglLookupContext(EGLContext context, _EGLDisplay *dpy)
1325e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu{
1335e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu   _EGLContext *ctx = (_EGLContext *) context;
134dbb866ab33862defc2749134805bafebf323fd11Chia-I Wu   if (!dpy || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, dpy))
1355e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu      ctx = NULL;
1365e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu   return ctx;
1375e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu}
1385e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu
1395e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu
1405e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu/**
1415e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu * Return the handle of a linked context, or EGL_NO_CONTEXT.
1425e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu */
1435e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wustatic INLINE EGLContext
1445e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu_eglGetContextHandle(_EGLContext *ctx)
1455e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu{
146ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu   _EGLResource *res = (_EGLResource *) ctx;
147ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu   return (res && _eglIsResourceLinked(res)) ?
148ecb3b3102a3022e31cf9d75ae099eddbe298517fChia-I Wu      (EGLContext) ctx : EGL_NO_CONTEXT;
1495e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu}
1505e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu
1515e66d1893234b3002d71985c05253321d4cdedc4Chia-I Wu
152adbff7e977c7c768e752a24fb643d68bdf961bfeBrian Paul#endif /* EGLCONTEXT_INCLUDED */
153