Changeset 2ab8ab3 in mainline for uspace/lib/ui/src/window.c
- Timestamp:
- 2021-02-16T18:12:05Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 68a552f
- Parents:
- ef734b7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/window.c
ref734b7 r2ab8ab3 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 84 84 }; 85 85 86 static void ui_window_app_update(void *, gfx_rect_t *); 86 static void ui_window_invalidate(void *, gfx_rect_t *); 87 static void ui_window_update(void *); 88 static void ui_window_app_invalidate(void *, gfx_rect_t *); 89 static void ui_window_app_update(void *); 87 90 88 91 /** Initialize window parameters structure. … … 123 126 ui_wdecor_t *wdecor = NULL; 124 127 dummy_gc_t *dgc = NULL; 128 gfx_bitmap_params_t bparams; 129 gfx_bitmap_alloc_t alloc; 130 gfx_bitmap_t *bmp = NULL; 131 mem_gc_t *memgc = NULL; 125 132 errno_t rc; 126 133 … … 196 203 } 197 204 198 rc = ui_resource_create(gc, &res); 205 #ifdef CONFIG_UI_CS_RENDER 206 /* Create window bitmap */ 207 gfx_bitmap_params_init(&bparams); 208 #ifndef CONFIG_WIN_DOUBLE_BUF 209 bparams.flags |= bmpf_direct_output; 210 #endif 211 212 /* Move rectangle so that top-left corner is 0,0 */ 213 gfx_rect_rtranslate(¶ms->rect.p0, ¶ms->rect, &bparams.rect); 214 215 rc = gfx_bitmap_create(gc, &bparams, NULL, &bmp); 216 if (rc != EOK) 217 goto error; 218 219 /* Create memory GC */ 220 rc = gfx_bitmap_get_alloc(bmp, &alloc); 221 if (rc != EOK) { 222 gfx_bitmap_destroy(window->app_bmp); 223 return rc; 224 } 225 226 rc = mem_gc_create(&bparams.rect, &alloc, ui_window_invalidate, 227 ui_window_update, (void *) window, &memgc); 228 if (rc != EOK) { 229 gfx_bitmap_destroy(window->app_bmp); 230 return rc; 231 } 232 233 window->bmp = bmp; 234 window->mgc = memgc; 235 window->gc = mem_gc_get_ctx(memgc); 236 window->realgc = gc; 237 #else 238 (void) ui_window_update; 239 (void) ui_window_invalidate; 240 (void) alloc; 241 (void) bparams; 242 window->gc = gc; 243 #endif 244 rc = ui_resource_create(window->gc, &res); 199 245 if (rc != EOK) 200 246 goto error; … … 211 257 window->dwindow = dwindow; 212 258 window->rect = dparams.rect; 213 window->gc = gc; 259 214 260 window->res = res; 215 261 window->wdecor = wdecor; … … 222 268 if (res != NULL) 223 269 ui_resource_destroy(res); 270 if (memgc != NULL) 271 mem_gc_delete(memgc); 272 if (bmp != NULL) 273 gfx_bitmap_destroy(bmp); 224 274 if (dgc != NULL) 225 275 dummygc_destroy(dgc); … … 242 292 ui_wdecor_destroy(window->wdecor); 243 293 ui_resource_destroy(window->res); 294 if (0 && window->app_mgc != NULL) 295 mem_gc_delete(window->app_mgc); 296 if (0 && window->app_bmp != NULL) 297 gfx_bitmap_destroy(window->app_bmp); 298 if (window->mgc != NULL) { 299 mem_gc_delete(window->mgc); 300 window->gc = NULL; 301 } 302 if (window->bmp != NULL) 303 gfx_bitmap_destroy(window->bmp); 244 304 gfx_context_delete(window->gc); 245 305 display_window_destroy(window->dwindow); … … 294 354 gfx_rect_t arect; 295 355 gfx_bitmap_t *app_bmp = NULL; 296 gfx_bitmap_params_t params; 297 gfx_bitmap_alloc_t alloc; 356 gfx_bitmap_t *win_bmp = NULL; 357 gfx_bitmap_params_t app_params; 358 gfx_bitmap_params_t win_params; 359 gfx_bitmap_alloc_t app_alloc; 360 gfx_bitmap_alloc_t win_alloc; 298 361 errno_t rc; 299 362 … … 305 368 gfx_rect_rtranslate(&offs, rect, &nrect); 306 369 370 /* mgc != NULL iff client-side rendering */ 371 if (window->mgc != NULL) { 372 /* Resize window bitmap */ 373 assert(window->bmp != NULL); 374 375 gfx_bitmap_params_init(&win_params); 376 #ifndef CONFIG_WIN_DOUBLE_BUF 377 win_params.flags |= bmpf_direct_output; 378 #endif 379 win_params.rect = nrect; 380 381 rc = gfx_bitmap_create(window->realgc, &win_params, NULL, 382 &win_bmp); 383 if (rc != EOK) 384 goto error; 385 386 rc = gfx_bitmap_get_alloc(win_bmp, &win_alloc); 387 if (rc != EOK) 388 goto error; 389 } 390 391 /* Application area GC? */ 307 392 if (window->app_gc != NULL) { 393 /* Resize application bitmap */ 308 394 assert(window->app_bmp != NULL); 309 395 310 gfx_bitmap_params_init(& params);396 gfx_bitmap_params_init(&app_params); 311 397 312 398 /* … … 315 401 */ 316 402 ui_wdecor_app_from_rect(window->wdecor->style, &nrect, &arect); 317 gfx_rect_rtranslate(&arect.p0, &arect, & params.rect);318 319 rc = gfx_bitmap_create(window->gc, & params, NULL,403 gfx_rect_rtranslate(&arect.p0, &arect, &app_params.rect); 404 405 rc = gfx_bitmap_create(window->gc, &app_params, NULL, 320 406 &app_bmp); 321 407 if (rc != EOK) 322 408 goto error; 323 409 324 rc = gfx_bitmap_get_alloc(app_bmp, &a lloc);410 rc = gfx_bitmap_get_alloc(app_bmp, &app_alloc); 325 411 if (rc != EOK) 326 412 goto error; … … 334 420 } 335 421 422 /* CLient side rendering? */ 423 if (window->mgc != NULL) { 424 mem_gc_retarget(window->mgc, &win_params.rect, &win_alloc); 425 426 gfx_bitmap_destroy(window->bmp); 427 window->bmp = win_bmp; 428 } 429 336 430 ui_wdecor_set_rect(window->wdecor, &nrect); 337 431 ui_wdecor_paint(window->wdecor); 338 432 gfx_update(window->gc); 433 434 /* Application area GC? */ 339 435 if (window->app_gc != NULL) { 340 mem_gc_retarget(window->app_mgc, & params.rect, &alloc);436 mem_gc_retarget(window->app_mgc, &app_params.rect, &app_alloc); 341 437 342 438 gfx_bitmap_destroy(window->app_bmp); … … 348 444 if (app_bmp != NULL) 349 445 gfx_bitmap_destroy(app_bmp); 446 if (win_bmp != NULL) 447 gfx_bitmap_destroy(win_bmp); 350 448 return rc; 351 449 } … … 420 518 } 421 519 422 rc = mem_gc_create(¶ms.rect, &alloc, ui_window_app_ update,423 (void *) window, &memgc);520 rc = mem_gc_create(¶ms.rect, &alloc, ui_window_app_invalidate, 521 ui_window_app_update, (void *) window, &memgc); 424 522 if (rc != EOK) { 425 523 gfx_bitmap_destroy(window->app_bmp); … … 696 794 return ui_control_paint(window->control); 697 795 796 rc = gfx_update(window->res->gc); 797 if (rc != EOK) 798 return rc; 799 698 800 return EOK; 699 801 } … … 710 812 } 711 813 712 /** Application area update callback814 /** Window invalidate callback 713 815 * 714 816 * @param arg Argument (ui_window_t *) 715 817 * @param rect Rectangle to update 716 818 */ 717 static void ui_window_app_update(void *arg, gfx_rect_t *rect) 819 static void ui_window_invalidate(void *arg, gfx_rect_t *rect) 820 { 821 ui_window_t *window = (ui_window_t *) arg; 822 gfx_rect_t env; 823 824 gfx_rect_envelope(&window->dirty_rect, rect, &env); 825 window->dirty_rect = env; 826 } 827 828 /** Window update callback 829 * 830 * @param arg Argument (ui_window_t *) 831 */ 832 static void ui_window_update(void *arg) 833 { 834 ui_window_t *window = (ui_window_t *) arg; 835 836 if (!gfx_rect_is_empty(&window->dirty_rect)) 837 (void) gfx_bitmap_render(window->bmp, &window->dirty_rect, NULL); 838 839 window->dirty_rect.p0.x = 0; 840 window->dirty_rect.p0.y = 0; 841 window->dirty_rect.p1.x = 0; 842 window->dirty_rect.p1.y = 0; 843 } 844 845 /** Application area invalidate callback 846 * 847 * @param arg Argument (ui_window_t *) 848 * @param rect Rectangle to update 849 */ 850 static void ui_window_app_invalidate(void *arg, gfx_rect_t *rect) 718 851 { 719 852 ui_window_t *window = (ui_window_t *) arg; … … 724 857 /* Render bitmap rectangle inside the application area */ 725 858 (void) gfx_bitmap_render(window->app_bmp, rect, &arect.p0); 859 /* 860 * TODO Update applications to call gfx_update(), then 861 * we can defer update to ui_window_app_update(). 862 */ 863 (void) gfx_update(window->res->gc); 864 } 865 866 /** Application area update callback 867 * 868 * @param arg Argument (ui_window_t *) 869 */ 870 static void ui_window_app_update(void *arg) 871 { 872 ui_window_t *window = (ui_window_t *) arg; 873 874 /* 875 * Not used since display is updated immediately 876 * in ui_window_app_invalidate 877 */ 878 (void) window; 726 879 } 727 880
Note:
See TracChangeset
for help on using the changeset viewer.