Changes in uspace/srv/hid/compositor/compositor.c [fbb2d0d:071fefec] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/compositor/compositor.c
rfbb2d0d r071fefec 58 58 59 59 #include <event.h> 60 #include < device/graph_dev.h>60 #include <graph_iface.h> 61 61 #include <io/keycode.h> 62 62 #include <io/mode.h> … … 72 72 #include <codec/tga.h> 73 73 74 #include "images.h"75 74 #include "compositor.h" 76 75 … … 162 161 static void input_disconnect(void); 163 162 164 165 163 static pointer_t *input_pointer(input_t *input) 166 164 { … … 168 166 } 169 167 170 static pointer_t *pointer_create( )168 static pointer_t *pointer_create(void) 171 169 { 172 170 pointer_t *p = (pointer_t *) malloc(sizeof(pointer_t)); 173 if (!p) {171 if (!p) 174 172 return NULL; 175 } 176 173 177 174 link_initialize(&p->link); 178 175 p->pos.x = coord_origin; … … 186 183 p->state = 0; 187 184 cursor_init(&p->cursor, CURSOR_DECODER_EMBEDDED, NULL); 188 185 189 186 /* Ghost window for transformation animation. */ 190 187 transform_identity(&p->ghost.transform); … … 199 196 p->accum_ghost.x = 0; 200 197 p->accum_ghost.y = 0; 201 198 202 199 return p; 203 200 } … … 211 208 } 212 209 213 static window_t *window_create( sysarg_t x_offset, sysarg_t y_offset)210 static window_t *window_create(void) 214 211 { 215 212 window_t *win = (window_t *) malloc(sizeof(window_t)); 216 if (!win) {213 if (!win) 217 214 return NULL; 218 } 219 215 220 216 link_initialize(&win->link); 221 217 atomic_set(&win->ref_cnt, 0); 222 218 prodcons_initialize(&win->queue); 223 219 transform_identity(&win->transform); 224 transform_translate(&win->transform, 225 coord_origin + x_offset, coord_origin + y_offset); 226 win->dx = coord_origin + x_offset; 227 win->dy = coord_origin + y_offset; 220 transform_translate(&win->transform, coord_origin, coord_origin); 221 win->dx = coord_origin; 222 win->dy = coord_origin; 228 223 win->fx = 1; 229 224 win->fy = 1; … … 231 226 win->opacity = 255; 232 227 win->surface = NULL; 233 228 234 229 return win; 235 230 } … … 294 289 sysarg_t *x_out, sysarg_t *y_out, sysarg_t *w_out, sysarg_t *h_out) 295 290 { 296 if ( w_in > 0 && h_in > 0) {291 if ((w_in > 0) && (h_in > 0)) { 297 292 sysarg_t x[4]; 298 293 sysarg_t y[4]; 294 299 295 comp_coord_from_client(x_in, y_in, win_trans, &x[0], &y[0]); 300 296 comp_coord_from_client(x_in + w_in - 1, y_in, win_trans, &x[1], &y[1]); 301 297 comp_coord_from_client(x_in + w_in - 1, y_in + h_in - 1, win_trans, &x[2], &y[2]); 302 298 comp_coord_from_client(x_in, y_in + h_in - 1, win_trans, &x[3], &y[3]); 299 303 300 (*x_out) = x[0]; 304 301 (*y_out) = y[0]; 305 302 (*w_out) = x[0]; 306 303 (*h_out) = y[0]; 307 for (int i = 1; i < 4; ++i) { 304 305 for (unsigned int i = 1; i < 4; ++i) { 308 306 (*x_out) = (x[i] < (*x_out)) ? x[i] : (*x_out); 309 307 (*y_out) = (y[i] < (*y_out)) ? y[i] : (*y_out); … … 311 309 (*h_out) = (y[i] > (*h_out)) ? y[i] : (*h_out); 312 310 } 311 313 312 (*w_out) = (*w_out) - (*x_out) + 1; 314 313 (*h_out) = (*h_out) - (*y_out) + 1; … … 321 320 } 322 321 323 static void comp_ restrict_pointers(void)322 static void comp_update_viewport_bound_rect(void) 324 323 { 325 324 fibril_mutex_lock(&viewport_list_mtx); 326 325 327 326 sysarg_t x_res = coord_origin; 328 327 sysarg_t y_res = coord_origin; 329 328 sysarg_t w_res = 0; 330 329 sysarg_t h_res = 0; 331 330 332 331 if (!list_empty(&viewport_list)) { 333 332 viewport_t *vp = (viewport_t *) list_first(&viewport_list); … … 336 335 surface_get_resolution(vp->surface, &w_res, &h_res); 337 336 } 338 337 339 338 list_foreach(viewport_list, link, viewport_t, vp) { 340 339 sysarg_t w_vp, h_vp; 341 340 surface_get_resolution(vp->surface, &w_vp, &h_vp); 342 rectangle_union( 343 x_res, y_res, w_res, h_res, 341 rectangle_union(x_res, y_res, w_res, h_res, 344 342 vp->pos.x, vp->pos.y, w_vp, h_vp, 345 343 &x_res, &y_res, &w_res, &h_res); 346 344 } 347 345 348 346 viewport_bound_rect.x = x_res; 349 347 viewport_bound_rect.y = y_res; 350 348 viewport_bound_rect.w = w_res; 351 349 viewport_bound_rect.h = h_res; 352 350 353 351 fibril_mutex_unlock(&viewport_list_mtx); 354 352 } 353 354 static void comp_restrict_pointers(void) 355 { 356 comp_update_viewport_bound_rect(); 357 355 358 fibril_mutex_lock(&pointer_list_mtx); 356 359 357 360 list_foreach(pointer_list, link, pointer_t, ptr) { 358 361 ptr->pos.x = ptr->pos.x > viewport_bound_rect.x ? ptr->pos.x : viewport_bound_rect.x; … … 363 366 ptr->pos.y : viewport_bound_rect.y + viewport_bound_rect.h; 364 367 } 365 368 366 369 fibril_mutex_unlock(&pointer_list_mtx); 367 370 } … … 642 645 } 643 646 647 static void comp_recalc_transform(window_t *win) 648 { 649 transform_t translate; 650 transform_identity(&translate); 651 transform_translate(&translate, win->dx, win->dy); 652 653 transform_t scale; 654 transform_identity(&scale); 655 if ((win->fx != 1) || (win->fy != 1)) 656 transform_scale(&scale, win->fx, win->fy); 657 658 transform_t rotate; 659 transform_identity(&rotate); 660 if (win->angle != 0) 661 transform_rotate(&rotate, win->angle); 662 663 transform_t transform; 664 transform_t temp; 665 transform_identity(&transform); 666 temp = transform; 667 transform_product(&transform, &temp, &translate); 668 temp = transform; 669 transform_product(&transform, &temp, &rotate); 670 temp = transform; 671 transform_product(&transform, &temp, &scale); 672 673 win->transform = transform; 674 } 675 644 676 static void comp_window_resize(window_t *win, ipc_callid_t iid, ipc_call_t *icall) 645 677 { 646 int rc;647 648 678 ipc_callid_t callid; 649 679 size_t size; 650 680 unsigned int flags; 651 681 652 682 /* Start sharing resized window with client. */ 653 683 if (!async_share_out_receive(&callid, &size, &flags)) { … … 655 685 return; 656 686 } 687 657 688 void *new_cell_storage; 658 rc = async_share_out_finalize(callid, &new_cell_storage);689 int rc = async_share_out_finalize(callid, &new_cell_storage); 659 690 if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) { 660 691 async_answer_0(iid, ENOMEM); 661 692 return; 662 693 } 663 694 664 695 /* Create new surface for the resized window. */ 665 surface_t *new_surface = surface_create( 666 IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall), 667 new_cell_storage, SURFACE_FLAG_SHARED); 696 surface_t *new_surface = surface_create(IPC_GET_ARG3(*icall), 697 IPC_GET_ARG4(*icall), new_cell_storage, SURFACE_FLAG_SHARED); 668 698 if (!new_surface) { 669 699 as_area_destroy(new_cell_storage); … … 671 701 return; 672 702 } 673 703 704 sysarg_t offset_x = IPC_GET_ARG1(*icall); 705 sysarg_t offset_y = IPC_GET_ARG2(*icall); 706 window_placement_flags_t placement_flags = 707 (window_placement_flags_t) IPC_GET_ARG5(*icall); 708 709 comp_update_viewport_bound_rect(); 710 674 711 /* Switch new surface with old surface and calculate damage. */ 675 712 fibril_mutex_lock(&window_list_mtx); 676 713 677 714 sysarg_t old_width = 0; 678 715 sysarg_t old_height = 0; 716 679 717 if (win->surface) { 680 718 surface_get_resolution(win->surface, &old_width, &old_height); 681 719 surface_destroy(win->surface); 682 720 } 683 721 684 722 win->surface = new_surface; 685 723 686 724 sysarg_t new_width = 0; 687 725 sysarg_t new_height = 0; 688 726 surface_get_resolution(win->surface, &new_width, &new_height); 689 690 sysarg_t x, y; 691 sysarg_t width = old_width > new_width ? old_width : new_width; 692 sysarg_t height = old_height > new_height ? old_height : new_height; 693 comp_coord_bounding_rect(0, 0, width, height, win->transform, &x, &y, &width, &height); 694 727 728 if (placement_flags & WINDOW_PLACEMENT_CENTER_X) 729 win->dx = viewport_bound_rect.x + viewport_bound_rect.w / 2 - 730 new_width / 2; 731 732 if (placement_flags & WINDOW_PLACEMENT_CENTER_Y) 733 win->dy = viewport_bound_rect.y + viewport_bound_rect.h / 2 - 734 new_height / 2; 735 736 if (placement_flags & WINDOW_PLACEMENT_LEFT) 737 win->dx = viewport_bound_rect.x; 738 739 if (placement_flags & WINDOW_PLACEMENT_TOP) 740 win->dy = viewport_bound_rect.y; 741 742 if (placement_flags & WINDOW_PLACEMENT_RIGHT) 743 win->dx = viewport_bound_rect.x + viewport_bound_rect.w - 744 new_width; 745 746 if (placement_flags & WINDOW_PLACEMENT_BOTTOM) 747 win->dy = viewport_bound_rect.y + viewport_bound_rect.h - 748 new_height; 749 750 if (placement_flags & WINDOW_PLACEMENT_ABSOLUTE_X) 751 win->dx = coord_origin + offset_x; 752 753 if (placement_flags & WINDOW_PLACEMENT_ABSOLUTE_Y) 754 win->dy = coord_origin + offset_y; 755 756 /* Transform the window and calculate damage. */ 757 sysarg_t x1; 758 sysarg_t y1; 759 sysarg_t width1; 760 sysarg_t height1; 761 762 comp_coord_bounding_rect(0, 0, old_width, old_height, win->transform, 763 &x1, &y1, &width1, &height1); 764 765 comp_recalc_transform(win); 766 767 sysarg_t x2; 768 sysarg_t y2; 769 sysarg_t width2; 770 sysarg_t height2; 771 772 comp_coord_bounding_rect(0, 0, new_width, new_height, win->transform, 773 &x2, &y2, &width2, &height2); 774 775 sysarg_t x; 776 sysarg_t y; 777 sysarg_t width; 778 sysarg_t height; 779 780 rectangle_union(x1, y1, width1, height1, x2, y2, width2, height2, 781 &x, &y, &width, &height); 782 695 783 fibril_mutex_unlock(&window_list_mtx); 696 784 697 785 comp_damage(x, y, width, height); 698 786 699 787 async_answer_0(iid, EOK); 700 788 } … … 703 791 { 704 792 fibril_mutex_lock(&window_list_mtx); 705 793 706 794 list_foreach(window_list, link, window_t, window) { 707 795 if (window == target) { … … 711 799 } 712 800 } 713 801 714 802 fibril_mutex_unlock(&window_list_mtx); 715 803 free(event); … … 719 807 { 720 808 fibril_mutex_lock(&window_list_mtx); 809 721 810 window_t *win = (window_t *) list_first(&window_list); 722 if (win) {811 if (win) 723 812 prodcons_produce(&win->queue, &event->link); 724 } else {813 else 725 814 free(event); 726 }815 727 816 fibril_mutex_unlock(&window_list_mtx); 728 817 } … … 801 890 fibril_mutex_lock(&window_list_mtx); 802 891 803 window_t *win = window_create( IPC_GET_ARG1(call), IPC_GET_ARG2(call));892 window_t *win = window_create(); 804 893 if (!win) { 805 894 async_answer_2(callid, ENOMEM, 0, 0); … … 1173 1262 } 1174 1263 1175 static void comp_recalc_transform(window_t *win)1176 {1177 transform_t translate;1178 transform_identity(&translate);1179 transform_translate(&translate, win->dx, win->dy);1180 1181 transform_t scale;1182 transform_identity(&scale);1183 if (win->fx != 1 || win->fy != 1) {1184 transform_scale(&scale, win->fx, win->fy);1185 }1186 1187 transform_t rotate;1188 transform_identity(&rotate);1189 if (win->angle != 0) {1190 transform_rotate(&rotate, win->angle);1191 }1192 1193 transform_t transform;1194 transform_t temp;1195 transform_identity(&transform);1196 temp = transform;1197 transform_multiply(&transform, &temp, &translate);1198 temp = transform;1199 transform_multiply(&transform, &temp, &rotate);1200 temp = transform;1201 transform_multiply(&transform, &temp, &scale);1202 1203 1204 win->transform = transform;1205 }1206 1207 1264 static void comp_window_animate(pointer_t *pointer, window_t *win, 1208 1265 sysarg_t *dmg_x, sysarg_t *dmg_y, sysarg_t *dmg_width, sysarg_t *dmg_height) … … 1226 1283 double cx = 0; 1227 1284 double cy = 0; 1228 if (pointer->grab_flags & GF_MOVE_X) { 1285 1286 if (pointer->grab_flags & GF_MOVE_X) 1229 1287 cx = 1; 1230 }1231 if (pointer->grab_flags & GF_MOVE_Y) {1288 1289 if (pointer->grab_flags & GF_MOVE_Y) 1232 1290 cy = 1; 1233 } 1234 1235 if ((scale || resize) && (win->angle != 0)) { 1291 1292 if (((scale) || (resize)) && (win->angle != 0)) { 1236 1293 transform_t rotate; 1237 1294 transform_identity(&rotate); 1295 1238 1296 transform_rotate(&rotate, win->angle); 1239 1297 transform_apply_linear(&rotate, &cx, &cy); 1240 1298 } 1241 1299 1242 cx = (cx < 0) ? (-1 * cx) : cx; 1300 cx = (cx < 0) ? (-1 * cx) : cx; 1243 1301 cy = (cy < 0) ? (-1 * cy) : cy; 1244 1302 1245 1303 win->dx += (cx * dx); 1246 1304 win->dy += (cy * dy); 1247 1305 } 1248 1306 1249 if ( scale || resize) {1307 if ((scale) || (resize)) { 1250 1308 double _dx = dx; 1251 1309 double _dy = dy; … … 1263 1321 if (fx > 0) { 1264 1322 #if ANIMATE_WINDOW_TRANSFORMS == 0 1265 if (scale) win->fx *= fx; 1323 if (scale) 1324 win->fx *= fx; 1266 1325 #endif 1267 1326 #if ANIMATE_WINDOW_TRANSFORMS == 1 … … 1444 1503 { 1445 1504 pointer_t *pointer = input_pointer(input); 1446 1505 1506 comp_update_viewport_bound_rect(); 1507 1447 1508 /* Update pointer position. */ 1448 1509 fibril_mutex_lock(&pointer_list_mtx); 1510 1449 1511 desktop_point_t old_pos = pointer->pos; 1512 1450 1513 sysarg_t cursor_width; 1451 1514 sysarg_t cursor_height; 1452 surface_get_resolution(pointer->cursor.states[pointer->state], 1515 surface_get_resolution(pointer->cursor.states[pointer->state], 1453 1516 &cursor_width, &cursor_height); 1454 if (pointer->pos.x + dx < viewport_bound_rect.x) { 1517 1518 if (pointer->pos.x + dx < viewport_bound_rect.x) 1455 1519 dx = -1 * (pointer->pos.x - viewport_bound_rect.x); 1456 }1457 if (pointer->pos.y + dy < viewport_bound_rect.y) {1520 1521 if (pointer->pos.y + dy < viewport_bound_rect.y) 1458 1522 dy = -1 * (pointer->pos.y - viewport_bound_rect.y); 1459 }1460 if (pointer->pos.x + dx > viewport_bound_rect.x + viewport_bound_rect.w) {1523 1524 if (pointer->pos.x + dx > viewport_bound_rect.x + viewport_bound_rect.w) 1461 1525 dx = (viewport_bound_rect.x + viewport_bound_rect.w - pointer->pos.x); 1462 }1463 if (pointer->pos.y + dy > viewport_bound_rect.y + viewport_bound_rect.h) {1526 1527 if (pointer->pos.y + dy > viewport_bound_rect.y + viewport_bound_rect.h) 1464 1528 dy = (viewport_bound_rect.y + viewport_bound_rect.h - pointer->pos.y); 1465 }1529 1466 1530 pointer->pos.x += dx; 1467 1531 pointer->pos.y += dy; … … 1469 1533 comp_damage(old_pos.x, old_pos.y, cursor_width, cursor_height); 1470 1534 comp_damage(old_pos.x + dx, old_pos.y + dy, cursor_width, cursor_height); 1471 1535 1472 1536 fibril_mutex_lock(&window_list_mtx); 1473 1537 fibril_mutex_lock(&pointer_list_mtx); … … 1630 1694 1631 1695 #if ANIMATE_WINDOW_TRANSFORMS == 0 1632 sysarg_t pre_x = 0; 1696 sysarg_t pre_x = 0; 1633 1697 sysarg_t pre_y = 0; 1634 1698 sysarg_t pre_width = 0; … … 1662 1726 link_initialize(&event_top->link); 1663 1727 event_top->type = ET_WINDOW_RESIZE; 1664 1728 1729 event_top->data.resize.offset_x = 0; 1730 event_top->data.resize.offset_y = 0; 1731 1665 1732 int dx = (int) (((double) width) * (scale_back_x - 1.0)); 1666 1733 int dy = (int) (((double) height) * (scale_back_y - 1.0)); 1667 1668 if (pointer->grab_flags & GF_RESIZE_X) { 1669 event_top->data.rsz.width = 1670 ((((int) width) + dx) >= 0) ? (width + dx) : 0; 1671 } else { 1672 event_top->data.rsz.width = width; 1673 } 1674 1675 if (pointer->grab_flags & GF_RESIZE_Y) { 1676 event_top->data.rsz.height = 1677 ((((int) height) + dy) >= 0) ? (height + dy) : 0; 1678 } else { 1679 event_top->data.rsz.height = height; 1680 } 1734 1735 if (pointer->grab_flags & GF_RESIZE_X) 1736 event_top->data.resize.width = 1737 ((((int) width) + dx) >= 0) ? (width + dx) : 0; 1738 else 1739 event_top->data.resize.width = width; 1740 1741 if (pointer->grab_flags & GF_RESIZE_Y) 1742 event_top->data.resize.height = 1743 ((((int) height) + dy) >= 0) ? (height + dy) : 0; 1744 else 1745 event_top->data.resize.height = height; 1746 1747 event_top->data.resize.placement_flags = 1748 WINDOW_PLACEMENT_ANY; 1681 1749 } 1682 1750 … … 1746 1814 key == KC_O || key == KC_P); 1747 1815 bool kconsole_switch = (mods & KM_ALT) && (key == KC_M); 1748 bool compositor_test = (mods & KM_ALT) && (key == KC_H);1749 1816 1750 1817 bool filter = (type == KEY_RELEASE) && (win_transform || win_resize || 1751 1818 win_opacity || win_close || win_switch || viewport_move || 1752 viewport_change || kconsole_switch || compositor_test);1819 viewport_change || kconsole_switch); 1753 1820 1754 1821 if (filter) { … … 1772 1839 break; 1773 1840 case KC_Q: 1774 win->angle += (PI / 2);1841 win->angle += 0.1; 1775 1842 break; 1776 1843 case KC_E: 1777 win->angle += -(PI / 2);1844 win->angle -= 0.1; 1778 1845 break; 1779 1846 case KC_R: … … 1816 1883 return ENOMEM; 1817 1884 } 1818 1885 1819 1886 sysarg_t width, height; 1820 1887 surface_get_resolution(win->surface, &width, &height); 1821 1888 1822 1889 link_initialize(&event->link); 1823 1890 event->type = ET_WINDOW_RESIZE; 1824 1891 1892 event->data.resize.offset_x = 0; 1893 event->data.resize.offset_y = 0; 1894 1825 1895 switch (key) { 1826 1896 case KC_T: 1827 event->data.r sz.width = width;1828 event->data.r sz.height = (height >= 20) ? height - 20 : 0;1897 event->data.resize.width = width; 1898 event->data.resize.height = (height >= 20) ? height - 20 : 0; 1829 1899 break; 1830 1900 case KC_G: 1831 event->data.r sz.width = width;1832 event->data.r sz.height = height + 20;1901 event->data.resize.width = width; 1902 event->data.resize.height = height + 20; 1833 1903 break; 1834 1904 case KC_B: 1835 event->data.r sz.width = (width >= 20) ? width - 20 : 0;;1836 event->data.r sz.height = height;1905 event->data.resize.width = (width >= 20) ? width - 20 : 0;; 1906 event->data.resize.height = height; 1837 1907 break; 1838 1908 case KC_N: 1839 event->data.r sz.width = width + 20;1840 event->data.r sz.height = height;1909 event->data.resize.width = width + 20; 1910 event->data.resize.height = height; 1841 1911 break; 1842 1912 default: 1843 event->data.rsz.width = 0; 1844 event->data.rsz.height = 0; 1845 break; 1846 } 1847 1913 event->data.resize.width = 0; 1914 event->data.resize.height = 0; 1915 break; 1916 } 1917 1918 event->data.resize.placement_flags = WINDOW_PLACEMENT_ANY; 1919 1848 1920 fibril_mutex_unlock(&window_list_mtx); 1849 1921 comp_post_event_top(event); … … 2014 2086 } else if (kconsole_switch) { 2015 2087 __SYSCALL0(SYS_DEBUG_ACTIVATE_CONSOLE); 2016 } else if (compositor_test) {2017 fibril_mutex_lock(&window_list_mtx);2018 2019 window_t *red_win = window_create(0, 0);2020 red_win->surface = surface_create(250, 150, NULL, 0);2021 pixel_t red_pix = PIXEL(255, 240, 0, 0);2022 for (sysarg_t y = 0; y < 150; ++y) {2023 for (sysarg_t x = 0; x < 250; ++x) {2024 surface_put_pixel(red_win->surface, x, y, red_pix);2025 }2026 }2027 list_prepend(&red_win->link, &window_list);2028 2029 window_t *blue_win = window_create(0, 0);2030 blue_win->surface = surface_create(200, 100, NULL, 0);2031 pixel_t blue_pix = PIXEL(255, 0, 0, 240);2032 for (sysarg_t y = 0; y < 100; ++y) {2033 for (sysarg_t x = 0; x < 200; ++x) {2034 surface_put_pixel(blue_win->surface, x, y, blue_pix);2035 }2036 }2037 list_prepend(&blue_win->link, &window_list);2038 2039 window_t *nameic_win = window_create(0, 0);2040 nameic_win->surface = decode_tga((void *) nameic_tga, nameic_tga_size, 0);2041 list_prepend(&nameic_win->link, &window_list);2042 2043 fibril_mutex_unlock(&window_list_mtx);2044 comp_damage(0, 0, UINT32_MAX, UINT32_MAX);2045 2088 } else { 2046 2089 window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
Note:
See TracChangeset
for help on using the changeset viewer.