Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/compositor/compositor.c

    r3b98311 r428bd07  
    9090typedef struct {
    9191        link_t link;
    92         atomic_t ref_cnt;
    9392        service_id_t in_dsid;
    9493        service_id_t out_dsid;
     
    139138} viewport_t;
    140139
    141 static desktop_rect_t viewport_bound_rect;
    142140static FIBRIL_MUTEX_INITIALIZE(viewport_list_mtx);
    143141static LIST_INITIALIZE(viewport_list);
     
    217215
    218216        link_initialize(&win->link);
    219         atomic_set(&win->ref_cnt, 0);
    220217        prodcons_initialize(&win->queue);
    221218        transform_identity(&win->transform);
     
    235232static void window_destroy(window_t *win)
    236233{
    237         if (win && atomic_get(&win->ref_cnt) == 0) {
    238                 while (!list_empty(&win->queue.list)) {
    239                         window_event_t *event = (window_event_t *) list_first(&win->queue.list);
    240                         list_remove(&event->link);
    241                         free(event);
    242                 }
    243 
     234        if (win) {
    244235                if (win->surface) {
    245236                        surface_destroy(win->surface);
     
    319310}
    320311
    321 static void comp_restrict_pointers(void)
    322 {
    323         fibril_mutex_lock(&viewport_list_mtx);
    324 
    325         sysarg_t x_res = coord_origin;
    326         sysarg_t y_res = coord_origin;
    327         sysarg_t w_res = 0;
    328         sysarg_t h_res = 0;
    329 
    330         if (!list_empty(&viewport_list)) {
    331                 viewport_t *vp = (viewport_t *) list_first(&viewport_list);
    332                 x_res = vp->pos.x;
    333                 y_res = vp->pos.y;
    334                 surface_get_resolution(vp->surface, &w_res, &h_res);
    335         }
    336 
    337         list_foreach(viewport_list, link) {
    338                 viewport_t *vp = list_get_instance(link, viewport_t, link);
    339                 sysarg_t w_vp, h_vp;
    340                 surface_get_resolution(vp->surface, &w_vp, &h_vp);
    341                 rectangle_union(
    342                     x_res, y_res, w_res, h_res,
    343                     vp->pos.x, vp->pos.y, w_vp, h_vp,
    344                     &x_res, &y_res, &w_res, &h_res);
    345         }
    346 
    347         viewport_bound_rect.x = x_res;
    348         viewport_bound_rect.y = y_res;
    349         viewport_bound_rect.w = w_res;
    350         viewport_bound_rect.h = h_res;
    351 
    352         fibril_mutex_unlock(&viewport_list_mtx);
    353 
    354         fibril_mutex_lock(&pointer_list_mtx);
    355 
    356         list_foreach(pointer_list, link) {
    357                 pointer_t *ptr = list_get_instance(link, pointer_t, link);
    358                 ptr->pos.x = ptr->pos.x > viewport_bound_rect.x ? ptr->pos.x : viewport_bound_rect.x;
    359                 ptr->pos.y = ptr->pos.y > viewport_bound_rect.y ? ptr->pos.y : viewport_bound_rect.y;
    360                 ptr->pos.x = ptr->pos.x < viewport_bound_rect.x + viewport_bound_rect.w ?
    361                     ptr->pos.x : viewport_bound_rect.x + viewport_bound_rect.w;
    362                 ptr->pos.y = ptr->pos.y < viewport_bound_rect.y + viewport_bound_rect.h ?
    363                     ptr->pos.y : viewport_bound_rect.y + viewport_bound_rect.h;
    364         }
    365 
    366         fibril_mutex_unlock(&pointer_list_mtx);
    367 }
    368 
    369312static void comp_damage(sysarg_t x_dmg_glob, sysarg_t y_dmg_glob,
    370313    sysarg_t w_dmg_glob, sysarg_t h_dmg_glob)
     
    752695        }
    753696
    754         loc_service_unregister(win->in_dsid);
    755         loc_service_unregister(win->out_dsid);
    756 
    757         /* In case the client was killed, input fibril of the window might be
    758          * still blocked on the condition within comp_window_get_event. */
    759         window_event_t *event_dummy = (window_event_t *) malloc(sizeof(window_event_t));
    760         if (event_dummy) {
    761                 link_initialize(&event_dummy->link);
    762                 prodcons_produce(&win->queue, &event_dummy->link);
    763         }
    764 
    765697        /* Calculate damage. */
    766698        sysarg_t x = 0;
     
    774706        }
    775707
     708        /* Release window resources. */
     709        loc_service_unregister(win->in_dsid);
     710        loc_service_unregister(win->out_dsid);
     711        while (!list_empty(&win->queue.list)) {
     712                list_remove(list_first(&win->queue.list));
     713        }
     714        window_destroy(win);
     715
    776716        comp_damage(x, y, width, height);
    777717
     
    873813
    874814        if (win) {
    875                 atomic_inc(&win->ref_cnt);
    876815                async_answer_0(iid, EOK);
    877816        } else {
     
    886825
    887826                        if (!IPC_GET_IMETHOD(call)) {
    888                                 async_answer_0(callid, EOK);
    889                                 atomic_dec(&win->ref_cnt);
    890                                 window_destroy(win);
     827                                async_answer_0(callid, EINVAL);
    891828                                return;
    892829                        }
     
    905842
    906843                        if (!IPC_GET_IMETHOD(call)) {
    907                                 comp_window_close(win, callid, &call);
    908                                 atomic_dec(&win->ref_cnt);
    909                                 window_destroy(win);
     844                                async_answer_0(callid, EINVAL);
    910845                                return;
    911846                        }
     
    922857                                break;
    923858                        case WINDOW_CLOSE:
    924                                 /* Postpone the closing until the phone is hung up to cover
    925                                  * the case when the client is killed abruptly. */
    926                                 async_answer_0(callid, EOK);
     859                                comp_window_close(win, callid, &call);
    927860                                break;
    928861                        case WINDOW_CLOSE_REQUEST:
     
    978911        async_answer_0(iid, EOK);
    979912
    980         comp_restrict_pointers();
    981913        comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
    982914}
     
    1024956                fibril_mutex_unlock(&viewport_list_mtx);
    1025957                async_answer_0(iid, EOK);
    1026 
    1027                 comp_restrict_pointers();
    1028                 comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
    1029958        }
    1030959}
     
    14621391        surface_get_resolution(pointer->cursor.states[pointer->state],
    14631392             &cursor_width, &cursor_height);
    1464         if (pointer->pos.x + dx < viewport_bound_rect.x) {
    1465                 dx = -1 * (pointer->pos.x - viewport_bound_rect.x);
    1466         }
    1467         if (pointer->pos.y + dy < viewport_bound_rect.y) {
    1468                 dy = -1 * (pointer->pos.y - viewport_bound_rect.y);
    1469         }
    1470         if (pointer->pos.x + dx > viewport_bound_rect.x + viewport_bound_rect.w) {
    1471                 dx = (viewport_bound_rect.x + viewport_bound_rect.w - pointer->pos.x);
    1472         }
    1473         if (pointer->pos.y + dy > viewport_bound_rect.y + viewport_bound_rect.h) {
    1474                 dy = (viewport_bound_rect.y + viewport_bound_rect.h - pointer->pos.y);
    1475         }
    14761393        pointer->pos.x += dx;
    14771394        pointer->pos.y += dy;
     
    19931910                        fibril_mutex_unlock(&viewport_list_mtx);
    19941911
    1995                         comp_restrict_pointers();
    19961912                        comp_damage(x, y, width, height);
    19971913                } else {
     
    20461962                }
    20471963                list_prepend(&blue_win->link, &window_list);
    2048                
     1964
     1965                window_t *helenos_win = window_create(0, 0);
     1966                helenos_win->surface = decode_tga((void *) helenos_tga, helenos_tga_size, 0);
     1967                list_prepend(&helenos_win->link, &window_list);
     1968
    20491969                window_t *nameic_win = window_create(0, 0);
    20501970                nameic_win->surface = decode_tga((void *) nameic_tga, nameic_tga_size, 0);
     
    21722092        /* Establish input bidirectional connection. */
    21732093        rc = input_connect(input_svc);
    2174         if (rc != EOK)
     2094        if (rc != EOK) {
     2095                printf("%s: Failed to connect to input service.\n", NAME);
    21752096                return rc;
     2097        }
    21762098
    21772099        /* Create viewports and connect them to visualizers. */
     
    21792101        rc = loc_category_get_id("visualizer", &cat_id, IPC_FLAG_BLOCKING);
    21802102        if (rc != EOK) {
     2103                printf("%s: Failed to get visualizer category.\n", NAME);
    21812104                input_disconnect();
    21822105                return -1;
     
    21872110        rc = loc_category_get_svcs(cat_id, &svcs, &svcs_cnt);
    21882111        if (rc != EOK || svcs_cnt == 0) {
     2112                printf("%s: Failed to get visualizer category services.\n", NAME);
    21892113                input_disconnect();
    21902114                return -1;
     
    22032127       
    22042128        if (list_empty(&viewport_list)) {
     2129                printf("%s: Failed to get view ports.\n", NAME);
    22052130                input_disconnect();
    22062131                return -1;
    22072132        }
    2208 
    2209         comp_restrict_pointers();
     2133       
    22102134        comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
    22112135       
Note: See TracChangeset for help on using the changeset viewer.