2008-11-02 08:26:08 -07:00
|
|
|
/*
|
|
|
|
* GLX implementation that uses Apple's OpenGL.framework
|
2009-09-06 13:44:18 -06:00
|
|
|
* (Indirect rendering path -- it's also used for some direct mode code too)
|
2008-11-02 08:26:08 -07:00
|
|
|
*
|
2012-06-10 07:21:05 -06:00
|
|
|
* Copyright (c) 2007-2012 Apple Inc.
|
2008-11-02 08:26:08 -07:00
|
|
|
* Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved.
|
|
|
|
* Copyright (c) 2002 Greg Parker. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Portions of this file are copied from Mesa's xf86glx.c,
|
|
|
|
* which contains the following copyright:
|
|
|
|
*
|
|
|
|
* Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
#include <AvailabilityMacros.h>
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
#include <dlfcn.h>
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
#include <OpenGL/OpenGL.h>
|
2011-11-05 07:32:40 -06:00
|
|
|
#include <OpenGL/gl.h> /* Just to prevent glxserver.h from loading mesa's and colliding with OpenGL.h */
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
#include <X11/Xproto.h>
|
2008-11-02 08:26:08 -07:00
|
|
|
#include <GL/glxproto.h>
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
#include <glxserver.h>
|
|
|
|
#include <glxutil.h>
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
#include "x-hash.h"
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
#include "visualConfigs.h"
|
|
|
|
#include "dri.h"
|
2015-11-07 09:48:51 -07:00
|
|
|
#include "extension_string.h"
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
#include "darwin.h"
|
2012-06-10 07:21:05 -06:00
|
|
|
#define GLAQUA_DEBUG_MSG(msg, args ...) ASL_LOG(ASL_LEVEL_DEBUG, "GLXAqua", \
|
|
|
|
msg, \
|
|
|
|
## args)
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLXprovider *
|
|
|
|
GlxGetDRISWrastProvider(void);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
setup_dispatch_table(void);
|
|
|
|
GLuint
|
|
|
|
__glFloorLog2(GLuint val);
|
|
|
|
void
|
|
|
|
warn_func(void * p1, char *format, ...);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
// some prototypes
|
2012-06-10 07:21:05 -06:00
|
|
|
static __GLXscreen *
|
|
|
|
__glXAquaScreenProbe(ScreenPtr pScreen);
|
|
|
|
static __GLXdrawable *
|
|
|
|
__glXAquaScreenCreateDrawable(ClientPtr client, __GLXscreen *screen,
|
|
|
|
DrawablePtr pDraw, XID drawId, int type,
|
|
|
|
XID glxDrawId,
|
|
|
|
__GLXconfig *conf);
|
|
|
|
|
|
|
|
static void
|
|
|
|
__glXAquaContextDestroy(__GLXcontext *baseContext);
|
|
|
|
static int
|
|
|
|
__glXAquaContextMakeCurrent(__GLXcontext *baseContext);
|
|
|
|
static int
|
|
|
|
__glXAquaContextLoseCurrent(__GLXcontext *baseContext);
|
|
|
|
static int
|
|
|
|
__glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc,
|
|
|
|
unsigned long mask);
|
|
|
|
|
|
|
|
static CGLPixelFormatObj
|
|
|
|
makeFormat(__GLXconfig *conf);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
__GLXprovider __glXDRISWRastProvider = {
|
2009-09-06 13:44:18 -06:00
|
|
|
__glXAquaScreenProbe,
|
|
|
|
"Core OpenGL",
|
2008-11-02 08:26:08 -07:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
typedef struct __GLXAquaScreen __GLXAquaScreen;
|
|
|
|
typedef struct __GLXAquaContext __GLXAquaContext;
|
2008-11-02 08:26:08 -07:00
|
|
|
typedef struct __GLXAquaDrawable __GLXAquaDrawable;
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/*
|
|
|
|
* The following structs must keep the base as the first member.
|
|
|
|
* It's used to treat the start of the struct as a different struct
|
2012-06-10 07:21:05 -06:00
|
|
|
* in GLX.
|
2011-11-05 07:32:40 -06:00
|
|
|
*
|
2012-06-10 07:21:05 -06:00
|
|
|
* Note: these structs should be initialized with xcalloc or memset
|
2011-11-05 07:32:40 -06:00
|
|
|
* prior to usage, and some of them require initializing
|
|
|
|
* the base with function pointers.
|
|
|
|
*/
|
2008-11-02 08:26:08 -07:00
|
|
|
struct __GLXAquaScreen {
|
2009-09-06 13:44:18 -06:00
|
|
|
__GLXscreen base;
|
2015-11-07 09:48:51 -07:00
|
|
|
|
|
|
|
/* Supported GLX extensions */
|
|
|
|
unsigned char glx_enable_bits[__GLX_EXT_BYTES];
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
int index;
|
2008-11-02 08:26:08 -07:00
|
|
|
int num_vis;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct __GLXAquaContext {
|
2009-09-06 13:44:18 -06:00
|
|
|
__GLXcontext base;
|
|
|
|
CGLContextObj ctx;
|
|
|
|
CGLPixelFormatObj pixelFormat;
|
|
|
|
xp_surface_id sid;
|
2012-06-10 07:21:05 -06:00
|
|
|
unsigned isAttached : 1;
|
2008-11-02 08:26:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct __GLXAquaDrawable {
|
2009-09-06 13:44:18 -06:00
|
|
|
__GLXdrawable base;
|
2008-11-02 08:26:08 -07:00
|
|
|
DrawablePtr pDraw;
|
|
|
|
xp_surface_id sid;
|
2009-09-06 13:44:18 -06:00
|
|
|
__GLXAquaContext *context;
|
2008-11-02 08:26:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static __GLXcontext *
|
|
|
|
__glXAquaScreenCreateContext(__GLXscreen *screen,
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLXconfig *conf,
|
2013-06-07 11:28:45 -06:00
|
|
|
__GLXcontext *baseShareContext,
|
|
|
|
unsigned num_attribs,
|
|
|
|
const uint32_t *attribs,
|
|
|
|
int *error)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
__GLXAquaContext *context;
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLXAquaContext *shareContext = (__GLXAquaContext *)baseShareContext;
|
2009-09-06 13:44:18 -06:00
|
|
|
CGLError gl_err;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
/* Unused (for now?) */
|
|
|
|
(void)num_attribs;
|
|
|
|
(void)attribs;
|
|
|
|
(void)error;
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
GLAQUA_DEBUG_MSG("glXAquaScreenCreateContext\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
context = calloc(1, sizeof(__GLXAquaContext));
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (context == NULL)
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
memset(context, 0, sizeof *context);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
context->base.pGlxScreen = screen;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
context->base.destroy = __glXAquaContextDestroy;
|
|
|
|
context->base.makeCurrent = __glXAquaContextMakeCurrent;
|
|
|
|
context->base.loseCurrent = __glXAquaContextLoseCurrent;
|
|
|
|
context->base.copy = __glXAquaContextCopy;
|
2009-09-06 13:44:18 -06:00
|
|
|
/*FIXME verify that the context->base is fully initialized. */
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
context->pixelFormat = makeFormat(conf);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (!context->pixelFormat) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(context);
|
2008-11-02 08:26:08 -07:00
|
|
|
return NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
context->ctx = NULL;
|
|
|
|
gl_err = CGLCreateContext(context->pixelFormat,
|
2012-06-10 07:21:05 -06:00
|
|
|
shareContext ? shareContext->ctx : NULL,
|
|
|
|
&context->ctx);
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (gl_err != 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF("CGLCreateContext error: %s\n", CGLErrorString(gl_err));
|
|
|
|
CGLDestroyPixelFormat(context->pixelFormat);
|
|
|
|
free(context);
|
|
|
|
return NULL;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
setup_dispatch_table();
|
2008-11-02 08:26:08 -07:00
|
|
|
GLAQUA_DEBUG_MSG("glAquaCreateContext done\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
return &context->base;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* maps from surface id -> list of __GLcontext */
|
|
|
|
static x_hash_table *surface_hash;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
__glXAquaContextDestroy(__GLXcontext *baseContext)
|
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
x_list *lst;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLXAquaContext *context = (__GLXAquaContext *)baseContext;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
GLAQUA_DEBUG_MSG("glAquaContextDestroy (ctx %p)\n", baseContext);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (context != NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (context->sid != 0 && surface_hash != NULL) {
|
|
|
|
lst =
|
|
|
|
x_hash_table_lookup(surface_hash, x_cvt_uint_to_vptr(
|
|
|
|
context->sid), NULL);
|
|
|
|
lst = x_list_remove(lst, context);
|
|
|
|
x_hash_table_insert(surface_hash, x_cvt_uint_to_vptr(
|
|
|
|
context->sid), lst);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->ctx != NULL)
|
|
|
|
CGLDestroyContext(context->ctx);
|
|
|
|
|
|
|
|
if (context->pixelFormat != NULL)
|
|
|
|
CGLDestroyPixelFormat(context->pixelFormat);
|
|
|
|
|
|
|
|
free(context);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static int
|
|
|
|
__glXAquaContextLoseCurrent(__GLXcontext *baseContext)
|
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
CGLError gl_err;
|
|
|
|
|
|
|
|
GLAQUA_DEBUG_MSG("glAquaLoseCurrent (ctx 0x%p)\n", baseContext);
|
|
|
|
|
|
|
|
gl_err = CGLSetCurrentContext(NULL);
|
|
|
|
if (gl_err != 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/*
|
2011-11-05 07:32:40 -06:00
|
|
|
* There should be no need to set __glXLastContext to NULL here, because
|
2012-06-10 07:21:05 -06:00
|
|
|
* glxcmds.c does it as part of the context cache flush after calling
|
2011-11-05 07:32:40 -06:00
|
|
|
* this.
|
|
|
|
*/
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called when a surface is destroyed as a side effect of destroying
|
|
|
|
the window it's attached to. */
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
surface_notify(void *_arg, void *data)
|
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
DRISurfaceNotifyArg *arg = (DRISurfaceNotifyArg *)_arg;
|
|
|
|
__GLXAquaDrawable *draw = (__GLXAquaDrawable *)data;
|
|
|
|
__GLXAquaContext *context;
|
|
|
|
x_list *lst;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (_arg == NULL || data == NULL) {
|
|
|
|
ErrorF("surface_notify called with bad params");
|
|
|
|
return;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
GLAQUA_DEBUG_MSG("surface_notify(%p, %p)\n", _arg, data);
|
|
|
|
switch (arg->kind) {
|
|
|
|
case AppleDRISurfaceNotifyDestroyed:
|
|
|
|
if (surface_hash != NULL)
|
2009-09-06 13:44:18 -06:00
|
|
|
x_hash_table_remove(surface_hash, x_cvt_uint_to_vptr(arg->id));
|
2012-06-10 07:21:05 -06:00
|
|
|
draw->pDraw = NULL;
|
|
|
|
draw->sid = 0;
|
2008-11-02 08:26:08 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AppleDRISurfaceNotifyChanged:
|
|
|
|
if (surface_hash != NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
lst =
|
|
|
|
x_hash_table_lookup(surface_hash, x_cvt_uint_to_vptr(
|
|
|
|
arg->id), NULL);
|
|
|
|
for (; lst != NULL; lst = lst->next) {
|
2008-11-02 08:26:08 -07:00
|
|
|
context = lst->data;
|
|
|
|
xp_update_gl_context(context->ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF("surface_notify: unknown kind %d\n", arg->kind);
|
|
|
|
break;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static BOOL
|
|
|
|
attach(__GLXAquaContext *context, __GLXAquaDrawable *draw)
|
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
DrawablePtr pDraw;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
GLAQUA_DEBUG_MSG("attach(%p, %p)\n", context, draw);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (NULL == context || NULL == draw)
|
|
|
|
return TRUE;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
pDraw = draw->base.pDraw;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (NULL == pDraw) {
|
|
|
|
ErrorF("%s:%s() pDraw is NULL!\n", __FILE__, __func__);
|
|
|
|
return TRUE;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (draw->sid == 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
//if (!quartzProcs->CreateSurface(pDraw->pScreen, pDraw->id, pDraw,
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!DRICreateSurface(pDraw->pScreen, pDraw->id, pDraw,
|
2012-06-10 07:21:05 -06:00
|
|
|
0, &draw->sid, NULL,
|
|
|
|
surface_notify, draw))
|
2009-09-06 13:44:18 -06:00
|
|
|
return TRUE;
|
2008-11-02 08:26:08 -07:00
|
|
|
draw->pDraw = pDraw;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (!context->isAttached || context->sid != draw->sid) {
|
|
|
|
x_list *lst;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (xp_attach_gl_context(context->ctx, draw->sid) != Success) {
|
2012-06-10 07:21:05 -06:00
|
|
|
//quartzProcs->DestroySurface(pDraw->pScreen, pDraw->id, pDraw,
|
2008-11-02 08:26:08 -07:00
|
|
|
DRIDestroySurface(pDraw->pScreen, pDraw->id, pDraw,
|
2012-06-10 07:21:05 -06:00
|
|
|
surface_notify, draw);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (surface_hash != NULL)
|
2012-06-10 07:21:05 -06:00
|
|
|
x_hash_table_remove(surface_hash,
|
|
|
|
x_cvt_uint_to_vptr(draw->sid));
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
draw->sid = 0;
|
2009-09-06 13:44:18 -06:00
|
|
|
return TRUE;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
context->isAttached = TRUE;
|
|
|
|
context->sid = draw->sid;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (surface_hash == NULL)
|
|
|
|
surface_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
lst =
|
|
|
|
x_hash_table_lookup(surface_hash, x_cvt_uint_to_vptr(
|
|
|
|
context->sid), NULL);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (x_list_find(lst, context) == NULL) {
|
|
|
|
lst = x_list_prepend(lst, context);
|
2012-06-10 07:21:05 -06:00
|
|
|
x_hash_table_insert(surface_hash, x_cvt_uint_to_vptr(
|
|
|
|
context->sid), lst);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
GLAQUA_DEBUG_MSG("attached 0x%x to 0x%x\n", (unsigned int)pDraw->id,
|
|
|
|
(unsigned int)draw->sid);
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
draw->context = context;
|
|
|
|
|
|
|
|
return FALSE;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 // unused
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
unattach(__GLXAquaContext *context)
|
|
|
|
{
|
|
|
|
x_list *lst;
|
|
|
|
GLAQUA_DEBUG_MSG("unattach\n");
|
|
|
|
if (context == NULL) {
|
|
|
|
ErrorF("Tried to unattach a null context\n");
|
|
|
|
return;
|
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
if (context->isAttached) {
|
|
|
|
GLAQUA_DEBUG_MSG("unattaching\n");
|
|
|
|
|
|
|
|
if (surface_hash != NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
lst = x_hash_table_lookup(surface_hash, (void *)context->sid,
|
|
|
|
NULL);
|
2008-11-02 08:26:08 -07:00
|
|
|
lst = x_list_remove(lst, context);
|
2012-06-10 07:21:05 -06:00
|
|
|
x_hash_table_insert(surface_hash, (void *)context->sid, lst);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CGLClearDrawable(context->ctx);
|
|
|
|
context->isAttached = FALSE;
|
|
|
|
context->sid = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static int
|
|
|
|
__glXAquaContextMakeCurrent(__GLXcontext *baseContext)
|
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
CGLError gl_err;
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLXAquaContext *context = (__GLXAquaContext *)baseContext;
|
|
|
|
__GLXAquaDrawable *drawPriv = (__GLXAquaDrawable *)context->base.drawPriv;
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
GLAQUA_DEBUG_MSG("glAquaMakeCurrent (ctx 0x%p)\n", baseContext);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (attach(context, drawPriv))
|
|
|
|
return /*error*/ 0;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
gl_err = CGLSetCurrentContext(context->ctx);
|
|
|
|
if (gl_err != 0)
|
|
|
|
ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
return gl_err == 0;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static int
|
|
|
|
__glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc,
|
|
|
|
unsigned long mask)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
CGLError gl_err;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLXAquaContext *dst = (__GLXAquaContext *)baseDst;
|
|
|
|
__GLXAquaContext *src = (__GLXAquaContext *)baseSrc;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
GLAQUA_DEBUG_MSG("GLXAquaContextCopy\n");
|
|
|
|
|
|
|
|
gl_err = CGLCopyContext(src->ctx, dst->ctx, mask);
|
|
|
|
if (gl_err != 0)
|
|
|
|
ErrorF("CGLCopyContext error: %s\n", CGLErrorString(gl_err));
|
|
|
|
|
|
|
|
return gl_err == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Drawing surface notification callbacks */
|
2012-06-10 07:21:05 -06:00
|
|
|
static GLboolean
|
|
|
|
__glXAquaDrawableSwapBuffers(ClientPtr client, __GLXdrawable *base)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
CGLError err;
|
|
|
|
__GLXAquaDrawable *drawable;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
// GLAQUA_DEBUG_MSG("glAquaDrawableSwapBuffers(%p)\n",base);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (!base) {
|
|
|
|
ErrorF("%s passed NULL\n", __func__);
|
|
|
|
return GL_FALSE;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
drawable = (__GLXAquaDrawable *)base;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (NULL == drawable->context) {
|
|
|
|
ErrorF("%s called with a NULL->context for drawable %p!\n",
|
|
|
|
__func__, (void *)drawable);
|
|
|
|
return GL_FALSE;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
err = CGLFlushDrawable(drawable->context->ctx);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (kCGLNoError != err) {
|
|
|
|
ErrorF("CGLFlushDrawable error: %s in %s\n", CGLErrorString(err),
|
|
|
|
__func__);
|
|
|
|
return GL_FALSE;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
return GL_TRUE;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static CGLPixelFormatObj
|
|
|
|
makeFormat(__GLXconfig *conf)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
CGLPixelFormatAttribute attr[64];
|
|
|
|
CGLPixelFormatObj fobj;
|
|
|
|
GLint formats;
|
|
|
|
CGLError error;
|
|
|
|
int i = 0;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (conf->doubleBufferMode)
|
|
|
|
attr[i++] = kCGLPFADoubleBuffer;
|
|
|
|
|
|
|
|
if (conf->stereoMode)
|
|
|
|
attr[i++] = kCGLPFAStereo;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
attr[i++] = kCGLPFAColorSize;
|
|
|
|
attr[i++] = conf->redBits + conf->greenBits + conf->blueBits;
|
|
|
|
attr[i++] = kCGLPFAAlphaSize;
|
|
|
|
attr[i++] = conf->alphaBits;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((conf->accumRedBits + conf->accumGreenBits + conf->accumBlueBits +
|
|
|
|
conf->accumAlphaBits) > 0) {
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
attr[i++] = kCGLPFAAccumSize;
|
2009-09-06 13:44:18 -06:00
|
|
|
attr[i++] = conf->accumRedBits + conf->accumGreenBits
|
2012-06-10 07:21:05 -06:00
|
|
|
+ conf->accumBlueBits + conf->accumAlphaBits;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
attr[i++] = kCGLPFADepthSize;
|
|
|
|
attr[i++] = conf->depthBits;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (conf->stencilBits) {
|
|
|
|
attr[i++] = kCGLPFAStencilSize;
|
|
|
|
attr[i++] = conf->stencilBits;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (conf->numAuxBuffers > 0) {
|
|
|
|
attr[i++] = kCGLPFAAuxBuffers;
|
|
|
|
attr[i++] = conf->numAuxBuffers;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (conf->sampleBuffers > 0) {
|
|
|
|
attr[i++] = kCGLPFASampleBuffers;
|
|
|
|
attr[i++] = conf->sampleBuffers;
|
|
|
|
attr[i++] = kCGLPFASamples;
|
|
|
|
attr[i++] = conf->samples;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
attr[i] = 0;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
error = CGLChoosePixelFormat(attr, &fobj, &formats);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (error) {
|
|
|
|
ErrorF("error: creating pixel format %s\n", CGLErrorString(error));
|
|
|
|
return NULL;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
return fobj;
|
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
__glXAquaScreenDestroy(__GLXscreen *screen)
|
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
GLAQUA_DEBUG_MSG("glXAquaScreenDestroy(%p)\n", screen);
|
|
|
|
__glXScreenDestroy(screen);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(screen);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* This is called by __glXInitScreens(). */
|
2012-06-10 07:21:05 -06:00
|
|
|
static __GLXscreen *
|
|
|
|
__glXAquaScreenProbe(ScreenPtr pScreen)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
__GLXAquaScreen *screen;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
GLAQUA_DEBUG_MSG("glXAquaScreenProbe\n");
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pScreen == NULL)
|
|
|
|
return NULL;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
screen = calloc(1, sizeof *screen);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (NULL == screen)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
screen->base.destroy = __glXAquaScreenDestroy;
|
|
|
|
screen->base.createContext = __glXAquaScreenCreateContext;
|
2009-09-06 13:44:18 -06:00
|
|
|
screen->base.createDrawable = __glXAquaScreenCreateDrawable;
|
|
|
|
screen->base.swapInterval = /*FIXME*/ NULL;
|
2012-06-10 07:21:05 -06:00
|
|
|
screen->base.pScreen = pScreen;
|
|
|
|
|
|
|
|
screen->base.fbconfigs = __glXAquaCreateVisualConfigs(
|
|
|
|
&screen->base.numFBConfigs, pScreen->myNum);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
__glXScreenInit(&screen->base, pScreen);
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
screen->base.GLXmajor = 1;
|
|
|
|
screen->base.GLXminor = 4;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2015-11-07 09:48:51 -07:00
|
|
|
memset(screen->glx_enable_bits, 0, __GLX_EXT_BYTES);
|
|
|
|
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_visual_info");
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_visual_rating");
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_EXT_import_context");
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_OML_swap_method");
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_SGIX_fbconfig");
|
|
|
|
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_SGIS_multisample");
|
|
|
|
__glXEnableExtension(screen->glx_enable_bits, "GLX_ARB_multisample");
|
|
|
|
|
|
|
|
//__glXEnableExtension(screen->glx_enable_bits, "GLX_ARB_create_context");
|
|
|
|
//__glXEnableExtension(screen->glx_enable_bits, "GLX_ARB_create_context_profile");
|
|
|
|
|
|
|
|
// Generate the GLX extensions string (overrides that set by __glXScreenInit())
|
|
|
|
{
|
|
|
|
unsigned int buffer_size =
|
|
|
|
__glXGetExtensionString(screen->glx_enable_bits, NULL);
|
|
|
|
if (buffer_size > 0) {
|
|
|
|
free(screen->base.GLXextensions);
|
|
|
|
|
|
|
|
screen->base.GLXextensions = xnfalloc(buffer_size);
|
|
|
|
__glXGetExtensionString(screen->glx_enable_bits,
|
|
|
|
screen->base.GLXextensions);
|
|
|
|
}
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
return &screen->base;
|
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
#if 0 // unused
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
__glXAquaDrawableCopySubBuffer(__GLXdrawable *drawable,
|
|
|
|
int x, int y, int w, int h)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
/*TODO finish me*/
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
#endif
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
__glXAquaDrawableDestroy(__GLXdrawable *base)
|
|
|
|
{
|
|
|
|
/* gstaplin: base is the head of the structure, so it's at the same
|
2009-09-06 13:44:18 -06:00
|
|
|
* offset in memory.
|
|
|
|
* Is this safe with strict aliasing? I noticed that the other dri code
|
|
|
|
* does this too...
|
|
|
|
*/
|
|
|
|
__GLXAquaDrawable *glxPriv = (__GLXAquaDrawable *)base;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
GLAQUA_DEBUG_MSG("TRACE");
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
/* It doesn't work to call DRIDestroySurface here, the drawable's
|
|
|
|
already gone.. But dri.c notices the window destruction and
|
|
|
|
frees the surface itself. */
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/*gstaplin: verify the statement above. The surface destroy
|
2012-06-10 07:21:05 -06:00
|
|
|
*messages weren't making it through, and may still not be.
|
|
|
|
*We need a good test case for surface creation and destruction.
|
|
|
|
*We also need a good way to enable introspection on the server
|
|
|
|
*to validate the test, beyond using gdb with print.
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(glxPriv);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static __GLXdrawable *
|
2010-12-05 08:36:02 -07:00
|
|
|
__glXAquaScreenCreateDrawable(ClientPtr client,
|
|
|
|
__GLXscreen *screen,
|
2012-06-10 07:21:05 -06:00
|
|
|
DrawablePtr pDraw,
|
|
|
|
XID drawId,
|
|
|
|
int type,
|
|
|
|
XID glxDrawId,
|
|
|
|
__GLXconfig *conf)
|
|
|
|
{
|
|
|
|
__GLXAquaDrawable *glxPriv;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
glxPriv = malloc(sizeof *glxPriv);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (glxPriv == NULL)
|
|
|
|
return NULL;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
memset(glxPriv, 0, sizeof *glxPriv);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!__glXDrawableInit(&glxPriv->base, screen, pDraw, type, glxDrawId,
|
|
|
|
conf)) {
|
|
|
|
free(glxPriv);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
glxPriv->base.destroy = __glXAquaDrawableDestroy;
|
|
|
|
glxPriv->base.swapBuffers = __glXAquaDrawableSwapBuffers;
|
|
|
|
glxPriv->base.copySubBuffer = NULL; /* __glXAquaDrawableCopySubBuffer; */
|
|
|
|
|
|
|
|
glxPriv->pDraw = pDraw;
|
|
|
|
glxPriv->sid = 0;
|
|
|
|
glxPriv->context = NULL;
|
|
|
|
|
|
|
|
return &glxPriv->base;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extra goodies for glx
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
GLuint
|
|
|
|
__glFloorLog2(GLuint val)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
while (val > 1) {
|
|
|
|
c++;
|
|
|
|
val >>= 1;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
#ifndef OPENGL_FRAMEWORK_PATH
|
2012-06-10 07:21:05 -06:00
|
|
|
#define OPENGL_FRAMEWORK_PATH \
|
|
|
|
"/System/Library/Frameworks/OpenGL.framework/OpenGL"
|
2010-07-27 13:02:24 -06:00
|
|
|
#endif
|
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
static void *opengl_framework_handle;
|
|
|
|
|
|
|
|
static glx_func_ptr
|
|
|
|
get_proc_address(const char *sym)
|
|
|
|
{
|
|
|
|
return (glx_func_ptr) dlsym(opengl_framework_handle, sym);
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
setup_dispatch_table(void)
|
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
const char *opengl_framework_path;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
if (opengl_framework_handle) {
|
2011-11-05 07:32:40 -06:00
|
|
|
return;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
opengl_framework_path = getenv("OPENGL_FRAMEWORK_PATH");
|
|
|
|
if (!opengl_framework_path) {
|
|
|
|
opengl_framework_path = OPENGL_FRAMEWORK_PATH;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
(void)dlerror(); /*drain dlerror */
|
2014-05-02 13:27:46 -06:00
|
|
|
opengl_framework_handle = dlopen(opengl_framework_path, RTLD_LOCAL);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
if (!opengl_framework_handle) {
|
2011-11-05 07:32:40 -06:00
|
|
|
ErrorF("unable to dlopen %s : %s, using RTLD_DEFAULT\n",
|
2012-06-10 07:21:05 -06:00
|
|
|
opengl_framework_path, dlerror());
|
2014-05-02 13:27:46 -06:00
|
|
|
opengl_framework_handle = RTLD_DEFAULT;
|
2011-11-05 07:32:40 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
__glXsetGetProcAddress(get_proc_address);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|