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