[c8cf261] | 1 | /*
|
---|
[88d828e] | 2 | * Copyright (c) 2022 Jiri Svoboda
|
---|
[c8cf261] | 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 | /**
|
---|
[38e5f36c] | 33 | * @file Display server display
|
---|
[c8cf261] | 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <errno.h>
|
---|
[8aef01c] | 37 | #include <gfx/bitmap.h>
|
---|
[159776f] | 38 | #include <gfx/context.h>
|
---|
[c79545e] | 39 | #include <gfx/render.h>
|
---|
[c8cf261] | 40 | #include <io/log.h>
|
---|
[8aef01c] | 41 | #include <memgfx/memgc.h>
|
---|
[6af4b4f] | 42 | #include <stdlib.h>
|
---|
[b3c185b6] | 43 | #include "client.h"
|
---|
[5271e4c] | 44 | #include "clonegc.h"
|
---|
[4d8002d] | 45 | #include "cursimg.h"
|
---|
| 46 | #include "cursor.h"
|
---|
[913add60] | 47 | #include "display.h"
|
---|
[cf32dbd] | 48 | #include "seat.h"
|
---|
[6af4b4f] | 49 | #include "window.h"
|
---|
[913add60] | 50 | #include "wmclient.h"
|
---|
[c8cf261] | 51 |
|
---|
[8aef01c] | 52 | static gfx_context_t *ds_display_get_unbuf_gc(ds_display_t *);
|
---|
[2ab8ab3] | 53 | static void ds_display_invalidate_cb(void *, gfx_rect_t *);
|
---|
| 54 | static void ds_display_update_cb(void *);
|
---|
[8aef01c] | 55 |
|
---|
[1215db9] | 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 |
|
---|
[6af4b4f] | 61 | /** Create display.
|
---|
| 62 | *
|
---|
[159776f] | 63 | * @param gc Graphics context for displaying output
|
---|
[8aef01c] | 64 | * @param flags Display flags
|
---|
[6af4b4f] | 65 | * @param rdisp Place to store pointer to new display.
|
---|
| 66 | * @return EOK on success, ENOMEM if out of memory
|
---|
| 67 | */
|
---|
[8aef01c] | 68 | errno_t ds_display_create(gfx_context_t *gc, ds_display_flags_t flags,
|
---|
| 69 | ds_display_t **rdisp)
|
---|
[6af4b4f] | 70 | {
|
---|
| 71 | ds_display_t *disp;
|
---|
[4d8002d] | 72 | ds_cursor_t *cursor;
|
---|
| 73 | int i;
|
---|
[c79545e] | 74 | errno_t rc;
|
---|
[6af4b4f] | 75 |
|
---|
| 76 | disp = calloc(1, sizeof(ds_display_t));
|
---|
| 77 | if (disp == NULL)
|
---|
| 78 | return ENOMEM;
|
---|
| 79 |
|
---|
[c79545e] | 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 |
|
---|
[4d8002d] | 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 |
|
---|
[c11ee605] | 97 | fibril_mutex_initialize(&disp->lock);
|
---|
[b3c185b6] | 98 | list_initialize(&disp->clients);
|
---|
[913add60] | 99 | list_initialize(&disp->wmclients);
|
---|
[b3c185b6] | 100 | disp->next_wnd_id = 1;
|
---|
[87a7cdb] | 101 | list_initialize(&disp->ddevs);
|
---|
[cf32dbd] | 102 | list_initialize(&disp->seats);
|
---|
[fd777a2] | 103 | list_initialize(&disp->windows);
|
---|
[8aef01c] | 104 | disp->flags = flags;
|
---|
[6af4b4f] | 105 | *rdisp = disp;
|
---|
| 106 | return EOK;
|
---|
[4d8002d] | 107 | error:
|
---|
| 108 | ds_display_destroy(disp);
|
---|
| 109 | return rc;
|
---|
[6af4b4f] | 110 | }
|
---|
| 111 |
|
---|
| 112 | /** Destroy display.
|
---|
| 113 | *
|
---|
| 114 | * @param disp Display
|
---|
| 115 | */
|
---|
| 116 | void ds_display_destroy(ds_display_t *disp)
|
---|
| 117 | {
|
---|
[b3c185b6] | 118 | assert(list_empty(&disp->clients));
|
---|
[913add60] | 119 | assert(list_empty(&disp->wmclients));
|
---|
[cf32dbd] | 120 | assert(list_empty(&disp->seats));
|
---|
[4d8002d] | 121 | /* XXX destroy cursors */
|
---|
[c79545e] | 122 | gfx_color_delete(disp->bg_color);
|
---|
[6af4b4f] | 123 | free(disp);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[c11ee605] | 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 | */
|
---|
| 133 | void 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 | */
|
---|
| 142 | void ds_display_unlock(ds_display_t *disp)
|
---|
| 143 | {
|
---|
| 144 | fibril_mutex_unlock(&disp->lock);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
[aeb3037] | 147 | /** Get display information.
|
---|
| 148 | *
|
---|
| 149 | * @param disp Display
|
---|
| 150 | */
|
---|
| 151 | void ds_display_get_info(ds_display_t *disp, display_info_t *info)
|
---|
| 152 | {
|
---|
| 153 | info->rect = disp->rect;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[b3c185b6] | 156 | /** Add client to display.
|
---|
[6af4b4f] | 157 | *
|
---|
| 158 | * @param disp Display
|
---|
[cf32dbd] | 159 | * @param client Client
|
---|
[6af4b4f] | 160 | */
|
---|
[b3c185b6] | 161 | void ds_display_add_client(ds_display_t *disp, ds_client_t *client)
|
---|
[6af4b4f] | 162 | {
|
---|
[b3c185b6] | 163 | assert(client->display == NULL);
|
---|
| 164 | assert(!link_used(&client->lclients));
|
---|
[6af4b4f] | 165 |
|
---|
[b3c185b6] | 166 | client->display = disp;
|
---|
| 167 | list_append(&client->lclients, &disp->clients);
|
---|
[c8cf261] | 168 | }
|
---|
| 169 |
|
---|
[b3c185b6] | 170 | /** Remove client from display.
|
---|
[6af4b4f] | 171 | *
|
---|
[cf32dbd] | 172 | * @param client Client
|
---|
[6af4b4f] | 173 | */
|
---|
[b3c185b6] | 174 | void ds_display_remove_client(ds_client_t *client)
|
---|
[6af4b4f] | 175 | {
|
---|
[b3c185b6] | 176 | list_remove(&client->lclients);
|
---|
| 177 | client->display = NULL;
|
---|
[6af4b4f] | 178 | }
|
---|
| 179 |
|
---|
[b3c185b6] | 180 | /** Get first client in display.
|
---|
[6af4b4f] | 181 | *
|
---|
| 182 | * @param disp Display
|
---|
[b3c185b6] | 183 | * @return First client or @c NULL if there is none
|
---|
[6af4b4f] | 184 | */
|
---|
[b3c185b6] | 185 | ds_client_t *ds_display_first_client(ds_display_t *disp)
|
---|
[6af4b4f] | 186 | {
|
---|
[b3c185b6] | 187 | link_t *link = list_first(&disp->clients);
|
---|
[6af4b4f] | 188 |
|
---|
[b3c185b6] | 189 | if (link == NULL)
|
---|
| 190 | return NULL;
|
---|
[6af4b4f] | 191 |
|
---|
[b3c185b6] | 192 | return list_get_instance(link, ds_client_t, lclients);
|
---|
[6af4b4f] | 193 | }
|
---|
| 194 |
|
---|
[b3c185b6] | 195 | /** Get next client in display.
|
---|
[6af4b4f] | 196 | *
|
---|
[b3c185b6] | 197 | * @param client Current client
|
---|
| 198 | * @return Next client or @c NULL if there is none
|
---|
[6af4b4f] | 199 | */
|
---|
[b3c185b6] | 200 | ds_client_t *ds_display_next_client(ds_client_t *client)
|
---|
[6af4b4f] | 201 | {
|
---|
[b3c185b6] | 202 | link_t *link = list_next(&client->lclients, &client->display->clients);
|
---|
[6af4b4f] | 203 |
|
---|
| 204 | if (link == NULL)
|
---|
| 205 | return NULL;
|
---|
| 206 |
|
---|
[b3c185b6] | 207 | return list_get_instance(link, ds_client_t, lclients);
|
---|
[6af4b4f] | 208 | }
|
---|
| 209 |
|
---|
[913add60] | 210 | /** Add WM client to display.
|
---|
| 211 | *
|
---|
| 212 | * @param disp Display
|
---|
| 213 | * @param wmclient WM client
|
---|
| 214 | */
|
---|
| 215 | void 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 | */
|
---|
| 228 | void 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 | */
|
---|
| 239 | ds_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 | */
|
---|
| 254 | ds_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 |
|
---|
[b3c185b6] | 265 | /** Find window in all clients by ID.
|
---|
[6af4b4f] | 266 | *
|
---|
[b3c185b6] | 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
|
---|
[6af4b4f] | 273 | */
|
---|
[b3c185b6] | 274 | ds_window_t *ds_display_find_window(ds_display_t *display, ds_wnd_id_t id)
|
---|
[6af4b4f] | 275 | {
|
---|
[b3c185b6] | 276 | ds_client_t *client;
|
---|
| 277 | ds_window_t *wnd;
|
---|
[6af4b4f] | 278 |
|
---|
[b3c185b6] | 279 | client = ds_display_first_client(display);
|
---|
| 280 | while (client != NULL) {
|
---|
| 281 | wnd = ds_client_find_window(client, id);
|
---|
[195b7b3] | 282 | if (wnd != NULL)
|
---|
[b3c185b6] | 283 | return wnd;
|
---|
[195b7b3] | 284 |
|
---|
[b3c185b6] | 285 | client = ds_display_next_client(client);
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | return NULL;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
[24cf391a] | 291 | /** Find window by display position.
|
---|
| 292 | *
|
---|
| 293 | * @param display Display
|
---|
| 294 | * @param pos Display position
|
---|
| 295 | */
|
---|
| 296 | ds_window_t *ds_display_window_by_pos(ds_display_t *display, gfx_coord2_t *pos)
|
---|
| 297 | {
|
---|
| 298 | ds_window_t *wnd;
|
---|
[fb420e48] | 299 | gfx_rect_t drect;
|
---|
[24cf391a] | 300 |
|
---|
| 301 | wnd = ds_display_first_window(display);
|
---|
| 302 | while (wnd != NULL) {
|
---|
[fb420e48] | 303 | /* Window bounding rectangle on display */
|
---|
| 304 | gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
|
---|
| 305 |
|
---|
| 306 | if (gfx_pix_inside_rect(pos, &drect))
|
---|
[24cf391a] | 307 | return wnd;
|
---|
| 308 |
|
---|
| 309 | wnd = ds_display_next_window(wnd);
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | return NULL;
|
---|
| 313 | }
|
---|
| 314 |
|
---|
[fd777a2] | 315 | /** Add window to display.
|
---|
| 316 | *
|
---|
| 317 | * @param display Display
|
---|
| 318 | * @param wnd Window
|
---|
| 319 | */
|
---|
| 320 | void ds_display_add_window(ds_display_t *display, ds_window_t *wnd)
|
---|
| 321 | {
|
---|
[913add60] | 322 | ds_wmclient_t *wmclient;
|
---|
| 323 |
|
---|
[fd777a2] | 324 | assert(wnd->display == NULL);
|
---|
| 325 | assert(!link_used(&wnd->ldwindows));
|
---|
| 326 |
|
---|
| 327 | wnd->display = display;
|
---|
| 328 | list_prepend(&wnd->ldwindows, &display->windows);
|
---|
[913add60] | 329 |
|
---|
| 330 | /* Notify window managers about the new window */
|
---|
| 331 | wmclient = ds_display_first_wmclient(display);
|
---|
| 332 | while (wmclient != NULL) {
|
---|
| 333 | ds_wmclient_post_wnd_added_event(wmclient, wnd->id);
|
---|
| 334 | wmclient = ds_display_next_wmclient(wmclient);
|
---|
| 335 | }
|
---|
[fd777a2] | 336 | }
|
---|
| 337 |
|
---|
| 338 | /** Remove window from display.
|
---|
| 339 | *
|
---|
| 340 | * @param wnd Window
|
---|
| 341 | */
|
---|
| 342 | void ds_display_remove_window(ds_window_t *wnd)
|
---|
| 343 | {
|
---|
[913add60] | 344 | ds_wmclient_t *wmclient;
|
---|
| 345 | ds_display_t *display;
|
---|
| 346 |
|
---|
| 347 | display = wnd->display;
|
---|
| 348 |
|
---|
[fd777a2] | 349 | list_remove(&wnd->ldwindows);
|
---|
| 350 | wnd->display = NULL;
|
---|
[913add60] | 351 |
|
---|
| 352 | /* Notify window managers about the removed window */
|
---|
| 353 | wmclient = ds_display_first_wmclient(display);
|
---|
| 354 | while (wmclient != NULL) {
|
---|
| 355 | ds_wmclient_post_wnd_removed_event(wmclient, wnd->id);
|
---|
| 356 | wmclient = ds_display_next_wmclient(wmclient);
|
---|
| 357 | }
|
---|
| 358 | }
|
---|
| 359 |
|
---|
| 360 | /** Move window to top.
|
---|
| 361 | *
|
---|
| 362 | * @param display Display
|
---|
| 363 | * @param wnd Window
|
---|
| 364 | */
|
---|
| 365 | void ds_display_window_to_top(ds_window_t *wnd)
|
---|
| 366 | {
|
---|
| 367 | assert(wnd->display != NULL);
|
---|
| 368 | assert(link_used(&wnd->ldwindows));
|
---|
| 369 |
|
---|
| 370 | list_remove(&wnd->ldwindows);
|
---|
| 371 | list_prepend(&wnd->ldwindows, &wnd->display->windows);
|
---|
[fd777a2] | 372 | }
|
---|
| 373 |
|
---|
| 374 | /** Get first window in display.
|
---|
| 375 | *
|
---|
| 376 | * @param display Display
|
---|
| 377 | * @return First window or @c NULL if there is none
|
---|
| 378 | */
|
---|
| 379 | ds_window_t *ds_display_first_window(ds_display_t *display)
|
---|
| 380 | {
|
---|
| 381 | link_t *link = list_first(&display->windows);
|
---|
| 382 |
|
---|
| 383 | if (link == NULL)
|
---|
| 384 | return NULL;
|
---|
| 385 |
|
---|
| 386 | return list_get_instance(link, ds_window_t, ldwindows);
|
---|
| 387 | }
|
---|
| 388 |
|
---|
[2012fe0] | 389 | /** Get last window in display.
|
---|
| 390 | *
|
---|
| 391 | * @param display Display
|
---|
| 392 | * @return Last window or @c NULL if there is none
|
---|
| 393 | */
|
---|
| 394 | ds_window_t *ds_display_last_window(ds_display_t *display)
|
---|
| 395 | {
|
---|
| 396 | link_t *link = list_last(&display->windows);
|
---|
| 397 |
|
---|
| 398 | if (link == NULL)
|
---|
| 399 | return NULL;
|
---|
| 400 |
|
---|
| 401 | return list_get_instance(link, ds_window_t, ldwindows);
|
---|
| 402 | }
|
---|
| 403 |
|
---|
[fd777a2] | 404 | /** Get next window in client.
|
---|
| 405 | *
|
---|
| 406 | * @param wnd Current window
|
---|
| 407 | * @return Next window or @c NULL if there is none
|
---|
| 408 | */
|
---|
| 409 | ds_window_t *ds_display_next_window(ds_window_t *wnd)
|
---|
| 410 | {
|
---|
| 411 | link_t *link = list_next(&wnd->ldwindows, &wnd->display->windows);
|
---|
| 412 |
|
---|
| 413 | if (link == NULL)
|
---|
| 414 | return NULL;
|
---|
| 415 |
|
---|
| 416 | return list_get_instance(link, ds_window_t, ldwindows);
|
---|
| 417 | }
|
---|
| 418 |
|
---|
[2012fe0] | 419 | /** Get previous window in client.
|
---|
| 420 | *
|
---|
| 421 | * @param wnd Current window
|
---|
| 422 | * @return Previous window or @c NULL if there is none
|
---|
| 423 | */
|
---|
| 424 | ds_window_t *ds_display_prev_window(ds_window_t *wnd)
|
---|
| 425 | {
|
---|
| 426 | link_t *link = list_prev(&wnd->ldwindows, &wnd->display->windows);
|
---|
| 427 |
|
---|
| 428 | if (link == NULL)
|
---|
| 429 | return NULL;
|
---|
| 430 |
|
---|
| 431 | return list_get_instance(link, ds_window_t, ldwindows);
|
---|
| 432 | }
|
---|
| 433 |
|
---|
[cf32dbd] | 434 | /** Post keyboard event to a display.
|
---|
| 435 | *
|
---|
| 436 | * The event is routed to the correct window by first determining the
|
---|
| 437 | * seat the keyboard device belongs to and then the event is sent to the
|
---|
| 438 | * window focused by that seat.
|
---|
| 439 | *
|
---|
| 440 | * @param display Display
|
---|
| 441 | * @param event Event
|
---|
| 442 | */
|
---|
[b3c185b6] | 443 | errno_t ds_display_post_kbd_event(ds_display_t *display, kbd_event_t *event)
|
---|
| 444 | {
|
---|
[cf32dbd] | 445 | ds_seat_t *seat;
|
---|
[b3c185b6] | 446 |
|
---|
[88d828e] | 447 | /* Determine which seat the event belongs to */
|
---|
| 448 | seat = ds_display_seat_by_idev(display, event->kbd_id);
|
---|
[cf32dbd] | 449 | if (seat == NULL)
|
---|
[b3c185b6] | 450 | return EOK;
|
---|
| 451 |
|
---|
[cf32dbd] | 452 | return ds_seat_post_kbd_event(seat, event);
|
---|
| 453 | }
|
---|
| 454 |
|
---|
[24cf391a] | 455 | /** Post position event to a display.
|
---|
| 456 | *
|
---|
| 457 | * @param display Display
|
---|
| 458 | * @param event Event
|
---|
| 459 | */
|
---|
[4fbdc3d] | 460 | errno_t ds_display_post_ptd_event(ds_display_t *display, ptd_event_t *event)
|
---|
[24cf391a] | 461 | {
|
---|
| 462 | ds_seat_t *seat;
|
---|
| 463 |
|
---|
[88d828e] | 464 | /* Determine which seat the event belongs to */
|
---|
| 465 | seat = ds_display_seat_by_idev(display, event->pos_id);
|
---|
[4fbdc3d] | 466 | if (seat == NULL)
|
---|
| 467 | return EOK;
|
---|
[24cf391a] | 468 |
|
---|
[4fbdc3d] | 469 | return ds_seat_post_ptd_event(seat, event);
|
---|
[24cf391a] | 470 | }
|
---|
| 471 |
|
---|
[cf32dbd] | 472 | /** Add seat to display.
|
---|
| 473 | *
|
---|
| 474 | * @param disp Display
|
---|
| 475 | * @param seat Seat
|
---|
| 476 | */
|
---|
| 477 | void ds_display_add_seat(ds_display_t *disp, ds_seat_t *seat)
|
---|
| 478 | {
|
---|
| 479 | assert(seat->display == NULL);
|
---|
| 480 | assert(!link_used(&seat->lseats));
|
---|
| 481 |
|
---|
| 482 | seat->display = disp;
|
---|
| 483 | list_append(&seat->lseats, &disp->seats);
|
---|
| 484 | }
|
---|
| 485 |
|
---|
| 486 | /** Remove seat from display.
|
---|
| 487 | *
|
---|
| 488 | * @param seat Seat
|
---|
| 489 | */
|
---|
| 490 | void ds_display_remove_seat(ds_seat_t *seat)
|
---|
| 491 | {
|
---|
| 492 | list_remove(&seat->lseats);
|
---|
| 493 | seat->display = NULL;
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | /** Get first seat in display.
|
---|
| 497 | *
|
---|
| 498 | * @param disp Display
|
---|
| 499 | * @return First seat or @c NULL if there is none
|
---|
| 500 | */
|
---|
| 501 | ds_seat_t *ds_display_first_seat(ds_display_t *disp)
|
---|
| 502 | {
|
---|
| 503 | link_t *link = list_first(&disp->seats);
|
---|
| 504 |
|
---|
| 505 | if (link == NULL)
|
---|
| 506 | return NULL;
|
---|
| 507 |
|
---|
| 508 | return list_get_instance(link, ds_seat_t, lseats);
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | /** Get next seat in display.
|
---|
| 512 | *
|
---|
| 513 | * @param seat Current seat
|
---|
| 514 | * @return Next seat or @c NULL if there is none
|
---|
| 515 | */
|
---|
| 516 | ds_seat_t *ds_display_next_seat(ds_seat_t *seat)
|
---|
| 517 | {
|
---|
| 518 | link_t *link = list_next(&seat->lseats, &seat->display->seats);
|
---|
| 519 |
|
---|
| 520 | if (link == NULL)
|
---|
| 521 | return NULL;
|
---|
[6af4b4f] | 522 |
|
---|
[cf32dbd] | 523 | return list_get_instance(link, ds_seat_t, lseats);
|
---|
[6af4b4f] | 524 | }
|
---|
| 525 |
|
---|
[88d828e] | 526 | /** Get seat which owns the specified input device.
|
---|
| 527 | *
|
---|
| 528 | * @param disp Display
|
---|
| 529 | * @param idev_id Input device ID
|
---|
| 530 | * @return Seat which owns device with ID @a idev_id or @c NULL if not found
|
---|
| 531 | */
|
---|
| 532 | ds_seat_t *ds_display_seat_by_idev(ds_display_t *disp, ds_idev_id_t idev_id)
|
---|
| 533 | {
|
---|
| 534 | // TODO Multi-seat
|
---|
| 535 | (void) idev_id;
|
---|
| 536 |
|
---|
| 537 | return ds_display_first_seat(disp);
|
---|
| 538 | }
|
---|
| 539 |
|
---|
[8aef01c] | 540 | /** Allocate back buffer for display.
|
---|
| 541 | *
|
---|
| 542 | * @param disp Display
|
---|
| 543 | * @return EOK on success or if no back buffer is required, otherwise
|
---|
| 544 | * an error code.
|
---|
| 545 | */
|
---|
| 546 | static errno_t ds_display_alloc_backbuf(ds_display_t *disp)
|
---|
| 547 | {
|
---|
| 548 | gfx_context_t *ugc;
|
---|
| 549 | gfx_bitmap_params_t params;
|
---|
| 550 | gfx_bitmap_alloc_t alloc;
|
---|
| 551 | errno_t rc;
|
---|
| 552 |
|
---|
| 553 | /* Allocate backbuffer */
|
---|
| 554 | if ((disp->flags & df_disp_double_buf) == 0) {
|
---|
| 555 | /* Not double buffering. Nothing to do. */
|
---|
| 556 | return EOK;
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | ugc = ds_display_get_unbuf_gc(disp);
|
---|
| 560 |
|
---|
| 561 | gfx_bitmap_params_init(¶ms);
|
---|
| 562 | params.rect = disp->rect;
|
---|
| 563 |
|
---|
| 564 | rc = gfx_bitmap_create(ugc, ¶ms, NULL,
|
---|
| 565 | &disp->backbuf);
|
---|
| 566 | if (rc != EOK)
|
---|
| 567 | goto error;
|
---|
| 568 |
|
---|
| 569 | rc = gfx_bitmap_get_alloc(disp->backbuf, &alloc);
|
---|
| 570 | if (rc != EOK)
|
---|
| 571 | goto error;
|
---|
| 572 |
|
---|
[1215db9] | 573 | rc = mem_gc_create(&disp->rect, &alloc, &ds_display_mem_gc_cb,
|
---|
| 574 | (void *) disp, &disp->bbgc);
|
---|
[8aef01c] | 575 | if (rc != EOK)
|
---|
| 576 | goto error;
|
---|
| 577 |
|
---|
| 578 | disp->dirty_rect.p0.x = 0;
|
---|
| 579 | disp->dirty_rect.p0.y = 0;
|
---|
| 580 | disp->dirty_rect.p1.x = 0;
|
---|
| 581 | disp->dirty_rect.p1.y = 0;
|
---|
| 582 |
|
---|
| 583 | return EOK;
|
---|
| 584 | error:
|
---|
| 585 | if (disp->backbuf != NULL) {
|
---|
| 586 | gfx_bitmap_destroy(disp->backbuf);
|
---|
| 587 | disp->backbuf = NULL;
|
---|
| 588 | }
|
---|
| 589 |
|
---|
| 590 | return rc;
|
---|
| 591 | }
|
---|
| 592 |
|
---|
[87a7cdb] | 593 | /** Add display device to display.
|
---|
| 594 | *
|
---|
| 595 | * @param disp Display
|
---|
| 596 | * @param ddev Display device
|
---|
[8aef01c] | 597 | * @return EOK on success, or an error code
|
---|
[87a7cdb] | 598 | */
|
---|
[8aef01c] | 599 | errno_t ds_display_add_ddev(ds_display_t *disp, ds_ddev_t *ddev)
|
---|
[87a7cdb] | 600 | {
|
---|
[8aef01c] | 601 | errno_t rc;
|
---|
| 602 |
|
---|
[87a7cdb] | 603 | assert(ddev->display == NULL);
|
---|
| 604 | assert(!link_used(&ddev->lddevs));
|
---|
| 605 |
|
---|
| 606 | ddev->display = disp;
|
---|
| 607 | list_append(&ddev->lddevs, &disp->ddevs);
|
---|
[8aef01c] | 608 |
|
---|
| 609 | /* First display device */
|
---|
| 610 | if (gfx_rect_is_empty(&disp->rect)) {
|
---|
| 611 | /* Set screen dimensions */
|
---|
| 612 | disp->rect = ddev->info.rect;
|
---|
| 613 |
|
---|
[5271e4c] | 614 | /* Create cloning GC */
|
---|
| 615 | rc = ds_clonegc_create(ddev->gc, &disp->fbgc);
|
---|
| 616 | if (rc != EOK) {
|
---|
| 617 | // XXX Remove output
|
---|
| 618 | return ENOMEM;
|
---|
| 619 | }
|
---|
| 620 |
|
---|
[8aef01c] | 621 | /* Allocate backbuffer */
|
---|
| 622 | rc = ds_display_alloc_backbuf(disp);
|
---|
[5271e4c] | 623 | if (rc != EOK) {
|
---|
| 624 | // XXX Remove output
|
---|
| 625 | // XXX Delete clone GC
|
---|
| 626 | goto error;
|
---|
| 627 | }
|
---|
| 628 | } else {
|
---|
| 629 | /* Add new output device to cloning GC */
|
---|
| 630 | rc = ds_clonegc_add_output(disp->fbgc, ddev->gc);
|
---|
[8aef01c] | 631 | if (rc != EOK)
|
---|
| 632 | goto error;
|
---|
| 633 | }
|
---|
| 634 |
|
---|
| 635 | return EOK;
|
---|
| 636 | error:
|
---|
| 637 | disp->rect.p0.x = 0;
|
---|
| 638 | disp->rect.p0.y = 0;
|
---|
| 639 | disp->rect.p1.x = 0;
|
---|
| 640 | disp->rect.p1.y = 0;
|
---|
| 641 | list_remove(&ddev->lddevs);
|
---|
| 642 | return rc;
|
---|
[87a7cdb] | 643 | }
|
---|
| 644 |
|
---|
| 645 | /** Remove display device from display.
|
---|
| 646 | *
|
---|
| 647 | * @param ddev Display device
|
---|
| 648 | */
|
---|
| 649 | void ds_display_remove_ddev(ds_ddev_t *ddev)
|
---|
| 650 | {
|
---|
| 651 | list_remove(&ddev->lddevs);
|
---|
| 652 | ddev->display = NULL;
|
---|
| 653 | }
|
---|
| 654 |
|
---|
| 655 | /** Get first display device in display.
|
---|
| 656 | *
|
---|
| 657 | * @param disp Display
|
---|
| 658 | * @return First display device or @c NULL if there is none
|
---|
| 659 | */
|
---|
| 660 | ds_ddev_t *ds_display_first_ddev(ds_display_t *disp)
|
---|
| 661 | {
|
---|
| 662 | link_t *link = list_first(&disp->ddevs);
|
---|
| 663 |
|
---|
| 664 | if (link == NULL)
|
---|
| 665 | return NULL;
|
---|
| 666 |
|
---|
| 667 | return list_get_instance(link, ds_ddev_t, lddevs);
|
---|
| 668 | }
|
---|
| 669 |
|
---|
| 670 | /** Get next display device in display.
|
---|
| 671 | *
|
---|
| 672 | * @param ddev Current display device
|
---|
| 673 | * @return Next display device or @c NULL if there is none
|
---|
| 674 | */
|
---|
| 675 | ds_ddev_t *ds_display_next_ddev(ds_ddev_t *ddev)
|
---|
| 676 | {
|
---|
| 677 | link_t *link = list_next(&ddev->lddevs, &ddev->display->ddevs);
|
---|
| 678 |
|
---|
| 679 | if (link == NULL)
|
---|
| 680 | return NULL;
|
---|
| 681 |
|
---|
| 682 | return list_get_instance(link, ds_ddev_t, lddevs);
|
---|
| 683 | }
|
---|
| 684 |
|
---|
[4d8002d] | 685 | /** Add cursor to display.
|
---|
| 686 | *
|
---|
| 687 | * @param display Display
|
---|
| 688 | * @param cursor Cursor
|
---|
| 689 | */
|
---|
| 690 | void ds_display_add_cursor(ds_display_t *display, ds_cursor_t *cursor)
|
---|
| 691 | {
|
---|
| 692 | assert(cursor->display == NULL);
|
---|
| 693 | assert(!link_used(&cursor->ldisplay));
|
---|
| 694 |
|
---|
| 695 | cursor->display = display;
|
---|
| 696 | list_prepend(&cursor->ldisplay, &display->cursors);
|
---|
| 697 | }
|
---|
| 698 |
|
---|
| 699 | /** Remove cursor from display.
|
---|
| 700 | *
|
---|
| 701 | * @param cursor Cursor
|
---|
| 702 | */
|
---|
| 703 | void ds_display_remove_cursor(ds_cursor_t *cursor)
|
---|
| 704 | {
|
---|
| 705 | list_remove(&cursor->ldisplay);
|
---|
| 706 | cursor->display = NULL;
|
---|
| 707 | }
|
---|
| 708 |
|
---|
[84e74ea] | 709 | /** Get unbuffered GC.
|
---|
| 710 | *
|
---|
| 711 | * Get the display's (unbuffered) graphic context. If the display
|
---|
| 712 | * is double-buffered, this returns GC of the front buffer. If the display
|
---|
| 713 | * is unbuffered, this is the same as @c ds_display_get_gc().
|
---|
| 714 | *
|
---|
| 715 | * @param display Display
|
---|
| 716 | * @return Unbuffered GC
|
---|
| 717 | */
|
---|
[8aef01c] | 718 | static gfx_context_t *ds_display_get_unbuf_gc(ds_display_t *display)
|
---|
[87a7cdb] | 719 | {
|
---|
[5271e4c] | 720 | /* In case of unit tests */
|
---|
| 721 | if (display->fbgc == NULL)
|
---|
[4fbdc3d] | 722 | return NULL;
|
---|
[87a7cdb] | 723 |
|
---|
[5271e4c] | 724 | return ds_clonegc_get_ctx(display->fbgc);
|
---|
[87a7cdb] | 725 | }
|
---|
| 726 |
|
---|
[84e74ea] | 727 | /** Get display GC.
|
---|
| 728 | *
|
---|
| 729 | * Get the graphic context used to paint the display. This is to be used
|
---|
| 730 | * for all display server paint operations.
|
---|
| 731 | *
|
---|
| 732 | * @param display Display
|
---|
| 733 | * @return Graphic context for painting to the display
|
---|
| 734 | */
|
---|
[8aef01c] | 735 | gfx_context_t *ds_display_get_gc(ds_display_t *display)
|
---|
| 736 | {
|
---|
| 737 | if ((display->flags & df_disp_double_buf) != 0)
|
---|
| 738 | return mem_gc_get_ctx(display->bbgc);
|
---|
| 739 | else
|
---|
| 740 | return ds_display_get_unbuf_gc(display);
|
---|
| 741 | }
|
---|
| 742 |
|
---|
[c79545e] | 743 | /** Paint display background.
|
---|
| 744 | *
|
---|
| 745 | * @param display Display
|
---|
| 746 | * @param rect Bounding rectangle or @c NULL to repaint entire display
|
---|
| 747 | */
|
---|
| 748 | errno_t ds_display_paint_bg(ds_display_t *disp, gfx_rect_t *rect)
|
---|
| 749 | {
|
---|
| 750 | gfx_rect_t crect;
|
---|
| 751 | gfx_context_t *gc;
|
---|
| 752 | errno_t rc;
|
---|
| 753 |
|
---|
| 754 | if (rect != NULL)
|
---|
[e1f2079] | 755 | gfx_rect_clip(&disp->rect, rect, &crect);
|
---|
[c79545e] | 756 | else
|
---|
[e1f2079] | 757 | crect = disp->rect;
|
---|
[c79545e] | 758 |
|
---|
[84e74ea] | 759 | gc = ds_display_get_gc(disp);
|
---|
[f5191b4] | 760 | if (gc == NULL)
|
---|
| 761 | return EOK;
|
---|
[c79545e] | 762 |
|
---|
| 763 | rc = gfx_set_color(gc, disp->bg_color);
|
---|
| 764 | if (rc != EOK)
|
---|
| 765 | return rc;
|
---|
| 766 |
|
---|
| 767 | return gfx_fill_rect(gc, &crect);
|
---|
| 768 | }
|
---|
| 769 |
|
---|
[8aef01c] | 770 | /** Update front buffer from back buffer.
|
---|
| 771 | *
|
---|
| 772 | * If the display is not double-buffered, no action is taken.
|
---|
| 773 | *
|
---|
| 774 | * @param disp Display
|
---|
| 775 | * @return EOK on success, or an error code
|
---|
| 776 | */
|
---|
| 777 | static errno_t ds_display_update(ds_display_t *disp)
|
---|
| 778 | {
|
---|
| 779 | errno_t rc;
|
---|
| 780 |
|
---|
| 781 | if (disp->backbuf == NULL) {
|
---|
| 782 | /* Not double-buffered, nothing to do. */
|
---|
| 783 | return EOK;
|
---|
| 784 | }
|
---|
| 785 |
|
---|
| 786 | rc = gfx_bitmap_render(disp->backbuf, &disp->dirty_rect, NULL);
|
---|
| 787 | if (rc != EOK)
|
---|
| 788 | return rc;
|
---|
| 789 |
|
---|
| 790 | disp->dirty_rect.p0.x = 0;
|
---|
| 791 | disp->dirty_rect.p0.y = 0;
|
---|
| 792 | disp->dirty_rect.p1.x = 0;
|
---|
| 793 | disp->dirty_rect.p1.y = 0;
|
---|
| 794 |
|
---|
| 795 | return EOK;
|
---|
| 796 | }
|
---|
| 797 |
|
---|
[2012fe0] | 798 | /** Paint display.
|
---|
| 799 | *
|
---|
| 800 | * @param display Display
|
---|
| 801 | * @param rect Bounding rectangle or @c NULL to repaint entire display
|
---|
| 802 | */
|
---|
| 803 | errno_t ds_display_paint(ds_display_t *disp, gfx_rect_t *rect)
|
---|
| 804 | {
|
---|
| 805 | errno_t rc;
|
---|
| 806 | ds_window_t *wnd;
|
---|
[978c9bc5] | 807 | ds_seat_t *seat;
|
---|
[2012fe0] | 808 |
|
---|
| 809 | /* Paint background */
|
---|
| 810 | rc = ds_display_paint_bg(disp, rect);
|
---|
| 811 | if (rc != EOK)
|
---|
| 812 | return rc;
|
---|
| 813 |
|
---|
| 814 | /* Paint windows bottom to top */
|
---|
| 815 | wnd = ds_display_last_window(disp);
|
---|
| 816 | while (wnd != NULL) {
|
---|
| 817 | rc = ds_window_paint(wnd, rect);
|
---|
| 818 | if (rc != EOK)
|
---|
| 819 | return rc;
|
---|
| 820 |
|
---|
| 821 | wnd = ds_display_prev_window(wnd);
|
---|
| 822 | }
|
---|
| 823 |
|
---|
[6301a24f] | 824 | /* Paint window previews for windows being resized or moved */
|
---|
| 825 | wnd = ds_display_last_window(disp);
|
---|
| 826 | while (wnd != NULL) {
|
---|
| 827 | rc = ds_window_paint_preview(wnd, rect);
|
---|
| 828 | if (rc != EOK)
|
---|
| 829 | return rc;
|
---|
| 830 |
|
---|
| 831 | wnd = ds_display_prev_window(wnd);
|
---|
| 832 | }
|
---|
| 833 |
|
---|
| 834 | /* Paint pointers */
|
---|
[978c9bc5] | 835 | seat = ds_display_first_seat(disp);
|
---|
| 836 | while (seat != NULL) {
|
---|
| 837 | rc = ds_seat_paint_pointer(seat, rect);
|
---|
| 838 | if (rc != EOK)
|
---|
| 839 | return rc;
|
---|
| 840 |
|
---|
| 841 | seat = ds_display_next_seat(seat);
|
---|
| 842 | }
|
---|
| 843 |
|
---|
[8aef01c] | 844 | return ds_display_update(disp);
|
---|
| 845 | }
|
---|
| 846 |
|
---|
[2ab8ab3] | 847 | /** Display invalidate callback.
|
---|
[8aef01c] | 848 | *
|
---|
| 849 | * Called by backbuffer memory GC when something is rendered into it.
|
---|
| 850 | * Updates the display's dirty rectangle.
|
---|
| 851 | *
|
---|
| 852 | * @param arg Argument (display cast as void *)
|
---|
| 853 | * @param rect Rectangle to update
|
---|
| 854 | */
|
---|
[2ab8ab3] | 855 | static void ds_display_invalidate_cb(void *arg, gfx_rect_t *rect)
|
---|
[8aef01c] | 856 | {
|
---|
| 857 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
| 858 | gfx_rect_t env;
|
---|
| 859 |
|
---|
| 860 | gfx_rect_envelope(&disp->dirty_rect, rect, &env);
|
---|
| 861 | disp->dirty_rect = env;
|
---|
[2012fe0] | 862 | }
|
---|
| 863 |
|
---|
[2ab8ab3] | 864 | /** Display update callback.
|
---|
| 865 | *
|
---|
| 866 | * @param arg Argument (display cast as void *)
|
---|
| 867 | */
|
---|
| 868 | static void ds_display_update_cb(void *arg)
|
---|
| 869 | {
|
---|
| 870 | ds_display_t *disp = (ds_display_t *) arg;
|
---|
| 871 |
|
---|
| 872 | (void) disp;
|
---|
| 873 | }
|
---|
| 874 |
|
---|
[c8cf261] | 875 | /** @}
|
---|
| 876 | */
|
---|