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
|
/* Copyright (c) 2001, Stanford University
* All rights reserved
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#include "server_dispatch.h"
#include "server.h"
#include "cr_error.h"
#include "cr_unpack.h"
#include "cr_mem.h"
#include "state/cr_statetypes.h"
/* This code copied from the tilesorter (fooey) */
typedef struct BucketRegion *BucketRegion_ptr;
typedef struct BucketRegion {
CRbitvalue id;
CRrecti extents;
BucketRegion_ptr right;
BucketRegion_ptr up;
} BucketRegion;
#define HASHRANGE 256
#define BKT_DOWNHASH(a, range) ((a)*HASHRANGE/(range))
#define BKT_UPHASH(a, range) ((a)*HASHRANGE/(range) + ((a)*HASHRANGE%(range)?1:0))
struct BucketingInfo {
BucketRegion *rhash[HASHRANGE][HASHRANGE];
BucketRegion *rlist;
};
/*
* At this point we know that the tiles are uniformly sized so we can use
* a hash-based bucketing method. Setup the hash table now.
*/
static GLboolean
fillBucketingHash(CRMuralInfo *mural)
{
#if 0
int i, j, k, m;
int r_len = 0;
int xinc, yinc;
int rlist_alloc = 64 * 128;
BucketRegion *rptr;
struct BucketingInfo *bucketInfo;
if (mural->bucketInfo) {
crFree(mural->bucketInfo->rlist);
crFree(mural->bucketInfo);
mural->bucketInfo = NULL;
}
bucketInfo = (struct BucketingInfo *) crCalloc(sizeof(struct BucketingInfo));
if (!bucketInfo)
return GL_FALSE;
/* Allocate rlist (don't free it!!!) */
bucketInfo->rlist = (BucketRegion *) crAlloc(rlist_alloc * sizeof(BucketRegion));
for ( i = 0; i < HASHRANGE; i++ )
{
for ( j = 0; j < HASHRANGE; j++ )
{
bucketInfo->rhash[i][j] = NULL;
}
}
/* Fill the rlist */
xinc = mural->extents[0].imagewindow.x2 - mural->extents[0].imagewindow.x1;
yinc = mural->extents[0].imagewindow.y2 - mural->extents[0].imagewindow.y1;
CRASSERT(xinc > 0 || mural->width == 0);
CRASSERT(yinc > 0 || mural->height == 0);
rptr = bucketInfo->rlist;
for (i=0; i < (int) mural->width; i+=xinc)
{
for (j=0; j < (int) mural->height; j+=yinc)
{
for (k=0; k < mural->numExtents; k++)
{
if (mural->extents[k].imagewindow.x1 == i &&
mural->extents[k].imagewindow.y1 == j)
{
rptr->extents = mural->extents[k].imagewindow; /* x1,y1,x2,y2 */
rptr->id = k;
break;
}
}
if (k == mural->numExtents)
{
rptr->extents.x1 = i;
rptr->extents.y1 = j;
rptr->extents.x2 = i + xinc;
rptr->extents.y2 = j + yinc;
rptr->id = -1;
}
rptr++;
}
}
r_len = rptr - bucketInfo->rlist;
/* Fill hash table */
for (i = 0; i < r_len; i++)
{
BucketRegion *r = &bucketInfo->rlist[i];
for (k=BKT_DOWNHASH(r->extents.x1, (int)mural->width);
k<=BKT_UPHASH(r->extents.x2, (int)mural->width) &&
k < HASHRANGE;
k++)
{
for (m=BKT_DOWNHASH(r->extents.y1, (int)mural->height);
m<=BKT_UPHASH(r->extents.y2, (int)mural->height) &&
m < HASHRANGE;
m++)
{
if ( bucketInfo->rhash[m][k] == NULL ||
(bucketInfo->rhash[m][k]->extents.x1 > r->extents.x1 &&
bucketInfo->rhash[m][k]->extents.y1 > r->extents.y1))
{
bucketInfo->rhash[m][k] = r;
}
}
}
}
/* Initialize links */
for (i=0; i<r_len; i++)
{
BucketRegion *r = &bucketInfo->rlist[i];
r->right = NULL;
r->up = NULL;
}
/* Build links */
for (i=0; i<r_len; i++)
{
BucketRegion *r = &bucketInfo->rlist[i];
for (j=0; j<r_len; j++)
{
BucketRegion *q = &bucketInfo->rlist[j];
if (r==q)
continue;
/* Right Edge */
if (r->extents.x2 == q->extents.x1 &&
r->extents.y1 == q->extents.y1 &&
r->extents.y2 == q->extents.y2)
{
r->right = q;
}
/* Upper Edge */
if (r->extents.y2 == q->extents.y1 &&
r->extents.x1 == q->extents.x1 &&
r->extents.x2 == q->extents.x2)
{
r->up = q;
}
}
}
mural->bucketInfo = bucketInfo;
#endif
return GL_TRUE;
}
/*
* Check if the tiles are the same size. If so, initialize hash-based
* bucketing.
*/
GLboolean
crServerInitializeBucketing(CRMuralInfo *mural)
{
#if 0
int optTileWidth = 0, optTileHeight = 0;
int i;
for (i = 0; i < mural->numExtents; i++)
{
const int w = mural->extents[i].imagewindow.x2 -
mural->extents[i].imagewindow.x1;
const int h = mural->extents[i].imagewindow.y2 -
mural->extents[i].imagewindow.y1;
if (optTileWidth == 0 && optTileHeight == 0) {
/* First tile */
optTileWidth = w;
optTileHeight = h;
}
else
{
/* Subsequent tile - make sure it's the same size as first and
* falls on the expected x/y location.
*/
if (w != optTileWidth || h != optTileHeight) {
crWarning("Tile %d, %d .. %d, %d is not the right size!",
mural->extents[i].imagewindow.x1, mural->extents[i].imagewindow.y1,
mural->extents[i].imagewindow.x2, mural->extents[i].imagewindow.y2);
crWarning("All tiles must be same size with optimize_bucket.");
crWarning("Turning off optimize_bucket for this mural.");
return GL_FALSE;
}
else if ((mural->extents[i].imagewindow.x1 % optTileWidth) != 0 ||
(mural->extents[i].imagewindow.x2 % optTileWidth) != 0 ||
(mural->extents[i].imagewindow.y1 % optTileHeight) != 0 ||
(mural->extents[i].imagewindow.y2 % optTileHeight) != 0)
{
crWarning("Tile %d, %d .. %d, %d is not positioned correctly "
"to use optimize_bucket.",
mural->extents[i].imagewindow.x1, mural->extents[i].imagewindow.y1,
mural->extents[i].imagewindow.x2, mural->extents[i].imagewindow.y2);
crWarning("Turning off optimize_bucket for this mural.");
return GL_FALSE;
}
}
}
#endif
return fillBucketingHash(mural);
}
/**
* Process a crBoundsInfoCR message/function. This is a bounding box
* followed by a payload of arbitrary Chromium rendering commands.
* The tilesort SPU will send this.
* Note: the bounding box is in mural pixel coordinates (y=0=bottom)
*/
void SERVER_DISPATCH_APIENTRY
crServerDispatchBoundsInfoCR( const CRrecti *bounds, const GLbyte *payload,
GLint len, GLint num_opcodes )
{
CRMuralInfo *mural = cr_server.curClient->currentMural;
char *data_ptr = (char*)(payload + ((num_opcodes + 3 ) & ~0x03));
unsigned int bx, by;
/* Save current unpacker state */
crUnpackPush();
#if 0
/* pass bounds info to first SPU */
{
/* bias bounds to extent/window coords */
CRrecti bounds2;
const int dx = mural->extents[0].imagewindow.x1;
const int dy = mural->extents[0].imagewindow.y1;
if (bounds->x1 == -CR_MAXINT) {
/* "infinite" bounds: convert to full image bounds */
bounds2.x1 = 0;
bounds2.y1 = 0;
bounds2.x2 = mural->extents[0].imagewindow.x2 - dx; /* width */
bounds2.y2 = mural->extents[0].imagewindow.y2 - dy; /* height */
}
else {
bounds2.x1 = bounds->x1 - dx;
bounds2.y1 = bounds->y1 - dy;
bounds2.x2 = bounds->x2 - dx;
bounds2.y2 = bounds->y2 - dy;
}
cr_server.head_spu->dispatch_table.BoundsInfoCR(&bounds2, NULL, 0, 0);
}
if (!mural->viewportValidated) {
crServerComputeViewportBounds(&(cr_server.curClient->currentCtxInfo->pContext->viewport),
mural);
}
bx = BKT_DOWNHASH(bounds->x1, mural->width);
by = BKT_DOWNHASH(bounds->y1, mural->height);
/* Check for out of bounds, and optimizeBucket to enable */
if (mural->optimizeBucket && (bx <= HASHRANGE) && (by <= HASHRANGE))
{
const struct BucketingInfo *bucketInfo = mural->bucketInfo;
const BucketRegion *r;
const BucketRegion *p;
CRASSERT(bucketInfo);
for (r = bucketInfo->rhash[by][bx]; r && bounds->y2 >= r->extents.y1;
r = r->up)
{
for (p=r; p && bounds->x2 >= p->extents.x1; p = p->right)
{
if ( p->id != (unsigned int) -1 &&
bounds->x1 < p->extents.x2 &&
bounds->y1 < p->extents.y2 &&
bounds->y2 >= p->extents.y1 )
{
mural->curExtent = p->id;
if (cr_server.run_queue->client->currentCtxInfo && cr_server.run_queue->client->currentCtxInfo->pContext) {
crServerSetOutputBounds( mural, mural->curExtent );
}
crUnpack( data_ptr, data_ptr-1, num_opcodes, &(cr_server.dispatch) );
}
}
}
}
else
{
/* non-optimized bucketing - unpack/render for each tile/extent */
int i;
for ( i = 0; i < mural->numExtents; i++ )
{
CRExtent *extent = &mural->extents[i];
if (cr_server.localTileSpec ||
(extent->imagewindow.x2 > bounds->x1 &&
extent->imagewindow.x1 < bounds->x2 &&
extent->imagewindow.y2 > bounds->y1 &&
extent->imagewindow.y1 < bounds->y2))
{
mural->curExtent = i;
if (cr_server.run_queue->client->currentCtxInfo && cr_server.run_queue->client->currentCtxInfo->pContext) {
crServerSetOutputBounds( mural, i );
}
crUnpack( data_ptr, data_ptr-1, num_opcodes, &(cr_server.dispatch) );
}
}
}
#endif
/* Restore previous unpacker state */
crUnpackPop();
}
|