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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
|
/* Copyright (c) 2001, Stanford University
* All rights reserved
*
* See the file LICENSE.txt for information on redistributing this software.
*/
/**
* \mainpage OpenGL_stub
*
* \section OpenGL_stubIntroduction Introduction
*
* Chromium consists of all the top-level files in the cr
* directory. The OpenGL_stub module basically takes care of API dispatch,
* and OpenGL state management.
*
*/
/**
* This file manages OpenGL rendering contexts in the faker library.
* The big issue is switching between Chromium and native GL context
* management. This is where we support multiple client OpenGL
* windows. Typically, one window is handled by Chromium while any
* other windows are handled by the native OpenGL library.
*/
#include "chromium.h"
#include "cr_error.h"
#include "cr_spu.h"
#include "cr_mem.h"
#include "cr_string.h"
#include "cr_environment.h"
#include "stub.h"
/**
* This function should be called from MakeCurrent(). It'll detect if
* we're in a multi-thread situation, and do the right thing for dispatch.
*/
#ifdef CHROMIUM_THREADSAFE
static void
stubCheckMultithread( void )
{
static unsigned long knownID;
static GLboolean firstCall = GL_TRUE;
if (stub.threadSafe)
return; /* nothing new, nothing to do */
if (firstCall) {
knownID = crThreadID();
firstCall = GL_FALSE;
}
else if (knownID != crThreadID()) {
/* going thread-safe now! */
stub.threadSafe = GL_TRUE;
crSPUCopyDispatchTable(&glim, &stubThreadsafeDispatch);
}
}
#endif
/**
* Install the given dispatch table as the table used for all gl* calls.
*/
static void
stubSetDispatch( SPUDispatchTable *table )
{
CRASSERT(table);
#ifdef CHROMIUM_THREADSAFE
/* always set the per-thread dispatch pointer */
crSetTSD(&stub.dispatchTSD, (void *) table);
if (stub.threadSafe) {
/* Do nothing - the thread-safe dispatch functions will call GetTSD()
* to get a pointer to the dispatch table, and jump through it.
*/
}
else
#endif
{
/* Single thread mode - just install the caller's dispatch table */
/* This conditional is an optimization to try to avoid unnecessary
* copying. It seems to work with atlantis, multiwin, etc. but
* _could_ be a problem. (Brian)
*/
if (glim.copy_of != table->copy_of)
crSPUCopyDispatchTable(&glim, table);
}
}
void stubForcedFlush(GLint con)
{
#if 0
GLint buffer;
stub.spu->dispatch_table.GetIntegerv(GL_DRAW_BUFFER, &buffer);
stub.spu->dispatch_table.DrawBuffer(GL_FRONT);
stub.spu->dispatch_table.Flush();
stub.spu->dispatch_table.DrawBuffer(buffer);
#else
if (con)
{
stub.spu->dispatch_table.VBoxConFlush(con);
}
else
{
stub.spu->dispatch_table.Flush();
}
#endif
}
void stubConChromiumParameteriCR(GLint con, GLenum param, GLint value)
{
// if (con)
stub.spu->dispatch_table.VBoxConChromiumParameteriCR(con, param, value);
// else
// crError("VBoxConChromiumParameteriCR called with null connection");
}
void stubConChromiumParametervCR(GLint con, GLenum target, GLenum type, GLsizei count, const GLvoid *values)
{
// if (con)
stub.spu->dispatch_table.VBoxConChromiumParametervCR(con, target, type, count, values);
// else
// crError("VBoxConChromiumParameteriCR called with null connection");
}
void stubConFlush(GLint con)
{
if (con)
stub.spu->dispatch_table.VBoxConFlush(con);
else
crError("stubConFlush called with null connection");
}
static void stubWindowCleanupForContextsCB(unsigned long key, void *data1, void *data2)
{
ContextInfo *context = (ContextInfo *) data1;
RT_NOREF(key);
CRASSERT(context);
if (context->currentDrawable == data2)
context->currentDrawable = NULL;
}
void stubDestroyWindow( GLint con, GLint window )
{
WindowInfo *winInfo = (WindowInfo *)
crHashtableSearch(stub.windowTable, (unsigned int) window);
if (winInfo && winInfo->type == CHROMIUM && stub.spu)
{
crHashtableLock(stub.windowTable);
stub.spu->dispatch_table.VBoxWindowDestroy(con, winInfo->spuWindow );
#ifdef WINDOWS
if (winInfo->hVisibleRegion != INVALID_HANDLE_VALUE)
{
DeleteObject(winInfo->hVisibleRegion);
}
#elif defined(GLX)
if (winInfo->pVisibleRegions)
{
XFree(winInfo->pVisibleRegions);
}
# ifdef CR_NEWWINTRACK
if (winInfo->syncDpy)
{
XCloseDisplay(winInfo->syncDpy);
}
# endif
#endif
stubForcedFlush(con);
crHashtableWalk(stub.contextTable, stubWindowCleanupForContextsCB, winInfo);
crHashtableDelete(stub.windowTable, window, crFree);
crHashtableUnlock(stub.windowTable);
}
}
/**
* Create a new _Chromium_ window, not GLX, WGL or CGL.
* Called by crWindowCreate() only.
*/
GLint
stubNewWindow( const char *dpyName, GLint visBits )
{
WindowInfo *winInfo;
GLint spuWin, size[2];
spuWin = stub.spu->dispatch_table.WindowCreate( dpyName, visBits );
if (spuWin < 0) {
return -1;
}
winInfo = (WindowInfo *) crCalloc(sizeof(WindowInfo));
if (!winInfo) {
stub.spu->dispatch_table.WindowDestroy(spuWin);
return -1;
}
winInfo->type = CHROMIUM;
/* Ask the head SPU for the initial window size */
size[0] = size[1] = 0;
stub.spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, 0, GL_INT, 2, size);
if (size[0] == 0 && size[1] == 0) {
/* use some reasonable defaults */
size[0] = size[1] = 512;
}
winInfo->width = size[0];
winInfo->height = size[1];
#ifdef VBOX_WITH_WDDM
if (stub.bRunningUnderWDDM)
{
crError("Should not be here: WindowCreate/Destroy & VBoxPackGetInjectID require connection id!");
winInfo->mapped = 0;
}
else
#endif
{
winInfo->mapped = 1;
}
if (!dpyName)
dpyName = "";
crStrncpy(winInfo->dpyName, dpyName, MAX_DPY_NAME);
winInfo->dpyName[MAX_DPY_NAME-1] = 0;
/* Use spuWin as the hash table index and GLX/WGL handle */
#ifdef WINDOWS
winInfo->drawable = (HDC) spuWin;
winInfo->hVisibleRegion = INVALID_HANDLE_VALUE;
#elif defined(Darwin)
winInfo->drawable = (CGSWindowID) spuWin;
#elif defined(GLX)
winInfo->drawable = (GLXDrawable) spuWin;
winInfo->pVisibleRegions = NULL;
winInfo->cVisibleRegions = 0;
#endif
#ifdef CR_NEWWINTRACK
winInfo->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID(0);
#endif
winInfo->spuWindow = spuWin;
crHashtableAdd(stub.windowTable, (unsigned int) spuWin, winInfo);
return spuWin;
}
#ifdef GLX
# if 0 /* unused */
static XErrorHandler oldErrorHandler;
static unsigned char lastXError = Success;
static int
errorHandler (Display *dpy, XErrorEvent *e)
{
RT_NOREF(dpy);
lastXError = e->error_code;
return 0;
}
# endif /* unused */
#endif
GLboolean
stubIsWindowVisible(WindowInfo *win)
{
#if defined(WINDOWS)
# ifdef VBOX_WITH_WDDM
if (stub.bRunningUnderWDDM)
return win->mapped;
# endif
return GL_TRUE;
#elif defined(Darwin)
return GL_TRUE;
#elif defined(GLX)
Display *dpy = stubGetWindowDisplay(win);
if (dpy)
{
XWindowAttributes attr;
XLOCK(dpy);
XGetWindowAttributes(dpy, win->drawable, &attr);
XUNLOCK(dpy);
if (attr.map_state == IsUnmapped)
{
return GL_FALSE;
}
# if 1
return GL_TRUE;
# else
if (attr.override_redirect)
{
return GL_TRUE;
}
if (!stub.bXExtensionsChecked)
{
stubCheckXExtensions(win);
}
if (!stub.bHaveXComposite)
{
return GL_TRUE;
}
else
{
Pixmap p;
crLockMutex(&stub.mutex);
XLOCK(dpy);
XSync(dpy, false);
oldErrorHandler = XSetErrorHandler(errorHandler);
/** @todo this will create new pixmap for window every call*/
p = XCompositeNameWindowPixmap(dpy, win->drawable);
XSync(dpy, false);
XSetErrorHandler(oldErrorHandler);
XUNLOCK(dpy);
switch (lastXError)
{
case Success:
XFreePixmap(dpy, p);
crUnlockMutex(&stub.mutex);
return GL_FALSE;
break;
case BadMatch:
/*Window isn't redirected*/
lastXError = Success;
break;
default:
crWarning("Unexpected XError %i", (int)lastXError);
lastXError = Success;
}
crUnlockMutex(&stub.mutex);
return GL_TRUE;
}
# endif
}
else {
/* probably created by crWindowCreate() */
return win->mapped;
}
#endif
}
/**
* Given a Windows HDC or GLX Drawable, return the corresponding
* WindowInfo structure. Create a new one if needed.
*/
WindowInfo *
#ifdef WINDOWS
stubGetWindowInfo( HDC drawable )
#elif defined(Darwin)
stubGetWindowInfo( CGSWindowID drawable )
#elif defined(GLX)
stubGetWindowInfo( Display *dpy, GLXDrawable drawable )
#endif
{
#ifndef WINDOWS
WindowInfo *winInfo = (WindowInfo *) crHashtableSearch(stub.windowTable, (unsigned int) drawable);
#else
WindowInfo *winInfo;
HWND hwnd;
hwnd = WindowFromDC(drawable);
if (!hwnd)
{
return NULL;
}
winInfo = (WindowInfo *) crHashtableSearch(stub.windowTable, (unsigned int) hwnd);
#endif
if (!winInfo) {
winInfo = (WindowInfo *) crCalloc(sizeof(WindowInfo));
if (!winInfo)
return NULL;
#ifdef GLX
crStrncpy(winInfo->dpyName, DisplayString(dpy), MAX_DPY_NAME);
winInfo->dpyName[MAX_DPY_NAME-1] = 0;
winInfo->dpy = dpy;
winInfo->pVisibleRegions = NULL;
#elif defined(Darwin)
winInfo->connection = _CGSDefaultConnection(); // store our connection as default
#elif defined(WINDOWS)
winInfo->hVisibleRegion = INVALID_HANDLE_VALUE;
winInfo->hWnd = hwnd;
#endif
winInfo->drawable = drawable;
winInfo->type = UNDECIDED;
winInfo->spuWindow = -1;
#ifdef VBOX_WITH_WDDM
if (stub.bRunningUnderWDDM)
winInfo->mapped = 0;
else
#endif
{
winInfo->mapped = -1; /* don't know */
}
winInfo->pOwner = NULL;
#ifdef CR_NEWWINTRACK
winInfo->u32ClientID = -1;
#endif
#ifndef WINDOWS
crHashtableAdd(stub.windowTable, (unsigned int) drawable, winInfo);
#else
crHashtableAdd(stub.windowTable, (unsigned int) hwnd, winInfo);
#endif
}
#ifdef WINDOWS
else
{
winInfo->drawable = drawable;
}
#endif
return winInfo;
}
static void stubWindowCheckOwnerCB(unsigned long key, void *data1, void *data2);
static void
stubContextFree( ContextInfo *context )
{
crMemZero(context, sizeof(ContextInfo)); /* just to be safe */
crFree(context);
}
static void
stubDestroyContextLocked( ContextInfo *context )
{
unsigned long contextId = context->id;
if (context->type == NATIVE) {
#ifdef WINDOWS
stub.wsInterface.wglDeleteContext( context->hglrc );
#elif defined(Darwin)
stub.wsInterface.CGLDestroyContext( context->cglc );
#elif defined(GLX)
stub.wsInterface.glXDestroyContext( context->dpy, context->glxContext );
#endif
}
else if (context->type == CHROMIUM) {
/* Have pack SPU or tilesort SPU, etc. destroy the context */
CRASSERT(context->spuContext >= 0);
stub.spu->dispatch_table.DestroyContext( context->spuContext );
crHashtableWalk(stub.windowTable, stubWindowCheckOwnerCB, context);
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
if (context->spuConnection)
{
stub.spu->dispatch_table.VBoxConDestroy(context->spuConnection);
context->spuConnection = 0;
}
#endif
}
#ifdef GLX
crFreeHashtable(context->pGLXPixmapsHash, crFree);
#endif
crHashtableDelete(stub.contextTable, contextId, NULL);
}
#ifdef CHROMIUM_THREADSAFE
static DECLCALLBACK(void) stubContextDtor(void*pvContext)
{
stubContextFree((ContextInfo*)pvContext);
}
#endif
/**
* Allocate a new ContextInfo object, initialize it, put it into the
* context hash table. If type==CHROMIUM, call the head SPU's
* CreateContext() function too.
*/
ContextInfo *
stubNewContext(char *dpyName, GLint visBits, ContextType type, unsigned long shareCtx
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
, struct VBOXUHGSMI *pHgsmi
#endif
)
{
GLint spuContext = -1, spuShareCtx = 0, spuConnection = 0;
ContextInfo *context;
if (shareCtx > 0) {
/* translate shareCtx to a SPU context ID */
context = (ContextInfo *)
crHashtableSearch(stub.contextTable, shareCtx);
if (context)
spuShareCtx = context->spuContext;
}
if (type == CHROMIUM) {
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
if (pHgsmi)
{
spuConnection = stub.spu->dispatch_table.VBoxConCreate(pHgsmi);
if (!spuConnection)
{
crWarning("VBoxConCreate failed");
return NULL;
}
}
#endif
spuContext
= stub.spu->dispatch_table.VBoxCreateContext(spuConnection, dpyName, visBits, spuShareCtx);
if (spuContext < 0)
{
crWarning("VBoxCreateContext failed");
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
if (spuConnection)
stub.spu->dispatch_table.VBoxConDestroy(spuConnection);
#endif
return NULL;
}
}
context = crCalloc(sizeof(ContextInfo));
if (!context) {
stub.spu->dispatch_table.DestroyContext(spuContext);
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
if (spuConnection)
stub.spu->dispatch_table.VBoxConDestroy(spuConnection);
#endif
return NULL;
}
if (!dpyName)
dpyName = "";
context->id = stub.freeContextNumber++;
context->type = type;
context->spuContext = spuContext;
context->visBits = visBits;
context->currentDrawable = NULL;
crStrncpy(context->dpyName, dpyName, MAX_DPY_NAME);
context->dpyName[MAX_DPY_NAME-1] = 0;
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
context->spuConnection = spuConnection;
context->pHgsmi = pHgsmi;
#endif
#ifdef CHROMIUM_THREADSAFE
VBoxTlsRefInit(context, stubContextDtor);
#endif
#if defined(GLX) || defined(DARWIN)
context->share = (ContextInfo *)
crHashtableSearch(stub.contextTable, (unsigned long) shareCtx);
#endif
#ifdef GLX
context->pGLXPixmapsHash = crAllocHashtable();
context->damageQueryFailed = GL_FALSE;
context->damageEventsBase = 0;
#endif
crHashtableAdd(stub.contextTable, context->id, (void *) context);
return context;
}
#ifdef Darwin
#define SET_ATTR(l,i,a) ( (l)[(i)++] = (a) )
#define SET_ATTR_V(l,i,a,v) ( SET_ATTR(l,i,a), SET_ATTR(l,i,v) )
void stubSetPFA( ContextInfo *ctx, CGLPixelFormatAttribute *attribs, int size, GLint *num ) {
GLuint visual = ctx->visBits;
int i = 0;
CRASSERT(visual & CR_RGB_BIT);
SET_ATTR_V(attribs, i, kCGLPFAColorSize, 8);
if( visual & CR_DEPTH_BIT )
SET_ATTR_V(attribs, i, kCGLPFADepthSize, 16);
if( visual & CR_ACCUM_BIT )
SET_ATTR_V(attribs, i, kCGLPFAAccumSize, 1);
if( visual & CR_STENCIL_BIT )
SET_ATTR_V(attribs, i, kCGLPFAStencilSize, 1);
if( visual & CR_ALPHA_BIT )
SET_ATTR_V(attribs, i, kCGLPFAAlphaSize, 1);
if( visual & CR_DOUBLE_BIT )
SET_ATTR(attribs, i, kCGLPFADoubleBuffer);
if( visual & CR_STEREO_BIT )
SET_ATTR(attribs, i, kCGLPFAStereo);
/* SET_ATTR_V(attribs, i, kCGLPFASampleBuffers, 1);
SET_ATTR_V(attribs, i, kCGLPFASamples, 0);
SET_ATTR_V(attribs, i, kCGLPFADisplayMask, 0); */
SET_ATTR(attribs, i, kCGLPFABackingStore);
//SET_ATTR(attribs, i, kCGLPFAWindow); // kCGLPFAWindow deprecated starting from OSX 10.7
SET_ATTR_V(attribs, i, kCGLPFADisplayMask, ctx->disp_mask);
SET_ATTR(attribs, i, 0);
*num = i;
}
#endif
#ifndef GLX
/**
* This creates a native GLX/WGL context.
*/
static GLboolean
InstantiateNativeContext( WindowInfo *window, ContextInfo *context )
{
#ifdef WINDOWS
context->hglrc = stub.wsInterface.wglCreateContext( window->drawable );
return context->hglrc ? GL_TRUE : GL_FALSE;
#elif defined(Darwin)
CGLContextObj shareCtx = NULL;
CGLPixelFormatObj pix;
long npix;
CGLPixelFormatAttribute attribs[16];
GLint ind = 0;
if( context->share ) {
if( context->cglc != context->share->cglc ) {
crWarning("CGLCreateContext() is trying to share a non-existant "
"CGL context. Setting share context to zero.");
shareCtx = 0;
}
else
shareCtx = context->cglc;
}
stubSetPFA( context, attribs, 16, &ind );
stub.wsInterface.CGLChoosePixelFormat( attribs, &pix, &npix );
stub.wsInterface.CGLCreateContext( pix, shareCtx, &context->cglc );
if( !context->cglc )
crError("InstantiateNativeContext: Couldn't Create the context!");
stub.wsInterface.CGLDestroyPixelFormat( pix );
if( context->parambits ) {
/* Set the delayed parameters */
if( context->parambits & VISBIT_SWAP_RECT )
stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPSwapRectangle, context->swap_rect );
if( context->parambits & VISBIT_SWAP_INTERVAL )
stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPSwapInterval, &(context->swap_interval) );
if( context->parambits & VISBIT_CLIENT_STORAGE )
stub.wsInterface.CGLSetParameter( context->cglc, kCGLCPClientStorage, (long*)&(context->client_storage) );
context->parambits = 0;
}
return context->cglc ? GL_TRUE : GL_FALSE;
#elif defined(GLX)
GLXContext shareCtx = 0;
/* sort out context sharing here */
if (context->share) {
if (context->glxContext != context->share->glxContext) {
crWarning("glXCreateContext() is trying to share a non-existant "
"GLX context. Setting share context to zero.");
shareCtx = 0;
}
else {
shareCtx = context->glxContext;
}
}
context->glxContext = stub.wsInterface.glXCreateContext( window->dpy,
context->visual, shareCtx, context->direct );
return context->glxContext ? GL_TRUE : GL_FALSE;
#endif
}
#endif /* !GLX */
/**
* Utility functions to get window size and titlebar text.
*/
#ifdef WINDOWS
void
stubGetWindowGeometry(WindowInfo *window, int *x, int *y,
unsigned int *w, unsigned int *h )
{
RECT rect;
if (!window->drawable || !window->hWnd) {
*w = *h = 0;
return;
}
if (window->hWnd!=WindowFromDC(window->drawable))
{
crWarning("Window(%i) DC is no longer valid", window->spuWindow);
return;
}
if (!GetClientRect(window->hWnd, &rect))
{
crWarning("GetClientRect failed for %p", window->hWnd);
*w = *h = 0;
return;
}
*w = rect.right - rect.left;
*h = rect.bottom - rect.top;
if (!ClientToScreen( window->hWnd, (LPPOINT) &rect ))
{
crWarning("ClientToScreen failed for %p", window->hWnd);
*w = *h = 0;
return;
}
*x = rect.left;
*y = rect.top;
}
static void
GetWindowTitle( const WindowInfo *window, char *title )
{
/* XXX - we don't handle recurseUp */
if (window->hWnd)
GetWindowText(window->hWnd, title, 100);
else
title[0] = 0;
}
static void
GetCursorPosition(WindowInfo *window, int pos[2])
{
RECT rect;
POINT point;
GLint size[2], x, y;
unsigned int NativeHeight, NativeWidth, ChromiumHeight, ChromiumWidth;
float WidthRatio, HeightRatio;
static int DebugFlag = 0;
// apparently the "window" parameter passed to this
// function contains the native window information
HWND NATIVEhwnd = window->hWnd;
if (NATIVEhwnd!=WindowFromDC(window->drawable))
{
crWarning("Window(%i) DC is no longer valid", window->spuWindow);
return;
}
// get the native window's height and width
stubGetWindowGeometry(window, &x, &y, &NativeWidth, &NativeHeight);
// get the spu window's height and width
stub.spu->dispatch_table.GetChromiumParametervCR(GL_WINDOW_SIZE_CR, window->spuWindow, GL_INT, 2, size);
ChromiumWidth = size[0];
ChromiumHeight = size[1];
// get the ratio of the size of the native window to the cr window
WidthRatio = (float)ChromiumWidth / (float)NativeWidth;
HeightRatio = (float)ChromiumHeight / (float)NativeHeight;
// output some debug information at the beginning
if(DebugFlag)
{
DebugFlag = 0;
crDebug("Native Window Handle = %d", NATIVEhwnd);
crDebug("Native Width = %i", NativeWidth);
crDebug("Native Height = %i", NativeHeight);
crDebug("Chromium Width = %i", ChromiumWidth);
crDebug("Chromium Height = %i", ChromiumHeight);
}
if (NATIVEhwnd)
{
GetClientRect( NATIVEhwnd, &rect );
GetCursorPos (&point);
// make sure these coordinates are relative to the native window,
// not the whole desktop
ScreenToClient(NATIVEhwnd, &point);
// calculate the new position of the virtual cursor
pos[0] = (int)(point.x * WidthRatio);
pos[1] = (int)((NativeHeight - point.y) * HeightRatio);
}
else
{
pos[0] = 0;
pos[1] = 0;
}
}
#elif defined(Darwin)
extern OSStatus CGSGetScreenRectForWindow( CGSConnectionID cid, CGSWindowID wid, float *outRect );
extern OSStatus CGSGetWindowBounds( CGSConnectionID cid, CGSWindowID wid, float *bounds );
void
stubGetWindowGeometry( const WindowInfo *window, int *x, int *y, unsigned int *w, unsigned int *h )
{
float rect[4];
if( !window ||
!window->connection ||
!window->drawable ||
CGSGetWindowBounds( window->connection, window->drawable, rect ) != noErr )
{
*x = *y = 0;
*w = *h = 0;
} else {
*x = (int) rect[0];
*y = (int) rect[1];
*w = (int) rect[2];
*h = (int) rect[3];
}
}
static void
GetWindowTitle( const WindowInfo *window, char *title )
{
/* XXX \todo Darwin window Title */
title[0] = '\0';
}
static void
GetCursorPosition( const WindowInfo *window, int pos[2] )
{
Point mouse_pos;
float window_rect[4];
GetMouse( &mouse_pos );
CGSGetScreenRectForWindow( window->connection, window->drawable, window_rect );
pos[0] = mouse_pos.h - (int) window_rect[0];
pos[1] = (int) window_rect[3] - (mouse_pos.v - (int) window_rect[1]);
/*crDebug( "%i %i", pos[0], pos[1] );*/
}
#elif defined(GLX)
void
stubGetWindowGeometry(WindowInfo *window, int *x, int *y, unsigned int *w, unsigned int *h)
{
Window root, child;
unsigned int border, depth;
Display *dpy;
dpy = stubGetWindowDisplay(window);
/// @todo Performing those checks is expensive operation, especially for simple apps with high FPS.
// Disabling those triples glxgears fps, thus using xevents instead of per frame polling is much more preferred.
/// @todo Check similar on windows guests, though doubtful as there're no XSync like calls on windows.
if (window && dpy)
{
XLOCK(dpy);
}
if (!window
|| !dpy
|| !window->drawable
|| !XGetGeometry(dpy, window->drawable, &root, x, y, w, h, &border, &depth)
|| !XTranslateCoordinates(dpy, window->drawable, root, 0, 0, x, y, &child))
{
crWarning("Failed to get windows geometry for %p, try xwininfo", window);
*x = *y = 0;
*w = *h = 0;
}
if (window && dpy)
{
XUNLOCK(dpy);
}
}
static char *
GetWindowTitleHelper( Display *dpy, Window window, GLboolean recurseUp )
{
while (1) {
char *name;
if (!XFetchName(dpy, window, &name))
return NULL;
if (name[0]) {
return name;
}
else if (recurseUp) {
/* This window has no name, try the parent */
Status stat;
Window root, parent, *children;
unsigned int numChildren;
stat = XQueryTree( dpy, window, &root, &parent,
&children, &numChildren );
if (!stat || window == root)
return NULL;
if (children)
XFree(children);
window = parent;
}
else {
XFree(name);
return NULL;
}
}
}
static void
GetWindowTitle( const WindowInfo *window, char *title )
{
char *t = GetWindowTitleHelper(window->dpy, window->drawable, GL_TRUE);
if (t) {
crStrcpy(title, t);
XFree(t);
}
else {
title[0] = 0;
}
}
/**
*Return current cursor position in local window coords.
*/
static void
GetCursorPosition(WindowInfo *window, int pos[2] )
{
int rootX, rootY;
Window root, child;
unsigned int mask;
int x, y;
XLOCK(window->dpy);
Bool q = XQueryPointer(window->dpy, window->drawable, &root, &child,
&rootX, &rootY, &pos[0], &pos[1], &mask);
if (q) {
unsigned int w, h;
stubGetWindowGeometry( window, &x, &y, &w, &h );
/* invert Y */
pos[1] = (int) h - pos[1] - 1;
}
else {
pos[0] = pos[1] = 0;
}
XUNLOCK(window->dpy);
}
#endif
/**
* This function is called by MakeCurrent() and determines whether or
* not a new rendering context should be bound to Chromium or the native
* OpenGL.
* \return GL_FALSE if native OpenGL should be used, or GL_TRUE if Chromium
* should be used.
*/
static GLboolean
stubCheckUseChromium( WindowInfo *window )
{
int x, y;
unsigned int w, h;
/* If the provided window is CHROMIUM, we're clearly intended
* to create a CHROMIUM context.
*/
if (window->type == CHROMIUM)
return GL_TRUE;
if (stub.ignoreFreeglutMenus) {
const char *glutMenuTitle = "freeglut menu";
char title[1000];
GetWindowTitle(window, title);
if (crStrcmp(title, glutMenuTitle) == 0) {
crDebug("GL faker: Ignoring freeglut menu window");
return GL_FALSE;
}
}
/* If the user's specified a window count for Chromium, see if
* this window satisfies that criterium.
*/
stub.matchChromiumWindowCounter++;
if (stub.matchChromiumWindowCount > 0) {
if (stub.matchChromiumWindowCounter != stub.matchChromiumWindowCount) {
crDebug("Using native GL, app window doesn't meet match_window_count");
return GL_FALSE;
}
}
/* If the user's specified a window list to ignore, see if this
* window satisfies that criterium.
*/
if (stub.matchChromiumWindowID) {
GLuint i;
for (i = 0; i <= stub.numIgnoreWindowID; i++) {
if (stub.matchChromiumWindowID[i] == stub.matchChromiumWindowCounter) {
crDebug("Ignore window ID %d, using native GL", stub.matchChromiumWindowID[i]);
return GL_FALSE;
}
}
}
/* If the user's specified a minimum window size for Chromium, see if
* this window satisfies that criterium.
*/
if (stub.minChromiumWindowWidth > 0 &&
stub.minChromiumWindowHeight > 0) {
stubGetWindowGeometry( window, &x, &y, &w, &h );
if (w >= stub.minChromiumWindowWidth &&
h >= stub.minChromiumWindowHeight) {
/* Check for maximum sized window now too */
if (stub.maxChromiumWindowWidth &&
stub.maxChromiumWindowHeight) {
if (w < stub.maxChromiumWindowWidth &&
h < stub.maxChromiumWindowHeight)
return GL_TRUE;
else
return GL_FALSE;
}
return GL_TRUE;
}
crDebug("Using native GL, app window doesn't meet minimum_window_size");
return GL_FALSE;
}
else if (stub.matchWindowTitle) {
/* If the user's specified a window title for Chromium, see if this
* window satisfies that criterium.
*/
GLboolean wildcard = GL_FALSE;
char title[1000];
char *titlePattern;
int len;
/* check for leading '*' wildcard */
if (stub.matchWindowTitle[0] == '*') {
titlePattern = crStrdup( stub.matchWindowTitle + 1 );
wildcard = GL_TRUE;
}
else {
titlePattern = crStrdup( stub.matchWindowTitle );
}
/* check for trailing '*' wildcard */
len = crStrlen(titlePattern);
if (len > 0 && titlePattern[len - 1] == '*') {
titlePattern[len - 1] = '\0'; /* terminate here */
wildcard = GL_TRUE;
}
GetWindowTitle( window, title );
if (title[0]) {
if (wildcard) {
if (crStrstr(title, titlePattern)) {
crFree(titlePattern);
return GL_TRUE;
}
}
else if (crStrcmp(title, titlePattern) == 0) {
crFree(titlePattern);
return GL_TRUE;
}
}
crFree(titlePattern);
crDebug("Using native GL, app window title doesn't match match_window_title string (\"%s\" != \"%s\")", title, stub.matchWindowTitle);
return GL_FALSE;
}
/* Window title and size don't matter */
CRASSERT(stub.minChromiumWindowWidth == 0);
CRASSERT(stub.minChromiumWindowHeight == 0);
CRASSERT(stub.matchWindowTitle == NULL);
/* User hasn't specified a width/height or window title.
* We'll use chromium for this window (and context) if no other is.
*/
return GL_TRUE; /* use Chromium! */
}
static void stubWindowCheckOwnerCB(unsigned long key, void *data1, void *data2)
{
WindowInfo *pWindow = (WindowInfo *) data1;
ContextInfo *pCtx = (ContextInfo *) data2;
RT_NOREF(key);
if (pWindow->pOwner == pCtx)
{
#ifdef WINDOWS
/* Note: can't use WindowFromDC(context->pOwnWindow->drawable) here
because GL context is already released from DC and actual guest window
could be destroyed.
*/
stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->hWnd);
#else
stubDestroyWindow(CR_CTX_CON(pCtx), (GLint)pWindow->drawable);
#endif
}
}
GLboolean stubCtxCreate(ContextInfo *context)
{
/*
* Create a Chromium context.
*/
#if defined(GLX) || defined(DARWIN)
GLint spuShareCtx = context->share ? context->share->spuContext : 0;
#else
GLint spuShareCtx = 0;
#endif
GLint spuConnection = 0;
CRASSERT(stub.spu);
CRASSERT(stub.spu->dispatch_table.CreateContext);
context->type = CHROMIUM;
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
if (context->pHgsmi)
{
spuConnection = stub.spu->dispatch_table.VBoxConCreate(context->pHgsmi);
if (!spuConnection)
{
crError("VBoxConCreate failed");
return GL_FALSE;
}
context->spuConnection = spuConnection;
}
#endif
context->spuContext
= stub.spu->dispatch_table.VBoxCreateContext(spuConnection, context->dpyName,
context->visBits,
spuShareCtx);
return GL_TRUE;
}
GLboolean stubCtxCheckCreate(ContextInfo *context)
{
if (context->type == UNDECIDED)
return stubCtxCreate(context);
return CHROMIUM == context->type;
}
GLboolean
stubMakeCurrent( WindowInfo *window, ContextInfo *context )
{
GLboolean retVal = GL_FALSE;
/*
* Get WindowInfo and ContextInfo pointers.
*/
if (!context || !window) {
ContextInfo * currentContext = stubGetCurrentContext();
if (currentContext)
currentContext->currentDrawable = NULL;
if (context)
context->currentDrawable = NULL;
stubSetCurrentContext(NULL);
return GL_TRUE; /* OK */
}
#ifdef CHROMIUM_THREADSAFE
stubCheckMultithread();
#endif
if (context->type == UNDECIDED) {
/* Here's where we really create contexts */
#ifdef CHROMIUM_THREADSAFE
crLockMutex(&stub.mutex);
#endif
if (stubCheckUseChromium(window)) {
GLint spuConnection = 0;
if (!stubCtxCreate(context))
{
crWarning("stubCtxCreate failed");
return GL_FALSE;
}
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
spuConnection = context->spuConnection;
#endif
if (window->spuWindow == -1)
{
/*crDebug("(1)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/
window->spuWindow = stub.spu->dispatch_table.VBoxWindowCreate(spuConnection, window->dpyName, context->visBits );
#ifdef CR_NEWWINTRACK
window->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID(spuConnection);
#endif
}
}
#ifndef GLX
else {
/*
* Create a native OpenGL context.
*/
if (!InstantiateNativeContext(window, context))
{
# ifdef CHROMIUM_THREADSAFE
crUnlockMutex(&stub.mutex);
# endif
return 0; /* false */
}
context->type = NATIVE;
}
#endif /* !GLX */
#ifdef CHROMIUM_THREADSAFE
crUnlockMutex(&stub.mutex);
#endif
}
if (context->type == NATIVE) {
/*
* Native OpenGL MakeCurrent().
*/
#ifdef WINDOWS
retVal = (GLboolean) stub.wsInterface.wglMakeCurrent( window->drawable, context->hglrc );
#elif defined(Darwin)
// XXX \todo We need to differentiate between these two..
retVal = ( stub.wsInterface.CGLSetSurface(context->cglc, window->connection, window->drawable, window->surface) == noErr );
retVal = ( stub.wsInterface.CGLSetCurrentContext(context->cglc) == noErr );
#elif defined(GLX)
retVal = (GLboolean) stub.wsInterface.glXMakeCurrent( window->dpy, window->drawable, context->glxContext );
#endif
}
else {
/*
* SPU chain MakeCurrent().
*/
CRASSERT(context->type == CHROMIUM);
CRASSERT(context->spuContext >= 0);
/*if (context->currentDrawable && context->currentDrawable != window)
crDebug("Rebinding context %p to a different window", context);*/
if (window->type == NATIVE) {
crWarning("Can't rebind a chromium context to a native window\n");
retVal = 0;
}
else {
if (window->spuWindow == -1)
{
/*crDebug("(2)stubMakeCurrent ctx=%p(%i) window=%p(%i)", context, context->spuContext, window, window->spuWindow);*/
window->spuWindow = stub.spu->dispatch_table.VBoxWindowCreate(
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
context->spuConnection,
#else
0,
#endif
window->dpyName, context->visBits );
#ifdef CR_NEWWINTRACK
window->u32ClientID = stub.spu->dispatch_table.VBoxPackGetInjectID(
# if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
context->spuConnection
# else
0
# endif
);
#endif
if (context->currentDrawable && context->currentDrawable->type==CHROMIUM
&& context->currentDrawable->pOwner==context)
{
#ifdef WINDOWS
if (context->currentDrawable->hWnd!=WindowFromDC(context->currentDrawable->drawable))
{
stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->hWnd);
}
#else
Window root;
int x, y;
unsigned int border, depth, w, h;
XLOCK(context->currentDrawable->dpy);
if (!XGetGeometry(context->currentDrawable->dpy, context->currentDrawable->drawable, &root, &x, &y, &w, &h, &border, &depth))
{
stubDestroyWindow(CR_CTX_CON(context), (GLint)context->currentDrawable->drawable);
}
XUNLOCK(context->currentDrawable->dpy);
#endif
}
}
if (window->spuWindow != (GLint)window->drawable)
stub.spu->dispatch_table.MakeCurrent( window->spuWindow, (GLint) window->drawable, context->spuContext );
else
stub.spu->dispatch_table.MakeCurrent( window->spuWindow, 0, /* native window handle */ context->spuContext );
retVal = 1;
}
}
window->type = context->type;
window->pOwner = context;
context->currentDrawable = window;
stubSetCurrentContext(context);
if (retVal) {
/* Now, if we've transitions from Chromium to native rendering, or
* vice versa, we have to change all the OpenGL entrypoint pointers.
*/
if (context->type == NATIVE) {
/* Switch to native API */
/*printf(" Switching to native API\n");*/
stubSetDispatch(&stub.nativeDispatch);
}
else if (context->type == CHROMIUM) {
/* Switch to stub (SPU) API */
/*printf(" Switching to spu API\n");*/
stubSetDispatch(&stub.spuDispatch);
}
else {
/* no API switch needed */
}
}
if (!window->width && window->type == CHROMIUM) {
/* One time window setup */
int x, y;
unsigned int winW, winH;
stubGetWindowGeometry( window, &x, &y, &winW, &winH );
/* If we're not using GLX/WGL (no app window) we'll always get
* a width and height of zero here. In that case, skip the viewport
* call since we're probably using a tilesort SPU with fake_window_dims
* which the tilesort SPU will use for the viewport.
*/
window->width = winW;
window->height = winH;
#if defined(WINDOWS) && defined(VBOX_WITH_WDDM)
if (stubIsWindowVisible(window))
#endif
{
if (stub.trackWindowSize)
stub.spuDispatch.WindowSize( window->spuWindow, winW, winH );
if (stub.trackWindowPos)
stub.spuDispatch.WindowPosition(window->spuWindow, x, y);
if (winW > 0 && winH > 0)
stub.spu->dispatch_table.Viewport( 0, 0, winW, winH );
}
#ifdef VBOX_WITH_WDDM
if (stub.trackWindowVisibleRgn)
stub.spu->dispatch_table.WindowVisibleRegion(window->spuWindow, 0, NULL);
#endif
}
/* Update window mapping state.
* Basically, this lets us hide render SPU windows which correspond
* to unmapped application windows. Without this, "pertly" (for example)
* opens *lots* of temporary windows which otherwise clutter the screen.
*/
if (stub.trackWindowVisibility && window->type == CHROMIUM && window->drawable) {
const int mapped = stubIsWindowVisible(window);
if (mapped != window->mapped) {
crDebug("Dispatched: WindowShow(%i, %i)", window->spuWindow, mapped);
stub.spu->dispatch_table.WindowShow(window->spuWindow, mapped);
window->mapped = mapped;
}
}
return retVal;
}
void
stubDestroyContext( unsigned long contextId )
{
ContextInfo *context;
if (!stub.contextTable) {
return;
}
/* the lock order is windowTable->contextTable (see wglMakeCurrent_prox, glXMakeCurrent)
* this is why we need to take a windowTable lock since we will later do stub.windowTable access & locking */
crHashtableLock(stub.windowTable);
crHashtableLock(stub.contextTable);
context = (ContextInfo *) crHashtableSearch(stub.contextTable, contextId);
if (context)
stubDestroyContextLocked(context);
else
crError("No context.");
#ifdef CHROMIUM_THREADSAFE
if (stubGetCurrentContext() == context) {
stubSetCurrentContext(NULL);
}
VBoxTlsRefMarkDestroy(context);
VBoxTlsRefRelease(context);
#else
if (stubGetCurrentContext() == context) {
stubSetCurrentContext(NULL);
}
stubContextFree(context);
#endif
crHashtableUnlock(stub.contextTable);
crHashtableUnlock(stub.windowTable);
}
void
stubSwapBuffers(WindowInfo *window, GLint flags)
{
if (!window)
return;
/* Determine if this window is being rendered natively or through
* Chromium.
*/
if (window->type == NATIVE) {
/*printf("*** Swapping native window %d\n", (int) drawable);*/
#ifdef WINDOWS
(void) stub.wsInterface.wglSwapBuffers( window->drawable );
#elif defined(Darwin)
/* ...is this ok? */
/* stub.wsInterface.CGLFlushDrawable( context->cglc ); */
crDebug("stubSwapBuffers: unable to swap (no context!)");
#elif defined(GLX)
stub.wsInterface.glXSwapBuffers( window->dpy, window->drawable );
#endif
}
else if (window->type == CHROMIUM) {
/* Let the SPU do the buffer swap */
/*printf("*** Swapping chromium window %d\n", (int) drawable);*/
if (stub.appDrawCursor) {
int pos[2];
GetCursorPosition(window, pos);
stub.spu->dispatch_table.ChromiumParametervCR(GL_CURSOR_POSITION_CR, GL_INT, 2, pos);
}
stub.spu->dispatch_table.SwapBuffers( window->spuWindow, flags );
}
else {
crDebug("Calling SwapBuffers on a window we haven't seen before (no-op).");
}
}
|