2 Copyright (c) 2008, 2009 Apple Inc.
4 Permission is hereby granted, free of charge, to any person
5 obtaining a copy of this software and associated documentation files
6 (the "Software"), to deal in the Software without restriction,
7 including without limitation the rights to use, copy, modify, merge,
8 publish, distribute, sublicense, and/or sell copies of the Software,
9 and to permit persons to whom the Software is furnished to do so,
10 subject to the following conditions:
12 The above copyright notice and this permission notice shall be
13 included in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
19 HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
24 Except as contained in this notice, the name(s) of the above
25 copyright holders shall not be used in advertising or otherwise to
26 promote the sale, use or other dealings in this Software without
27 prior written authorization.
37 #include "apple_glx.h"
38 #include "apple_glx_context.h"
39 #include "apple_cgl.h"
41 static bool initialized
= false;
42 static int dri_event_base
= 0;
44 const GLuint __glXDefaultPixelStore
[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 };
46 #ifndef OPENGL_LIB_PATH
47 #define OPENGL_LIB_PATH "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
50 static void *libgl_handle
= NULL
;
52 static bool diagnostic
= false;
55 apple_glx_diagnostic(const char *fmt
, ...)
60 fprintf(stderr
, "DIAG: ");
63 vfprintf(stderr
, fmt
, vl
);
69 apple_get_dri_event_base(void)
73 "error: dri_event_base called before apple_init_glx!\n");
76 return dri_event_base
;
80 surface_notify_handler(Display
* dpy
, unsigned int uid
, int kind
)
84 case AppleDRISurfaceNotifyDestroyed
:
85 apple_glx_diagnostic("%s: surface destroyed %u\n", __func__
, uid
);
86 apple_glx_surface_destroy(uid
);
89 case AppleDRISurfaceNotifyChanged
:{
92 updated
= apple_glx_context_surface_changed(uid
, pthread_self());
94 apple_glx_diagnostic("surface notify updated %d\n", updated
);
99 fprintf(stderr
, "unhandled kind of event: %d in %s\n", kind
, __func__
);
104 apple_glx_get_client_id(void)
106 static xp_client_id id
;
109 if ((XP_Success
!= xp_init(XP_IN_BACKGROUND
)) ||
110 (Success
!= xp_get_client_id(&id
))) {
118 /* Return true if an error occured. */
120 apple_init_glx(Display
* dpy
)
122 int eventBase
, errorBase
;
123 int major
, minor
, patch
;
125 if (!XAppleDRIQueryExtension(dpy
, &eventBase
, &errorBase
))
128 if (!XAppleDRIQueryVersion(dpy
, &major
, &minor
, &patch
))
134 if (getenv("LIBGL_DIAGNOSTIC")) {
135 printf("initializing libGL in %s\n", __func__
);
140 apple_xgl_init_direct();
141 libgl_handle
= dlopen(OPENGL_LIB_PATH
, RTLD_LAZY
);
142 (void) apple_glx_get_client_id();
144 XAppleDRISetSurfaceNotifyHandler(surface_notify_handler
);
146 /* This should really be per display. */
147 dri_event_base
= eventBase
;
154 apple_glx_swap_buffers(void *ptr
)
156 struct apple_glx_context
*ac
= ptr
;
158 /* This may not be needed with CGLFlushDrawable: */
160 apple_cgl
.flush_drawable(ac
->context_obj
);
164 apple_glx_get_proc_address(const GLubyte
* procname
)
168 char *pname
= (char *) procname
;
170 assert(NULL
!= procname
);
177 if ((pname
!= strstr(pname
, "glX")) && (pname
!= strstr(pname
, "gl"))) {
179 "warning: get proc address request is not for a gl or glX function");
183 /* Search using the default symbols first. */
184 (void) dlerror(); /*drain dlerror */
185 h
= dlopen(NULL
, RTLD_NOW
);
187 fprintf(stderr
, "warning: get proc address: %s\n", dlerror());
194 /* Try the libGL.dylib from the OpenGL.framework. */
195 s
= dlsym(libgl_handle
, pname
);
204 apple_glx_waitx(Display
* dpy
, void *ptr
)
206 struct apple_private_context
*ac
= ptr
;