Changeset afcf704 in mainline for uspace/lib/gui/window.c
- Timestamp:
- 2020-06-14T22:23:34Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c45d8696
- Parents:
- 28f8f6f2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gui/window.c
r28f8f6f2 rafcf704 414 414 } 415 415 416 /* Allocate resources for new surface. */417 surface_t *new_surface = surface_create(width, height, NULL,418 SURFACE_FLAG_SHARED);419 if (!new_surface)420 return;421 422 gfx_bitmap_params_init(¶ms);423 params.rect.p0.x = 0;424 params.rect.p0.y = 0;425 params.rect.p1.x = width;426 params.rect.p1.y = height;427 428 alloc.pitch = width * sizeof(uint32_t);429 alloc.off0 = 0;430 alloc.pixels = surface_direct_access(new_surface);431 432 rc = gfx_bitmap_create(win->gc, ¶ms, &alloc, &new_bitmap);433 if (rc != EOK) {434 surface_destroy(new_surface);435 return;436 }437 438 /* Switch new and old surface. */439 416 fibril_mutex_lock(&win->guard); 440 surface_t *old_surface = win->surface; 441 gfx_bitmap_t *old_bitmap = win->bitmap; 442 win->surface = new_surface; 443 win->bitmap = new_bitmap; 444 fibril_mutex_unlock(&win->guard); 445 446 /* 447 * Let all widgets in the tree alter their position and size. 448 * Widgets might also paint themselves onto the new surface. 449 */ 450 win->root.rearrange(&win->root, 0, 0, width, height); 451 452 fibril_mutex_lock(&win->guard); 453 surface_reset_damaged_region(win->surface); 454 fibril_mutex_unlock(&win->guard); 417 418 /* Deallocate old bitmap. */ 419 if (win->bitmap != NULL) { 420 gfx_bitmap_destroy(win->bitmap); 421 win->bitmap = NULL; 422 } 423 424 /* Deallocate old surface. */ 425 if (win->surface != NULL) { 426 surface_destroy(win->surface); 427 win->surface = NULL; 428 } 455 429 456 430 /* Resize the display window. */ … … 463 437 464 438 rc = display_window_resize(win->dwindow, &offs, &nrect); 439 if (rc != EOK) 440 return; 441 442 gfx_bitmap_params_init(¶ms); 443 #ifndef CONFIG_WIN_DOUBLE_BUF 444 params.flags = bmpf_direct_output; 445 #else 446 params.flags = 0; 447 #endif 448 params.rect.p0.x = 0; 449 params.rect.p0.y = 0; 450 params.rect.p1.x = width; 451 params.rect.p1.y = height; 452 453 rc = gfx_bitmap_create(win->gc, ¶ms, NULL, &new_bitmap); 465 454 if (rc != EOK) { 466 /* Rollback to old surface. Reverse all changes. */ 467 468 sysarg_t old_width = 0; 469 sysarg_t old_height = 0; 470 if (old_surface) 471 surface_get_resolution(old_surface, &old_width, &old_height); 472 473 fibril_mutex_lock(&win->guard); 474 new_surface = win->surface; 475 win->surface = old_surface; 476 win->bitmap = old_bitmap; 455 if (rc == ENOTSUP) { 456 /* Direct output is not supported */ 457 params.flags &= ~bmpf_direct_output; 458 rc = gfx_bitmap_create(win->gc, ¶ms, NULL, &new_bitmap); 459 if (rc != EOK) { 460 fibril_mutex_unlock(&win->guard); 461 return; 462 } 463 } 464 } 465 466 rc = gfx_bitmap_get_alloc(new_bitmap, &alloc); 467 if (rc != EOK) { 477 468 fibril_mutex_unlock(&win->guard); 478 479 win->root.rearrange(&win->root, 0, 0, old_width, old_height); 480 481 if (win->surface) { 482 fibril_mutex_lock(&win->guard); 483 surface_reset_damaged_region(win->surface); 484 fibril_mutex_unlock(&win->guard); 485 } 486 487 surface_destroy(new_surface); 488 return; 489 } 490 491 if (old_bitmap != NULL) 492 gfx_bitmap_destroy(old_bitmap); 493 /* Deallocate old surface. */ 494 if (old_surface) 495 surface_destroy(old_surface); 469 return; 470 } 471 472 /* Allocate new surface. */ 473 surface_t *new_surface = surface_create(width, height, alloc.pixels, 0); 474 if (!new_surface) { 475 gfx_bitmap_destroy(new_bitmap); 476 fibril_mutex_unlock(&win->guard); 477 return; 478 } 479 480 /* Switch in new surface and bitmap. */ 481 win->surface = new_surface; 482 win->bitmap = new_bitmap; 483 fibril_mutex_unlock(&win->guard); 484 485 /* 486 * Let all widgets in the tree alter their position and size. 487 * Widgets might also paint themselves onto the new surface. 488 */ 489 win->root.rearrange(&win->root, 0, 0, width, height); 490 491 fibril_mutex_lock(&win->guard); 492 surface_reset_damaged_region(win->surface); 493 fibril_mutex_unlock(&win->guard); 496 494 497 495 if (placement_flags != WINDOW_PLACEMENT_ANY) {
Note:
See TracChangeset
for help on using the changeset viewer.