source: mainline/uspace/srv/hid/display/display.c@ 06176e1

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

Minimizing windows

  • Property mode set to 100644
File size: 22.0 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 ds_window_is_visible(wnd))
308 return wnd;
309
310 wnd = ds_display_next_window(wnd);
311 }
312
313 return NULL;
314}
315
316/** Add window to window list.
317 *
318 * Topmost windows are enlisted before any other window. Non-topmost
319 * windows are enlisted before any other non-topmost window.
320 *
321 * @param display Display
322 * @param wnd Window
323 */
324void ds_display_enlist_window(ds_display_t *display, ds_window_t *wnd)
325{
326 ds_window_t *w;
327
328 assert(wnd->display == display);
329 assert(!link_used(&wnd->ldwindows));
330
331 if ((wnd->flags & wndf_topmost) == 0) {
332 /* Find the first non-topmost window */
333 w = ds_display_first_window(display);
334 while (w != NULL && (w->flags & wndf_topmost) != 0)
335 w = ds_display_next_window(w);
336
337 if (w != NULL)
338 list_insert_before(&wnd->ldwindows, &w->ldwindows);
339 else
340 list_append(&wnd->ldwindows, &display->windows);
341 } else {
342 /* Insert at the beginning */
343 list_prepend(&wnd->ldwindows, &display->windows);
344 }
345
346}
347
348/** Add window to display.
349 *
350 * @param display Display
351 * @param wnd Window
352 */
353void ds_display_add_window(ds_display_t *display, ds_window_t *wnd)
354{
355 ds_wmclient_t *wmclient;
356
357 assert(wnd->display == NULL);
358 assert(!link_used(&wnd->ldwindows));
359
360 wnd->display = display;
361 ds_display_enlist_window(display, wnd);
362
363 /* Notify window managers about the new window */
364 wmclient = ds_display_first_wmclient(display);
365 while (wmclient != NULL) {
366 ds_wmclient_post_wnd_added_event(wmclient, wnd->id);
367 wmclient = ds_display_next_wmclient(wmclient);
368 }
369}
370
371/** Remove window from display.
372 *
373 * @param wnd Window
374 */
375void ds_display_remove_window(ds_window_t *wnd)
376{
377 ds_wmclient_t *wmclient;
378 ds_display_t *display;
379
380 display = wnd->display;
381
382 list_remove(&wnd->ldwindows);
383 wnd->display = NULL;
384
385 /* Notify window managers about the removed window */
386 wmclient = ds_display_first_wmclient(display);
387 while (wmclient != NULL) {
388 ds_wmclient_post_wnd_removed_event(wmclient, wnd->id);
389 wmclient = ds_display_next_wmclient(wmclient);
390 }
391}
392
393/** Move window to top.
394 *
395 * @param display Display
396 * @param wnd Window
397 */
398void ds_display_window_to_top(ds_window_t *wnd)
399{
400 assert(wnd->display != NULL);
401 assert(link_used(&wnd->ldwindows));
402
403 list_remove(&wnd->ldwindows);
404 ds_display_enlist_window(wnd->display, wnd);
405}
406
407/** Get first window in display.
408 *
409 * @param display Display
410 * @return First window or @c NULL if there is none
411 */
412ds_window_t *ds_display_first_window(ds_display_t *display)
413{
414 link_t *link = list_first(&display->windows);
415
416 if (link == NULL)
417 return NULL;
418
419 return list_get_instance(link, ds_window_t, ldwindows);
420}
421
422/** Get last window in display.
423 *
424 * @param display Display
425 * @return Last window or @c NULL if there is none
426 */
427ds_window_t *ds_display_last_window(ds_display_t *display)
428{
429 link_t *link = list_last(&display->windows);
430
431 if (link == NULL)
432 return NULL;
433
434 return list_get_instance(link, ds_window_t, ldwindows);
435}
436
437/** Get next window in client.
438 *
439 * @param wnd Current window
440 * @return Next window or @c NULL if there is none
441 */
442ds_window_t *ds_display_next_window(ds_window_t *wnd)
443{
444 link_t *link = list_next(&wnd->ldwindows, &wnd->display->windows);
445
446 if (link == NULL)
447 return NULL;
448
449 return list_get_instance(link, ds_window_t, ldwindows);
450}
451
452/** Get previous window in client.
453 *
454 * @param wnd Current window
455 * @return Previous window or @c NULL if there is none
456 */
457ds_window_t *ds_display_prev_window(ds_window_t *wnd)
458{
459 link_t *link = list_prev(&wnd->ldwindows, &wnd->display->windows);
460
461 if (link == NULL)
462 return NULL;
463
464 return list_get_instance(link, ds_window_t, ldwindows);
465}
466
467/** Post keyboard event to a display.
468 *
469 * The event is routed to the correct window by first determining the
470 * seat the keyboard device belongs to and then the event is sent to the
471 * window focused by that seat.
472 *
473 * @param display Display
474 * @param event Event
475 */
476errno_t ds_display_post_kbd_event(ds_display_t *display, kbd_event_t *event)
477{
478 ds_seat_t *seat;
479
480 /* Determine which seat the event belongs to */
481 seat = ds_display_seat_by_idev(display, event->kbd_id);
482 if (seat == NULL)
483 return EOK;
484
485 return ds_seat_post_kbd_event(seat, event);
486}
487
488/** Post position event to a display.
489 *
490 * @param display Display
491 * @param event Event
492 */
493errno_t ds_display_post_ptd_event(ds_display_t *display, ptd_event_t *event)
494{
495 ds_seat_t *seat;
496
497 /* Determine which seat the event belongs to */
498 seat = ds_display_seat_by_idev(display, event->pos_id);
499 if (seat == NULL)
500 return EOK;
501
502 return ds_seat_post_ptd_event(seat, event);
503}
504
505/** Add seat to display.
506 *
507 * @param disp Display
508 * @param seat Seat
509 */
510void ds_display_add_seat(ds_display_t *disp, ds_seat_t *seat)
511{
512 assert(seat->display == NULL);
513 assert(!link_used(&seat->lseats));
514
515 seat->display = disp;
516 list_append(&seat->lseats, &disp->seats);
517}
518
519/** Remove seat from display.
520 *
521 * @param seat Seat
522 */
523void ds_display_remove_seat(ds_seat_t *seat)
524{
525 list_remove(&seat->lseats);
526 seat->display = NULL;
527}
528
529/** Get first seat in display.
530 *
531 * @param disp Display
532 * @return First seat or @c NULL if there is none
533 */
534ds_seat_t *ds_display_first_seat(ds_display_t *disp)
535{
536 link_t *link = list_first(&disp->seats);
537
538 if (link == NULL)
539 return NULL;
540
541 return list_get_instance(link, ds_seat_t, lseats);
542}
543
544/** Get next seat in display.
545 *
546 * @param seat Current seat
547 * @return Next seat or @c NULL if there is none
548 */
549ds_seat_t *ds_display_next_seat(ds_seat_t *seat)
550{
551 link_t *link = list_next(&seat->lseats, &seat->display->seats);
552
553 if (link == NULL)
554 return NULL;
555
556 return list_get_instance(link, ds_seat_t, lseats);
557}
558
559/** Get seat which owns the specified input device.
560 *
561 * @param disp Display
562 * @param idev_id Input device ID
563 * @return Seat which owns device with ID @a idev_id or @c NULL if not found
564 */
565ds_seat_t *ds_display_seat_by_idev(ds_display_t *disp, ds_idev_id_t idev_id)
566{
567 // TODO Multi-seat
568 (void) idev_id;
569
570 return ds_display_first_seat(disp);
571}
572
573/** Allocate back buffer for display.
574 *
575 * @param disp Display
576 * @return EOK on success or if no back buffer is required, otherwise
577 * an error code.
578 */
579static errno_t ds_display_alloc_backbuf(ds_display_t *disp)
580{
581 gfx_context_t *ugc;
582 gfx_bitmap_params_t params;
583 gfx_bitmap_alloc_t alloc;
584 errno_t rc;
585
586 /* Allocate backbuffer */
587 if ((disp->flags & df_disp_double_buf) == 0) {
588 /* Not double buffering. Nothing to do. */
589 return EOK;
590 }
591
592 ugc = ds_display_get_unbuf_gc(disp);
593
594 gfx_bitmap_params_init(&params);
595 params.rect = disp->rect;
596
597 rc = gfx_bitmap_create(ugc, &params, NULL,
598 &disp->backbuf);
599 if (rc != EOK)
600 goto error;
601
602 rc = gfx_bitmap_get_alloc(disp->backbuf, &alloc);
603 if (rc != EOK)
604 goto error;
605
606 rc = mem_gc_create(&disp->rect, &alloc, &ds_display_mem_gc_cb,
607 (void *) disp, &disp->bbgc);
608 if (rc != EOK)
609 goto error;
610
611 disp->dirty_rect.p0.x = 0;
612 disp->dirty_rect.p0.y = 0;
613 disp->dirty_rect.p1.x = 0;
614 disp->dirty_rect.p1.y = 0;
615
616 return EOK;
617error:
618 if (disp->backbuf != NULL) {
619 gfx_bitmap_destroy(disp->backbuf);
620 disp->backbuf = NULL;
621 }
622
623 return rc;
624}
625
626/** Add display device to display.
627 *
628 * @param disp Display
629 * @param ddev Display device
630 * @return EOK on success, or an error code
631 */
632errno_t ds_display_add_ddev(ds_display_t *disp, ds_ddev_t *ddev)
633{
634 errno_t rc;
635
636 assert(ddev->display == NULL);
637 assert(!link_used(&ddev->lddevs));
638
639 ddev->display = disp;
640 list_append(&ddev->lddevs, &disp->ddevs);
641
642 /* First display device */
643 if (gfx_rect_is_empty(&disp->rect)) {
644 /* Set screen dimensions */
645 disp->rect = ddev->info.rect;
646
647 /* Create cloning GC */
648 rc = ds_clonegc_create(ddev->gc, &disp->fbgc);
649 if (rc != EOK) {
650 // XXX Remove output
651 return ENOMEM;
652 }
653
654 /* Allocate backbuffer */
655 rc = ds_display_alloc_backbuf(disp);
656 if (rc != EOK) {
657 // XXX Remove output
658 // XXX Delete clone GC
659 goto error;
660 }
661 } else {
662 /* Add new output device to cloning GC */
663 rc = ds_clonegc_add_output(disp->fbgc, ddev->gc);
664 if (rc != EOK)
665 goto error;
666 }
667
668 ds_display_update_max_rect(disp);
669
670 return EOK;
671error:
672 disp->rect.p0.x = 0;
673 disp->rect.p0.y = 0;
674 disp->rect.p1.x = 0;
675 disp->rect.p1.y = 0;
676 list_remove(&ddev->lddevs);
677 return rc;
678}
679
680/** Remove display device from display.
681 *
682 * @param ddev Display device
683 */
684void ds_display_remove_ddev(ds_ddev_t *ddev)
685{
686 list_remove(&ddev->lddevs);
687 ddev->display = NULL;
688}
689
690/** Get first display device in display.
691 *
692 * @param disp Display
693 * @return First display device or @c NULL if there is none
694 */
695ds_ddev_t *ds_display_first_ddev(ds_display_t *disp)
696{
697 link_t *link = list_first(&disp->ddevs);
698
699 if (link == NULL)
700 return NULL;
701
702 return list_get_instance(link, ds_ddev_t, lddevs);
703}
704
705/** Get next display device in display.
706 *
707 * @param ddev Current display device
708 * @return Next display device or @c NULL if there is none
709 */
710ds_ddev_t *ds_display_next_ddev(ds_ddev_t *ddev)
711{
712 link_t *link = list_next(&ddev->lddevs, &ddev->display->ddevs);
713
714 if (link == NULL)
715 return NULL;
716
717 return list_get_instance(link, ds_ddev_t, lddevs);
718}
719
720/** Add cursor to display.
721 *
722 * @param display Display
723 * @param cursor Cursor
724 */
725void ds_display_add_cursor(ds_display_t *display, ds_cursor_t *cursor)
726{
727 assert(cursor->display == NULL);
728 assert(!link_used(&cursor->ldisplay));
729
730 cursor->display = display;
731 list_prepend(&cursor->ldisplay, &display->cursors);
732}
733
734/** Remove cursor from display.
735 *
736 * @param cursor Cursor
737 */
738void ds_display_remove_cursor(ds_cursor_t *cursor)
739{
740 list_remove(&cursor->ldisplay);
741 cursor->display = NULL;
742}
743
744/** Update display maximize rectangle.
745 *
746 * Recalculate the maximize rectangle (the rectangle used for maximized
747 * windows).
748 *
749 * @param display Display
750 */
751void ds_display_update_max_rect(ds_display_t *display)
752{
753 ds_window_t *wnd;
754 gfx_rect_t max_rect;
755 gfx_rect_t drect;
756
757 /* Start with the entire display */
758 max_rect = display->rect;
759
760 wnd = ds_display_first_window(display);
761 while (wnd != NULL) {
762 /* Should maximized windows avoid this window? */
763 if ((wnd->flags & wndf_avoid) != 0) {
764 /* Window bounding rectangle on display */
765 gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
766
767 /* Crop maximized rectangle */
768 ds_display_crop_max_rect(&drect, &max_rect);
769 }
770
771 wnd = ds_display_next_window(wnd);
772 }
773
774 /* Update the maximize rectangle */
775 display->max_rect = max_rect;
776}
777
778/** Crop maximize rectangle.
779 *
780 * Use the avoid rectangle @a arect to crop off maximization rectangle
781 * @a mrect. If @a arect covers the top, bottom, left or right part
782 * of @a mrect, it will be cropped off. Otherwise there will be
783 * no effect.
784 *
785 * @param arect Avoid rectangle
786 * @param mrect Maximize rectangle to be modified
787 */
788void ds_display_crop_max_rect(gfx_rect_t *arect, gfx_rect_t *mrect)
789{
790 if (arect->p0.x == mrect->p0.x && arect->p0.y == mrect->p0.y &&
791 arect->p1.x == mrect->p1.x) {
792 /* Cropp off top part */
793 mrect->p0.y = arect->p1.y;
794 } else if (arect->p0.x == mrect->p0.x && arect->p1.x == mrect->p1.x &&
795 arect->p1.y == mrect->p1.y) {
796 /* Cropp off bottom part */
797 mrect->p1.y = arect->p0.y;
798 } else if (arect->p0.x == mrect->p0.x && arect->p0.y == mrect->p0.y &&
799 arect->p1.y == mrect->p1.y) {
800 /* Cropp off left part */
801 mrect->p0.x = arect->p1.x;
802 } else if (arect->p0.y == mrect->p0.y && arect->p1.x == mrect->p1.x &&
803 arect->p1.y == mrect->p1.y) {
804 /* Cropp off right part */
805 mrect->p1.x = arect->p0.x;
806 }
807}
808
809/** Get unbuffered GC.
810 *
811 * Get the display's (unbuffered) graphic context. If the display
812 * is double-buffered, this returns GC of the front buffer. If the display
813 * is unbuffered, this is the same as @c ds_display_get_gc().
814 *
815 * @param display Display
816 * @return Unbuffered GC
817 */
818static gfx_context_t *ds_display_get_unbuf_gc(ds_display_t *display)
819{
820 /* In case of unit tests */
821 if (display->fbgc == NULL)
822 return NULL;
823
824 return ds_clonegc_get_ctx(display->fbgc);
825}
826
827/** Get display GC.
828 *
829 * Get the graphic context used to paint the display. This is to be used
830 * for all display server paint operations.
831 *
832 * @param display Display
833 * @return Graphic context for painting to the display
834 */
835gfx_context_t *ds_display_get_gc(ds_display_t *display)
836{
837 if ((display->flags & df_disp_double_buf) != 0)
838 return mem_gc_get_ctx(display->bbgc);
839 else
840 return ds_display_get_unbuf_gc(display);
841}
842
843/** Paint display background.
844 *
845 * @param display Display
846 * @param rect Bounding rectangle or @c NULL to repaint entire display
847 */
848errno_t ds_display_paint_bg(ds_display_t *disp, gfx_rect_t *rect)
849{
850 gfx_rect_t crect;
851 gfx_context_t *gc;
852 errno_t rc;
853
854 if (rect != NULL)
855 gfx_rect_clip(&disp->rect, rect, &crect);
856 else
857 crect = disp->rect;
858
859 gc = ds_display_get_gc(disp);
860 if (gc == NULL)
861 return EOK;
862
863 rc = gfx_set_color(gc, disp->bg_color);
864 if (rc != EOK)
865 return rc;
866
867 return gfx_fill_rect(gc, &crect);
868}
869
870/** Update front buffer from back buffer.
871 *
872 * If the display is not double-buffered, no action is taken.
873 *
874 * @param disp Display
875 * @return EOK on success, or an error code
876 */
877static errno_t ds_display_update(ds_display_t *disp)
878{
879 errno_t rc;
880
881 if (disp->backbuf == NULL) {
882 /* Not double-buffered, nothing to do. */
883 return EOK;
884 }
885
886 rc = gfx_bitmap_render(disp->backbuf, &disp->dirty_rect, NULL);
887 if (rc != EOK)
888 return rc;
889
890 disp->dirty_rect.p0.x = 0;
891 disp->dirty_rect.p0.y = 0;
892 disp->dirty_rect.p1.x = 0;
893 disp->dirty_rect.p1.y = 0;
894
895 return EOK;
896}
897
898/** Paint display.
899 *
900 * @param display Display
901 * @param rect Bounding rectangle or @c NULL to repaint entire display
902 */
903errno_t ds_display_paint(ds_display_t *disp, gfx_rect_t *rect)
904{
905 errno_t rc;
906 ds_window_t *wnd;
907 ds_seat_t *seat;
908
909 /* Paint background */
910 rc = ds_display_paint_bg(disp, rect);
911 if (rc != EOK)
912 return rc;
913
914 /* Paint windows bottom to top */
915 wnd = ds_display_last_window(disp);
916 while (wnd != NULL) {
917 rc = ds_window_paint(wnd, rect);
918 if (rc != EOK)
919 return rc;
920
921 wnd = ds_display_prev_window(wnd);
922 }
923
924 /* Paint window previews for windows being resized or moved */
925 wnd = ds_display_last_window(disp);
926 while (wnd != NULL) {
927 rc = ds_window_paint_preview(wnd, rect);
928 if (rc != EOK)
929 return rc;
930
931 wnd = ds_display_prev_window(wnd);
932 }
933
934 /* Paint pointers */
935 seat = ds_display_first_seat(disp);
936 while (seat != NULL) {
937 rc = ds_seat_paint_pointer(seat, rect);
938 if (rc != EOK)
939 return rc;
940
941 seat = ds_display_next_seat(seat);
942 }
943
944 return ds_display_update(disp);
945}
946
947/** Display invalidate callback.
948 *
949 * Called by backbuffer memory GC when something is rendered into it.
950 * Updates the display's dirty rectangle.
951 *
952 * @param arg Argument (display cast as void *)
953 * @param rect Rectangle to update
954 */
955static void ds_display_invalidate_cb(void *arg, gfx_rect_t *rect)
956{
957 ds_display_t *disp = (ds_display_t *) arg;
958 gfx_rect_t env;
959
960 gfx_rect_envelope(&disp->dirty_rect, rect, &env);
961 disp->dirty_rect = env;
962}
963
964/** Display update callback.
965 *
966 * @param arg Argument (display cast as void *)
967 */
968static void ds_display_update_cb(void *arg)
969{
970 ds_display_t *disp = (ds_display_t *) arg;
971
972 (void) disp;
973}
974
975/** @}
976 */
Note: See TracBrowser for help on using the repository browser.