Changeset 4645b2c in mainline for uspace/lib/gui/window.c


Ignore:
Timestamp:
2020-01-29T15:36:37Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3275736
Parents:
f5191b4
git-author:
Jiri Svoboda <jiri@…> (2020-01-28 19:36:08)
git-committer:
Jiri Svoboda <jiri@…> (2020-01-29 15:36:37)
Message:

Start porting libgui over to libdisplay/libgfx

File:
1 edited

Legend:

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

    rf5191b4 r4645b2c  
    4848#include <adt/list.h>
    4949
    50 #include <async.h>
    5150#include <loc.h>
    5251
     
    5655#include <draw/drawctx.h>
    5756#include <draw/surface.h>
     57#include <display.h>
    5858
    5959#include "common.h"
     
    283283                        flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X;
    284284                        flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y;
    285                         win_grab(widget->window->osess, event.pos_id, flags);
     285                        //win_grab(widget->window->osess, event.pos_id, flags);
    286286                } else if (bottom && left && allowed_button) {
    287287                        window_grab_flags_t flags = GF_EMPTY;
     
    289289                        flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X;
    290290                        flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y;
    291                         win_grab(widget->window->osess, event.pos_id, flags);
     291                        //win_grab(widget->window->osess, event.pos_id, flags);
    292292                } else if (bottom && right && allowed_button) {
    293293                        window_grab_flags_t flags = GF_EMPTY;
    294294                        flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X;
    295295                        flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y;
    296                         win_grab(widget->window->osess, event.pos_id, flags);
     296                        //win_grab(widget->window->osess, event.pos_id, flags);
    297297                } else if (top && right && allowed_button) {
    298298                        window_grab_flags_t flags = GF_EMPTY;
     
    300300                        flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X;
    301301                        flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y;
    302                         win_grab(widget->window->osess, event.pos_id, flags);
     302                        //win_grab(widget->window->osess, event.pos_id, flags);
    303303                } else if (top && allowed_button) {
    304304                        window_grab_flags_t flags = GF_EMPTY;
    305305                        flags |= GF_MOVE_Y;
    306306                        flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y;
    307                         win_grab(widget->window->osess, event.pos_id, flags);
     307                        //win_grab(widget->window->osess, event.pos_id, flags);
    308308                } else if (left && allowed_button) {
    309309                        window_grab_flags_t flags = GF_EMPTY;
    310310                        flags |= GF_MOVE_X;
    311311                        flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X;
    312                         win_grab(widget->window->osess, event.pos_id, flags);
     312                        //win_grab(widget->window->osess, event.pos_id, flags);
    313313                } else if (bottom && allowed_button) {
    314314                        window_grab_flags_t flags = GF_EMPTY;
    315315                        flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y;
    316                         win_grab(widget->window->osess, event.pos_id, flags);
     316                        //win_grab(widget->window->osess, event.pos_id, flags);
    317317                } else if (right && allowed_button) {
    318318                        window_grab_flags_t flags = GF_EMPTY;
    319319                        flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X;
    320                         win_grab(widget->window->osess, event.pos_id, flags);
     320                        //win_grab(widget->window->osess, event.pos_id, flags);
    321321                } else if (close && btn_left) {
    322                         win_close_request(widget->window->osess);
     322                        //win_close_request(widget->window->osess);
    323323                } else if (header && btn_left) {
    324324                        window_grab_flags_t flags = GF_EMPTY;
    325325                        flags |= GF_MOVE_X;
    326326                        flags |= GF_MOVE_Y;
    327                         win_grab(widget->window->osess, event.pos_id, flags);
     327                        //win_grab(widget->window->osess, event.pos_id, flags);
    328328                } else {
    329329                        list_foreach(widget->children, link, widget_t, child) {
     
    370370    sysarg_t width, sysarg_t height, window_placement_flags_t placement_flags)
    371371{
     372        gfx_bitmap_params_t params;
     373        gfx_bitmap_alloc_t alloc;
     374
    372375        if (width < 2 * border_thickness + header_min_width) {
    373                 win_damage(win->osess, 0, 0, 0, 0);
     376                //win_damage(win->osess, 0, 0, 0, 0);
    374377                return;
    375378        }
    376379
    377380        if (height < 2 * border_thickness + header_height) {
    378                 win_damage(win->osess, 0, 0, 0, 0);
     381                //win_damage(win->osess, 0, 0, 0, 0);
    379382                return;
    380383        }
     
    386389                return;
    387390
     391        gfx_bitmap_t *new_bitmap = NULL;
     392
     393        params.rect.p0.x = 0;
     394        params.rect.p0.y = 0;
     395        params.rect.p1.x = width;
     396        params.rect.p1.y = height;
     397
     398        alloc.pitch = width * sizeof(uint32_t);
     399        alloc.off0 = 0;
     400        alloc.pixels = surface_direct_access(new_surface);
     401
     402        errno_t rc = gfx_bitmap_create(win->gc, &params, &alloc, &new_bitmap);
     403        if (rc != EOK) {
     404                surface_destroy(new_surface);
     405                return;
     406        }
     407
    388408        /* Switch new and old surface. */
    389409        fibril_mutex_lock(&win->guard);
    390410        surface_t *old_surface = win->surface;
     411        gfx_bitmap_t *old_bitmap = win->bitmap;
    391412        win->surface = new_surface;
     413        win->bitmap = new_bitmap;
    392414        fibril_mutex_unlock(&win->guard);
    393415
     
    403425
    404426        /* Inform compositor about new surface. */
    405         errno_t rc = win_resize(win->osess, offset_x, offset_y, width, height,
    406             placement_flags, surface_direct_access(new_surface));
     427//      errno_t rc = win_resize(win->osess, offset_x, offset_y, width, height,
     428//          placement_flags, surface_direct_access(new_surface));
     429        rc = EOK;
    407430
    408431        if (rc != EOK) {
     
    429452                surface_destroy(new_surface);
    430453        } else {
     454                if (old_bitmap != NULL)
     455                        gfx_bitmap_destroy(old_bitmap);
    431456                /* Deallocate old surface. */
    432457                if (old_surface)
    433458                        surface_destroy(old_surface);
     459
     460                (void) gfx_bitmap_render(win->bitmap, NULL, NULL);
    434461        }
    435462}
     
    443470{
    444471        sysarg_t x, y, width, height;
     472        gfx_rect_t rect;
    445473        fibril_mutex_lock(&win->guard);
    446474        surface_get_damaged_region(win->surface, &x, &y, &width, &height);
     
    448476        fibril_mutex_unlock(&win->guard);
    449477
     478
    450479        if (width > 0 && height > 0) {
    451480                /* Notify compositor. */
    452                 win_damage(win->osess, x, y, width, height);
     481                //win_damage(win->osess, x, y, width, height);
     482
     483                rect.p0.x = x;
     484                rect.p0.y = y;
     485                rect.p1.x = x + width;
     486                rect.p1.y = y + height;
     487
     488                printf("render damaged region: %d,%d,%d,%d,\n",
     489                    (int)x,(int)y,(int)width,(int)height);
     490                (void) gfx_bitmap_render(win->bitmap, &rect, NULL);
    453491        }
    454492}
     
    472510        win->focus = NULL;
    473511
    474         win_close(win->osess);
    475         async_hangup(win->isess);
    476         async_hangup(win->osess);
     512        display_window_destroy(win->dwindow);
     513        display_close(win->display);
    477514
    478515        while (!list_empty(&win->events.list)) {
     
    562599static errno_t fetch_input(void *arg)
    563600{
    564         errno_t rc;
    565         bool terminate = false;
    566         window_t *win = (window_t *) arg;
    567 
    568         while (true) {
     601//      errno_t rc;
     602//      bool terminate = false;
     603//      window_t *win = (window_t *) arg;
     604
     605/*      while (true) {
    569606                window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
    570607
     
    587624                }
    588625        }
    589 
     626*/
    590627        return 0;
    591628}
     
    616653        win->surface = NULL;
    617654
    618         service_id_t reg_dsid;
    619         errno_t rc = loc_service_get_id(winreg, &reg_dsid, 0);
     655        errno_t rc = display_open(winreg, &win->display);
    620656        if (rc != EOK) {
    621657                free(win);
     
    623659        }
    624660
    625         async_sess_t *reg_sess =
    626             loc_service_connect(reg_dsid, INTERFACE_COMPOSITOR, 0);
    627         if (reg_sess == NULL) {
     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);
    628673                free(win);
    629674                return NULL;
    630675        }
    631676
    632         service_id_t in_dsid;
    633         service_id_t out_dsid;
    634         rc = win_register(reg_sess, flags, &in_dsid, &out_dsid);
    635         async_hangup(reg_sess);
     677        rc = display_window_get_gc(win->dwindow, &win->gc);
    636678        if (rc != EOK) {
    637                 free(win);
    638                 return NULL;
    639         }
    640 
    641         win->osess = loc_service_connect(out_dsid, INTERFACE_COMPOSITOR, 0);
    642         if (win->osess == NULL) {
    643                 free(win);
    644                 return NULL;
    645         }
    646 
    647         win->isess = loc_service_connect(in_dsid, INTERFACE_COMPOSITOR, 0);
    648         if (win->isess == NULL) {
    649                 async_hangup(win->osess);
     679                (void) display_window_destroy(win->dwindow);
     680                display_close(win->display);
    650681                free(win);
    651682                return NULL;
     
    746777{
    747778        /* Request compositor to init closing cascade. */
    748         win_close_request(win->osess);
     779        //win_close_request(win->osess);
    749780}
    750781
Note: See TracChangeset for help on using the changeset viewer.