1 | /*
|
---|
2 | * Copyright (c) 2019 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup display
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /**
|
---|
33 | * @file Display server display
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <errno.h>
|
---|
37 | #include <gfx/bitmap.h>
|
---|
38 | #include <gfx/context.h>
|
---|
39 | #include <gfx/render.h>
|
---|
40 | #include <io/log.h>
|
---|
41 | #include <memgfx/memgc.h>
|
---|
42 | #include <stdlib.h>
|
---|
43 | #include "client.h"
|
---|
44 | #include "clonegc.h"
|
---|
45 | #include "cursimg.h"
|
---|
46 | #include "cursor.h"
|
---|
47 | #include "seat.h"
|
---|
48 | #include "window.h"
|
---|
49 | #include "display.h"
|
---|
50 |
|
---|
51 | static gfx_context_t *ds_display_get_unbuf_gc(ds_display_t *);
|
---|
52 | static void ds_display_update_cb(void *, gfx_rect_t *);
|
---|
53 |
|
---|
54 | /** Create display.
|
---|
55 | *
|
---|
56 | * @param gc Graphics context for displaying output
|
---|
57 | * @param flags Display flags
|
---|
58 | * @param rdisp Place to store pointer to new display.
|
---|
59 | * @return EOK on success, ENOMEM if out of memory
|
---|
60 | */
|
---|
61 | errno_t ds_display_create(gfx_context_t *gc, ds_display_flags_t flags,
|
---|
62 | ds_display_t **rdisp)
|
---|
63 | {
|
---|
64 | ds_display_t *disp;
|
---|
65 | ds_cursor_t *cursor;
|
---|
66 | int i;
|
---|
67 | errno_t rc;
|
---|
68 |
|
---|
69 | disp = calloc(1, sizeof(ds_display_t));
|
---|
70 | if (disp == NULL)
|
---|
71 | return ENOMEM;
|
---|
72 |
|
---|
73 | rc = gfx_color_new_rgb_i16(0x8000, 0xc800, 0xffff, &disp->bg_color);
|
---|
74 | if (rc != EOK) {
|
---|
75 | free(disp);
|
---|
76 | return ENOMEM;
|
---|
77 | }
|
---|
78 |
|
---|
79 | list_initialize(&disp->cursors);
|
---|
80 |
|
---|
81 | for (i = 0; i < dcurs_limit; i++) {
|
---|
82 | rc = ds_cursor_create(disp, &ds_cursimg[i].rect,
|
---|
83 | ds_cursimg[i].image, &cursor);
|
---|
84 | if (rc != EOK)
|
---|
85 | goto error;
|
---|
86 |
|
---|
87 | disp->cursor[i] = cursor;
|
---|
88 | }
|
---|
89 |
|
---|
90 | fibril_mutex_initialize(&disp->lock);
|
---|
91 | list_initialize(&disp->clients);
|
---|
92 | disp->next_wnd_id = 1;
|
---|
93 | list_initialize(&disp->ddevs);
|
---|
94 | list_initialize(&disp->seats);
|
---|
95 | list_initialize(&disp->windows);
|
---|
96 | disp->flags = flags;
|
---|
97 | *rdisp = disp;
|
---|
98 | return EOK;
|
---|
99 | error:
|
---|
100 | ds_display_destroy(disp);
|
---|
101 | return rc;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /** Destroy display.
|
---|
105 | *
|
---|
106 | * @param disp Display
|
---|
107 | */
|
---|
108 | void ds_display_destroy(ds_display_t *disp)
|
---|
109 | {
|
---|
110 | assert(list_empty(&disp->clients));
|
---|
111 | assert(list_empty(&disp->seats));
|
---|
112 | /* XXX destroy cursors */
|
---|
113 | gfx_color_delete(disp->bg_color);
|
---|
114 | free(disp);
|
---|
115 | }
|
---|
116 |
|
---|
117 | /** Lock display.
|
---|
118 | *
|
---|
119 | * This should be called in any thread that wishes to access the display
|
---|
120 | * or its child objects (e.g. windows).
|
---|
121 | *
|
---|
122 | * @param disp Display
|
---|
123 | */
|
---|
124 | void ds_display_lock(ds_display_t *disp)
|
---|
125 | {
|
---|
126 | fibril_mutex_lock(&disp->lock);
|
---|
127 | }
|
---|
128 |
|
---|
129 | /** Unlock display.
|
---|
130 | *
|
---|
131 | * @param disp Display
|
---|
132 | */
|
---|
133 | void ds_display_unlock(ds_display_t *disp)
|
---|
134 | {
|
---|
135 | fibril_mutex_unlock(&disp->lock);
|
---|
136 | }
|
---|
137 |
|
---|
138 | /** Get display information.
|
---|
139 | *
|
---|
140 | * @param disp Display
|
---|
141 | */
|
---|
142 | void ds_display_get_info(ds_display_t *disp, display_info_t *info)
|
---|
143 | {
|
---|
144 | info->rect = disp->rect;
|
---|
145 | }
|
---|
146 |
|
---|
147 | /** Add client to display.
|
---|
148 | *
|
---|
149 | * @param disp Display
|
---|
150 | * @param client Client
|
---|
151 | */
|
---|
152 | void ds_display_add_client(ds_display_t *disp, ds_client_t *client)
|
---|
153 | {
|
---|
154 | assert(client->display == NULL);
|
---|
155 | assert(!link_used(&client->lclients));
|
---|
156 |
|
---|
157 | client->display = disp;
|
---|
158 | list_append(&client->lclients, &disp->clients);
|
---|
159 | }
|
---|
160 |
|
---|
161 | /** Remove client from display.
|
---|
162 | *
|
---|
163 | * @param client Client
|
---|
164 | */
|
---|
165 | void ds_display_remove_client(ds_client_t *client)
|
---|
166 | {
|
---|
167 | list_remove(&client->lclients);
|
---|
168 | client->display = NULL;
|
---|
169 | }
|
---|
170 |
|
---|
171 | /** Get first client in display.
|
---|
172 | *
|
---|
173 | * @param disp Display
|
---|
174 | * @return First client or @c NULL if there is none
|
---|
175 | */
|
---|
176 | ds_client_t *ds_display_first_client(ds_display_t *disp)
|
---|
177 | {
|
---|
178 | link_t *link = list_first(&disp->clients);
|
---|
179 |
|
---|
180 | if (link == NULL)
|
---|
181 | return NULL;
|
---|
182 |
|
---|
183 | return list_get_instance(link, ds_client_t, lclients);
|
---|
184 | }
|
---|
185 |
|
---|
186 | /** Get next client in display.
|
---|
187 | *
|
---|
188 | * @param client Current client
|
---|
189 | * @return Next client or @c NULL if there is none
|
---|
190 | */
|
---|
191 | ds_client_t *ds_display_next_client(ds_client_t *client)
|
---|
192 | {
|
---|
193 | link_t *link = list_next(&client->lclients, &client->display->clients);
|
---|
194 |
|
---|
195 | if (link == NULL)
|
---|
196 | return NULL;
|
---|
197 |
|
---|
198 | return list_get_instance(link, ds_client_t, lclients);
|
---|
199 | }
|
---|
200 |
|
---|
201 | /** Find window in all clients by ID.
|
---|
202 | *
|
---|
203 | * XXX This is just a hack needed to match GC connection to a window,
|
---|
204 | * as we don't have a good safe way to pass the GC endpoint to our client
|
---|
205 | * on demand.
|
---|
206 | *
|
---|
207 | * @param display Display
|
---|
208 | * @param id Window ID
|
---|
209 | */
|
---|
210 | ds_window_t *ds_display_find_window(ds_display_t *display, ds_wnd_id_t id)
|
---|
211 | {
|
---|
212 | ds_client_t *client;
|
---|
213 | ds_window_t *wnd;
|
---|
214 |
|
---|
215 | client = ds_display_first_client(display);
|
---|
216 | while (client != NULL) {
|
---|
217 | wnd = ds_client_find_window(client, id);
|
---|
218 | if (wnd != NULL)
|
---|
219 | return wnd;
|
---|
220 |
|
---|
221 | client = ds_display_next_client(client);
|
---|
222 | }
|
---|
223 |
|
---|
224 | return NULL;
|
---|
225 | }
|
---|
226 |
|
---|
227 | /** Find window by display position.
|
---|
228 | *
|
---|
229 | * @param display Display
|
---|
230 | * @param pos Display position
|
---|
231 | */
|
---|
232 | ds_window_t *ds_display_window_by_pos(ds_display_t *display, gfx_coord2_t *pos)
|
---|
233 | {
|
---|
234 | ds_window_t *wnd;
|
---|
235 | gfx_rect_t drect;
|
---|
236 |
|
---|
237 | wnd = ds_display_first_window(display);
|
---|
238 | while (wnd != NULL) {
|
---|
239 | /* Window bounding rectangle on display */
|
---|
240 | gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
|
---|
241 |
|
---|
242 | if (gfx_pix_inside_rect(pos, &drect))
|
---|
243 | return wnd;
|
---|
244 |
|
---|
245 | wnd = ds_display_next_window(wnd);
|
---|
246 | }
|
---|
247 |
|
---|
248 | return NULL;
|
---|
249 | }
|
---|
250 |
|
---|
251 | /** Add window to display.
|
---|
252 | *
|
---|
253 | * @param display Display
|
---|
254 | * @param wnd Window
|
---|
255 | */
|
---|
256 | void ds_display_add_window(ds_display_t *display, ds_window_t *wnd)
|
---|
257 | {
|
---|
258 | assert(wnd->display == NULL);
|
---|
259 | assert(!link_used(&wnd->ldwindows));
|
---|
260 |
|
---|
261 | wnd->display = display;
|
---|
262 | list_prepend(&wnd->ldwindows, &display->windows);
|
---|
263 | }
|
---|
264 |
|
---|
265 | /** Remove window from display.
|
---|
266 | *
|
---|
267 | * @param wnd Window
|
---|
268 | */
|
---|
269 | void ds_display_remove_window(ds_window_t *wnd)
|
---|
270 | {
|
---|
271 | list_remove(&wnd->ldwindows);
|
---|
272 | wnd->display = NULL;
|
---|
273 | }
|
---|
274 |
|
---|
275 | /** Get first window in display.
|
---|
276 | *
|
---|
277 | * @param display Display
|
---|
278 | * @return First window or @c NULL if there is none
|
---|
279 | */
|
---|
280 | ds_window_t *ds_display_first_window(ds_display_t *display)
|
---|
281 | {
|
---|
282 | link_t *link = list_first(&display->windows);
|
---|
283 |
|
---|
284 | if (link == NULL)
|
---|
285 | return NULL;
|
---|
286 |
|
---|
287 | return list_get_instance(link, ds_window_t, ldwindows);
|
---|
288 | }
|
---|
289 |
|
---|
290 | /** Get last window in display.
|
---|
291 | *
|
---|
292 | * @param display Display
|
---|
293 | * @return Last window or @c NULL if there is none
|
---|
294 | */
|
---|
295 | ds_window_t *ds_display_last_window(ds_display_t *display)
|
---|
296 | {
|
---|
297 | link_t *link = list_last(&display->windows);
|
---|
298 |
|
---|
299 | if (link == NULL)
|
---|
300 | return NULL;
|
---|
301 |
|
---|
302 | return list_get_instance(link, ds_window_t, ldwindows);
|
---|
303 | }
|
---|
304 |
|
---|
305 | /** Get next window in client.
|
---|
306 | *
|
---|
307 | * @param wnd Current window
|
---|
308 | * @return Next window or @c NULL if there is none
|
---|
309 | */
|
---|
310 | ds_window_t *ds_display_next_window(ds_window_t *wnd)
|
---|
311 | {
|
---|
312 | link_t *link = list_next(&wnd->ldwindows, &wnd->display->windows);
|
---|
313 |
|
---|
314 | if (link == NULL)
|
---|
315 | return NULL;
|
---|
316 |
|
---|
317 | return list_get_instance(link, ds_window_t, ldwindows);
|
---|
318 | }
|
---|
319 |
|
---|
320 | /** Get previous window in client.
|
---|
321 | *
|
---|
322 | * @param wnd Current window
|
---|
323 | * @return Previous window or @c NULL if there is none
|
---|
324 | */
|
---|
325 | ds_window_t *ds_display_prev_window(ds_window_t *wnd)
|
---|
326 | {
|
---|
327 | link_t *link = list_prev(&wnd->ldwindows, &wnd->display->windows);
|
---|
328 |
|
---|
329 | if (link == NULL)
|
---|
330 | return NULL;
|
---|
331 |
|
---|
332 | return list_get_instance(link, ds_window_t, ldwindows);
|
---|
333 | }
|
---|
334 |
|
---|
335 | /** Post keyboard event to a display.
|
---|
336 | *
|
---|
337 | * The event is routed to the correct window by first determining the
|
---|
338 | * seat the keyboard device belongs to and then the event is sent to the
|
---|
339 | * window focused by that seat.
|
---|
340 | *
|
---|
341 | * @param display Display
|
---|
342 | * @param event Event
|
---|
343 | */
|
---|
344 | errno_t ds_display_post_kbd_event(ds_display_t *display, kbd_event_t *event)
|
---|
345 | {
|
---|
346 | ds_seat_t *seat;
|
---|
347 |
|
---|
348 | // TODO Determine which seat the event belongs to
|
---|
349 | seat = ds_display_first_seat(display);
|
---|
350 | if (seat == NULL)
|
---|
351 | return EOK;
|
---|
352 |
|
---|
353 | return ds_seat_post_kbd_event(seat, event);
|
---|
354 | }
|
---|
355 |
|
---|
356 | /** Post position event to a display.
|
---|
357 | *
|
---|
358 | * @param display Display
|
---|
359 | * @param event Event
|
---|
360 | */
|
---|
361 | errno_t ds_display_post_ptd_event(ds_display_t *display, ptd_event_t *event)
|
---|
362 | {
|
---|
363 | ds_seat_t *seat;
|
---|
364 |
|
---|
365 | // TODO Determine which seat the event belongs to
|
---|
366 | seat = ds_display_first_seat(display);
|
---|
367 | if (seat == NULL)
|
---|
368 | return EOK;
|
---|
369 |
|
---|
370 | return ds_seat_post_ptd_event(seat, event);
|
---|
371 | }
|
---|
372 |
|
---|
373 | /** Add seat to display.
|
---|
374 | *
|
---|
375 | * @param disp Display
|
---|
376 | * @param seat Seat
|
---|
377 | */
|
---|
378 | void ds_display_add_seat(ds_display_t *disp, ds_seat_t *seat)
|
---|
379 | {
|
---|
380 | assert(seat->display == NULL);
|
---|
381 | assert(!link_used(&seat->lseats));
|
---|
382 |
|
---|
383 | seat->display = disp;
|
---|
384 | list_append(&seat->lseats, &disp->seats);
|
---|
385 | }
|
---|
386 |
|
---|
387 | /** Remove seat from display.
|
---|
388 | *
|
---|
389 | * @param seat Seat
|
---|
390 | */
|
---|
391 | void ds_display_remove_seat(ds_seat_t *seat)
|
---|
392 | {
|
---|
393 | list_remove(&seat->lseats);
|
---|
394 | seat->display = NULL;
|
---|
395 | }
|
---|
396 |
|
---|
397 | /** Get first seat in display.
|
---|
398 | *
|
---|
399 | * @param disp Display
|
---|
400 | * @return First seat or @c NULL if there is none
|
---|
401 | */
|
---|
402 | ds_seat_t *ds_display_first_seat(ds_display_t *disp)
|
---|
403 | {
|
---|
404 | link_t *link = list_first(&disp->seats);
|
---|
405 |
|
---|
406 | if (link == NULL)
|
---|
407 | return NULL;
|
---|
408 |
|
---|
409 | return list_get_instance(link, ds_seat_t, lseats);
|
---|
410 | }
|
---|
411 |
|
---|
412 | /** Get next seat in display.
|
---|
413 | *
|
---|
414 | * @param seat Current seat
|
---|
415 | * @return Next seat or @c NULL if there is none
|
---|
416 | */
|
---|
417 | ds_seat_t *ds_display_next_seat(ds_seat_t *seat)
|
---|
418 | {
|
---|
419 | link_t *link = list_next(&seat->lseats, &seat->display->seats);
|
---|
420 |
|
---|
421 | if (link == NULL)
|
---|
422 | return NULL;
|
---|
423 |
|
---|
424 | return list_get_instance(link, ds_seat_t, lseats);
|
---|
425 | }
|
---|
426 |
|
---|
427 | /** Allocate back buffer for display.
|
---|
428 | *
|
---|
429 | * @param disp Display
|
---|
430 | * @return EOK on success or if no back buffer is required, otherwise
|
---|
431 | * an error code.
|
---|
432 | */
|
---|
433 | static errno_t ds_display_alloc_backbuf(ds_display_t *disp)
|
---|
434 | {
|
---|
435 | gfx_context_t *ugc;
|
---|
436 | gfx_bitmap_params_t params;
|
---|
437 | gfx_bitmap_alloc_t alloc;
|
---|
438 | errno_t rc;
|
---|
439 |
|
---|
440 | /* Allocate backbuffer */
|
---|
441 | if ((disp->flags & df_disp_double_buf) == 0) {
|
---|
442 | /* Not double buffering. Nothing to do. */
|
---|
443 | return EOK;
|
---|
444 | }
|
---|
445 |
|
---|
446 | ugc = ds_display_get_unbuf_gc(disp);
|
---|
447 |
|
---|
448 | gfx_bitmap_params_init(¶ms);
|
---|
449 | params.rect = disp->rect;
|
---|
450 |
|
---|
451 | rc = gfx_bitmap_create(ugc, ¶ms, NULL,
|
---|
452 | &disp->backbuf);
|
---|
453 | if (rc != EOK)
|
---|
454 | goto error;
|
---|
455 |
|
---|
456 | rc = gfx_bitmap_get_alloc(disp->backbuf, &alloc);
|
---|
457 | if (rc != EOK)
|
---|
458 | goto error;
|
---|
459 |
|
---|
460 | rc = mem_gc_create(&disp->rect, &alloc,
|
---|
461 | ds_display_update_cb, (void *) disp, &disp->bbgc);
|
---|
462 | if (rc != EOK)
|
---|
463 | goto error;
|
---|
464 |
|
---|
465 | disp->dirty_rect.p0.x = 0;
|
---|
466 | disp->dirty_rect.p0.y = 0;
|
---|
467 | disp->dirty_rect.p1.x = 0;
|
---|
468 | disp->dirty_rect.p1.y = 0;
|
---|
469 |
|
---|
470 | return EOK;
|
---|
471 | error:
|
---|
472 | if (disp->backbuf != NULL) {
|
---|
473 | gfx_bitmap_destroy(disp->backbuf);
|
---|
474 | disp->backbuf = NULL;
|
---|
475 | }
|
---|
476 |
|
---|
477 | return rc;
|
---|
478 | }
|
---|
479 |
|
---|
480 | /** Add display device to display.
|
---|
481 | *
|
---|
482 | * @param disp Display
|
---|
483 | * @param ddev Display device
|
---|
484 | * @return EOK on success, or an error code
|
---|
485 | */
|
---|
486 | errno_t ds_display_add_ddev(ds_display_t *disp, ds_ddev_t *ddev)
|
---|
487 | {
|
---|
488 | errno_t rc;
|
---|
489 |
|
---|
490 | assert(ddev->display == NULL);
|
---|
491 | assert(!link_used(&ddev->lddevs));
|
---|
492 |
|
---|
493 | ddev->display = disp;
|
---|
494 | list_append(&ddev->lddevs, &disp->ddevs);
|
---|
495 |
|
---|
496 | /* First display device */
|
---|
497 | if (gfx_rect_is_empty(&disp->rect)) {
|
---|
498 | /* Set screen dimensions */
|
---|
499 | disp->rect = ddev->info.rect;
|
---|
500 |
|
---|
501 | /* Create cloning GC */
|
---|
502 | rc = ds_clonegc_create(ddev->gc, &disp->fbgc);
|
---|
503 | if (rc != EOK) {
|
---|
504 | // XXX Remove output
|
---|
505 | return ENOMEM;
|
---|
506 | }
|
---|
507 |
|
---|
508 | /* Allocate backbuffer */
|
---|
509 | rc = ds_display_alloc_backbuf(disp);
|
---|
510 | if (rc != EOK) {
|
---|
511 | // XXX Remove output
|
---|
512 | // XXX Delete clone GC
|
---|
513 | goto error;
|
---|
514 | }
|
---|
515 | } else {
|
---|
516 | /* Add new output device to cloning GC */
|
---|
517 | rc = ds_clonegc_add_output(disp->fbgc, ddev->gc);
|
---|
518 | if (rc != EOK)
|
---|
519 | goto error;
|
---|
520 | }
|
---|
521 |
|
---|
522 | return EOK;
|
---|
523 | error:
|
---|
524 | disp->rect.p0.x = 0;
|
---|
525 | disp->rect.p0.y = 0;
|
---|
526 | disp->rect.p1.x = 0;
|
---|
527 | disp->rect.p1.y = 0;
|
---|
528 | list_remove(&ddev->lddevs);
|
---|
529 | return rc;
|
---|
530 | }
|
---|
531 |
|
---|
532 | /** Remove display device from display.
|
---|
533 | *
|
---|
534 | * @param ddev Display device
|
---|
535 | */
|
---|
536 | void ds_display_remove_ddev(ds_ddev_t *ddev)
|
---|
537 | {
|
---|
538 | list_remove(&ddev->lddevs);
|
---|
539 | ddev->display = NULL;
|
---|
540 | }
|
---|
541 |
|
---|
542 | /** Get first display device in display.
|
---|
543 | *
|
---|
544 | * @param disp Display
|
---|
545 | * @return First display device or @c NULL if there is none
|
---|
546 | */
|
---|
547 | ds_ddev_t *ds_display_first_ddev(ds_display_t *disp)
|
---|
548 | {
|
---|
549 | link_t *link = list_first(&disp->ddevs);
|
---|
550 |
|
---|
551 | if (link == NULL)
|
---|
552 | return NULL;
|
---|
553 |
|
---|
554 | return list_get_instance(link, ds_ddev_t, lddevs);
|
---|
555 | }
|
---|
556 |
|
---|
557 | /** Get next display device in display.
|
---|
558 | *
|
---|
559 | * @param ddev Current display device
|
---|
560 | * @return Next display device or @c NULL if there is none
|
---|
561 | */
|
---|
562 | ds_ddev_t *ds_display_next_ddev(ds_ddev_t *ddev)
|
---|
563 | {
|
---|
564 | link_t *link = list_next(&ddev->lddevs, &ddev->display->ddevs);
|
---|
565 |
|
---|
566 | if (link == NULL)
|
---|
567 | return NULL;
|
---|
568 |
|
---|
569 | return list_get_instance(link, ds_ddev_t, lddevs);
|
---|
570 | }
|
---|
571 |
|
---|
572 | /** Add cursor to display.
|
---|
573 | *
|
---|
574 | * @param display Display
|
---|
575 | * @param cursor Cursor
|
---|
576 | */
|
---|
577 | void ds_display_add_cursor(ds_display_t *display, ds_cursor_t *cursor)
|
---|
578 | {
|
---|
579 | assert(cursor->display == NULL);
|
---|
580 | assert(!link_used(&cursor->ldisplay));
|
---|
581 |
|
---|
582 | cursor->display = display;
|
---|
583 | list_prepend(&cursor->ldisplay, &display->cursors);
|
---|
584 | }
|
---|
585 |
|
---|
586 | /** Remove cursor from display.
|
---|
587 | *
|
---|
588 | * @param cursor Cursor
|
---|
589 | */
|
---|
590 | void ds_display_remove_cursor(ds_cursor_t *cursor)
|
---|
591 | {
|
---|
592 | list_remove(&cursor->ldisplay);
|
---|
593 | cursor->display = NULL;
|
---|
594 | }
|
---|
595 |
|
---|
596 | /** Get unbuffered GC.
|
---|
597 | *
|
---|
598 | * Get the display's (unbuffered) graphic context. If the display
|
---|
599 | * is double-buffered, this returns GC of the front buffer. If the display
|
---|
600 | * is unbuffered, this is the same as @c ds_display_get_gc().
|
---|
601 | *
|
---|
602 | * @param display Display
|
---|
603 | * @return Unbuffered GC
|
---|
604 | */
|
---|
605 | static gfx_context_t *ds_display_get_unbuf_gc(ds_display_t *display)
|
---|
606 | {
|
---|
607 | /* In case of unit tests */
|
---|
608 | if (display->fbgc == NULL)
|
---|
609 | return NULL;
|
---|
610 |
|
---|
611 | return ds_clonegc_get_ctx(display->fbgc);
|
---|
612 | }
|
---|
613 |
|
---|
614 | /** Get display GC.
|
---|
615 | *
|
---|
616 | * Get the graphic context used to paint the display. This is to be used
|
---|
617 | * for all display server paint operations.
|
---|
618 | *
|
---|
619 | * @param display Display
|
---|
620 | * @return Graphic context for painting to the display
|
---|
621 | */
|
---|
622 | gfx_context_t *ds_display_get_gc(ds_display_t *display)
|
---|
623 | {
|
---|
624 | if ((display->flags & df_disp_double_buf) != 0)
|
---|
625 | return mem_gc_get_ctx(display->bbgc);
|
---|
626 | else
|
---|
627 | return ds_display_get_unbuf_gc(display);
|
---|
628 | }
|
---|
629 |
|
---|
630 | /** Paint display background.
|
---|
631 | *
|
---|
632 | * @param display Display
|
---|
633 | * @param rect Bounding rectangle or @c NULL to repaint entire display
|
---|
634 | */
|
---|
635 | errno_t ds_display_paint_bg(ds_display_t *disp, gfx_rect_t *rect)
|
---|
636 | {
|
---|
637 | gfx_rect_t crect;
|
---|
638 | gfx_context_t *gc;
|
---|
639 | errno_t rc;
|
---|
640 |
|
---|
641 | if (rect != NULL)
|
---|
642 | gfx_rect_clip(&disp->rect, rect, &crect);
|
---|
643 | else
|
---|
644 | crect = disp->rect;
|
---|
645 |
|
---|
646 | gc = ds_display_get_gc(disp);
|
---|
647 | if (gc == NULL)
|
---|
648 | return EOK;
|
---|
649 |
|
---|
650 | rc = gfx_set_color(gc, disp->bg_color);
|
---|
651 | if (rc != EOK)
|
---|
652 | return rc;
|
---|
653 |
|
---|
654 | return gfx_fill_rect(gc, &crect);
|
---|
655 | }
|
---|
656 |
|
---|
657 | /** Update front buffer from back buffer.
|
---|
658 | *
|
---|
659 | * If the display is not double-buffered, no action is taken.
|
---|
660 | *
|
---|
661 | * @param disp Display
|
---|
662 | * @return EOK on success, or an error code
|
---|
663 | */
|
---|
664 | static errno_t ds_display_update(ds_display_t *disp)
|
---|
665 | {
|
---|
666 | errno_t rc;
|
---|
667 |
|
---|
668 | if (disp->backbuf == NULL) {
|
---|
669 | /* Not double-buffered, nothing to do. */
|
---|
670 | return EOK;
|
---|
671 | }
|
---|
672 |
|
---|
673 | rc = gfx_bitmap_render(disp->backbuf, &disp->dirty_rect, NULL);
|
---|
674 | if (rc != EOK)
|
---|
675 | return rc;
|
---|
676 |
|
---|
677 | disp->dirty_rect.p0.x = 0;
|
---|
678 | disp->dirty_rect.p0.y = 0;
|
---|
679 | disp->dirty_rect.p1.x = 0;
|
---|
680 | disp->dirty_rect.p1.y = 0;
|
---|
681 |
|
---|
682 | return EOK;
|
---|
683 | }
|
---|
684 |
|
---|
685 | /** Paint display.
|
---|
686 | *
|
---|
687 | * @param display Display
|
---|
688 | * @param rect Bounding rectangle or @c NULL to repaint entire display
|
---|
689 | */
|
---|
690 | errno_t ds_display_paint(ds_display_t *disp, gfx_rect_t *rect)
|
---|
691 | {
|
---|
692 | errno_t rc;
|
---|
693 | ds_window_t *wnd;
|
---|
694 | ds_seat_t *seat;
|
---|
695 |
|
---|
696 | /* Paint background */
|
---|
697 | rc = ds_display_paint_bg(disp, rect);
|
---|
698 | if (rc != EOK)
|
---|
699 | return rc;
|
---|
700 |
|
---|
701 | /* Paint windows bottom to top */
|
---|
702 | wnd = ds_display_last_window(disp);
|
---|
703 | while (wnd != NULL) {
|
---|
704 | rc = ds_window_paint(wnd, rect);
|
---|
705 | if (rc != EOK)
|
---|
706 | return rc;
|
---|
707 |
|
---|
708 | wnd = ds_display_prev_window(wnd);
|
---|
709 | }
|
---|
710 |
|
---|
711 | /* Paint window previews for windows being resized or moved */
|
---|
712 | wnd = ds_display_last_window(disp);
|
---|
713 | while (wnd != NULL) {
|
---|
714 | rc = ds_window_paint_preview(wnd, rect);
|
---|
715 | if (rc != EOK)
|
---|
716 | return rc;
|
---|
717 |
|
---|
718 | wnd = ds_display_prev_window(wnd);
|
---|
719 | }
|
---|
720 |
|
---|
721 | /* Paint pointers */
|
---|
722 | seat = ds_display_first_seat(disp);
|
---|
723 | while (seat != NULL) {
|
---|
724 | rc = ds_seat_paint_pointer(seat, rect);
|
---|
725 | if (rc != EOK)
|
---|
726 | return rc;
|
---|
727 |
|
---|
728 | seat = ds_display_next_seat(seat);
|
---|
729 | }
|
---|
730 |
|
---|
731 | return ds_display_update(disp);
|
---|
732 | }
|
---|
733 |
|
---|
734 | /** Display update callback.
|
---|
735 | *
|
---|
736 | * Called by backbuffer memory GC when something is rendered into it.
|
---|
737 | * Updates the display's dirty rectangle.
|
---|
738 | *
|
---|
739 | * @param arg Argument (display cast as void *)
|
---|
740 | * @param rect Rectangle to update
|
---|
741 | */
|
---|
742 | static void ds_display_update_cb(void *arg, gfx_rect_t *rect)
|
---|
743 | {
|
---|
744 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
745 | gfx_rect_t env;
|
---|
746 |
|
---|
747 | gfx_rect_envelope(&disp->dirty_rect, rect, &env);
|
---|
748 | disp->dirty_rect = env;
|
---|
749 | }
|
---|
750 |
|
---|
751 | /** @}
|
---|
752 | */
|
---|