forked from notaz/mesa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglxcmds.c
2785 lines (2334 loc) · 75.2 KB
/
glxcmds.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
* Copyright (C) 1991-2000 Silicon Graphics, Inc. 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 including the dates of first publication and
* either this permission notice or a reference to
* http://oss.sgi.com/projects/FreeB/
* 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
* SILICON GRAPHICS, INC. 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.
*
* Except as contained in this notice, the name of Silicon Graphics, Inc.
* shall not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization from
* Silicon Graphics, Inc.
*/
/**
* \file glxcmds.c
* Client-side GLX interface.
*/
#include "glxclient.h"
#include "glapi.h"
#include "glxextensions.h"
#include "indirect.h"
#include "glx_error.h"
#ifdef GLX_DIRECT_RENDERING
#ifdef GLX_USE_APPLEGL
#include "apple/apple_glx_context.h"
#include "apple/apple_glx.h"
#include "util/debug.h"
#else
#ifndef GLX_USE_WINDOWSGL
#include <X11/extensions/xf86vmode.h>
#endif /* GLX_USE_WINDOWSGL */
#endif
#endif
#include <limits.h>
#include <X11/Xlib-xcb.h>
#include <xcb/xcb.h>
#include <xcb/glx.h>
#include "GL/mesa_glinterop.h"
static const char __glXGLXClientVendorName[] = "Mesa Project and SGI";
static const char __glXGLXClientVersion[] = "1.4";
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
/**
* Get the __DRIdrawable for the drawable associated with a GLXContext
*
* \param dpy The display associated with \c drawable.
* \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
* \param scrn_num If non-NULL, the drawables screen is stored there
* \returns A pointer to the context's __DRIdrawable on success, or NULL if
* the drawable is not associated with a direct-rendering context.
*/
_X_HIDDEN __GLXDRIdrawable *
GetGLXDRIDrawable(Display * dpy, GLXDrawable drawable)
{
struct glx_display *priv = __glXInitialize(dpy);
__GLXDRIdrawable *pdraw;
if (priv == NULL)
return NULL;
if (__glxHashLookup(priv->drawHash, drawable, (void *) &pdraw) == 0)
return pdraw;
return NULL;
}
#endif
_X_HIDDEN struct glx_drawable *
GetGLXDrawable(Display *dpy, GLXDrawable drawable)
{
struct glx_display *priv = __glXInitialize(dpy);
struct glx_drawable *glxDraw;
if (priv == NULL)
return NULL;
if (__glxHashLookup(priv->glXDrawHash, drawable, (void *) &glxDraw) == 0)
return glxDraw;
return NULL;
}
_X_HIDDEN int
InitGLXDrawable(Display *dpy, struct glx_drawable *glxDraw, XID xDrawable,
GLXDrawable drawable)
{
struct glx_display *priv = __glXInitialize(dpy);
if (!priv)
return -1;
glxDraw->xDrawable = xDrawable;
glxDraw->drawable = drawable;
glxDraw->lastEventSbc = 0;
glxDraw->eventSbcWrap = 0;
return __glxHashInsert(priv->glXDrawHash, drawable, glxDraw);
}
_X_HIDDEN void
DestroyGLXDrawable(Display *dpy, GLXDrawable drawable)
{
struct glx_display *priv = __glXInitialize(dpy);
struct glx_drawable *glxDraw;
if (!priv)
return;
glxDraw = GetGLXDrawable(dpy, drawable);
__glxHashDelete(priv->glXDrawHash, drawable);
free(glxDraw);
}
/**
* Get the GLX per-screen data structure associated with a GLX context.
*
* \param dpy Display for which the GLX per-screen information is to be
* retrieved.
* \param scrn Screen on \c dpy for which the GLX per-screen information is
* to be retrieved.
* \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
* specify a valid GLX screen, or NULL otherwise.
*
* \todo Should this function validate that \c scrn is within the screen
* number range for \c dpy?
*/
_X_HIDDEN struct glx_screen *
GetGLXScreenConfigs(Display * dpy, int scrn)
{
struct glx_display *const priv = __glXInitialize(dpy);
return (priv
&& priv->screens !=
NULL) ? priv->screens[scrn] : NULL;
}
static int
GetGLXPrivScreenConfig(Display * dpy, int scrn, struct glx_display ** ppriv,
struct glx_screen ** ppsc)
{
/* Initialize the extension, if needed . This has the added value
* of initializing/allocating the display private
*/
if (dpy == NULL) {
return GLX_NO_EXTENSION;
}
*ppriv = __glXInitialize(dpy);
if (*ppriv == NULL) {
return GLX_NO_EXTENSION;
}
/* Check screen number to see if its valid */
if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
return GLX_BAD_SCREEN;
}
/* Check to see if the GL is supported on this screen */
*ppsc = (*ppriv)->screens[scrn];
if ((*ppsc)->configs == NULL && (*ppsc)->visuals == NULL) {
/* No support for GL on this screen regardless of visual */
return GLX_BAD_VISUAL;
}
return Success;
}
/**
* Determine if a \c GLXFBConfig supplied by the application is valid.
*
* \param dpy Application supplied \c Display pointer.
* \param config Application supplied \c GLXFBConfig.
*
* \returns If the \c GLXFBConfig is valid, the a pointer to the matching
* \c struct glx_config structure is returned. Otherwise, \c NULL
* is returned.
*/
static struct glx_config *
ValidateGLXFBConfig(Display * dpy, GLXFBConfig fbconfig)
{
struct glx_display *const priv = __glXInitialize(dpy);
int num_screens = ScreenCount(dpy);
unsigned i;
struct glx_config *config;
if (priv != NULL) {
for (i = 0; i < num_screens; i++) {
for (config = priv->screens[i]->configs; config != NULL;
config = config->next) {
if (config == (struct glx_config *) fbconfig) {
return config;
}
}
}
}
return NULL;
}
/**
* Verifies context's GLX_RENDER_TYPE value with config.
*
* \param config GLX FBConfig which will support the returned renderType.
* \param renderType The context render type to be verified.
* \return True if the value of context renderType was approved, or 0 if no
* valid value was found.
*/
Bool
validate_renderType_against_config(const struct glx_config *config,
int renderType)
{
/* GLX_EXT_no_config_context supports any render type */
if (!config)
return renderType == GLX_DONT_CARE;
switch (renderType) {
case GLX_RGBA_TYPE:
return (config->renderType & GLX_RGBA_BIT) != 0;
case GLX_COLOR_INDEX_TYPE:
return (config->renderType & GLX_COLOR_INDEX_BIT) != 0;
case GLX_RGBA_FLOAT_TYPE_ARB:
return (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) != 0;
case GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT:
return (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) != 0;
default:
break;
}
return 0;
}
_X_HIDDEN Bool
glx_context_init(struct glx_context *gc,
struct glx_screen *psc, struct glx_config *config)
{
gc->majorOpcode = __glXSetupForCommand(psc->display->dpy);
if (!gc->majorOpcode)
return False;
gc->screen = psc->scr;
gc->psc = psc;
gc->config = config;
gc->isDirect = GL_TRUE;
gc->currentContextTag = -1;
if (!config)
gc->renderType = GLX_DONT_CARE;
return True;
}
/**
* Determine if a context uses direct rendering.
*
* \param dpy Display where the context was created.
* \param contextID ID of the context to be tested.
* \param error Out parameter, set to True on error if not NULL,
* otherwise raise the error to the application.
*
* \returns \c True if the context is direct rendering or not.
*/
static Bool
__glXIsDirect(Display * dpy, GLXContextID contextID, Bool *error)
{
xcb_connection_t *c;
xcb_generic_error_t *err;
xcb_glx_is_direct_reply_t *reply;
Bool is_direct;
c = XGetXCBConnection(dpy);
reply = xcb_glx_is_direct_reply(c, xcb_glx_is_direct(c, contextID), &err);
is_direct = (reply != NULL && reply->is_direct) ? True : False;
if (err != NULL) {
if (error)
*error = True;
else
__glXSendErrorForXcb(dpy, err);
free(err);
}
free(reply);
return is_direct;
}
/**
* Create a new context.
*
* \param renderType For FBConfigs, what is the rendering type?
*/
static GLXContext
CreateContext(Display *dpy, int generic_id, struct glx_config *config,
GLXContext shareList_user, Bool allowDirect,
unsigned code, int renderType)
{
struct glx_context *gc;
struct glx_screen *psc;
struct glx_context *shareList = (struct glx_context *) shareList_user;
if (dpy == NULL)
return NULL;
psc = GetGLXScreenConfigs(dpy, config->screen);
if (psc == NULL)
return NULL;
if (generic_id == None)
return NULL;
/* Some application may request an indirect context but we may want to force a direct
* one because Xorg only allows indirect contexts if they were enabled.
*/
if (!allowDirect &&
psc->force_direct_context) {
allowDirect = 1;
}
gc = NULL;
#ifdef GLX_USE_APPLEGL
gc = applegl_create_context(psc, config, shareList, renderType);
#else
if (allowDirect && psc->vtable->create_context)
gc = psc->vtable->create_context(psc, config, shareList, renderType);
if (!gc)
gc = indirect_create_context(psc, config, shareList, renderType);
#endif
if (!gc)
return NULL;
LockDisplay(dpy);
switch (code) {
case X_GLXCreateContext: {
xGLXCreateContextReq *req;
/* Send the glXCreateContext request */
GetReq(GLXCreateContext, req);
req->reqType = gc->majorOpcode;
req->glxCode = X_GLXCreateContext;
req->context = gc->xid = XAllocID(dpy);
req->visual = generic_id;
req->screen = config->screen;
req->shareList = shareList ? shareList->xid : None;
req->isDirect = gc->isDirect;
break;
}
case X_GLXCreateNewContext: {
xGLXCreateNewContextReq *req;
/* Send the glXCreateNewContext request */
GetReq(GLXCreateNewContext, req);
req->reqType = gc->majorOpcode;
req->glxCode = X_GLXCreateNewContext;
req->context = gc->xid = XAllocID(dpy);
req->fbconfig = generic_id;
req->screen = config->screen;
req->renderType = renderType;
req->shareList = shareList ? shareList->xid : None;
req->isDirect = gc->isDirect;
break;
}
case X_GLXvop_CreateContextWithConfigSGIX: {
xGLXVendorPrivateWithReplyReq *vpreq;
xGLXCreateContextWithConfigSGIXReq *req;
/* Send the glXCreateNewContext request */
GetReqExtra(GLXVendorPrivateWithReply,
sz_xGLXCreateContextWithConfigSGIXReq -
sz_xGLXVendorPrivateWithReplyReq, vpreq);
req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
req->reqType = gc->majorOpcode;
req->glxCode = X_GLXVendorPrivateWithReply;
req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
req->context = gc->xid = XAllocID(dpy);
req->fbconfig = generic_id;
req->screen = config->screen;
req->renderType = renderType;
req->shareList = shareList ? shareList->xid : None;
req->isDirect = gc->isDirect;
break;
}
default:
/* What to do here? This case is the sign of an internal error. It
* should never be reachable.
*/
break;
}
UnlockDisplay(dpy);
SyncHandle();
gc->share_xid = shareList ? shareList->xid : None;
gc->imported = GL_FALSE;
/* Unlike most X resource creation requests, we're about to return a handle
* with client-side state, not just an XID. To simplify error handling
* elsewhere in libGL, force a round-trip here to ensure the CreateContext
* request above succeeded.
*/
{
Bool error = False;
int isDirect = __glXIsDirect(dpy, gc->xid, &error);
if (error != False || isDirect != gc->isDirect) {
gc->vtable->destroy(gc);
gc = NULL;
}
}
return (GLXContext) gc;
}
_GLX_PUBLIC GLXContext
glXCreateContext(Display * dpy, XVisualInfo * vis,
GLXContext shareList, Bool allowDirect)
{
struct glx_config *config = NULL;
int renderType = GLX_RGBA_TYPE;
#if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
struct glx_screen *const psc = GetGLXScreenConfigs(dpy, vis->screen);
if (psc)
config = glx_config_find_visual(psc->visuals, vis->visualid);
if (config == NULL) {
__glXSendError(dpy, BadValue, vis->visualid, X_GLXCreateContext, True);
return None;
}
/* Choose the context render type based on DRI config values. It is
* unusual to set this type from config, but we have no other choice, as
* this old API does not provide renderType parameter.
*/
if (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) {
renderType = GLX_RGBA_FLOAT_TYPE_ARB;
} else if (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) {
renderType = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
} else if (config->renderType & GLX_RGBA_BIT) {
renderType = GLX_RGBA_TYPE;
} else if (config->renderType & GLX_COLOR_INDEX_BIT) {
renderType = GLX_COLOR_INDEX_TYPE;
}
#endif
return CreateContext(dpy, vis->visualid, config, shareList, allowDirect,
X_GLXCreateContext, renderType);
}
static void
glx_send_destroy_context(Display *dpy, XID xid)
{
CARD8 opcode = __glXSetupForCommand(dpy);
xGLXDestroyContextReq *req;
LockDisplay(dpy);
GetReq(GLXDestroyContext, req);
req->reqType = opcode;
req->glxCode = X_GLXDestroyContext;
req->context = xid;
UnlockDisplay(dpy);
SyncHandle();
}
/*
** Destroy the named context
*/
_GLX_PUBLIC void
glXDestroyContext(Display * dpy, GLXContext ctx)
{
struct glx_context *gc = (struct glx_context *) ctx;
if (gc == NULL || gc->xid == None)
return;
__glXLock();
if (!gc->imported)
glx_send_destroy_context(dpy, gc->xid);
if (gc->currentDpy) {
/* This context is bound to some thread. According to the man page,
* we should not actually delete the context until it's unbound.
* Note that we set gc->xid = None above. In MakeContextCurrent()
* we check for that and delete the context there.
*/
gc->xid = None;
} else {
gc->vtable->destroy(gc);
}
__glXUnlock();
}
/*
** Return the major and minor version #s for the GLX extension
*/
_GLX_PUBLIC Bool
glXQueryVersion(Display * dpy, int *major, int *minor)
{
struct glx_display *priv;
/* Init the extension. This fetches the major and minor version. */
priv = __glXInitialize(dpy);
if (!priv)
return False;
if (major)
*major = GLX_MAJOR_VERSION;
if (minor)
*minor = priv->minorVersion;
return True;
}
/*
** Query the existence of the GLX extension
*/
_GLX_PUBLIC Bool
glXQueryExtension(Display * dpy, int *errorBase, int *eventBase)
{
int major_op, erb, evb;
Bool rv;
rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
if (rv) {
if (errorBase)
*errorBase = erb;
if (eventBase)
*eventBase = evb;
}
return rv;
}
/*
** Put a barrier in the token stream that forces the GL to finish its
** work before X can proceed.
*/
_GLX_PUBLIC void
glXWaitGL(void)
{
struct glx_context *gc = __glXGetCurrentContext();
if (gc->vtable->wait_gl)
gc->vtable->wait_gl(gc);
}
/*
** Put a barrier in the token stream that forces X to finish its
** work before GL can proceed.
*/
_GLX_PUBLIC void
glXWaitX(void)
{
struct glx_context *gc = __glXGetCurrentContext();
if (gc->vtable->wait_x)
gc->vtable->wait_x(gc);
}
_GLX_PUBLIC void
glXUseXFont(Font font, int first, int count, int listBase)
{
struct glx_context *gc = __glXGetCurrentContext();
xGLXUseXFontReq *req;
Display *dpy = gc->currentDpy;
#ifdef GLX_DIRECT_RENDERING
if (gc->isDirect) {
DRI_glXUseXFont(gc, font, first, count, listBase);
return;
}
#endif
/* Flush any pending commands out */
__glXFlushRenderBuffer(gc, gc->pc);
/* Send the glXUseFont request */
LockDisplay(dpy);
GetReq(GLXUseXFont, req);
req->reqType = gc->majorOpcode;
req->glxCode = X_GLXUseXFont;
req->contextTag = gc->currentContextTag;
req->font = font;
req->first = first;
req->count = count;
req->listBase = listBase;
UnlockDisplay(dpy);
SyncHandle();
}
/************************************************************************/
/*
** Copy the source context to the destination context using the
** attribute "mask".
*/
_GLX_PUBLIC void
glXCopyContext(Display * dpy, GLXContext source_user,
GLXContext dest_user, unsigned long mask)
{
struct glx_context *source = (struct glx_context *) source_user;
struct glx_context *dest = (struct glx_context *) dest_user;
#ifdef GLX_USE_APPLEGL
struct glx_context *gc = __glXGetCurrentContext();
int errorcode;
bool x11error;
if(apple_glx_copy_context(gc->driContext, source->driContext, dest->driContext,
mask, &errorcode, &x11error)) {
__glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
}
#else
xGLXCopyContextReq *req;
struct glx_context *gc = __glXGetCurrentContext();
GLXContextTag tag;
CARD8 opcode;
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return;
}
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
if (gc->isDirect) {
/* NOT_DONE: This does not work yet */
}
#endif
/*
** If the source is the current context, send its tag so that the context
** can be flushed before the copy.
*/
if (source == gc && dpy == gc->currentDpy) {
tag = gc->currentContextTag;
}
else {
tag = 0;
}
/* Send the glXCopyContext request */
LockDisplay(dpy);
GetReq(GLXCopyContext, req);
req->reqType = opcode;
req->glxCode = X_GLXCopyContext;
req->source = source ? source->xid : None;
req->dest = dest ? dest->xid : None;
req->mask = mask;
req->contextTag = tag;
UnlockDisplay(dpy);
SyncHandle();
#endif /* GLX_USE_APPLEGL */
}
_GLX_PUBLIC Bool
glXIsDirect(Display * dpy, GLXContext gc_user)
{
struct glx_context *gc = (struct glx_context *) gc_user;
/* This is set for us at context creation */
return gc ? gc->isDirect : False;
}
_GLX_PUBLIC GLXPixmap
glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap)
{
#ifdef GLX_USE_APPLEGL
int screen = vis->screen;
struct glx_screen *const psc = GetGLXScreenConfigs(dpy, screen);
const struct glx_config *config;
config = glx_config_find_visual(psc->visuals, vis->visualid);
if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, config))
return None;
return pixmap;
#else
xGLXCreateGLXPixmapReq *req;
struct glx_drawable *glxDraw;
GLXPixmap xid;
CARD8 opcode;
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
struct glx_display *const priv = __glXInitialize(dpy);
if (priv == NULL)
return None;
#endif
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return None;
}
glxDraw = malloc(sizeof(*glxDraw));
if (!glxDraw)
return None;
/* Send the glXCreateGLXPixmap request */
LockDisplay(dpy);
GetReq(GLXCreateGLXPixmap, req);
req->reqType = opcode;
req->glxCode = X_GLXCreateGLXPixmap;
req->screen = vis->screen;
req->visual = vis->visualid;
req->pixmap = pixmap;
req->glxpixmap = xid = XAllocID(dpy);
UnlockDisplay(dpy);
SyncHandle();
if (InitGLXDrawable(dpy, glxDraw, pixmap, req->glxpixmap)) {
free(glxDraw);
return None;
}
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
do {
/* FIXME: Maybe delay __DRIdrawable creation until the drawable
* is actually bound to a context... */
__GLXDRIdrawable *pdraw;
struct glx_screen *psc;
struct glx_config *config;
psc = priv->screens[vis->screen];
if (psc->driScreen == NULL)
return xid;
config = glx_config_find_visual(psc->visuals, vis->visualid);
pdraw = psc->driScreen->createDrawable(psc, pixmap, xid, GLX_PIXMAP_BIT, config);
if (pdraw == NULL) {
fprintf(stderr, "failed to create pixmap\n");
xid = None;
break;
}
if (__glxHashInsert(priv->drawHash, xid, pdraw)) {
(*pdraw->destroyDrawable) (pdraw);
xid = None;
break;
}
} while (0);
if (xid == None) {
xGLXDestroyGLXPixmapReq *dreq;
LockDisplay(dpy);
GetReq(GLXDestroyGLXPixmap, dreq);
dreq->reqType = opcode;
dreq->glxCode = X_GLXDestroyGLXPixmap;
dreq->glxpixmap = xid;
UnlockDisplay(dpy);
SyncHandle();
}
#endif
return xid;
#endif
}
/*
** Destroy the named pixmap
*/
_GLX_PUBLIC void
glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap)
{
#ifdef GLX_USE_APPLEGL
if(apple_glx_pixmap_destroy(dpy, glxpixmap))
__glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false);
#else
xGLXDestroyGLXPixmapReq *req;
CARD8 opcode;
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return;
}
/* Send the glXDestroyGLXPixmap request */
LockDisplay(dpy);
GetReq(GLXDestroyGLXPixmap, req);
req->reqType = opcode;
req->glxCode = X_GLXDestroyGLXPixmap;
req->glxpixmap = glxpixmap;
UnlockDisplay(dpy);
SyncHandle();
DestroyGLXDrawable(dpy, glxpixmap);
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
{
struct glx_display *const priv = __glXInitialize(dpy);
__GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap);
if (priv != NULL && pdraw != NULL) {
(*pdraw->destroyDrawable) (pdraw);
__glxHashDelete(priv->drawHash, glxpixmap);
}
}
#endif
#endif /* GLX_USE_APPLEGL */
}
_GLX_PUBLIC void
glXSwapBuffers(Display * dpy, GLXDrawable drawable)
{
#ifdef GLX_USE_APPLEGL
struct glx_context * gc = __glXGetCurrentContext();
if(gc != &dummyContext && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) {
apple_glx_swap_buffers(gc->driContext);
} else {
__glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
}
#else
struct glx_context *gc;
GLXContextTag tag;
CARD8 opcode;
xcb_connection_t *c;
gc = __glXGetCurrentContext();
#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
{
__GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
if (pdraw != NULL) {
Bool flush = gc != &dummyContext && drawable == gc->currentDrawable;
if (pdraw->psc->driScreen->swapBuffers(pdraw, 0, 0, 0, flush) == -1)
__glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
return;
}
}
#endif
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return;
}
/*
** The calling thread may or may not have a current context. If it
** does, send the context tag so the server can do a flush.
*/
if ((gc != &dummyContext) && (dpy == gc->currentDpy) &&
((drawable == gc->currentDrawable)
|| (drawable == gc->currentReadable))) {
tag = gc->currentContextTag;
}
else {
tag = 0;
}
c = XGetXCBConnection(dpy);
xcb_glx_swap_buffers(c, tag, drawable);
xcb_flush(c);
#endif /* GLX_USE_APPLEGL */
}
/*
** Return configuration information for the given display, screen and
** visual combination.
*/
_GLX_PUBLIC int
glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute,
int *value_return)
{
struct glx_display *priv;
struct glx_screen *psc;
struct glx_config *config;
int status;
status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc);
if (status == Success) {
config = glx_config_find_visual(psc->visuals, vis->visualid);
/* Lookup attribute after first finding a match on the visual */
if (config != NULL) {
return glx_config_get(config, attribute, value_return);
}
status = GLX_BAD_VISUAL;
}
/*
** If we can't find the config for this visual, this visual is not
** supported by the OpenGL implementation on the server.
*/
if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) {
*value_return = False;
status = Success;
}
return status;
}
/************************************************************************/
static void
init_fbconfig_for_chooser(struct glx_config * config,
GLboolean fbconfig_style_tags)
{
memset(config, 0, sizeof(struct glx_config));
config->visualID = (XID) GLX_DONT_CARE;
config->visualType = GLX_DONT_CARE;
/* glXChooseFBConfig specifies different defaults for these properties than
* glXChooseVisual.
*/
if (fbconfig_style_tags) {
config->doubleBufferMode = GLX_DONT_CARE;
config->renderType = GLX_RGBA_BIT;
}
config->drawableType = GLX_WINDOW_BIT;
config->visualRating = GLX_DONT_CARE;
config->transparentPixel = GLX_NONE;
config->transparentRed = GLX_DONT_CARE;
config->transparentGreen = GLX_DONT_CARE;
config->transparentBlue = GLX_DONT_CARE;
config->transparentAlpha = GLX_DONT_CARE;
config->transparentIndex = GLX_DONT_CARE;
config->xRenderable = GLX_DONT_CARE;
config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE);
config->swapMethod = GLX_DONT_CARE;
config->sRGBCapable = GLX_DONT_CARE;
}
#define MATCH_DONT_CARE( param ) \
do { \
if ( ((int) a-> param != (int) GLX_DONT_CARE) \
&& (a-> param != b-> param) ) { \
return False; \
} \
} while ( 0 )
#define MATCH_MINIMUM( param ) \
do { \
if ( ((int) a-> param != (int) GLX_DONT_CARE) \
&& (a-> param > b-> param) ) { \
return False; \
} \
} while ( 0 )
#define MATCH_EXACT( param ) \
do { \
if ( a-> param != b-> param) { \
return False; \
} \
} while ( 0 )
/* Test that all bits from a are contained in b */
#define MATCH_MASK(param) \
do { \
if ( ((int) a-> param != (int) GLX_DONT_CARE) \
&& ((a->param & ~b->param) != 0) ) { \
return False; \
} \
} while (0);
/**
* Determine if two GLXFBConfigs are compatible.
*
* \param a Application specified config to test.
* \param b Server specified config to test against \c a.
*/
static Bool
fbconfigs_compatible(const struct glx_config * const a,
const struct glx_config * const b)