Changeset 3275736 in mainline


Ignore:
Timestamp:
2020-01-30T12:14:37Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
287688f
Parents:
4645b2c
git-author:
Jiri Svoboda <jiri@…> (2020-01-29 20:14:25)
git-committer:
Jiri Svoboda <jiri@…> (2020-01-30 12:14:37)
Message:

Create display window upon resize

GUI window size is not known when it is created. Until display server can
resize windows, need this hack so that we know the correct size when
creating the display window.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gui/window.c

    r4645b2c r3275736  
    370370    sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
    371371{
     372        display_wnd_params_t wparams;
     373        display_window_t *new_window = NULL;
    372374        gfx_bitmap_params_t params;
    373375        gfx_bitmap_alloc_t alloc;
     376        gfx_bitmap_t *new_bitmap = NULL;
     377        gfx_context_t *new_gc = NULL;
     378        errno_t rc;
    374379
    375380        if (width < 2 * border_thickness + header_min_width) {
     
    389394                return;
    390395
    391         gfx_bitmap_t *new_bitmap = NULL;
     396        display_wnd_params_init(&wparams);
     397        wparams.rect.p0.x = 0;
     398        wparams.rect.p0.y = 0;
     399        wparams.rect.p1.x = width;
     400        wparams.rect.p1.y = height;
     401
     402        rc = display_window_create(win->display, &wparams, NULL, NULL,
     403            &new_window);
     404        if (rc != EOK) {
     405                surface_destroy(new_surface);
     406                return;
     407        }
     408
     409        rc = display_window_get_gc(new_window, &new_gc);
     410        if (rc != EOK) {
     411                display_window_destroy(new_window);
     412                surface_destroy(new_surface);
     413                return;
     414        }
    392415
    393416        params.rect.p0.x = 0;
     
    400423        alloc.pixels = surface_direct_access(new_surface);
    401424
    402         errno_t rc = gfx_bitmap_create(win->gc, &params, &alloc, &new_bitmap);
     425        rc = gfx_bitmap_create(new_gc, &params, &alloc, &new_bitmap);
    403426        if (rc != EOK) {
     427                gfx_context_delete(new_gc);
     428                display_window_destroy(new_window);
    404429                surface_destroy(new_surface);
    405430                return;
     
    410435        surface_t *old_surface = win->surface;
    411436        gfx_bitmap_t *old_bitmap = win->bitmap;
     437        display_window_t *old_window = win->dwindow;
     438        gfx_context_t *old_gc = win->gc;
    412439        win->surface = new_surface;
    413440        win->bitmap = new_bitmap;
     441        win->dwindow = new_window;
     442        win->gc = new_gc;
    414443        fibril_mutex_unlock(&win->guard);
    415444
     
    440469                new_surface = win->surface;
    441470                win->surface = old_surface;
     471                win->bitmap = old_bitmap;
     472                win->dwindow = old_window;
     473                win->gc = old_gc;
    442474                fibril_mutex_unlock(&win->guard);
    443475
     
    452484                surface_destroy(new_surface);
    453485        } else {
     486                if (old_window != NULL)
     487                        display_window_destroy(old_window);
     488                if (old_gc != NULL)
     489                        gfx_context_delete(old_gc);
    454490                if (old_bitmap != NULL)
    455491                        gfx_bitmap_destroy(old_bitmap);
     
    488524                printf("render damaged region: %d,%d,%d,%d,\n",
    489525                    (int)x,(int)y,(int)width,(int)height);
    490                 (void) gfx_bitmap_render(win->bitmap, &rect, NULL);
     526                if (win->bitmap != NULL)
     527                        (void) gfx_bitmap_render(win->bitmap, &rect, NULL);
    491528        }
    492529}
     
    631668    window_flags_t flags, const char *caption)
    632669{
    633         window_t *win = (window_t *) malloc(sizeof(window_t));
     670        window_t *win = (window_t *) calloc(1, sizeof(window_t));
    634671        if (!win)
    635672                return NULL;
     
    659696        }
    660697
    661         display_wnd_params_t params;
    662         display_wnd_params_init(&params);
    663 
    664         params.rect.p0.x = 0;
    665         params.rect.p0.y = 0;
    666         params.rect.p1.x = 200;
    667         params.rect.p1.y = 100;
    668 
    669         rc = display_window_create(win->display, &params, NULL, NULL,
    670             &win->dwindow);
    671         if (rc != EOK) {
    672                 display_close(win->display);
    673                 free(win);
    674                 return NULL;
    675         }
    676 
    677         rc = display_window_get_gc(win->dwindow, &win->gc);
    678         if (rc != EOK) {
    679                 (void) display_window_destroy(win->dwindow);
    680                 display_close(win->display);
    681                 free(win);
    682                 return NULL;
    683         }
    684698
    685699        if (caption == NULL)
Note: See TracChangeset for help on using the changeset viewer.