1*61046927SAndroid Build Coastguard Worker /**************************************************************************
2*61046927SAndroid Build Coastguard Worker *
3*61046927SAndroid Build Coastguard Worker * Copyright 2008 VMware, Inc.
4*61046927SAndroid Build Coastguard Worker * Copyright 2009-2010 Chia-I Wu <[email protected]>
5*61046927SAndroid Build Coastguard Worker * Copyright 2010-2011 LunarG, Inc.
6*61046927SAndroid Build Coastguard Worker * All Rights Reserved.
7*61046927SAndroid Build Coastguard Worker *
8*61046927SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
9*61046927SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the
10*61046927SAndroid Build Coastguard Worker * "Software"), to deal in the Software without restriction, including
11*61046927SAndroid Build Coastguard Worker * without limitation the rights to use, copy, modify, merge, publish,
12*61046927SAndroid Build Coastguard Worker * distribute, sub license, and/or sell copies of the Software, and to
13*61046927SAndroid Build Coastguard Worker * permit persons to whom the Software is furnished to do so, subject to
14*61046927SAndroid Build Coastguard Worker * the following conditions:
15*61046927SAndroid Build Coastguard Worker *
16*61046927SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the
17*61046927SAndroid Build Coastguard Worker * next paragraph) shall be included in all copies or substantial portions
18*61046927SAndroid Build Coastguard Worker * of the Software.
19*61046927SAndroid Build Coastguard Worker *
20*61046927SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21*61046927SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22*61046927SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23*61046927SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24*61046927SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25*61046927SAndroid Build Coastguard Worker * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26*61046927SAndroid Build Coastguard Worker * DEALINGS IN THE SOFTWARE.
27*61046927SAndroid Build Coastguard Worker *
28*61046927SAndroid Build Coastguard Worker **************************************************************************/
29*61046927SAndroid Build Coastguard Worker
30*61046927SAndroid Build Coastguard Worker #ifndef EGLCONTEXT_INCLUDED
31*61046927SAndroid Build Coastguard Worker #define EGLCONTEXT_INCLUDED
32*61046927SAndroid Build Coastguard Worker
33*61046927SAndroid Build Coastguard Worker #include "egldisplay.h"
34*61046927SAndroid Build Coastguard Worker #include "egltypedefs.h"
35*61046927SAndroid Build Coastguard Worker
36*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
37*61046927SAndroid Build Coastguard Worker extern "C" {
38*61046927SAndroid Build Coastguard Worker #endif
39*61046927SAndroid Build Coastguard Worker
40*61046927SAndroid Build Coastguard Worker /**
41*61046927SAndroid Build Coastguard Worker * "Base" class for device driver contexts.
42*61046927SAndroid Build Coastguard Worker */
43*61046927SAndroid Build Coastguard Worker struct _egl_context {
44*61046927SAndroid Build Coastguard Worker /* A context is a display resource */
45*61046927SAndroid Build Coastguard Worker _EGLResource Resource;
46*61046927SAndroid Build Coastguard Worker
47*61046927SAndroid Build Coastguard Worker /* The bound status of the context */
48*61046927SAndroid Build Coastguard Worker _EGLThreadInfo *Binding;
49*61046927SAndroid Build Coastguard Worker _EGLSurface *DrawSurface;
50*61046927SAndroid Build Coastguard Worker _EGLSurface *ReadSurface;
51*61046927SAndroid Build Coastguard Worker
52*61046927SAndroid Build Coastguard Worker _EGLConfig *Config;
53*61046927SAndroid Build Coastguard Worker
54*61046927SAndroid Build Coastguard Worker EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */
55*61046927SAndroid Build Coastguard Worker EGLint ClientMajorVersion;
56*61046927SAndroid Build Coastguard Worker EGLint ClientMinorVersion;
57*61046927SAndroid Build Coastguard Worker EGLint Flags;
58*61046927SAndroid Build Coastguard Worker EGLint Profile;
59*61046927SAndroid Build Coastguard Worker EGLint ResetNotificationStrategy;
60*61046927SAndroid Build Coastguard Worker EGLint ContextPriority;
61*61046927SAndroid Build Coastguard Worker EGLBoolean NoError;
62*61046927SAndroid Build Coastguard Worker EGLint ReleaseBehavior;
63*61046927SAndroid Build Coastguard Worker EGLBoolean Protected; /* EGL_EXT_protected_content */
64*61046927SAndroid Build Coastguard Worker };
65*61046927SAndroid Build Coastguard Worker
66*61046927SAndroid Build Coastguard Worker extern EGLBoolean
67*61046927SAndroid Build Coastguard Worker _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, _EGLConfig *config,
68*61046927SAndroid Build Coastguard Worker _EGLContext *share_list, const EGLint *attrib_list);
69*61046927SAndroid Build Coastguard Worker
70*61046927SAndroid Build Coastguard Worker extern EGLBoolean
71*61046927SAndroid Build Coastguard Worker _eglQueryContext(_EGLContext *ctx, EGLint attribute, EGLint *value);
72*61046927SAndroid Build Coastguard Worker
73*61046927SAndroid Build Coastguard Worker extern EGLBoolean
74*61046927SAndroid Build Coastguard Worker _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,
75*61046927SAndroid Build Coastguard Worker _EGLContext **old_ctx, _EGLSurface **old_draw,
76*61046927SAndroid Build Coastguard Worker _EGLSurface **old_read);
77*61046927SAndroid Build Coastguard Worker
78*61046927SAndroid Build Coastguard Worker extern _EGLContext *
79*61046927SAndroid Build Coastguard Worker _eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t);
80*61046927SAndroid Build Coastguard Worker
81*61046927SAndroid Build Coastguard Worker /**
82*61046927SAndroid Build Coastguard Worker * Increment reference count for the context.
83*61046927SAndroid Build Coastguard Worker */
84*61046927SAndroid Build Coastguard Worker static inline _EGLContext *
_eglGetContext(_EGLContext * ctx)85*61046927SAndroid Build Coastguard Worker _eglGetContext(_EGLContext *ctx)
86*61046927SAndroid Build Coastguard Worker {
87*61046927SAndroid Build Coastguard Worker if (ctx)
88*61046927SAndroid Build Coastguard Worker _eglGetResource(&ctx->Resource);
89*61046927SAndroid Build Coastguard Worker return ctx;
90*61046927SAndroid Build Coastguard Worker }
91*61046927SAndroid Build Coastguard Worker
92*61046927SAndroid Build Coastguard Worker /**
93*61046927SAndroid Build Coastguard Worker * Decrement reference count for the context.
94*61046927SAndroid Build Coastguard Worker */
95*61046927SAndroid Build Coastguard Worker static inline EGLBoolean
_eglPutContext(_EGLContext * ctx)96*61046927SAndroid Build Coastguard Worker _eglPutContext(_EGLContext *ctx)
97*61046927SAndroid Build Coastguard Worker {
98*61046927SAndroid Build Coastguard Worker return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE;
99*61046927SAndroid Build Coastguard Worker }
100*61046927SAndroid Build Coastguard Worker
101*61046927SAndroid Build Coastguard Worker /**
102*61046927SAndroid Build Coastguard Worker * Link a context to its display and return the handle of the link.
103*61046927SAndroid Build Coastguard Worker * The handle can be passed to client directly.
104*61046927SAndroid Build Coastguard Worker */
105*61046927SAndroid Build Coastguard Worker static inline EGLContext
_eglLinkContext(_EGLContext * ctx)106*61046927SAndroid Build Coastguard Worker _eglLinkContext(_EGLContext *ctx)
107*61046927SAndroid Build Coastguard Worker {
108*61046927SAndroid Build Coastguard Worker _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
109*61046927SAndroid Build Coastguard Worker return (EGLContext)ctx;
110*61046927SAndroid Build Coastguard Worker }
111*61046927SAndroid Build Coastguard Worker
112*61046927SAndroid Build Coastguard Worker /**
113*61046927SAndroid Build Coastguard Worker * Unlink a linked context from its display.
114*61046927SAndroid Build Coastguard Worker * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
115*61046927SAndroid Build Coastguard Worker */
116*61046927SAndroid Build Coastguard Worker static inline void
_eglUnlinkContext(_EGLContext * ctx)117*61046927SAndroid Build Coastguard Worker _eglUnlinkContext(_EGLContext *ctx)
118*61046927SAndroid Build Coastguard Worker {
119*61046927SAndroid Build Coastguard Worker _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
120*61046927SAndroid Build Coastguard Worker }
121*61046927SAndroid Build Coastguard Worker
122*61046927SAndroid Build Coastguard Worker /**
123*61046927SAndroid Build Coastguard Worker * Lookup a handle to find the linked context.
124*61046927SAndroid Build Coastguard Worker * Return NULL if the handle has no corresponding linked context.
125*61046927SAndroid Build Coastguard Worker */
126*61046927SAndroid Build Coastguard Worker static inline _EGLContext *
_eglLookupContext(EGLContext context,_EGLDisplay * disp)127*61046927SAndroid Build Coastguard Worker _eglLookupContext(EGLContext context, _EGLDisplay *disp)
128*61046927SAndroid Build Coastguard Worker {
129*61046927SAndroid Build Coastguard Worker _EGLContext *ctx = (_EGLContext *)context;
130*61046927SAndroid Build Coastguard Worker if (!disp || !_eglCheckResource((void *)ctx, _EGL_RESOURCE_CONTEXT, disp))
131*61046927SAndroid Build Coastguard Worker ctx = NULL;
132*61046927SAndroid Build Coastguard Worker return ctx;
133*61046927SAndroid Build Coastguard Worker }
134*61046927SAndroid Build Coastguard Worker
135*61046927SAndroid Build Coastguard Worker /**
136*61046927SAndroid Build Coastguard Worker * Return the handle of a linked context, or EGL_NO_CONTEXT.
137*61046927SAndroid Build Coastguard Worker */
138*61046927SAndroid Build Coastguard Worker static inline EGLContext
_eglGetContextHandle(_EGLContext * ctx)139*61046927SAndroid Build Coastguard Worker _eglGetContextHandle(_EGLContext *ctx)
140*61046927SAndroid Build Coastguard Worker {
141*61046927SAndroid Build Coastguard Worker _EGLResource *res = (_EGLResource *)ctx;
142*61046927SAndroid Build Coastguard Worker return (res && _eglIsResourceLinked(res)) ? (EGLContext)ctx : EGL_NO_CONTEXT;
143*61046927SAndroid Build Coastguard Worker }
144*61046927SAndroid Build Coastguard Worker
145*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
146*61046927SAndroid Build Coastguard Worker }
147*61046927SAndroid Build Coastguard Worker #endif
148*61046927SAndroid Build Coastguard Worker
149*61046927SAndroid Build Coastguard Worker #endif /* EGLCONTEXT_INCLUDED */
150