Chia-I Wu | f2001df | 2011-07-02 17:57:30 +0900 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 3 | * Copyright 2008 VMware, Inc. |
Chia-I Wu | f2001df | 2011-07-02 17:57:30 +0900 | [diff] [blame] | 4 | * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com> |
| 5 | * Copyright 2010-2011 LunarG, Inc. |
| 6 | * All Rights Reserved. |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 9 | * copy of this software and associated documentation files (the |
| 10 | * "Software"), to deal in the Software without restriction, including |
| 11 | * without limitation the rights to use, copy, modify, merge, publish, |
| 12 | * distribute, sub license, and/or sell copies of the Software, and to |
| 13 | * permit persons to whom the Software is furnished to do so, subject to |
| 14 | * the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice (including the |
| 17 | * next paragraph) shall be included in all copies or substantial portions |
| 18 | * of the Software. |
| 19 | * |
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 23 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 26 | * DEALINGS IN THE SOFTWARE. |
| 27 | * |
| 28 | **************************************************************************/ |
| 29 | |
| 30 | |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 31 | #ifndef EGLCONTEXT_INCLUDED |
| 32 | #define EGLCONTEXT_INCLUDED |
| 33 | |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 34 | #include "c99_compat.h" |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 35 | |
| 36 | #include "egltypedefs.h" |
Chia-I Wu | ecb3b31 | 2010-01-24 20:32:34 +0800 | [diff] [blame] | 37 | #include "egldisplay.h" |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 38 | |
| 39 | |
Alexander von Gluck IV | 8362068 | 2015-05-13 17:13:37 -0500 | [diff] [blame] | 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 44 | /** |
| 45 | * "Base" class for device driver contexts. |
| 46 | */ |
| 47 | struct _egl_context |
| 48 | { |
Chia-I Wu | ecb3b31 | 2010-01-24 20:32:34 +0800 | [diff] [blame] | 49 | /* A context is a display resource */ |
| 50 | _EGLResource Resource; |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 51 | |
Chia-I Wu | 07ee013 | 2009-08-03 11:34:37 -0600 | [diff] [blame] | 52 | /* The bound status of the context */ |
| 53 | _EGLThreadInfo *Binding; |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 54 | _EGLSurface *DrawSurface; |
| 55 | _EGLSurface *ReadSurface; |
| 56 | |
Chia-I Wu | 07ee013 | 2009-08-03 11:34:37 -0600 | [diff] [blame] | 57 | _EGLConfig *Config; |
Brian Paul | d5078b9 | 2008-05-30 13:45:40 -0600 | [diff] [blame] | 58 | |
| 59 | EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */ |
Ian Romanick | 3fd79dd | 2012-07-18 15:59:15 -0700 | [diff] [blame] | 60 | EGLint ClientMajorVersion; |
| 61 | EGLint ClientMinorVersion; |
Ian Romanick | 63beb3d | 2012-07-19 11:10:15 -0700 | [diff] [blame] | 62 | EGLint Flags; |
| 63 | EGLint Profile; |
| 64 | EGLint ResetNotificationStrategy; |
Chris Wilson | 95ecf3d | 2016-10-27 19:34:46 +0100 | [diff] [blame] | 65 | EGLint ContextPriority; |
Grigori Goronzy | 4909519 | 2017-06-29 02:44:03 +0200 | [diff] [blame] | 66 | EGLBoolean NoError; |
Adam Jackson | c0be3aa | 2016-09-22 03:47:55 -0400 | [diff] [blame] | 67 | EGLint ReleaseBehavior; |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | |
Emil Velikov | dd438ae | 2015-02-28 17:20:01 +0000 | [diff] [blame] | 71 | extern EGLBoolean |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 72 | _eglInitContext(_EGLContext *ctx, _EGLDisplay *disp, |
Chia-I Wu | cca3134 | 2009-07-17 11:53:03 -0600 | [diff] [blame] | 73 | _EGLConfig *config, const EGLint *attrib_list); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 74 | |
| 75 | |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 76 | extern EGLBoolean |
Eric Engestrom | 9c6fa94 | 2020-07-31 01:38:41 +0200 | [diff] [blame^] | 77 | _eglQueryContext(const _EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx, EGLint attribute, EGLint *value); |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 78 | |
| 79 | |
Emil Velikov | dd438ae | 2015-02-28 17:20:01 +0000 | [diff] [blame] | 80 | extern EGLBoolean |
Chia-I Wu | d19afc5 | 2010-10-23 12:52:26 +0800 | [diff] [blame] | 81 | _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read, |
| 82 | _EGLContext **old_ctx, |
| 83 | _EGLSurface **old_draw, _EGLSurface **old_read); |
Chia-I Wu | 959481a | 2010-01-27 23:31:20 +0800 | [diff] [blame] | 84 | |
Eric Anholt | 3b7b6ad | 2012-12-27 17:39:37 -0800 | [diff] [blame] | 85 | extern _EGLContext * |
| 86 | _eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t); |
| 87 | |
Chia-I Wu | 959481a | 2010-01-27 23:31:20 +0800 | [diff] [blame] | 88 | |
Chia-I Wu | 07ee013 | 2009-08-03 11:34:37 -0600 | [diff] [blame] | 89 | /** |
Chia-I Wu | dc4f845 | 2010-10-23 11:59:03 +0800 | [diff] [blame] | 90 | * Increment reference count for the context. |
| 91 | */ |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 92 | static inline _EGLContext * |
Chia-I Wu | dc4f845 | 2010-10-23 11:59:03 +0800 | [diff] [blame] | 93 | _eglGetContext(_EGLContext *ctx) |
| 94 | { |
| 95 | if (ctx) |
| 96 | _eglGetResource(&ctx->Resource); |
| 97 | return ctx; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | /** |
| 102 | * Decrement reference count for the context. |
| 103 | */ |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 104 | static inline EGLBoolean |
Chia-I Wu | dc4f845 | 2010-10-23 11:59:03 +0800 | [diff] [blame] | 105 | _eglPutContext(_EGLContext *ctx) |
| 106 | { |
| 107 | return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | /** |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 112 | * Link a context to its display and return the handle of the link. |
Chia-I Wu | ecb3b31 | 2010-01-24 20:32:34 +0800 | [diff] [blame] | 113 | * The handle can be passed to client directly. |
| 114 | */ |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 115 | static inline EGLContext |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 116 | _eglLinkContext(_EGLContext *ctx) |
Chia-I Wu | 5e66d18 | 2010-01-23 22:53:59 +0800 | [diff] [blame] | 117 | { |
Chia-I Wu | 4ce33ec | 2010-10-23 00:37:19 +0800 | [diff] [blame] | 118 | _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); |
Chia-I Wu | ecb3b31 | 2010-01-24 20:32:34 +0800 | [diff] [blame] | 119 | return (EGLContext) ctx; |
Chia-I Wu | 5e66d18 | 2010-01-23 22:53:59 +0800 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | |
Chia-I Wu | ecb3b31 | 2010-01-24 20:32:34 +0800 | [diff] [blame] | 123 | /** |
| 124 | * Unlink a linked context from its display. |
| 125 | * Accessing an unlinked context should generate EGL_BAD_CONTEXT error. |
| 126 | */ |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 127 | static inline void |
Chia-I Wu | ecb3b31 | 2010-01-24 20:32:34 +0800 | [diff] [blame] | 128 | _eglUnlinkContext(_EGLContext *ctx) |
| 129 | { |
| 130 | _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT); |
| 131 | } |
Chia-I Wu | 5e66d18 | 2010-01-23 22:53:59 +0800 | [diff] [blame] | 132 | |
| 133 | |
| 134 | /** |
| 135 | * Lookup a handle to find the linked context. |
| 136 | * Return NULL if the handle has no corresponding linked context. |
| 137 | */ |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 138 | static inline _EGLContext * |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 139 | _eglLookupContext(EGLContext context, _EGLDisplay *disp) |
Chia-I Wu | 5e66d18 | 2010-01-23 22:53:59 +0800 | [diff] [blame] | 140 | { |
| 141 | _EGLContext *ctx = (_EGLContext *) context; |
Eric Engestrom | 54fa5ec | 2019-02-02 11:38:45 +0000 | [diff] [blame] | 142 | if (!disp || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, disp)) |
Chia-I Wu | 5e66d18 | 2010-01-23 22:53:59 +0800 | [diff] [blame] | 143 | ctx = NULL; |
| 144 | return ctx; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /** |
| 149 | * Return the handle of a linked context, or EGL_NO_CONTEXT. |
| 150 | */ |
Emil Velikov | 7bd1693 | 2015-02-28 16:35:22 +0000 | [diff] [blame] | 151 | static inline EGLContext |
Chia-I Wu | 5e66d18 | 2010-01-23 22:53:59 +0800 | [diff] [blame] | 152 | _eglGetContextHandle(_EGLContext *ctx) |
| 153 | { |
Chia-I Wu | ecb3b31 | 2010-01-24 20:32:34 +0800 | [diff] [blame] | 154 | _EGLResource *res = (_EGLResource *) ctx; |
| 155 | return (res && _eglIsResourceLinked(res)) ? |
| 156 | (EGLContext) ctx : EGL_NO_CONTEXT; |
Chia-I Wu | 5e66d18 | 2010-01-23 22:53:59 +0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | |
Alexander von Gluck IV | 8362068 | 2015-05-13 17:13:37 -0500 | [diff] [blame] | 160 | #ifdef __cplusplus |
| 161 | } |
| 162 | #endif |
| 163 | |
Brian Paul | adbff7e | 2005-04-22 21:09:39 +0000 | [diff] [blame] | 164 | #endif /* EGLCONTEXT_INCLUDED */ |