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
|
/**
* @file
*
* @section DESCRIPTION
* Handle "views" in the server.
* These are rectangular regions of in a screen "buffer",
* which often contain specific windows.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
//#include <poa/poa.h>
#include <unistd.h>
#include <directfb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include "view.h"
#include "buffer.h"
#include "client.h"
#include "display.h"
enum border_mode {
BORDER_NONE,
BORDER_BORDER,
BORDER_CORNER,
BORDER_OVERLAY,
NUM_BORDER
};
static struct view_tailq all_views;
static enum border_mode mode = BORDER_BORDER;
/*** LOOK UP VIEW STRUCT BY CLIENT ID AND VIEW ID ***/
struct view *
view_lookup(struct client *c, int viewid)
{
struct view *v;
TAILQ_FOREACH(v, &c->views, client_next)
if (v->id == viewid)
return v;
return NULL;
}
/*** UPDATE VIEW AREA ON SCREEN ***/
void
view_refresh(struct view *v)
{
int i;
/* Don't bother if the view isn't visible */
if (v->opacity == 0)
return;
if (mode == BORDER_OVERLAY) {
/* Fill entire view with label background */
v->wsurface->SetColor(v->wsurface,
v->label->bg.r, v->label->bg.g, v->label->bg.b,
0x80);
v->wsurface->FillRectangle(v->wsurface, 0, 0, v->spos.w, v->spos.h);
}
/* Transfer the actual guest content from the guest surface */
if (v->bpos.w == v->spos.w && v->bpos.h == v->spos.h)
v->wsurface->Blit(v->wsurface, v->vsurface, NULL, 0, 0);
else
v->wsurface->StretchBlit(v->wsurface, v->vsurface, NULL, NULL);
/* Draw borders and labels as appropriate */
switch (mode) {
case BORDER_BORDER:
v->wsurface->SetColor(v->wsurface,
v->label->bg.r, v->label->bg.g, v->label->bg.b,
0xff);
for (i = 0; i < SEC_BORDER; i++)
v->wsurface->DrawRectangle(v->wsurface,
i, i,
v->spos.w - 2 * i,
v->spos.h - 2 * i);
break;
case BORDER_CORNER:
v->wsurface->SetColor(v->wsurface,
v->label->bg.r, v->label->bg.g, v->label->bg.b,
0xff);
v->wsurface->FillTriangle(v->wsurface,
0, 0,
SEC_CORNER, 0,
0, SEC_CORNER);
v->wsurface->FillTriangle(v->wsurface,
v->spos.w, 0,
v->spos.w, SEC_CORNER,
v->spos.w - SEC_CORNER, 0);
v->wsurface->FillTriangle(v->wsurface,
v->spos.w, v->spos.h,
v->spos.w - SEC_CORNER, v->spos.h,
v->spos.w, v->spos.h - SEC_CORNER);
v->wsurface->FillTriangle(v->wsurface,
0, v->spos.h,
0, v->spos.h - SEC_CORNER,
SEC_CORNER, v->spos.h);
break;
case BORDER_OVERLAY:
if (!(v->flags & (VIEW_FLAGS_SERVER|VIEW_FLAGS_BACKGROUND)))
display_draw_label(v);
break;
default:
break;
}
v->wsurface->Flip(v->wsurface, NULL, DSFLIP_ONSYNC);
}
static void
view_free(struct view *v)
{
/* remove view from global list */
TAILQ_REMOVE(&all_views, v, view_next);
/* remove view from its buffer list */
TAILQ_REMOVE(&v->buffer->views, v, buffer_next);
/* remove view from its client list */
TAILQ_REMOVE(&v->client->views, v, client_next);
/* bump client view count */
v->client->num_views--;
/* free resources */
v->wsurface->Release(v->wsurface);
v->window->Destroy(v->window);
v->window->Release(v->window);
v->vsurface->Release(v->vsurface);
free(v);
}
/***************************
*** INTERFACE FUNCTIONS ***
***************************/
/*** INTERFACE: CREATE NEW VIEW ***/
struct view *
view_new(struct client *c, struct buffer *b, int id, unsigned int flags)
{
struct view *v;
IDirectFBSurface *vsurf, *wsurf;
DFBWindowDescription wdesc;
IDirectFBWindow *window;
if (c->num_views >= c->max_views)
return NULL;
/* create subsurface */
if (b->bsurface->GetSubSurface(b->bsurface, NULL, &vsurf) != DFB_OK)
return NULL;
/* create main window */
memset(&wdesc, 0, sizeof(wdesc));
wdesc.flags = DWDESC_CAPS | DWDESC_PIXELFORMAT | DWDESC_SURFACE_CAPS | DWDESC_OPTIONS;
wdesc.caps = DWCAPS_DOUBLEBUFFER | DWCAPS_NODECORATION | DWCAPS_NOFOCUS;
wdesc.surface_caps = DSCAPS_FLIPPING;
wdesc.pixelformat = DSPF_ARGB;
wdesc.options = DWOP_SCALE | DWOP_INDESTRUCTIBLE | DWOP_GHOST;
if (dl->CreateWindow(dl, &wdesc, &window) != DFB_OK)
return NULL;
window->GetSurface(window, &wsurf);
window->SetOpacity(window, 0);
window->SetStackingClass(window, (flags & VIEW_FLAGS_THUMBNAIL) ? DWSC_MIDDLE : DWSC_LOWER);
wsurf->SetRenderOptions(wsurf, DSRO_SMOOTH_UPSCALE | DSRO_SMOOTH_DOWNSCALE);
wsurf->SetPorterDuff(wsurf, DSPD_DST_OVER);
wsurf->SetBlittingFlags(wsurf, (mode == BORDER_OVERLAY) ? DSBLIT_BLEND_COLORALPHA : 0);
/* get memory for the view header */
v = calloc(1, sizeof(struct view));
if (!v)
return NULL;
v->id = id;
v->client = c;
v->buffer = b;
v->flags = flags;
v->label = &b->client->label;
v->bsurface = b->bsurface;
v->vsurface = vsurf;
v->window = window;
v->wsurface = wsurf;
/* bump client view count */
c->num_views++;
TAILQ_INSERT_HEAD(&all_views, v, view_next);
if (flags & VIEW_FLAGS_SERVER) {
TAILQ_INSERT_TAIL(&c->views, v, client_next);
TAILQ_INSERT_TAIL(&b->views, v, buffer_next);
} else {
TAILQ_INSERT_HEAD(&c->views, v, client_next);
TAILQ_INSERT_HEAD(&b->views, v, buffer_next);
/* notify display subsystem */
if (display_view_new(v) < 0) {
view_free(v);
return NULL;
}
}
return v;
}
/*** INTERFACE: DESTROY VIEW ***/
void
view_remove(struct view *v)
{
/* call display hook */
if (!(v->flags & VIEW_FLAGS_SERVER))
display_view_remove(v);
/* free view resources */
view_free(v);
}
int
view_show(struct view *v)
{
DFBRectangle zero = { 0, 0, 0, 0 };
int val = 0;
if (v->visible && (v->mapped || v->flags & VIEW_FLAGS_BACKGROUND))
val = 0xff;
/* Zero-sized views cannot be shown */
if (memcmp(&v->bpos, &zero, sizeof(zero)) == 0)
val = 0;
if (!(v->flags & VIEW_FLAGS_SERVER))
display_view_show(v);
if (val != v->opacity) {
v->opacity = val;
v->window->SetOpacity(v->window, val);
if (val)
view_refresh(v);
}
return 0;
}
int
view_update_surface(struct view *v)
{
IDirectFBSurface *bsurf, *vsurf;
/* XXX check if the view falls outside the surface boundaries */
bsurf = v->buffer->bsurface;
v->vsurface->Release(v->vsurface);
if (bsurf->GetSubSurface(bsurf, &v->bpos, &vsurf) != DFB_OK)
return -1;
v->bsurface = bsurf;
v->vsurface = vsurf;
view_refresh(v);
return 0;
}
/*** INTERFACE: SET VIEW POSITION, SIZE, AND BUFFER OFFSET ***/
int
view_set_viewport(struct view *v,
const DFBRectangle *bp, const DFBRectangle *sp,
int force_refresh)
{
/* Check if the view has moved within the buffer */
if (bp && memcmp(&v->bpos, bp, sizeof(DFBRectangle))) {
v->vsurface->MakeSubSurface(v->vsurface, v->bsurface, bp);
memcpy(&v->bpos, bp, sizeof(DFBRectangle));
}
/* Check if the window position has changed */
if (sp && memcmp(&v->spos, sp, sizeof(DFBRectangle))) {
v->window->SetBounds(v->window, sp->x, sp->y, sp->w, sp->h);
v->window->ResizeSurface(v->window, sp->w, sp->h);
memcpy(&v->spos, sp, sizeof(DFBRectangle));
/* Notify display subsystem */
if (!(v->flags & VIEW_FLAGS_SERVER))
display_view_resize(v);
}
if (force_refresh)
view_refresh(v);
return 0;
}
/*** INTERFACE: SET VIEW POSITION ONLY ***/
int
view_set_position(struct view *v, int x, int y)
{
if (v->spos.x != x || v->spos.y != y) {
v->window->MoveTo(v->window, x, y);
v->spos.x = x;
v->spos.y = y;
/* Notify display subsystem */
if (!(v->flags & VIEW_FLAGS_SERVER))
display_view_move(v);
}
return 0;
}
int
view_translate(struct view *v, int dx, int dy)
{
if (dx != 0 || dy != 0) {
v->window->Move(v->window, dx, dy);
v->spos.x += dx;
v->spos.y += dy;
/* Notify display subsystem */
if (!(v->flags & VIEW_FLAGS_SERVER))
display_view_move(v);
}
return 0;
}
int
view_stack(struct view *v, unsigned op, struct view *sibling)
{
struct display *d = v->display;
struct view *prev;
switch (op) {
case VIEW_STACK_TOP:
if (TAILQ_FIRST(&d->views) == v)
break;
TAILQ_REMOVE(&d->views, v, display_next);
TAILQ_INSERT_HEAD(&d->views, v, display_next);
v->window->RaiseToTop(v->window);
break;
case VIEW_STACK_BOTTOM:
if (TAILQ_LAST(&d->views, view_tailq) == v)
break;
TAILQ_REMOVE(&d->views, v, display_next);
TAILQ_INSERT_TAIL(&d->views, v, display_next);
v->window->LowerToBottom(v->window);
break;
case VIEW_STACK_ABOVE:
if (TAILQ_FIRST(&d->views) == v)
break;
/*
* We need to not only stack above the sibling, but also above
* all other views immediately above sibling that do not belong
* to the same guest as v/sibling (and are not v itself).
*/
while ((prev = TAILQ_PREV(sibling, view_tailq, display_next)))
{
if (prev->buffer == v->buffer && prev != v)
break;
sibling = prev;
}
/*
* This will occur if v is already in the right place.
* Also, this check prevents list corruption.
*/
if (v == sibling)
break;
TAILQ_REMOVE(&d->views, v, display_next);
TAILQ_INSERT_BEFORE(sibling, v, display_next);
v->window->PutAtop(v->window, sibling->window);
break;
case VIEW_STACK_BELOW:
if (TAILQ_LAST(&d->views, view_tailq) == v)
break;
if (TAILQ_NEXT(sibling, display_next) == v)
break;
TAILQ_REMOVE(&d->views, v, display_next);
TAILQ_INSERT_AFTER(&d->views, sibling, v, display_next);
v->window->PutBelow(v->window, sibling->window);
break;
}
return 0;
}
void
view_toggle_labeling(void)
{
struct view *v;
unsigned flags;
mode = (mode + 1) % NUM_BORDER;
flags = (mode == BORDER_OVERLAY) ? DSBLIT_BLEND_COLORALPHA : 0;
TAILQ_FOREACH(v, &all_views, view_next) {
v->wsurface->SetBlittingFlags(v->wsurface, flags);
view_refresh(v);
}
}
/*** DEBUG INTERFACES ***/
void
view_debug_dump(void)
{
struct view *v;
TAILQ_FOREACH(v, &all_views, view_next) {
fprintf(stderr, "View: %p Client: %d Buffer: %d ID: %x\n\tFlags: %x\n\t"
"Buffer Position: %d,%d %dx%d\n\tScreen Position: %d,%d %dx%d\n\t"
"Thumbnail Position: %d,%d %dx%d\n\t"
"Mapped: %d Visible: %d Opacity: %d\n",
v, v->client->id, v->buffer->id, v->id, v->flags,
v->bpos.x, v->bpos.y, v->bpos.w, v->bpos.h,
v->spos.x, v->spos.y, v->spos.w, v->spos.h,
v->tpos.x, v->tpos.y, v->tpos.w, v->tpos.h,
v->mapped, v->visible, v->opacity);
if (v->thumb)
fprintf(stderr, "\tThumbnail: %p Client: %d Buffer: %d ID: %x\n\tFlags: %x\n\t"
"Buffer Position: %d,%d %dx%d\n\tScreen Position: %d,%d %dx%d\n\t"
"Mapped: %d Visible: %d Opacity: %d\n\n",
v->thumb, v->thumb->client->id, v->thumb->buffer->id, v->thumb->id, v->thumb->flags,
v->thumb->bpos.x, v->thumb->bpos.y, v->thumb->bpos.w, v->thumb->bpos.h,
v->thumb->spos.x, v->thumb->spos.y, v->thumb->spos.w, v->thumb->spos.h,
v->thumb->mapped, v->thumb->visible, v->thumb->opacity);
else
fprintf(stderr, "\n");
}
}
|