-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.c
More file actions
543 lines (446 loc) · 12.4 KB
/
window.c
File metadata and controls
543 lines (446 loc) · 12.4 KB
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
/*
* GLOMP - transparent multipipe OpenGL
* Copyright (C) 2007 the GLOMP team (see AUTHORS)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Window/viewport/frustum handling
*/
#include "init.h"
#ifdef ENABLE_SINGLE_SCREEN
#include "single_screen.h"
#else
#include "multi_screen.h"
#endif
#include "overrides.h"
static int glxattribs[100]={
GLX_RED_SIZE, 4,
GLX_GREEN_SIZE, 4,
GLX_BLUE_SIZE, 4,
GLX_DEPTH_SIZE, 8,
None};
/*
* Our glXSwapBuffers function that intercepts the "real" function.
*
*/
void glXSwapBuffers(Display *dpy, GLXDrawable drawable)
{
int fnum=OVERRIDE_BASE;
fifo_output(&cmd_fifo,&fnum,sizeof(fnum));
fifo_flush(&cmd_fifo);
#ifdef ENABLE_SINGLE_SCREEN
single_screen_swap(dpy,drawable);
#else
multi_screen_swap(dpy,drawable);
#endif
}
void GLOMPglXSwapBuffers()
{
#ifdef ENABLE_SINGLE_SCREEN
single_screen_swap(NULL,0);
#else
multi_screen_swap(NULL,0);
#endif
}
/*on recupere les proprite de la fenetre (taille) pour les diviser par le nbr de cartes, afin de repartire les taches,puis on la lance*/
int XSetStandardProperties(
Display* dpy,
Window w,
_Xconst char* name,
_Xconst char* icon_string,
Pixmap icon_pixmap,
char** argv,
int argc,
XSizeHints* hints
)
{
/*on la relance betement*/
printf("XSetStandardProperties called\n");
return lib_XSetStandardProperties(dpy,w,name,icon_string,icon_pixmap,argv,argc,hints );
}
static void CreateWindow()
{
static int init=0;
int fnum=OVERRIDE_BASE+39;
int i,value;
if (init==1)
return;
init=1;
#ifdef ENABLE_SINGLE_SCREEN
single_screen_init_window(glxattribs);
#else
multi_screen_init_window(glxattribs);
#endif
fifo_output(&cmd_fifo,&fnum,sizeof(fnum));
fifo_output(&cmd_fifo,&width,sizeof(width));
fifo_output(&cmd_fifo,&height,sizeof(height));
i=0;
do
{
value=*(glxattribs+i);
fifo_output(&cmd_fifo,&value,sizeof(int));
i++;
}
while(value!=None);
}
GLXWindow XCreateWindow(Display *display, Window parent, int x, int y,
unsigned int width2, unsigned int height2, unsigned int border_width, int depth, unsigned int class, Visual *visual,
unsigned long valuemask, XSetWindowAttributes *attribute)
{
width=width2;
height=height2;
printf("XCreateWindow %d %d\n",width,height);
CreateWindow();
#ifdef ENABLE_SINGLE_SCREEN
return lib_XCreateWindow(display, parent, x, y,width, height, border_width,depth,class,visual,valuemask, attribute);
#else
if (!getenv("FORCE_GPU"))
{
XF86VidModeModeInfo **modes;
int modeNum;
lib_XF86VidModeGetAllModeLines(display, DefaultScreen(display), &modeNum, &modes);
width=modes[0]->hdisplay;
height=modes[0]->vdisplay;
attribute->override_redirect=True;
return lib_XCreateWindow(display, parent, x, y,width, height, border_width,depth,class,visual,valuemask | CWOverrideRedirect, attribute);
}
return lib_XCreateWindow(display, parent, x, y,width, height, border_width,depth,class,visual,valuemask, attribute);
#endif
}
void GLOMPXCreateWindow()
{
int i,value;
fifo_input(&cmd_fifo,&width,4);
fifo_input(&cmd_fifo,&height,4);
i=0;
do
{
fifo_input(&cmd_fifo,&value,4);
glxattribs[i]=value;
i++;
}
while(value!=None);
#ifdef ENABLE_SINGLE_SCREEN
single_screen_init_window(glxattribs);
#else
multi_screen_init_window(glxattribs);
#endif
}
GLXContext glXCreateNewContext(Display *dpy, GLXFBConfig config,
int render_type, GLXContext share_list,
Bool direct)
{
printf("glXCreateNewContext called !!!!!!!\n");
return lib_glXCreateNewContext(dpy,config,render_type,share_list,direct);
}
GLXWindow glXCreateWindow(Display *dpy, GLXFBConfig config, Window win, const int *attrib_list)
{
printf("glXCreateWindow called !!!!!!!\n");
return lib_glXCreateWindow(dpy,config,win,attrib_list);
}
GLXContext glXCreateContext(Display *dpy, XVisualInfo *vis,
GLXContext share_list, Bool direct)
{
printf("glXCreateContext called !!!!!!!\n");
CreateWindow();
return lib_glXCreateContext(dpy,vis,share_list,direct);
}
void glXDestroyContext(Display *dpy, GLXContext ctx)
{
printf("glXDestroyContext called !!!!!!!\n");
lib_glXDestroyContext(dpy,ctx);
}
Bool glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx)
{
printf("glXMakeCurrent called !!!!!!!\n");
return lib_glXMakeCurrent(dpy,drawable,ctx);
}
void glXCopyContext(Display *dpy, GLXContext src, GLXContext dst, unsigned long mask)
{
printf("glXCopyContext called !!!!!!!\n");
lib_glXCopyContext(dpy,src,dst,mask);
}
XVisualInfo* glXChooseVisual(Display *dpy, int screen,
int *attrib_list)
{
int i=0;
GLOMP_init();
while(attrib_list[i]!=None)
i++;
memcpy(glxattribs,attrib_list,i*sizeof(int));
return lib_glXChooseVisual(dpy,screen,attrib_list);
}
const char * glXQueryServerString(Display *dpy, int screen, int name)
{
printf("glXQueryServerString called !!!!!!!\n");
return lib_glXQueryServerString(dpy,screen,name);
}
const char * glXGetClientString(Display *dpy, int name)
{
printf("glXGetClientString called !!!!!!!\n");
return lib_glXGetClientString(dpy,name);
}
GLXFBConfig *glXChooseFBConfig(Display *dpy, int screen,
const int *attrib_list, int *nelements)
{
printf("glXChooseFBConfig called !!!!!!!\n");
return lib_glXChooseFBConfig(dpy,screen,attrib_list,nelements);
}
int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config,
int attribute, int *value)
{
printf("glXGetFBConfigAttrib called !!!!!!!\n");
return lib_glXGetFBConfigAttrib(dpy,config,attribute,value);
}
GLXPbuffer glXCreatePbuffer(Display *dpy, GLXFBConfig config,
const int *attrib_list)
{
printf("glXCreatePbuffer called !!!!!!!\n");
return lib_glXCreatePbuffer(dpy,config,attrib_list);
}
Bool glXIsDirect(Display *dpy, GLXContext ctx)
{
printf("glXIsDirect called !!!!!!!\n");
return lib_glXIsDirect(dpy,ctx);
}
Bool glXQueryVersion(Display *dpy, int *major, int *minor)
{
printf("glXQueryVersion called !!!!!!!\n");
return lib_glXQueryVersion(dpy,major,minor);
}
int glXGetConfig(Display *dpy, XVisualInfo *vis,
int attrib, int *value)
{
printf("glXGetConfig called !!!!!!!\n");
return lib_glXGetConfig(dpy,vis,attrib,value);
}
const char *glXQueryExtensionsString(Display *dpy, int screen)
{
printf("glXQueryExtensionsString called !!!!!!!\n");
return lib_glXQueryExtensionsString(dpy,screen);
}
void glFrustum ( GLdouble p0 , GLdouble p1 , GLdouble p2 , GLdouble p3 , GLdouble p4 , GLdouble p5 )
{
int fnum=OVERRIDE_BASE+1;
fifo_output(&cmd_fifo,&fnum,sizeof(fnum));
fifo_output(&cmd_fifo,&p0,8);
fifo_output(&cmd_fifo,&p1,8);
fifo_output(&cmd_fifo,&p2,8);
fifo_output(&cmd_fifo,&p3,8);
fifo_output(&cmd_fifo,&p4,8);
fifo_output(&cmd_fifo,&p5,8);
#ifdef ENABLE_SINGLE_SCREEN
int totalload=0;
int beforeload=0;
int i;
GLdouble newp2;
GLdouble newp3;
for(i=0;i<nbcarte;i++)
{
totalload+=client_load[i];
if (i<client_num)
beforeload+=client_load[i];
}
newp2=p2+(p3-p2)*((double)beforeload/(double)totalload);
newp3=p2+(p3-p2)*((double)(beforeload+client_load[client_num])/(double)totalload);
lib_glFrustum(p0,p1,newp2,newp3,p4,p5);
#else
tile_screen_glFrustum(client_num,p0,p1,p2,p3,p4,p5);
#endif
}
/*on a besoin de gerer la perspective donc on interceptent les info de glfrumstun*/
void GLOMPglFrustum()
{
int i;
GLdouble p0;
GLdouble p1;
GLdouble p2;
GLdouble p3;
GLdouble p4;
GLdouble p5;
GLdouble newp2;
GLdouble newp3;
fifo_input(&cmd_fifo,&p0,8);
fifo_input(&cmd_fifo,&p1,8);
fifo_input(&cmd_fifo,&p2,8);
fifo_input(&cmd_fifo,&p3,8);
fifo_input(&cmd_fifo,&p4,8);
fifo_input(&cmd_fifo,&p5,8);
#ifdef ENABLE_SINGLE_SCREEN
int totalload=0;
int beforeload=0;
for(i=0;i<nbcarte;i++)
{
totalload+=client_load[i];
if (i<client_num)
beforeload+=client_load[i];
}
newp2=p2+(p3-p2)*((double)beforeload/(double)totalload);
newp3=p2+(p3-p2)*((double)(beforeload+client_load[client_num])/(double)totalload);
printf("[%d] les anciennes %f %f --- les nexs %f %f\n",client_num,p2,p3,newp2,newp3);
lib_glFrustum(p0,p1,newp2,newp3,p4,p5);
#else
tile_screen_glFrustum(client_num,p0,p1,p2,p3,p4,p5);
#endif
}
#ifdef ENABLE_SINGLE_SCREEN
void glViewport ( GLint x,GLint y,GLsizei w,GLsizei h )
{
int i;
int fnum=OVERRIDE_BASE+40;
fifo_output(&cmd_fifo,&fnum,sizeof(fnum));
fifo_output(&cmd_fifo,&x,4);
fifo_output(&cmd_fifo,&y,4);
fifo_output(&cmd_fifo,&w,4);
fifo_output(&cmd_fifo,&h,4);
int totalload=0;
int beforeload=0;
GLsizei newp3;
GLint newp1;
for(i=0;i<nbcarte;i++)
{
totalload+=client_load[i];
if (i<client_num)
beforeload+=client_load[i];
}
newp1=y+h*((double)beforeload/(double)totalload);
newp3=h*(double)client_load[client_num]/(double)totalload;
printf("viewport:%d %d %d %d %d",client_num,y,h,newp1,newp3);
lib_glViewport(x,newp1,w,newp3);
}
void GLOMPglViewport()
{
int i;
GLsizei p2,p3,newp3;
GLint p0,p1,newp1;
fifo_input(&cmd_fifo,&p0,4);
fifo_input(&cmd_fifo,&p1,4);
fifo_input(&cmd_fifo,&p2,4);
fifo_input(&cmd_fifo,&p3,4);
int totalload=0;
int beforeload=0;
for(i=0;i<nbcarte;i++)
{
totalload+=client_load[i];
if (i<client_num)
beforeload+=client_load[i];
}
newp1=p1+p3*((double)beforeload/(double)totalload);
newp3=p3*(double)client_load[client_num]/(double)totalload;
printf("viewport:%d %d %d %d %d",client_num,p1,p3,newp1,newp3);
lib_glViewport(p0,newp1,p2,newp3);
}
#endif
void glOrtho ( GLdouble p0, GLdouble p1,GLdouble p2,GLdouble p3,GLdouble p4,GLdouble p5 )
{
int fnum=OVERRIDE_BASE+41;
fifo_output(&cmd_fifo,&fnum,sizeof(fnum));
fifo_output(&cmd_fifo,&p0,8);
fifo_output(&cmd_fifo,&p1,8);
fifo_output(&cmd_fifo,&p2,8);
fifo_output(&cmd_fifo,&p3,8);
fifo_output(&cmd_fifo,&p4,8);
fifo_output(&cmd_fifo,&p5,8);
#ifdef ENABLE_SINGLE_SCREEN
int totalload=0;
int beforeload=0;
int i;
GLdouble newp2;
GLdouble newp3;
for(i=0;i<nbcarte;i++)
{
totalload+=client_load[i];
if (i<client_num)
beforeload+=client_load[i];
}
newp2=p2+(p3-p2)*((double)beforeload/(double)totalload);
newp3=p2+(p3-p2)*((double)(beforeload+client_load[client_num])/(double)totalload);
lib_glOrtho(p0,p1,newp2,newp3,p4,p5);
#else
tile_screen_glOrtho(client_num,p0,p1,p2,p3,p4,p5);
#endif
}
void GLOMPglOrtho()
{
int i;
GLdouble p0;
GLdouble p1;
GLdouble p2;
GLdouble p3;
GLdouble p4;
GLdouble p5;
GLdouble newp2;
GLdouble newp3;
fifo_input(&cmd_fifo,&p0,8);
fifo_input(&cmd_fifo,&p1,8);
fifo_input(&cmd_fifo,&p2,8);
fifo_input(&cmd_fifo,&p3,8);
fifo_input(&cmd_fifo,&p4,8);
fifo_input(&cmd_fifo,&p5,8);
#ifdef ENABLE_SINGLE_SCREEN
int totalload=0;
int beforeload=0;
for(i=0;i<nbcarte;i++)
{
totalload+=client_load[i];
if (i<client_num)
beforeload+=client_load[i];
}
printf("%f %f\n",p2,p3);
newp2=p2+(p3-p2)*((double)beforeload/(double)totalload);
newp3=p2+(p3-p2)*((double)(beforeload+client_load[client_num])/(double)totalload);
printf("new %f %f\n",newp2,newp3);
lib_glOrtho(p0,p1,newp2,newp3,p4,p5);
#else
tile_screen_glOrtho(client_num,p0,p1,p2,p3,p4,p5);
#endif
}
static void server_quit()
{
int fnum=OVERRIDE_BASE+49;
fifo_output(&cmd_fifo,&fnum,sizeof(fnum));
}
void GLOMPquit()
{
#ifdef ENABLE_SINGLE_SCREEN
#else
multi_screen_close();
#endif
exit(0);
}
int XDestroyWindow ( Display * disp, Window parent)
{
//server_quit();
int r=lib_XDestroyWindow(disp,parent);
kill(0,SIGKILL);
return r;
}
int XCloseDisplay ( Display * disp)
{
//server_quit();
int r=lib_XCloseDisplay(disp);
kill(0,SIGKILL);
return r;
}
void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
GLdouble xmin, xmax, ymin, ymax;
ymax = zNear * tan(fovy * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
}