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
|
/* Copyright (c) 2001, Stanford University
* All rights reserved
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#include "cr_spu.h"
#include "chromium.h"
#include "cr_mem.h"
#include "cr_net.h"
#include "server_dispatch.h"
#include "server.h"
#ifdef VBOXCR_LOGFPS
#include <iprt/timer.h>
#include <iprt/ctype.h>
typedef struct VBOXCRFPS
{
uint64_t mPeriodSum;
uint64_t *mpaPeriods;
uint64_t mPrevTime;
uint64_t mcFrames;
uint32_t mcPeriods;
uint32_t miPeriod;
uint64_t mBytesSum;
uint32_t *mpaBytes;
uint64_t mBytesSentSum;
uint32_t *mpaBytesSent;
uint64_t mCallsSum;
uint32_t *mpaCalls;
uint64_t mOpsSum;
uint32_t *mpaOps;
uint64_t mTimeUsedSum;
uint64_t *mpaTimes;
} VBOXCRFPS, *PVBOXCRFPS;
void vboxCrFpsInit(PVBOXCRFPS pFps, uint32_t cPeriods)
{
crMemset(pFps, 0, sizeof (*pFps));
pFps->mcPeriods = cPeriods;
pFps->mpaPeriods = crCalloc(sizeof (pFps->mpaPeriods[0]) * cPeriods);
pFps->mpaBytes = crCalloc(sizeof (pFps->mpaBytes[0]) * cPeriods);
pFps->mpaBytesSent = crCalloc(sizeof (pFps->mpaBytesSent[0]) * cPeriods);
pFps->mpaCalls = crCalloc(sizeof (pFps->mpaCalls[0]) * cPeriods);
pFps->mpaOps = crCalloc(sizeof (pFps->mpaOps[0]) * cPeriods);
pFps->mpaTimes = crCalloc(sizeof (pFps->mpaTimes[0]) * cPeriods);
}
void vboxCrFpsTerm(PVBOXCRFPS pFps)
{
crFree(pFps->mpaPeriods);
crFree(pFps->mpaBytes);
crFree(pFps->mpaCalls);
}
void vboxCrFpsReportFrame(PVBOXCRFPS pFps)
{
uint64_t cur = RTTimeNanoTS();
uint64_t curBytes, curBytesSent, curCalls, curOps, curTimeUsed;
int i;
curBytes = 0;
curBytesSent = 0;
curCalls = 0;
curOps = 0;
curTimeUsed = 0;
for (i = 0; i < cr_server.numClients; i++)
{
if (cr_server.clients[i] && cr_server.clients[i]->conn)
{
curBytes += cr_server.clients[i]->conn->total_bytes_recv;
curBytesSent += cr_server.clients[i]->conn->total_bytes_sent;
curCalls += cr_server.clients[i]->conn->recv_count;
curOps += cr_server.clients[i]->conn->opcodes_count;
curTimeUsed += cr_server.clients[i]->timeUsed;
cr_server.clients[i]->conn->total_bytes_recv = 0;
cr_server.clients[i]->conn->total_bytes_sent = 0;
cr_server.clients[i]->conn->recv_count = 0;
cr_server.clients[i]->conn->opcodes_count = 0;
cr_server.clients[i]->timeUsed = 0;
}
}
if(pFps->mPrevTime)
{
uint64_t curPeriod = cur - pFps->mPrevTime;
pFps->mPeriodSum += curPeriod - pFps->mpaPeriods[pFps->miPeriod];
pFps->mpaPeriods[pFps->miPeriod] = curPeriod;
pFps->mBytesSum += curBytes - pFps->mpaBytes[pFps->miPeriod];
pFps->mpaBytes[pFps->miPeriod] = curBytes;
pFps->mBytesSentSum += curBytesSent - pFps->mpaBytesSent[pFps->miPeriod];
pFps->mpaBytesSent[pFps->miPeriod] = curBytesSent;
pFps->mCallsSum += curCalls - pFps->mpaCalls[pFps->miPeriod];
pFps->mpaCalls[pFps->miPeriod] = curCalls;
pFps->mOpsSum += curOps - pFps->mpaOps[pFps->miPeriod];
pFps->mpaOps[pFps->miPeriod] = curOps;
pFps->mTimeUsedSum += curTimeUsed - pFps->mpaTimes[pFps->miPeriod];
pFps->mpaTimes[pFps->miPeriod] = curTimeUsed;
++pFps->miPeriod;
pFps->miPeriod %= pFps->mcPeriods;
}
pFps->mPrevTime = cur;
++pFps->mcFrames;
}
uint64_t vboxCrFpsGetEveragePeriod(PVBOXCRFPS pFps)
{
return pFps->mPeriodSum / pFps->mcPeriods;
}
double vboxCrFpsGetFps(PVBOXCRFPS pFps)
{
return ((double)1000000000.0) / vboxCrFpsGetEveragePeriod(pFps);
}
double vboxCrFpsGetBps(PVBOXCRFPS pFps)
{
return vboxCrFpsGetFps(pFps) * pFps->mBytesSum / pFps->mcPeriods;
}
double vboxCrFpsGetBpsSent(PVBOXCRFPS pFps)
{
return vboxCrFpsGetFps(pFps) * pFps->mBytesSentSum / pFps->mcPeriods;
}
double vboxCrFpsGetCps(PVBOXCRFPS pFps)
{
return vboxCrFpsGetFps(pFps) * pFps->mCallsSum / pFps->mcPeriods;
}
double vboxCrFpsGetOps(PVBOXCRFPS pFps)
{
return vboxCrFpsGetFps(pFps) * pFps->mOpsSum / pFps->mcPeriods;
}
double vboxCrFpsGetTimeProcPercent(PVBOXCRFPS pFps)
{
return 100.0*pFps->mTimeUsedSum/pFps->mPeriodSum;
}
uint64_t vboxCrFpsGetNumFrames(PVBOXCRFPS pFps)
{
return pFps->mcFrames;
}
#endif
void SERVER_DISPATCH_APIENTRY crServerDispatchClear( GLenum mask )
{
CRMuralInfo *mural = cr_server.curClient->currentMural;
const RunQueue *q = cr_server.run_queue;
if (cr_server.only_swap_once)
{
/* NOTE: we only do the clear for the _last_ client in the list.
* This is because in multi-threaded apps the zeroeth client may
* be idle and never call glClear at all. See threadtest.c
* It's pretty likely that the last client will be active.
*/
if ((mask & GL_COLOR_BUFFER_BIT) &&
(cr_server.curClient != cr_server.clients[cr_server.numClients - 1]))
return;
}
cr_server.head_spu->dispatch_table.Clear( mask );
}
static void __draw_poly(CRPoly *p)
{
int b;
cr_server.head_spu->dispatch_table.Begin(GL_POLYGON);
for (b=0; b<p->npoints; b++)
cr_server.head_spu->dispatch_table.Vertex2dv(p->points+2*b);
cr_server.head_spu->dispatch_table.End();
}
void SERVER_DISPATCH_APIENTRY
crServerDispatchSwapBuffers( GLint window, GLint flags )
{
CRMuralInfo *mural;
CRContext *ctx;
#ifdef VBOXCR_LOGFPS
static VBOXCRFPS Fps;
static bool bFpsInited = false;
if (!bFpsInited)
{
vboxCrFpsInit(&Fps, 64 /* cPeriods */);
bFpsInited = true;
}
vboxCrFpsReportFrame(&Fps);
if(!(vboxCrFpsGetNumFrames(&Fps) % 31))
{
double fps = vboxCrFpsGetFps(&Fps);
double bps = vboxCrFpsGetBps(&Fps);
double bpsSent = vboxCrFpsGetBpsSent(&Fps);
double cps = vboxCrFpsGetCps(&Fps);
double ops = vboxCrFpsGetOps(&Fps);
double tup = vboxCrFpsGetTimeProcPercent(&Fps);
crDebug("fps: %f, rec Mbps: %.1f, send Mbps: %.1f, cps: %.1f, ops: %.0f, host %.1f%%",
fps, bps/(1024.0*1024.0), bpsSent/(1024.0*1024.0), cps, ops, tup);
}
#endif
mural = (CRMuralInfo *) crHashtableSearch(cr_server.muralTable, window);
if (!mural) {
return;
}
if (cr_server.only_swap_once)
{
/* NOTE: we only do the clear for the _last_ client in the list.
* This is because in multi-threaded apps the zeroeth client may
* be idle and never call glClear at all. See threadtest.c
* It's pretty likely that the last client will be active.
*/
if (cr_server.curClient != cr_server.clients[cr_server.numClients - 1])
{
return;
}
}
#if 0
if (cr_server.overlapBlending)
{
int a;
CRPoly *p;
GLboolean lighting, fog, blend, cull, tex[3];
GLenum mm, blendSrc, blendDst;
GLcolorf col;
CRContext *ctx = crStateGetCurrent();
const CRmatrix *baseProj;
/*
* I've probably missed some state here, or it
* might be easier just to push/pop it....
*/
lighting = ctx->lighting.lighting;
fog = ctx->fog.enable;
tex[0] = 0;
for (a=0; a<CR_MAX_TEXTURE_UNITS; a++)
{
if (!ctx->texture.unit[a].enabled1D) continue;
tex[0] = 1;
break;
}
tex[1] = 0;
for (a=0; a<CR_MAX_TEXTURE_UNITS; a++)
{
if (!ctx->texture.unit[a].enabled2D) continue;
tex[1] = 1;
break;
}
tex[2] = 0;
for (a=0; a<CR_MAX_TEXTURE_UNITS; a++)
{
if (!ctx->texture.unit[a].enabled3D) continue;
tex[2] = 1;
break;
}
cull = ctx->polygon.cullFace;
blend = ctx->buffer.blend;
blendSrc = ctx->buffer.blendSrcRGB;
blendDst = ctx->buffer.blendDstRGB;
mm = ctx->transform.matrixMode;
col.r = ctx->current.vertexAttrib[VERT_ATTRIB_COLOR0][0];
col.g = ctx->current.vertexAttrib[VERT_ATTRIB_COLOR0][1];
col.b = ctx->current.vertexAttrib[VERT_ATTRIB_COLOR0][2];
col.a = ctx->current.vertexAttrib[VERT_ATTRIB_COLOR0][3];
baseProj = &(cr_server.curClient->currentMural->extents[0].baseProjection);
switch(mm)
{
case GL_PROJECTION:
cr_server.head_spu->dispatch_table.PushMatrix();
cr_server.head_spu->dispatch_table.LoadMatrixf((GLfloat *) baseProj);
cr_server.head_spu->dispatch_table.MultMatrixf(cr_server.unnormalized_alignment_matrix);
cr_server.head_spu->dispatch_table.MatrixMode(GL_MODELVIEW);
cr_server.head_spu->dispatch_table.PushMatrix();
cr_server.head_spu->dispatch_table.LoadIdentity();
break;
default:
cr_server.head_spu->dispatch_table.MatrixMode(GL_MODELVIEW);
/* fall through */
case GL_MODELVIEW:
cr_server.head_spu->dispatch_table.PushMatrix();
cr_server.head_spu->dispatch_table.LoadIdentity();
cr_server.head_spu->dispatch_table.MatrixMode(GL_PROJECTION);
cr_server.head_spu->dispatch_table.PushMatrix();
cr_server.head_spu->dispatch_table.LoadMatrixf((GLfloat *) baseProj);
cr_server.head_spu->dispatch_table.MultMatrixf(cr_server.unnormalized_alignment_matrix);
break;
}
/* fix state */
if (lighting)
cr_server.head_spu->dispatch_table.Disable(GL_LIGHTING);
if (fog)
cr_server.head_spu->dispatch_table.Disable(GL_FOG);
if (tex[0])
cr_server.head_spu->dispatch_table.Disable(GL_TEXTURE_1D);
if (tex[1])
cr_server.head_spu->dispatch_table.Disable(GL_TEXTURE_2D);
if (tex[2])
cr_server.head_spu->dispatch_table.Disable(GL_TEXTURE_3D);
if (cull)
cr_server.head_spu->dispatch_table.Disable(GL_CULL_FACE);
/* Regular Blending */
if (cr_server.overlapBlending == 1)
{
if (!blend)
cr_server.head_spu->dispatch_table.Enable(GL_BLEND);
if ((blendSrc != GL_ZERO) && (blendDst != GL_SRC_ALPHA))
cr_server.head_spu->dispatch_table.BlendFunc(GL_ZERO, GL_SRC_ALPHA);
/* draw the blends */
for (a=1; a<cr_server.num_overlap_levels; a++)
{
if (a-1 < cr_server.num_overlap_intens)
{
cr_server.head_spu->dispatch_table.Color4f(0, 0, 0,
cr_server.overlap_intens[a-1]);
}
else
{
cr_server.head_spu->dispatch_table.Color4f(0, 0, 0, 1);
}
p = cr_server.overlap_geom[a];
while (p)
{
/* hopefully this isnt concave... */
__draw_poly(p);
p = p->next;
}
}
if (!blend)
cr_server.head_spu->dispatch_table.Disable(GL_BLEND);
if ((blendSrc != GL_ZERO) && (blendDst != GL_SRC_ALPHA))
cr_server.head_spu->dispatch_table.BlendFunc(blendSrc, blendDst);
}
else
/* Knockout Blending */
{
cr_server.head_spu->dispatch_table.Color4f(0, 0, 0, 1);
if (blend)
cr_server.head_spu->dispatch_table.Disable(GL_BLEND);
p = cr_server.overlap_knockout;
while (p)
{
__draw_poly(p);
p = p->next;
}
if (blend)
cr_server.head_spu->dispatch_table.Enable(GL_BLEND);
}
/* return things to normal */
switch (mm)
{
case GL_PROJECTION:
cr_server.head_spu->dispatch_table.PopMatrix();
cr_server.head_spu->dispatch_table.MatrixMode(GL_PROJECTION);
cr_server.head_spu->dispatch_table.PopMatrix();
break;
case GL_MODELVIEW:
cr_server.head_spu->dispatch_table.PopMatrix();
cr_server.head_spu->dispatch_table.MatrixMode(GL_MODELVIEW);
cr_server.head_spu->dispatch_table.PopMatrix();
break;
default:
cr_server.head_spu->dispatch_table.PopMatrix();
cr_server.head_spu->dispatch_table.MatrixMode(GL_MODELVIEW);
cr_server.head_spu->dispatch_table.PopMatrix();
cr_server.head_spu->dispatch_table.MatrixMode(mm);
break;
}
if (lighting)
cr_server.head_spu->dispatch_table.Enable(GL_LIGHTING);
if (fog)
cr_server.head_spu->dispatch_table.Enable(GL_FOG);
if (tex[0])
cr_server.head_spu->dispatch_table.Enable(GL_TEXTURE_1D);
if (tex[1])
cr_server.head_spu->dispatch_table.Enable(GL_TEXTURE_2D);
if (tex[2])
cr_server.head_spu->dispatch_table.Enable(GL_TEXTURE_3D);
if (cull)
cr_server.head_spu->dispatch_table.Enable(GL_CULL_FACE);
cr_server.head_spu->dispatch_table.Color4f(col.r, col.g, col.b, col.a);
}
#endif
/* Check if using a file network */
if (!cr_server.clients[0]->conn->actual_network && window == MAGIC_OFFSET)
window = 0;
ctx = crStateGetCurrent();
CRASSERT(cr_server.curClient && cr_server.curClient->currentMural == mural);
if (ctx->framebufferobject.drawFB
|| (ctx->buffer.drawBuffer != GL_FRONT && ctx->buffer.drawBuffer != GL_FRONT_LEFT))
mural->bFbDraw = GL_FALSE;
CR_SERVER_DUMP_SWAPBUFFERS_ENTER();
if (crServerIsRedirectedToFBO())
{
crServerMuralFBOSwapBuffers(mural);
crServerPresentFBO(mural);
}
else
{
cr_server.head_spu->dispatch_table.SwapBuffers( mural->spuWindow, flags );
}
CR_SERVER_DUMP_SWAPBUFFERS_LEAVE();
}
void SERVER_DISPATCH_APIENTRY
crServerDispatchFlush(void)
{
CRContext *ctx = crStateGetCurrent();
cr_server.head_spu->dispatch_table.Flush();
if (cr_server.curClient && cr_server.curClient->currentMural)
{
CRMuralInfo *mural = cr_server.curClient->currentMural;
if (mural->bFbDraw)
{
if (crServerIsRedirectedToFBO())
crServerPresentFBO(mural);
}
if (ctx->framebufferobject.drawFB
|| (ctx->buffer.drawBuffer != GL_FRONT && ctx->buffer.drawBuffer != GL_FRONT_LEFT))
mural->bFbDraw = GL_FALSE;
}
}
void SERVER_DISPATCH_APIENTRY
crServerDispatchFinish(void)
{
CRContext *ctx = crStateGetCurrent();
cr_server.head_spu->dispatch_table.Finish();
if (cr_server.curClient && cr_server.curClient->currentMural)
{
CRMuralInfo *mural = cr_server.curClient->currentMural;
if (mural->bFbDraw)
{
if (crServerIsRedirectedToFBO())
crServerPresentFBO(mural);
}
if (ctx->framebufferobject.drawFB
|| (ctx->buffer.drawBuffer != GL_FRONT && ctx->buffer.drawBuffer != GL_FRONT_LEFT))
mural->bFbDraw = GL_FALSE;
}
}
|