Home | History | Annotate | Download | only in main
      1 /**************************************************************************
      2  *
      3  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
      4  * Copyright 2009-2010 Chia-I Wu <olvaffe (at) 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 
     31 #ifndef EGLCONTEXT_INCLUDED
     32 #define EGLCONTEXT_INCLUDED
     33 
     34 
     35 #include "egltypedefs.h"
     36 #include "egldisplay.h"
     37 
     38 
     39 /**
     40  * "Base" class for device driver contexts.
     41  */
     42 struct _egl_context
     43 {
     44    /* A context is a display resource */
     45    _EGLResource Resource;
     46 
     47    /* The bound status of the context */
     48    _EGLThreadInfo *Binding;
     49    _EGLSurface *DrawSurface;
     50    _EGLSurface *ReadSurface;
     51 
     52    _EGLConfig *Config;
     53 
     54    EGLint ClientAPI; /**< EGL_OPENGL_ES_API, EGL_OPENGL_API, EGL_OPENVG_API */
     55    EGLint ClientMajorVersion;
     56    EGLint ClientMinorVersion;
     57    EGLint Flags;
     58    EGLint Profile;
     59    EGLint ResetNotificationStrategy;
     60 
     61    /* The real render buffer when a window surface is bound */
     62    EGLint WindowRenderBuffer;
     63 };
     64 
     65 
     66 PUBLIC EGLBoolean
     67 _eglInitContext(_EGLContext *ctx, _EGLDisplay *dpy,
     68                 _EGLConfig *config, const EGLint *attrib_list);
     69 
     70 
     71 extern EGLBoolean
     72 _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value);
     73 
     74 
     75 PUBLIC EGLBoolean
     76 _eglBindContext(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read,
     77                 _EGLContext **old_ctx,
     78                 _EGLSurface **old_draw, _EGLSurface **old_read);
     79 
     80 
     81 /**
     82  * Increment reference count for the context.
     83  */
     84 static INLINE _EGLContext *
     85 _eglGetContext(_EGLContext *ctx)
     86 {
     87    if (ctx)
     88       _eglGetResource(&ctx->Resource);
     89    return ctx;
     90 }
     91 
     92 
     93 /**
     94  * Decrement reference count for the context.
     95  */
     96 static INLINE EGLBoolean
     97 _eglPutContext(_EGLContext *ctx)
     98 {
     99    return (ctx) ? _eglPutResource(&ctx->Resource) : EGL_FALSE;
    100 }
    101 
    102 
    103 /**
    104  * Link a context to its display and return the handle of the link.
    105  * The handle can be passed to client directly.
    106  */
    107 static INLINE EGLContext
    108 _eglLinkContext(_EGLContext *ctx)
    109 {
    110    _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
    111    return (EGLContext) ctx;
    112 }
    113 
    114 
    115 /**
    116  * Unlink a linked context from its display.
    117  * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
    118  */
    119 static INLINE void
    120 _eglUnlinkContext(_EGLContext *ctx)
    121 {
    122    _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
    123 }
    124 
    125 
    126 /**
    127  * Lookup a handle to find the linked context.
    128  * Return NULL if the handle has no corresponding linked context.
    129  */
    130 static INLINE _EGLContext *
    131 _eglLookupContext(EGLContext context, _EGLDisplay *dpy)
    132 {
    133    _EGLContext *ctx = (_EGLContext *) context;
    134    if (!dpy || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, dpy))
    135       ctx = NULL;
    136    return ctx;
    137 }
    138 
    139 
    140 /**
    141  * Return the handle of a linked context, or EGL_NO_CONTEXT.
    142  */
    143 static INLINE EGLContext
    144 _eglGetContextHandle(_EGLContext *ctx)
    145 {
    146    _EGLResource *res = (_EGLResource *) ctx;
    147    return (res && _eglIsResourceLinked(res)) ?
    148       (EGLContext) ctx : EGL_NO_CONTEXT;
    149 }
    150 
    151 
    152 #endif /* EGLCONTEXT_INCLUDED */
    153