source: mainline/uspace/srv/hid/display/display.c@ 29a5a99

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 29a5a99 was 29a5a99, checked in by Jiri Svoboda <jiri@…>, 3 years ago

Maximized windows should avoid task bar

  • Property mode set to 100644
File size: 21.9 KB
Line 
1/*
2 * Copyright (c) 2022 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 "display.h"
48#include "seat.h"
49#include "window.h"
50#include "wmclient.h"
51
52static gfx_context_t *ds_display_get_unbuf_gc(ds_display_t *);
53static void ds_display_invalidate_cb(void *, gfx_rect_t *);
54static void ds_display_update_cb(void *);
55
56static mem_gc_cb_t ds_display_mem_gc_cb = {
57 .invalidate = ds_display_invalidate_cb,
58 .update = ds_display_update_cb
59};
60
61/** Create display.
62 *
63 * @param gc Graphics context for displaying output
64 * @param flags Display flags
65 * @param rdisp Place to store pointer to new display.
66 * @return EOK on success, ENOMEM if out of memory
67 */
68errno_t ds_display_create(gfx_context_t *gc, ds_display_flags_t flags,
69 ds_display_t **rdisp)
70{
71 ds_display_t *disp;
72 ds_cursor_t *cursor;
73 int i;
74 errno_t rc;
75
76 disp = calloc(1, sizeof(ds_display_t));
77 if (disp == NULL)
78 return ENOMEM;
79
80 rc = gfx_color_new_rgb_i16(0x8000, 0xc800, 0xffff, &disp->bg_color);
81 if (rc != EOK) {
82 free(disp);
83 return ENOMEM;
84 }
85
86 list_initialize(&disp->cursors);
87
88 for (i = 0; i < dcurs_limit; i++) {
89 rc = ds_cursor_create(disp, &ds_cursimg[i].rect,
90 ds_cursimg[i].image, &cursor);
91 if (rc != EOK)
92 goto error;
93
94 disp->cursor[i] = cursor;
95 }
96
97 fibril_mutex_initialize(&disp->lock);
98 list_initialize(&disp->clients);
99 list_initialize(&disp->wmclients);
100 disp->next_wnd_id = 1;
101 list_initialize(&disp->ddevs);
102 list_initialize(&disp->seats);
103 list_initialize(&disp->windows);
104 disp->flags = flags;
105 *rdisp = disp;
106 return EOK;
107error:
108 ds_display_destroy(disp);
109 return rc;
110}
111
112/** Destroy display.
113 *
114 * @param disp Display
115 */
116void ds_display_destroy(ds_display_t *disp)
117{
118 assert(list_empty(&disp->clients));
119 assert(list_empty(&disp->wmclients));
120 assert(list_empty(&disp->seats));
121 /* XXX destroy cursors */
122 gfx_color_delete(disp->bg_color);
123 free(disp);
124}
125
126/** Lock display.
127 *
128 * This should be called in any thread that wishes to access the display
129 * or its child objects (e.g. windows).
130 *
131 * @param disp Display
132 */
133void ds_display_lock(ds_display_t *disp)
134{
135 fibril_mutex_lock(&disp->lock);
136}
137
138/** Unlock display.
139 *
140 * @param disp Display
141 */
142void ds_display_unlock(ds_display_t *disp)
143{
144 fibril_mutex_unlock(&disp->lock);
145}
146
147/** Get display information.
148 *
149 * @param disp Display
150 */
151void ds_display_get_info(ds_display_t *disp, display_info_t *info)
152{
153 info->rect = disp->rect;
154}
155
156/** Add client to display.
157 *
158 * @param disp Display
159 * @param client Client
160 */
161void ds_display_add_client(ds_display_t *disp, ds_client_t *client)
162{
163 assert(client->display == NULL);
164 assert(!link_used(&client->lclients));
165
166 client->display = disp;
167 list_append(&client->lclients, &disp->clients);
168}
169
170/** Remove client from display.
171 *
172 * @param client Client
173 */
174void ds_display_remove_client(ds_client_t *client)
175{
176 list_remove(&client->lclients);
177 client->display = NULL;
178}
179
180/** Get first client in display.
181 *
182 * @param disp Display
183 * @return First client or @c NULL if there is none
184 */
185ds_client_t *ds_display_first_client(ds_display_t *disp)
186{
187 link_t *link = list_first(&disp->clients);
188
189 if (link == NULL)
190 return NULL;
191
192 return list_get_instance(link, ds_client_t, lclients);
193}
194
195/** Get next client in display.
196 *
197 * @param client Current client
198 * @return Next client or @c NULL if there is none
199 */
200ds_client_t *ds_display_next_client(ds_client_t *client)
201{
202 link_t *link = list_next(&client->lclients, &client->display->clients);
203
204 if (link == NULL)
205 return NULL;
206
207 return list_get_instance(link, ds_client_t, lclients);
208}
209
210/** Add WM client to display.
211 *
212 * @param disp Display
213 * @param wmclient WM client
214 */
215void ds_display_add_wmclient(ds_display_t *disp, ds_wmclient_t *wmclient)
216{
217 assert(wmclient->display == NULL);
218 assert(!link_used(&wmclient->lwmclients));
219
220 wmclient->display = disp;
221 list_append(&wmclient->lwmclients, &disp->wmclients);
222}
223
224/** Remove WM client from display.
225 *
226 * @param wmclient WM client
227 */
228void ds_display_remove_wmclient(ds_wmclient_t *wmclient)
229{
230 list_remove(&wmclient->lwmclients);
231 wmclient->display = NULL;
232}
233
234/** Get first WM client in display.
235 *
236 * @param disp Display
237 * @return First WM client or @c NULL if there is none
238 */
239ds_wmclient_t *ds_display_first_wmclient(ds_display_t *disp)
240{
241 link_t *link = list_first(&disp->wmclients);
242
243 if (link == NULL)
244 return NULL;
245
246 return list_get_instance(link, ds_wmclient_t, lwmclients);
247}
248
249/** Get next WM client in display.
250 *
251 * @param wmclient Current WM client
252 * @return Next WM client or @c NULL if there is none
253 */
254ds_wmclient_t *ds_display_next_wmclient(ds_wmclient_t *wmclient)
255{
256 link_t *link = list_next(&wmclient->lwmclients,
257 &wmclient->display->wmclients);
258
259 if (link == NULL)
260 return NULL;
261
262 return list_get_instance(link, ds_wmclient_t, lwmclients);
263}
264
265/** Find window in all clients by ID.
266 *
267 * XXX This is just a hack needed to match GC connection to a window,
268 * as we don't have a good safe way to pass the GC endpoint to our client
269 * on demand.
270 *
271 * @param display Display
272 * @param id Window ID
273 */
274ds_window_t *ds_display_find_window(ds_display_t *display, ds_wnd_id_t id)
275{
276 ds_client_t *client;
277 ds_window_t *wnd;
278
279 client = ds_display_first_client(display);
280 while (client != NULL) {
281 wnd = ds_client_find_window(client, id);
282 if (wnd != NULL)
283 return wnd;
284
285 client = ds_display_next_client(client);
286 }
287
288 return NULL;
289}
290
291/** Find window by display position.
292 *
293 * @param display Display
294 * @param pos Display position
295 */
296ds_window_t *ds_display_window_by_pos(ds_display_t *display, gfx_coord2_t *pos)
297{
298 ds_window_t *wnd;
299 gfx_rect_t drect;
300
301 wnd = ds_display_first_window(display);
302 while (wnd != NULL) {
303 /* Window bounding rectangle on display */
304 gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
305
306 if (gfx_pix_inside_rect(pos, &drect))
307 return wnd;
308
309 wnd = ds_display_next_window(wnd);
310 }
311
312 return NULL;
313}
314
315/** Add window to window list.
316 *
317 * Topmost windows are enlisted before any other window. Non-topmost
318 * windows are enlisted before any other non-topmost window.
319 *
320 * @param display Display
321 * @param wnd Window
322 */
323void ds_display_enlist_window(ds_display_t *display, ds_window_t *wnd)
324{
325 ds_window_t *w;
326
327 assert(wnd->display == display);
328 assert(!link_used(&wnd->ldwindows));
329
330 if ((wnd->flags & wndf_topmost) == 0) {
331 /* Find the first non-topmost window */
332 w = ds_display_first_window(display);
333 while (w != NULL && (w->flags & wndf_topmost) != 0)
334 w = ds_display_next_window(w);
335
336 if (w != NULL)
337 list_insert_before(&wnd->ldwindows, &w->ldwindows);
338 else
339 list_append(&wnd->ldwindows, &display->windows);
340 } else {
341 /* Insert at the beginning */
342 list_prepend(&wnd->ldwindows, &display->windows);
343 }
344
345}
346
347/** Add window to display.
348 *
349 * @param display Display
350 * @param wnd Window
351 */
352void ds_display_add_window(ds_display_t *display, ds_window_t *wnd)
353{
354 ds_wmclient_t *wmclient;
355
356 assert(wnd->display == NULL);
357 assert(!link_used(&wnd->ldwindows));
358
359 wnd->display = display;
360 ds_display_enlist_window(display, wnd);
361
362 /* Notify window managers about the new window */
363 wmclient = ds_display_first_wmclient(display);
364 while (wmclient != NULL) {
365 ds_wmclient_post_wnd_added_event(wmclient, wnd->id);
366 wmclient = ds_display_next_wmclient(wmclient);
367 }
368}
369
370/** Remove window from display.
371 *
372 * @param wnd Window
373 */
374void ds_display_remove_window(ds_window_t *wnd)
375{
376 ds_wmclient_t *wmclient;
377 ds_display_t *display;
378
379 display = wnd->display;
380
381 list_remove(&wnd->ldwindows);
382 wnd->display = NULL;
383
384 /* Notify window managers about the removed window */
385 wmclient = ds_display_first_wmclient(display);
386 while (wmclient != NULL) {
387 ds_wmclient_post_wnd_removed_event(wmclient, wnd->id);
388 wmclient = ds_display_next_wmclient(wmclient);
389 }
390}
391
392/** Move window to top.
393 *
394 * @param display Display
395 * @param wnd Window
396 */
397void ds_display_window_to_top(ds_window_t *wnd)
398{
399 assert(wnd->display != NULL);
400 assert(link_used(&wnd->ldwindows));
401
402 list_remove(&wnd->ldwindows);
403 ds_display_enlist_window(wnd->display, wnd);
404}
405
406/** Get first window in display.
407 *
408 * @param display Display
409 * @return First window or @c NULL if there is none
410 */
411ds_window_t *ds_display_first_window(ds_display_t *display)
412{
413 link_t *link = list_first(&display->windows);
414
415 if (link == NULL)
416 return NULL;
417
418 return list_get_instance(link, ds_window_t, ldwindows);
419}
420
421/** Get last window in display.
422 *
423 * @param display Display
424 * @return Last window or @c NULL if there is none
425 */
426ds_window_t *ds_display_last_window(ds_display_t *display)
427{
428 link_t *link = list_last(&display->windows);
429
430 if (link == NULL)
431 return NULL;
432
433 return list_get_instance(link, ds_window_t, ldwindows);
434}
435
436/** Get next window in client.
437 *
438 * @param wnd Current window
439 * @return Next window or @c NULL if there is none
440 */
441ds_window_t *ds_display_next_window(ds_window_t *wnd)
442{
443 link_t *link = list_next(&wnd->ldwindows, &wnd->display->windows);
444
445 if (link == NULL)
446 return NULL;
447
448 return list_get_instance(link, ds_window_t, ldwindows);
449}
450
451/** Get previous window in client.
452 *
453 * @param wnd Current window
454 * @return Previous window or @c NULL if there is none
455 */
456ds_window_t *ds_display_prev_window(ds_window_t *wnd)
457{
458 link_t *link = list_prev(&wnd->ldwindows, &wnd->display->windows);
459
460 if (link == NULL)
461 return NULL;
462
463 return list_get_instance(link, ds_window_t, ldwindows);
464}
465
466/** Post keyboard event to a display.
467 *
468 * The event is routed to the correct window by first determining the
469 * seat the keyboard device belongs to and then the event is sent to the
470 * window focused by that seat.
471 *
472 * @param display Display
473 * @param event Event
474 */
475errno_t ds_display_post_kbd_event(ds_display_t *display, kbd_event_t *event)
476{
477 ds_seat_t *seat;
478
479 /* Determine which seat the event belongs to */
480 seat = ds_display_seat_by_idev(display, event->kbd_id);
481 if (seat == NULL)
482 return EOK;
483
484 return ds_seat_post_kbd_event(seat, event);
485}
486
487/** Post position event to a display.
488 *
489 * @param display Display
490 * @param event Event
491 */
492errno_t ds_display_post_ptd_event(ds_display_t *display, ptd_event_t *event)
493{
494 ds_seat_t *seat;
495
496 /* Determine which seat the event belongs to */
497 seat = ds_display_seat_by_idev(display, event->pos_id);
498 if (seat == NULL)
499 return EOK;
500
501 return ds_seat_post_ptd_event(seat, event);
502}
503
504/** Add seat to display.
505 *
506 * @param disp Display
507 * @param seat Seat
508 */
509void ds_display_add_seat(ds_display_t *disp, ds_seat_t *seat)
510{
511 assert(seat->display == NULL);
512 assert(!link_used(&seat->lseats));
513
514 seat->display = disp;
515 list_append(&seat->lseats, &disp->seats);
516}
517
518/** Remove seat from display.
519 *
520 * @param seat Seat
521 */
522void ds_display_remove_seat(ds_seat_t *seat)
523{
524 list_remove(&seat->lseats);
525 seat->display = NULL;
526}
527
528/** Get first seat in display.
529 *
530 * @param disp Display
531 * @return First seat or @c NULL if there is none
532 */
533ds_seat_t *ds_display_first_seat(ds_display_t *disp)
534{
535 link_t *link = list_first(&disp->seats);
536
537 if (link == NULL)
538 return NULL;
539
540 return list_get_instance(link, ds_seat_t, lseats);
541}
542
543/** Get next seat in display.
544 *
545 * @param seat Current seat
546 * @return Next seat or @c NULL if there is none
547 */
548ds_seat_t *ds_display_next_seat(ds_seat_t *seat)
549{
550 link_t *link = list_next(&seat->lseats, &seat->display->seats);
551
552 if (link == NULL)
553 return NULL;
554
555 return list_get_instance(link, ds_seat_t, lseats);
556}
557
558/** Get seat which owns the specified input device.
559 *
560 * @param disp Display
561 * @param idev_id Input device ID
562 * @return Seat which owns device with ID @a idev_id or @c NULL if not found
563 */
564ds_seat_t *ds_display_seat_by_idev(ds_display_t *disp, ds_idev_id_t idev_id)
565{
566 // TODO Multi-seat
567 (void) idev_id;
568
569 return ds_display_first_seat(disp);
570}
571
572/** Allocate back buffer for display.
573 *
574 * @param disp Display
575 * @return EOK on success or if no back buffer is required, otherwise
576 * an error code.
577 */
578static errno_t ds_display_alloc_backbuf(ds_display_t *disp)
579{
580 gfx_context_t *ugc;
581 gfx_bitmap_params_t params;
582 gfx_bitmap_alloc_t alloc;
583 errno_t rc;
584
585 /* Allocate backbuffer */
586 if ((disp->flags & df_disp_double_buf) == 0) {
587 /* Not double buffering. Nothing to do. */
588 return EOK;
589 }
590
591 ugc = ds_display_get_unbuf_gc(disp);
592
593 gfx_bitmap_params_init(&params);
594 params.rect = disp->rect;
595
596 rc = gfx_bitmap_create(ugc, &params, NULL,
597 &disp->backbuf);
598 if (rc != EOK)
599 goto error;
600
601 rc = gfx_bitmap_get_alloc(disp->backbuf, &alloc);
602 if (rc != EOK)
603 goto error;
604
605 rc = mem_gc_create(&disp->rect, &alloc, &ds_display_mem_gc_cb,
606 (void *) disp, &disp->bbgc);
607 if (rc != EOK)
608 goto error;
609
610 disp->dirty_rect.p0.x = 0;
611 disp->dirty_rect.p0.y = 0;
612 disp->dirty_rect.p1.x = 0;
613 disp->dirty_rect.p1.y = 0;
614
615 return EOK;
616error:
617 if (disp->backbuf != NULL) {
618 gfx_bitmap_destroy(disp->backbuf);
619 disp->backbuf = NULL;
620 }
621
622 return rc;
623}
624
625/** Add display device to display.
626 *
627 * @param disp Display
628 * @param ddev Display device
629 * @return EOK on success, or an error code
630 */
631errno_t ds_display_add_ddev(ds_display_t *disp, ds_ddev_t *ddev)
632{
633 errno_t rc;
634
635 assert(ddev->display == NULL);
636 assert(!link_used(&ddev->lddevs));
637
638 ddev->display = disp;
639 list_append(&ddev->lddevs, &disp->ddevs);
640
641 /* First display device */
642 if (gfx_rect_is_empty(&disp->rect)) {
643 /* Set screen dimensions */
644 disp->rect = ddev->info.rect;
645
646 /* Create cloning GC */
647 rc = ds_clonegc_create(ddev->gc, &disp->fbgc);
648 if (rc != EOK) {
649 // XXX Remove output
650 return ENOMEM;
651 }
652
653 /* Allocate backbuffer */
654 rc = ds_display_alloc_backbuf(disp);
655 if (rc != EOK) {
656 // XXX Remove output
657 // XXX Delete clone GC
658 goto error;
659 }
660 } else {
661 /* Add new output device to cloning GC */
662 rc = ds_clonegc_add_output(disp->fbgc, ddev->gc);
663 if (rc != EOK)
664 goto error;
665 }
666
667 ds_display_update_max_rect(disp);
668
669 return EOK;
670error:
671 disp->rect.p0.x = 0;
672 disp->rect.p0.y = 0;
673 disp->rect.p1.x = 0;
674 disp->rect.p1.y = 0;
675 list_remove(&ddev->lddevs);
676 return rc;
677}
678
679/** Remove display device from display.
680 *
681 * @param ddev Display device
682 */
683void ds_display_remove_ddev(ds_ddev_t *ddev)
684{
685 list_remove(&ddev->lddevs);
686 ddev->display = NULL;
687}
688
689/** Get first display device in display.
690 *
691 * @param disp Display
692 * @return First display device or @c NULL if there is none
693 */
694ds_ddev_t *ds_display_first_ddev(ds_display_t *disp)
695{
696 link_t *link = list_first(&disp->ddevs);
697
698 if (link == NULL)
699 return NULL;
700
701 return list_get_instance(link, ds_ddev_t, lddevs);
702}
703
704/** Get next display device in display.
705 *
706 * @param ddev Current display device
707 * @return Next display device or @c NULL if there is none
708 */
709ds_ddev_t *ds_display_next_ddev(ds_ddev_t *ddev)
710{
711 link_t *link = list_next(&ddev->lddevs, &ddev->display->ddevs);
712
713 if (link == NULL)
714 return NULL;
715
716 return list_get_instance(link, ds_ddev_t, lddevs);
717}
718
719/** Add cursor to display.
720 *
721 * @param display Display
722 * @param cursor Cursor
723 */
724void ds_display_add_cursor(ds_display_t *display, ds_cursor_t *cursor)
725{
726 assert(cursor->display == NULL);
727 assert(!link_used(&cursor->ldisplay));
728
729 cursor->display = display;
730 list_prepend(&cursor->ldisplay, &display->cursors);
731}
732
733/** Remove cursor from display.
734 *
735 * @param cursor Cursor
736 */
737void ds_display_remove_cursor(ds_cursor_t *cursor)
738{
739 list_remove(&cursor->ldisplay);
740 cursor->display = NULL;
741}
742
743/** Update display maximize rectangle.
744 *
745 * Recalculate the maximize rectangle (the rectangle used for maximized
746 * windows).
747 *
748 * @param display Display
749 */
750void ds_display_update_max_rect(ds_display_t *display)
751{
752 ds_window_t *wnd;
753 gfx_rect_t max_rect;
754 gfx_rect_t drect;
755
756 /* Start with the entire display */
757 max_rect = display->rect;
758
759 wnd = ds_display_first_window(display);
760 while (wnd != NULL) {
761 /* Should maximized windows avoid this window? */
762 if ((wnd->flags & wndf_avoid) != 0) {
763 /* Window bounding rectangle on display */
764 gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
765
766 /* Crop maximized rectangle */
767 ds_display_crop_max_rect(&drect, &max_rect);
768 }
769
770 wnd = ds_display_next_window(wnd);
771 }
772
773 /* Update the maximize rectangle */
774 display->max_rect = max_rect;
775}
776
777/** Crop maximize rectangle.
778 *
779 * Use the avoid rectangle @a arect to crop off maximization rectangle
780 * @a mrect. If @a arect covers the top, bottom, left or right part
781 * of @a mrect, it will be cropped off. Otherwise there will be
782 * no effect.
783 *
784 * @param arect Avoid rectangle
785 * @param mrect Maximize rectangle to be modified
786 */
787void ds_display_crop_max_rect(gfx_rect_t *arect, gfx_rect_t *mrect)
788{
789 if (arect->p0.x == mrect->p0.x && arect->p0.y == mrect->p0.y &&
790 arect->p1.x == mrect->p1.x) {
791 /* Cropp off top part */
792 mrect->p0.y = arect->p1.y;
793 } else if (arect->p0.x == mrect->p0.x && arect->p1.x == mrect->p1.x &&
794 arect->p1.y == mrect->p1.y) {
795 /* Cropp off bottom part */
796 mrect->p1.y = arect->p0.y;
797 } else if (arect->p0.x == mrect->p0.x && arect->p0.y == mrect->p0.y &&
798 arect->p1.y == mrect->p1.y) {
799 /* Cropp off left part */
800 mrect->p0.x = arect->p1.x;
801 } else if (arect->p0.y == mrect->p0.y && arect->p1.x == mrect->p1.x &&
802 arect->p1.y == mrect->p1.y) {
803 /* Cropp off right part */
804 mrect->p1.x = arect->p0.x;
805 }
806}
807
808/** Get unbuffered GC.
809 *
810 * Get the display's (unbuffered) graphic context. If the display
811 * is double-buffered, this returns GC of the front buffer. If the display
812 * is unbuffered, this is the same as @c ds_display_get_gc().
813 *
814 * @param display Display
815 * @return Unbuffered GC
816 */
817static gfx_context_t *ds_display_get_unbuf_gc(ds_display_t *display)
818{
819 /* In case of unit tests */
820 if (display->fbgc == NULL)
821 return NULL;
822
823 return ds_clonegc_get_ctx(display->fbgc);
824}
825
826/** Get display GC.
827 *
828 * Get the graphic context used to paint the display. This is to be used
829 * for all display server paint operations.
830 *
831 * @param display Display
832 * @return Graphic context for painting to the display
833 */
834gfx_context_t *ds_display_get_gc(ds_display_t *display)
835{
836 if ((display->flags & df_disp_double_buf) != 0)
837 return mem_gc_get_ctx(display->bbgc);
838 else
839 return ds_display_get_unbuf_gc(display);
840}
841
842/** Paint display background.
843 *
844 * @param display Display
845 * @param rect Bounding rectangle or @c NULL to repaint entire display
846 */
847errno_t ds_display_paint_bg(ds_display_t *disp, gfx_rect_t *rect)
848{
849 gfx_rect_t crect;
850 gfx_context_t *gc;
851 errno_t rc;
852
853 if (rect != NULL)
854 gfx_rect_clip(&disp->rect, rect, &crect);
855 else
856 crect = disp->rect;
857
858 gc = ds_display_get_gc(disp);
859 if (gc == NULL)
860 return EOK;
861
862 rc = gfx_set_color(gc, disp->bg_color);
863 if (rc != EOK)
864 return rc;
865
866 return gfx_fill_rect(gc, &crect);
867}
868
869/** Update front buffer from back buffer.
870 *
871 * If the display is not double-buffered, no action is taken.
872 *
873 * @param disp Display
874 * @return EOK on success, or an error code
875 */
876static errno_t ds_display_update(ds_display_t *disp)
877{
878 errno_t rc;
879
880 if (disp->backbuf == NULL) {
881 /* Not double-buffered, nothing to do. */
882 return EOK;
883 }
884
885 rc = gfx_bitmap_render(disp->backbuf, &disp->dirty_rect, NULL);
886 if (rc != EOK)
887 return rc;
888
889 disp->dirty_rect.p0.x = 0;
890 disp->dirty_rect.p0.y = 0;
891 disp->dirty_rect.p1.x = 0;
892 disp->dirty_rect.p1.y = 0;
893
894 return EOK;
895}
896
897/** Paint display.
898 *
899 * @param display Display
900 * @param rect Bounding rectangle or @c NULL to repaint entire display
901 */
902errno_t ds_display_paint(ds_display_t *disp, gfx_rect_t *rect)
903{
904 errno_t rc;
905 ds_window_t *wnd;
906 ds_seat_t *seat;
907
908 /* Paint background */
909 rc = ds_display_paint_bg(disp, rect);
910 if (rc != EOK)
911 return rc;
912
913 /* Paint windows bottom to top */
914 wnd = ds_display_last_window(disp);
915 while (wnd != NULL) {
916 rc = ds_window_paint(wnd, rect);
917 if (rc != EOK)
918 return rc;
919
920 wnd = ds_display_prev_window(wnd);
921 }
922
923 /* Paint window previews for windows being resized or moved */
924 wnd = ds_display_last_window(disp);
925 while (wnd != NULL) {
926 rc = ds_window_paint_preview(wnd, rect);
927 if (rc != EOK)
928 return rc;
929
930 wnd = ds_display_prev_window(wnd);
931 }
932
933 /* Paint pointers */
934 seat = ds_display_first_seat(disp);
935 while (seat != NULL) {
936 rc = ds_seat_paint_pointer(seat, rect);
937 if (rc != EOK)
938 return rc;
939
940 seat = ds_display_next_seat(seat);
941 }
942
943 return ds_display_update(disp);
944}
945
946/** Display invalidate callback.
947 *
948 * Called by backbuffer memory GC when something is rendered into it.
949 * Updates the display's dirty rectangle.
950 *
951 * @param arg Argument (display cast as void *)
952 * @param rect Rectangle to update
953 */
954static void ds_display_invalidate_cb(void *arg, gfx_rect_t *rect)
955{
956 ds_display_t *disp = (ds_display_t *) arg;
957 gfx_rect_t env;
958
959 gfx_rect_envelope(&disp->dirty_rect, rect, &env);
960 disp->dirty_rect = env;
961}
962
963/** Display update callback.
964 *
965 * @param arg Argument (display cast as void *)
966 */
967static void ds_display_update_cb(void *arg)
968{
969 ds_display_t *disp = (ds_display_t *) arg;
970
971 (void) disp;
972}
973
974/** @}
975 */
Note: See TracBrowser for help on using the repository browser.