1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936
|
/*
Copyright (C) 2009-2010 Samsung Electronics
Copyright (C) 2009-2010 ProFUSION embedded systems
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "ewk_private.h"
#include "ewk_tiled_backing_store_private.h"
#include "ewk_tiled_matrix_private.h"
#include "ewk_tiled_model_private.h"
#include <Ecore.h>
#include <Eina.h>
#include <algorithm>
#include <errno.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
typedef struct _Ewk_Tiled_Backing_Store_Data Ewk_Tiled_Backing_Store_Data;
typedef struct _Ewk_Tiled_Backing_Store_Item Ewk_Tiled_Backing_Store_Item;
typedef struct _Ewk_Tiled_Backing_Store_Pre_Render_Request Ewk_Tiled_Backing_Store_Pre_Render_Request;
struct _Ewk_Tiled_Backing_Store_Item {
EINA_INLIST;
Ewk_Tile* tile;
Evas_Coord_Rectangle geometry;
bool smoothScale;
};
struct _Ewk_Tiled_Backing_Store_Pre_Render_Request {
EINA_INLIST;
unsigned long column, row;
float zoom;
};
struct _Ewk_Tiled_Backing_Store_Data {
Evas_Object_Smart_Clipped_Data base;
Evas_Object* self;
Evas_Object* contentsClipper;
struct {
Eina_Inlist** items;
Evas_Coord x, y, width, height;
unsigned long columns, rows;
struct {
Evas_Coord width, height;
float zoom;
bool zoomWeakSmoothScale : 1;
bool hasAlpha : 1;
} tile;
struct {
struct {
Evas_Coord x, y;
} current, old, base, zoomCenter;
} offset;
bool visible : 1;
} view;
Evas_Colorspace colorSpace;
struct {
Ewk_Tile_Matrix* matrix;
struct {
unsigned long column, row;
} base;
struct {
unsigned long columns, rows;
} current, old;
Evas_Coord width, height;
} model;
struct {
bool (*callback)(void* data, Ewk_Tile* tile, const Eina_Rectangle* area);
void* data;
Eina_Inlist* preRenderRequests;
Ecore_Idler* idler;
bool disabled;
bool suspend : 1;
} render;
struct {
void* (*preCallback)(void* data, Evas_Object* ewkBackingStore);
void* preData;
void* (*postCallback)(void* data, void* preData, Evas_Object* ewkBackingStore);
void* postData;
} process;
struct {
bool any : 1;
bool position : 1;
bool size : 1;
bool model : 1;
bool offset : 1;
bool contentsSize : 1;
} changed;
#ifdef DEBUG_MEM_LEAKS
Ecore_Event_Handler* signalUser;
#endif
};
static Evas_Smart_Class _parent_sc = EVAS_SMART_CLASS_INIT_NULL;
#define PRIV_DATA_GET_OR_RETURN(obj, ptr, ...) \
Ewk_Tiled_Backing_Store_Data* ptr = static_cast<Ewk_Tiled_Backing_Store_Data*>(evas_object_smart_data_get(obj)); \
if (!ptr) { \
CRITICAL("no private data in obj=%p", obj); \
return __VA_ARGS__; \
}
static void _ewk_tiled_backing_store_fill_renderers(Ewk_Tiled_Backing_Store_Data* priv);
static inline void _ewk_tiled_backing_store_changed(Ewk_Tiled_Backing_Store_Data* priv);
#ifdef DEBUG_MEM_LEAKS
static inline void _ewk_tiled_backing_store_view_dbg(const Ewk_Tiled_Backing_Store_Data* priv);
#endif
static inline void _ewk_tiled_backing_store_updates_process(Ewk_Tiled_Backing_Store_Data* priv)
{
/* Do not process updates. Note that we still want to get updates requests
* in the queue in order to not miss any updates after the render is
* resumed.
*/
if (priv->render.suspend || !priv->view.visible)
return;
void* data = priv->process.preCallback ? priv->process.preCallback(priv->process.preData, priv->self) : 0;
ewk_tile_matrix_updates_process(priv->model.matrix);
if (priv->process.postCallback)
priv->process.postCallback(priv->process.postData, data, priv->self);
}
static void _ewk_tiled_backing_store_flush(void* data)
{
Ewk_Tiled_Backing_Store_Data* priv = static_cast<Ewk_Tiled_Backing_Store_Data*>(data);
Ewk_Tile_Unused_Cache* tiledUnusedCache = ewk_tile_matrix_unused_cache_get(priv->model.matrix);
if (tiledUnusedCache) {
DBG("flush unused tile cache.");
ewk_tile_unused_cache_auto_flush(tiledUnusedCache);
} else
ERR("no cache?!");
}
static Ewk_Tile* _ewk_tiled_backing_store_tile_new(Ewk_Tiled_Backing_Store_Data* priv, unsigned long column, unsigned long row, float zoom)
{
Evas* evas = evas_object_evas_get(priv->self);
if (!evas) {
CRITICAL("evas_object_evas_get failed!");
return 0;
}
Ewk_Tile* tile = ewk_tile_matrix_tile_new(priv->model.matrix, evas, column, row, zoom);
if (!tile) {
CRITICAL("ewk_tile_matrix_tile_new failed!");
return 0;
}
return tile;
}
static void _ewk_tiled_backing_store_item_move(Ewk_Tiled_Backing_Store_Item* item, Evas_Coord x, Evas_Coord y)
{
item->geometry.x = x;
item->geometry.y = y;
if (item->tile)
evas_object_move(item->tile->image, x, y);
}
static void _ewk_tiled_backing_store_item_resize(Ewk_Tiled_Backing_Store_Item* item, Evas_Coord width, Evas_Coord height)
{
item->geometry.w = width;
item->geometry.h = height;
if (!item->tile)
return;
evas_object_resize(item->tile->image, width, height);
evas_object_image_fill_set(item->tile->image, 0, 0, width, height);
}
static void _ewk_tiled_backing_store_tile_associate(Ewk_Tiled_Backing_Store_Data* priv, Ewk_Tile* tile, Ewk_Tiled_Backing_Store_Item* item)
{
if (item->tile)
CRITICAL("item->tile=%p, but it should be 0!", item->tile);
item->tile = tile;
evas_object_move(item->tile->image, item->geometry.x, item->geometry.y);
evas_object_resize(item->tile->image, item->geometry.w, item->geometry.h);
evas_object_image_fill_set(item->tile->image, 0, 0, item->geometry.w, item->geometry.h);
evas_object_image_smooth_scale_set(item->tile->image, item->smoothScale);
evas_object_image_alpha_set(item->tile->image, priv->view.tile.hasAlpha);
if (!ewk_tile_visible_get(tile))
evas_object_smart_member_add(tile->image, priv->self);
ewk_tile_show(tile);
}
static void _ewk_tiled_backing_store_tile_dissociate(Ewk_Tiled_Backing_Store_Data* priv, Ewk_Tiled_Backing_Store_Item* item, double lastUsed)
{
ewk_tile_hide(item->tile);
if (!ewk_tile_visible_get(item->tile))
evas_object_smart_member_del(item->tile->image);
ewk_tile_matrix_tile_put(priv->model.matrix, item->tile, lastUsed);
Ewk_Tile_Unused_Cache* tileUnusedCache = ewk_tile_matrix_unused_cache_get(priv->model.matrix);
ewk_tile_unused_cache_auto_flush(tileUnusedCache);
item->tile = 0;
}
static void _ewk_tiled_backing_store_tile_dissociate_all(Ewk_Tiled_Backing_Store_Data* priv)
{
double last_used = ecore_loop_time_get();
for (unsigned long i = 0; i < priv->view.rows; ++i) {
Ewk_Tiled_Backing_Store_Item* item;
Eina_Inlist* list = priv->view.items[i];
EINA_INLIST_FOREACH(list, item) {
if (item->tile)
_ewk_tiled_backing_store_tile_dissociate(priv, item, last_used);
}
}
}
static inline bool _ewk_tiled_backing_store_pre_render_request_add(Ewk_Tiled_Backing_Store_Data* priv, unsigned long column, unsigned long row, float zoom)
{
Ewk_Tiled_Backing_Store_Pre_Render_Request* request = new Ewk_Tiled_Backing_Store_Pre_Render_Request;
priv->render.preRenderRequests = eina_inlist_append(priv->render.preRenderRequests, EINA_INLIST_GET(request));
request->column = column;
request->row = row;
request->zoom = zoom;
return true;
}
static inline void _ewk_tiled_backing_store_pre_render_request_del(Ewk_Tiled_Backing_Store_Data* priv, Ewk_Tiled_Backing_Store_Pre_Render_Request* request)
{
priv->render.preRenderRequests = eina_inlist_remove(priv->render.preRenderRequests, EINA_INLIST_GET(request));
delete request;
}
static inline Ewk_Tiled_Backing_Store_Pre_Render_Request* _ewk_tiled_backing_store_pre_render_request_first(const Ewk_Tiled_Backing_Store_Data* priv)
{
return EINA_INLIST_CONTAINER_GET(priv->render.preRenderRequests, Ewk_Tiled_Backing_Store_Pre_Render_Request);
}
static void _ewk_tiled_backing_store_pre_render_request_flush(Ewk_Tiled_Backing_Store_Data* priv)
{
Eina_Inlist** preRenderList = &priv->render.preRenderRequests;
while (*preRenderList) {
Ewk_Tiled_Backing_Store_Pre_Render_Request* request;
request = _ewk_tiled_backing_store_pre_render_request_first(priv);
*preRenderList = eina_inlist_remove(*preRenderList, *preRenderList);
delete request;
}
}
static void _ewk_tiled_backing_store_pre_render_request_clear(Ewk_Tiled_Backing_Store_Data* priv)
{
Eina_Inlist** preRenderList = &priv->render.preRenderRequests;
Eina_Inlist* iter = *preRenderList;
while (iter) {
Ewk_Tiled_Backing_Store_Pre_Render_Request* request = EINA_INLIST_CONTAINER_GET(iter, Ewk_Tiled_Backing_Store_Pre_Render_Request);
Eina_Inlist* next = iter->next;
*preRenderList = eina_inlist_remove(*preRenderList, iter);
iter = next;
delete request;
}
}
/* assumes priv->process.preCallback was called if required! */
static void _ewk_tiled_backing_store_pre_render_request_process_single(Ewk_Tiled_Backing_Store_Data* priv)
{
Ewk_Tile_Matrix* tileMatrix = priv->model.matrix;
double last_used = ecore_loop_time_get();
Ewk_Tiled_Backing_Store_Pre_Render_Request* request = _ewk_tiled_backing_store_pre_render_request_first(priv);
if (!request)
return;
unsigned long column = request->column;
unsigned long row = request->row;
float zoom = request->zoom;
if (ewk_tile_matrix_tile_exact_exists(tileMatrix, column, row, zoom)) {
DBG("no pre-render required for tile %lu,%lu @ %f.", column, row, zoom);
_ewk_tiled_backing_store_pre_render_request_del(priv, request);
ewk_tile_unused_cache_auto_flush(ewk_tile_matrix_unused_cache_get(priv->model.matrix));
return;
}
Ewk_Tile* tile = _ewk_tiled_backing_store_tile_new(priv, column, row, zoom);
if (!tile) {
_ewk_tiled_backing_store_pre_render_request_del(priv, request);
ewk_tile_unused_cache_auto_flush(ewk_tile_matrix_unused_cache_get(priv->model.matrix));
return;
}
Eina_Rectangle area;
EINA_RECTANGLE_SET(&area, 0, 0, priv->view.tile.width, priv->view.tile.height);
priv->render.callback(priv->render.data, tile, &area);
evas_object_image_data_update_add(tile->image, area.x, area.y, area.w, area.h);
ewk_tile_matrix_tile_updates_clear(tileMatrix, tile);
ewk_tile_matrix_tile_put(tileMatrix, tile, last_used);
}
static Eina_Bool _ewk_tiled_backing_store_item_process_idler_cb(void* data)
{
Ewk_Tiled_Backing_Store_Data* priv = static_cast<Ewk_Tiled_Backing_Store_Data*>(data);
if (priv->process.preCallback)
data = priv->process.preCallback(priv->process.preData, priv->self);
_ewk_tiled_backing_store_pre_render_request_process_single(priv);
if (priv->process.postCallback)
priv->process.postCallback(priv->process.postData, data, priv->self);
if (!priv->render.preRenderRequests) {
priv->render.idler = 0;
return false;
}
return true;
}
static inline void _ewk_tiled_backing_store_item_process_idler_stop(Ewk_Tiled_Backing_Store_Data* priv)
{
if (!priv->render.idler)
return;
ecore_idler_del(priv->render.idler);
priv->render.idler = 0;
}
static inline void _ewk_tiled_backing_store_item_process_idler_start(Ewk_Tiled_Backing_Store_Data* priv)
{
if (priv->render.idler || !priv->view.visible)
return;
priv->render.idler = ecore_idler_add(_ewk_tiled_backing_store_item_process_idler_cb, priv);
}
static bool _ewk_tiled_backing_store_disable_render(Ewk_Tiled_Backing_Store_Data* priv)
{
if (priv->render.suspend)
return true;
priv->render.suspend = true;
_ewk_tiled_backing_store_item_process_idler_stop(priv);
return true;
}
static bool _ewk_tiled_backing_store_enable_render(Ewk_Tiled_Backing_Store_Data* priv)
{
if (!priv->render.suspend)
return true;
priv->render.suspend = false;
_ewk_tiled_backing_store_fill_renderers(priv);
_ewk_tiled_backing_store_item_process_idler_start(priv);
return true;
}
static inline bool _ewk_tiled_backing_store_item_fill(Ewk_Tiled_Backing_Store_Data* priv, Ewk_Tiled_Backing_Store_Item* item, unsigned long column, unsigned long row)
{
if (!priv->view.visible)
return false;
unsigned long currentColumn = priv->model.base.column + column;
unsigned long currentRow = priv->model.base.row + row;
double lastUsed = ecore_loop_time_get();
if (currentColumn >= priv->model.current.columns || currentRow >= priv->model.current.rows) {
if (item->tile)
_ewk_tiled_backing_store_tile_dissociate(priv, item, lastUsed);
} else {
const float zoom = priv->view.tile.zoom;
if (item->tile) {
Ewk_Tile* old = item->tile;
if (old->row != currentRow || old->column != currentColumn || old->zoom != zoom)
_ewk_tiled_backing_store_tile_dissociate(priv, item, lastUsed);
else if (old->row == currentRow && old->column == currentColumn && old->zoom == zoom)
return true;
}
Ewk_Tile* tile = ewk_tile_matrix_tile_exact_get(priv->model.matrix, currentColumn, currentRow, zoom);
if (!tile) {
/* NOTE: it never returns 0 if item->tile was set! */
if (item->tile) {
CRITICAL("item->tile=%p, but it should be 0!", item->tile);
_ewk_tiled_backing_store_tile_dissociate(priv, item,
lastUsed);
}
/* Do not add new requests to the render queue */
if (!priv->render.suspend) {
tile = _ewk_tiled_backing_store_tile_new(priv, currentColumn, currentRow, zoom);
if (!tile)
return false;
_ewk_tiled_backing_store_tile_associate(priv, tile, item);
}
} else if (tile != item->tile) {
if (item->tile)
_ewk_tiled_backing_store_tile_dissociate(priv,
item, lastUsed);
_ewk_tiled_backing_store_tile_associate(priv, tile, item);
}
}
return true;
}
static Ewk_Tiled_Backing_Store_Item* _ewk_tiled_backing_store_item_add(Ewk_Tiled_Backing_Store_Data* priv, unsigned long column, unsigned long row)
{
DBG("ewkBackingStore=%p", priv->self);
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
Evas_Coord x = priv->view.offset.base.x + priv->view.x + tileWidth * column;
Evas_Coord y = priv->view.offset.base.y + priv->view.y + tileHeight * row;
OwnPtr<Ewk_Tiled_Backing_Store_Item> item = adoptPtr(new Ewk_Tiled_Backing_Store_Item);
item->tile = 0;
item->smoothScale = priv->view.tile.zoomWeakSmoothScale;
_ewk_tiled_backing_store_item_move(item.get(), x, y);
_ewk_tiled_backing_store_item_resize(item.get(), tileWidth, tileHeight);
if (!_ewk_tiled_backing_store_item_fill(priv, item.get(), column, row))
return 0;
return item.leakPtr();
}
static void _ewk_tiled_backing_store_item_del(Ewk_Tiled_Backing_Store_Data* priv, Ewk_Tiled_Backing_Store_Item* item)
{
if (item->tile) {
double last_used = ecore_loop_time_get();
_ewk_tiled_backing_store_tile_dissociate(priv, item, last_used);
}
delete item;
}
static void _ewk_tiled_backing_store_item_smooth_scale_set(Ewk_Tiled_Backing_Store_Item* item, bool smoothScale)
{
if (item->smoothScale == smoothScale)
return;
if (item->tile)
evas_object_image_smooth_scale_set(item->tile->image, smoothScale);
}
static inline void _ewk_tiled_backing_store_changed(Ewk_Tiled_Backing_Store_Data* priv)
{
if (priv->changed.any)
return;
evas_object_smart_changed(priv->self);
priv->changed.any = true;
}
static void _ewk_tiled_backing_store_view_cols_end_del(Ewk_Tiled_Backing_Store_Data* priv, Eina_Inlist** rowList, unsigned long count)
{
if (!count)
return;
Eina_Inlist* nextItem = (*rowList)->last;
for (unsigned long i = 0; i < count; ++i) {
Ewk_Tiled_Backing_Store_Item* item;
item = EINA_INLIST_CONTAINER_GET(nextItem, Ewk_Tiled_Backing_Store_Item);
nextItem = nextItem->prev;
*rowList = eina_inlist_remove(*rowList, EINA_INLIST_GET(item));
_ewk_tiled_backing_store_item_del(priv, item);
}
}
static bool _ewk_tiled_backing_store_view_cols_end_add(Ewk_Tiled_Backing_Store_Data* priv, Eina_Inlist** rowList, unsigned long baseColumn, unsigned long count)
{
const unsigned long row = rowList - priv->view.items;
for (unsigned long i = 0; i < count; ++i, ++baseColumn) {
Ewk_Tiled_Backing_Store_Item* item = _ewk_tiled_backing_store_item_add(priv, baseColumn, row);
if (!item) {
CRITICAL("failed to add column %lu of %lu in row %lu.", i, count, row);
_ewk_tiled_backing_store_view_cols_end_del(priv, rowList, i);
return false;
}
*rowList = eina_inlist_append(*rowList, EINA_INLIST_GET(item));
}
return true;
}
static void _ewk_tiled_backing_store_view_row_del(Ewk_Tiled_Backing_Store_Data* priv, Eina_Inlist* row)
{
while (row) {
Ewk_Tiled_Backing_Store_Item* item = EINA_INLIST_CONTAINER_GET(row, Ewk_Tiled_Backing_Store_Item);
row = row->next;
_ewk_tiled_backing_store_item_del(priv, item);
}
}
static void _ewk_tiled_backing_store_view_rows_range_del(Ewk_Tiled_Backing_Store_Data* priv, Eina_Inlist** start, Eina_Inlist** end)
{
for (; start < end; ++start) {
_ewk_tiled_backing_store_view_row_del(priv, *start);
*start = 0;
}
}
static void _ewk_tiled_backing_store_view_rows_all_del(Ewk_Tiled_Backing_Store_Data* priv)
{
Eina_Inlist** start = priv->view.items;
Eina_Inlist** end = priv->view.items + priv->view.rows;
_ewk_tiled_backing_store_view_rows_range_del(priv, start, end);
free(priv->view.items);
priv->view.items = 0;
priv->view.columns = 0;
priv->view.rows = 0;
}
static void _ewk_tiled_backing_store_render(void* data, Ewk_Tile* tile, const Eina_Rectangle* area)
{
Ewk_Tiled_Backing_Store_Data* priv = static_cast<Ewk_Tiled_Backing_Store_Data*>(data);
INFO("TODO %p (visible? %d) [%lu,%lu] %d,%d + %dx%d",
tile, tile->visible, tile->column, tile->row, area->x, area->y, area->w, area->h);
if (!tile->visible)
return;
if (priv->view.tile.width != tile->width || priv->view.tile.height != tile->height)
return; // todo: remove me later, don't even flag as dirty!
EINA_SAFETY_ON_NULL_RETURN(priv->render.callback);
if (!priv->render.callback(priv->render.data, tile, area))
return;
evas_object_image_data_update_add(tile->image, area->x, area->y, area->w, area->h);
}
static inline void _ewk_tiled_backing_store_model_matrix_create(Ewk_Tiled_Backing_Store_Data* priv, Ewk_Tile_Unused_Cache* tileUnusedCache)
{
if (priv->model.matrix) {
_ewk_tiled_backing_store_view_rows_all_del(priv);
priv->changed.offset = false;
priv->changed.size = true;
ewk_tile_matrix_free(priv->model.matrix);
}
priv->model.matrix = ewk_tile_matrix_new(tileUnusedCache, priv->model.current.columns, priv->model.current.rows, priv->view.tile.zoom, priv->colorSpace, _ewk_tiled_backing_store_render, priv);
}
static void _ewk_tiled_backing_store_smart_member_del(Evas_Object* ewkBackingStore, Evas_Object* member)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
if (!priv->contentsClipper)
return;
evas_object_clip_unset(member);
if (!evas_object_clipees_get(priv->contentsClipper))
evas_object_hide(priv->contentsClipper);
}
static void _ewk_tiled_backing_store_smart_member_add(Evas_Object* ewkBackingStore, Evas_Object* member)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
if (!priv->contentsClipper)
return;
evas_object_clip_set(member, priv->contentsClipper);
if (priv->view.visible)
evas_object_show(priv->contentsClipper);
}
#ifdef DEBUG_MEM_LEAKS
static void _ewk_tiled_backing_store_mem_dbg(Ewk_Tiled_Backing_Store_Data* priv)
{
static unsigned run = 0;
++run;
printf("\n--- BEGIN DEBUG TILED BACKING STORE MEMORY [%d] --\n"
"tile=%0.2f, obj=%p, priv=%p, view.items=%p, matrix=%p\n",
run, ecore_loop_time_get(),
priv->self, priv, priv->view.items, priv->model.matrix);
ewk_tile_matrix_dbg(priv->model.matrix);
ewk_tile_accounting_dbg();
printf("--- END DEBUG TILED BACKING STORE MEMORY [%d] --\n\n", run);
}
static bool _ewk_tiled_backing_store_sig_usr(void* data, int type, void* event)
{
Ecore_Event_Signal_User* signalUser = static_cast<Ecore_Event_Signal_User*>(event);
Ewk_Tiled_Backing_Store_Data* priv = static_cast<Ewk_Tiled_Backing_Store_Data*>(data);
if (signalUser->number == 2) {
Ewk_Tile_Unused_Cache* tileUnusedCache = ewk_tile_matrix_unused_cache_get(priv->model.matrix);
ewk_tile_unused_cache_auto_flush(tileUnusedCache);
}
_ewk_tiled_backing_store_view_dbg(priv);
_ewk_tiled_backing_store_mem_dbg(priv);
return true;
}
#endif
static void _ewk_tiled_backing_store_smart_add(Evas_Object* ewkBackingStore)
{
DBG("ewkBackingStore=%p", ewkBackingStore);
Ewk_Tiled_Backing_Store_Data* priv = static_cast<Ewk_Tiled_Backing_Store_Data*>(calloc(1, sizeof(*priv)));
if (!priv)
return;
priv->self = ewkBackingStore;
priv->view.tile.zoom = 1.0;
priv->view.tile.width = defaultTileWidth;
priv->view.tile.height = defaultTileHeigth;
priv->view.offset.current.x = 0;
priv->view.offset.current.y = 0;
priv->view.offset.old.x = 0;
priv->view.offset.old.y = 0;
priv->view.offset.base.x = 0;
priv->view.offset.base.y = 0;
priv->model.base.column = 0;
priv->model.base.row = 0;
priv->model.current.columns = 1;
priv->model.current.rows = 1;
priv->model.old.columns = 0;
priv->model.old.rows = 0;
priv->model.width = 0;
priv->model.height = 0;
priv->render.suspend = false;
priv->colorSpace = EVAS_COLORSPACE_ARGB8888; // TODO: detect it.
evas_object_smart_data_set(ewkBackingStore, priv);
_parent_sc.add(ewkBackingStore);
priv->contentsClipper = evas_object_rectangle_add(
evas_object_evas_get(ewkBackingStore));
evas_object_move(priv->contentsClipper, 0, 0);
evas_object_resize(priv->contentsClipper,
priv->model.width, priv->model.height);
evas_object_color_set(priv->contentsClipper, 255, 255, 255, 255);
evas_object_show(priv->contentsClipper);
evas_object_smart_member_add(priv->contentsClipper, ewkBackingStore);
_ewk_tiled_backing_store_model_matrix_create(priv, 0);
evas_object_move(priv->base.clipper, 0, 0);
evas_object_resize(priv->base.clipper, 0, 0);
evas_object_clip_set(priv->contentsClipper, priv->base.clipper);
#ifdef DEBUG_MEM_LEAKS
priv->signalUser = ecore_event_handler_add
(ECORE_EVENT_SIGNAL_USER, _ewk_tiled_backing_store_sig_usr, priv);
#endif
}
static void _ewk_tiled_backing_store_smart_del(Evas_Object* ewkBackingStore)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
DBG("ewkBackingStore=%p", ewkBackingStore);
Ewk_Tile_Unused_Cache* tileUnusedCache = ewk_tile_matrix_unused_cache_get(priv->model.matrix);
ewk_tile_unused_cache_unlock_area(tileUnusedCache);
_ewk_tiled_backing_store_flush(priv);
_ewk_tiled_backing_store_pre_render_request_flush(priv);
_ewk_tiled_backing_store_item_process_idler_stop(priv);
_ewk_tiled_backing_store_view_rows_all_del(priv);
#ifdef DEBUG_MEM_LEAKS
_ewk_tiled_backing_store_mem_dbg(priv);
if (priv->sig_usr)
ecore_event_handler_del(priv->sig_usr);
#endif
ewk_tile_matrix_free(priv->model.matrix);
evas_object_smart_member_del(priv->contentsClipper);
evas_object_del(priv->contentsClipper);
_parent_sc.del(ewkBackingStore);
#ifdef DEBUG_MEM_LEAKS
printf("\nIMPORTANT: TILED BACKING STORE DELETED (may be real leaks)\n");
ewk_tile_accounting_dbg();
#endif
}
static void _ewk_tiled_backing_store_smart_move(Evas_Object* ewkBackingStore, Evas_Coord x, Evas_Coord y)
{
DBG("ewkBackingStore=%p, new pos: %dx%d", ewkBackingStore, x, y);
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
if (priv->changed.position)
return;
if (priv->view.x == x && priv->view.y == y)
return;
priv->changed.position = true;
_ewk_tiled_backing_store_changed(priv);
}
static void _ewk_tiled_backing_store_smart_resize(Evas_Object* ewkBackingStore, Evas_Coord width, Evas_Coord height)
{
DBG("ewkBackingStore=%p, new size: %dx%d", ewkBackingStore, width, height);
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
if (priv->changed.size)
return;
if (priv->view.width == width && priv->view.height == height)
return;
priv->changed.size = true;
_ewk_tiled_backing_store_changed(priv);
}
static void _ewk_tiled_backing_store_smart_show(Evas_Object* ewkBackingStore)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
priv->view.visible = true;
ewk_tiled_backing_store_enable_render(ewkBackingStore);
_parent_sc.show(ewkBackingStore);
}
static void _ewk_tiled_backing_store_smart_hide(Evas_Object* ewkBackingStore)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
priv->view.visible = false;
ewk_tiled_backing_store_disable_render(ewkBackingStore);
_ewk_tiled_backing_store_tile_dissociate_all(priv);
_parent_sc.hide(ewkBackingStore);
}
static void _ewk_tiled_backing_store_recalc_renderers(Ewk_Tiled_Backing_Store_Data* priv, Evas_Coord width, Evas_Coord height, Evas_Coord tileWidth, Evas_Coord tileHeight)
{
INFO("ewkBackingStore=%p, new size: %dx%d", priv->self, width, height);
unsigned long columns = 1 + static_cast<unsigned long>(ceil(width / static_cast<float>(tileWidth)));
unsigned long rows = 1 + static_cast<unsigned long>(ceil(height / static_cast<float>(tileHeight)));
INFO("ewkBackingStore=%p new grid size columns: %lu, rows: %lu, was %lu, %lu", priv->self, columns, rows, priv->view.columns, priv->view.rows);
if (priv->view.columns == columns && priv->view.rows == rows)
return;
unsigned long oldCols = priv->view.columns;
unsigned long oldRows = priv->view.rows;
if (rows < oldRows) {
Eina_Inlist** start = priv->view.items + rows;
Eina_Inlist** end = priv->view.items + oldRows;
_ewk_tiled_backing_store_view_rows_range_del(priv, start, end);
}
void* newItems = realloc(priv->view.items, sizeof(Eina_Inlist*) * rows);
if (!newItems)
return;
priv->view.items = static_cast<Eina_Inlist**>(newItems);
priv->view.rows = rows;
priv->view.columns = columns;
if (rows > oldRows) {
Eina_Inlist** start = priv->view.items + oldRows;
Eina_Inlist** end = priv->view.items + rows;
for (; start < end; ++start) {
*start = 0;
bool result = _ewk_tiled_backing_store_view_cols_end_add(priv, start, 0, columns);
if (!result) {
CRITICAL("failed to allocate %ld columns", columns);
_ewk_tiled_backing_store_view_rows_range_del(priv, priv->view.items + oldRows, start);
priv->view.rows = oldRows;
return;
}
}
}
if (columns != oldCols) {
long todo = columns - oldCols;
Eina_Inlist** start = priv->view.items;
Eina_Inlist** end = start + std::min(oldRows, rows);
if (todo > 0) {
for (; start < end; ++start) {
bool result = _ewk_tiled_backing_store_view_cols_end_add(priv, start, oldCols, todo);
if (!result) {
CRITICAL("failed to allocate %ld columns!", todo);
for (start--; start >= priv->view.items; --start)
_ewk_tiled_backing_store_view_cols_end_del(priv, start, todo);
if (rows > oldRows) {
start = priv->view.items + oldRows;
end = priv->view.items + rows;
for (; start < end; start++)
_ewk_tiled_backing_store_view_cols_end_del(priv, start, todo);
}
return;
}
}
} else if (todo < 0) {
todo = -todo;
for (; start < end; ++start)
_ewk_tiled_backing_store_view_cols_end_del(priv, start, todo);
}
}
_ewk_tiled_backing_store_fill_renderers(priv);
}
static void _ewk_tiled_backing_store_smart_calculate_size(Ewk_Tiled_Backing_Store_Data* priv, Evas_Coord width, Evas_Coord height)
{
evas_object_resize(priv->base.clipper, width, height);
priv->view.width = width;
priv->view.height = height;
_ewk_tiled_backing_store_recalc_renderers(priv, width, height, priv->view.tile.width, priv->view.tile.height);
}
#ifdef DEBUG_MEM_LEAKS
// TODO: remove me later.
static inline void _ewk_tiled_backing_store_view_dbg(const Ewk_Tiled_Backing_Store_Data* priv)
{
printf("tiles=%2ld,%2ld model=%2ld,%2ld [%dx%d] base=%+3ld,%+4ld offset=%+4d,%+4d old=%+4d,%+4d base=%+3d,%+3d\n",
priv->view.columns, priv->view.rows,
priv->model.current.columns, priv->model.current.rows,
priv->model.width, priv->model.height,
priv->model.base.column, priv->model.base.row,
priv->view.offset.current.x, priv->view.offset.current.y,
priv->view.offset.old.x, priv->view.offset.old.y,
priv->view.offset.base.x, priv->view.offset.base.y);
Eina_Inlist** start = priv->view.items;
Eina_Inlist** end = priv->view.items + priv->view.rows;
for (; start < end; ++start) {
const Ewk_Tiled_Backing_Store_Item* item;
EINA_INLIST_FOREACH(*start, item) {
printf(" %+4d,%+4d ", item->geometry.x, item->geometry.y);
if (!item->tile)
printf(" ;");
else
printf("%8p %lu,%lu;", item->tile, item->tile->column, item->tile->row);
}
printf("\n");
}
printf("---\n");
}
#endif
/**
* @internal
* Move top row down as last.
*
* The final result is visually the same, but logically the top that
* went out of screen is now at bottom and filled with new model items.
*
* This is worth just when @a count is smaller than @c
* priv->view.rows, after that one is refilling the whole matrix so it
* is better to trigger full refill.
*
* @param count the number of times to repeat the process.
*/
static void _ewk_tiled_backing_store_view_wrap_up(Ewk_Tiled_Backing_Store_Data* priv, Evas_Coord x, Evas_Coord y, unsigned long count)
{
unsigned long lastRow = priv->view.rows - 1;
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
Evas_Coord offsetY = priv->view.offset.base.y + count * tileHeight;
Evas_Coord tilePositionY = y + (lastRow - count + 1) * tileHeight + offsetY;
Evas_Coord originX = x + priv->view.offset.base.x;
Eina_Inlist** start = priv->view.items;
Eina_Inlist** end = start + lastRow;
for (; count > 0; --count) {
Eina_Inlist** it;
Eina_Inlist* temp = *start;
for (it = start; it < end; ++it)
*it = *(it + 1);
*it = temp;
++priv->model.base.row;
Evas_Coord tilePositionX = originX;
unsigned long column = 0;
Ewk_Tiled_Backing_Store_Item* item;
EINA_INLIST_FOREACH(temp, item) {
_ewk_tiled_backing_store_item_move(item, tilePositionX, tilePositionY);
tilePositionX += tileWidth;
_ewk_tiled_backing_store_item_fill(priv, item, column, lastRow);
++column;
}
tilePositionY += tileHeight;
}
priv->view.offset.base.y = offsetY;
}
/**
* @internal
* Move bottom row up as first.
*
* The final result is visually the same, but logically the bottom that
* went out of screen is now at top and filled with new model items.
*
* This is worth just when @a count is smaller than @c
* priv->view.rows, after that one is refilling the whole matrix so it
* is better to trigger full refill.
*
* @param count the number of times to repeat the process.
*/
static void _ewk_tiled_backing_store_view_wrap_down(Ewk_Tiled_Backing_Store_Data* priv, Evas_Coord x, Evas_Coord y, unsigned long count)
{
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
Evas_Coord offsetY = priv->view.offset.base.y - count * tileHeight;
Evas_Coord tilePositionY = y + offsetY + (count - 1) * tileHeight;
Evas_Coord originX = x + priv->view.offset.base.x;
Eina_Inlist** start = priv->view.items + priv->view.rows - 1;
Eina_Inlist** end = priv->view.items;
for (; count > 0; --count) {
Eina_Inlist** it;
Eina_Inlist* temp = *start;
Evas_Coord tilePositionX = originX;
for (it = start; it > end; --it)
*it = *(it - 1);
*it = temp;
--priv->model.base.row;
unsigned long column = 0;
Ewk_Tiled_Backing_Store_Item* item;
EINA_INLIST_FOREACH(temp, item) {
_ewk_tiled_backing_store_item_move(item, tilePositionX, tilePositionY);
tilePositionX += tileWidth;
_ewk_tiled_backing_store_item_fill(priv, item, column, 0);
++column;
}
tilePositionY -= tileHeight;
}
priv->view.offset.base.y = offsetY;
}
/**
* @internal
* Move left-most (first) column right as last (right-most).
*
* The final result is visually the same, but logically the first column that
* went out of screen is now at last and filled with new model items.
*
* This is worth just when @a count is smaller than @c
* priv->view.columns, after that one is refilling the whole matrix so it
* is better to trigger full refill.
*
* @param count the number of times to repeat the process.
*/
static void _ewk_tiled_backing_store_view_wrap_left(Ewk_Tiled_Backing_Store_Data* priv, Evas_Coord x, Evas_Coord y, unsigned long count)
{
unsigned long lastColumn = priv->view.columns - 1;
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
Evas_Coord offsetX = priv->view.offset.base.x + count * tileWidth;
Evas_Coord offsetY = y + priv->view.offset.base.y;
unsigned long baseColumn = lastColumn - count + 1;
Evas_Coord originX = x + baseColumn * tileWidth + offsetX;
Eina_Inlist** it = priv->view.items;
Eina_Inlist** end = it + priv->view.rows;
priv->model.base.column += count;
for (unsigned long row = 0; it < end; ++it, ++row) {
Evas_Coord tilePositionX = originX;
unsigned long column = baseColumn;
for (unsigned long i = 0; i < count; ++i, ++column, tilePositionX += tileWidth) {
Ewk_Tiled_Backing_Store_Item* item = EINA_INLIST_CONTAINER_GET(*it, Ewk_Tiled_Backing_Store_Item);
*it = eina_inlist_demote(*it, *it);
_ewk_tiled_backing_store_item_move(item, tilePositionX, offsetY);
_ewk_tiled_backing_store_item_fill(priv, item, column, row);
}
offsetY += tileHeight;
}
priv->view.offset.base.x = offsetX;
}
/**
* @internal
* Move right-most (last) column left as first (left-most).
*
* The final result is visually the same, but logically the last column that
* went out of screen is now at first and filled with new model items.
*
* This is worth just when @a count is smaller than @c
* priv->view.columns, after that one is refilling the whole matrix so it
* is better to trigger full refill.
*
* @param count the number of times to repeat the process.
*/
static void _ewk_tiled_backing_store_view_wrap_right(Ewk_Tiled_Backing_Store_Data* priv, Evas_Coord x, Evas_Coord y, unsigned long count)
{
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
Evas_Coord offsetX = priv->view.offset.base.x - count * tileWidth;
Evas_Coord tilePositionY = y + priv->view.offset.base.y;
unsigned long baseColumn = count - 1;
Evas_Coord originX = x + baseColumn * tileWidth + offsetX;
Eina_Inlist** it = priv->view.items;
Eina_Inlist** end = it + priv->view.rows;
priv->model.base.column -= count;
for (unsigned long row = 0; it < end; ++it, ++row) {
Evas_Coord tilePositionX = originX;
unsigned long column = baseColumn;
for (unsigned long i = 0; i < count; ++i, --column, tilePositionX -= tileWidth) {
Ewk_Tiled_Backing_Store_Item* item = EINA_INLIST_CONTAINER_GET((*it)->last, Ewk_Tiled_Backing_Store_Item);
*it = eina_inlist_promote(*it, (*it)->last);
_ewk_tiled_backing_store_item_move(item, tilePositionX, tilePositionY);
_ewk_tiled_backing_store_item_fill(priv, item, column, row);
}
tilePositionY += tileHeight;
}
priv->view.offset.base.x = offsetX;
}
static void _ewk_tiled_backing_store_view_refill(Ewk_Tiled_Backing_Store_Data* priv, Evas_Coord x, Evas_Coord y, int stepX, int stepY)
{
evas_object_move(priv->base.clipper, x, y);
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
Evas_Coord baseTilePositionX = x + priv->view.offset.base.x;
Evas_Coord tilePositionY = y + priv->view.offset.base.y;
Eina_Inlist** it = priv->view.items;
Eina_Inlist** end = it + priv->view.rows;
priv->model.base.column -= stepX;
priv->model.base.row -= stepY;
for (unsigned long row = 0; it < end; ++it, ++row) {
Ewk_Tiled_Backing_Store_Item* item;
Evas_Coord newTilePositionX = baseTilePositionX;
unsigned long column = 0;
EINA_INLIST_FOREACH(*it, item) {
_ewk_tiled_backing_store_item_fill(priv, item, column, row);
_ewk_tiled_backing_store_item_move(item, newTilePositionX, tilePositionY);
++column;
newTilePositionX += tileWidth;
}
tilePositionY += tileHeight;
}
}
static void _ewk_tiled_backing_store_view_pos_apply(Ewk_Tiled_Backing_Store_Data* priv, Evas_Coord x, Evas_Coord y)
{
evas_object_move(priv->base.clipper, x, y);
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
Evas_Coord baseTilePositionX = x + priv->view.offset.base.x;
Evas_Coord baseTilePositionY = y + priv->view.offset.base.y;
Eina_Inlist** it = priv->view.items;
Eina_Inlist** end = it + priv->view.rows;
for (; it < end; ++it) {
Ewk_Tiled_Backing_Store_Item* item;
Evas_Coord offsetX = baseTilePositionX;
EINA_INLIST_FOREACH(*it, item) {
_ewk_tiled_backing_store_item_move(item, offsetX, baseTilePositionY);
offsetX += tileWidth;
}
baseTilePositionY += tileHeight;
}
}
static void _ewk_tiled_backing_store_smart_calculate_offset_force(Ewk_Tiled_Backing_Store_Data* priv)
{
Evas_Coord deltaX = priv->view.offset.current.x - priv->view.offset.old.x;
Evas_Coord deltaY = priv->view.offset.current.y - priv->view.offset.old.y;
INFO("ewkBackingStore=%p, offset: %+4d, %+4d (%+4d, %+4d)",
priv->self, deltaX, deltaY, priv->view.offset.current.x, priv->view.offset.current.y);
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
unsigned long newColumn = -priv->view.offset.current.x / tileWidth;
int stepX = priv->model.base.column - newColumn;
unsigned long newRow = -priv->view.offset.current.y / tileHeight;
int stepY = priv->model.base.row - newRow;
priv->view.offset.old.x = priv->view.offset.current.x;
priv->view.offset.old.y = priv->view.offset.current.y;
evas_object_move(priv->contentsClipper, priv->view.offset.current.x + priv->view.x, priv->view.offset.current.y + priv->view.y);
priv->view.offset.base.x += deltaX - stepX * tileWidth;
priv->view.offset.base.y += deltaY - stepY * tileHeight;
_ewk_tiled_backing_store_view_refill(priv, priv->view.x, priv->view.y, stepX, stepY);
}
static void _ewk_tiled_backing_store_smart_calculate_offset(Ewk_Tiled_Backing_Store_Data* priv, Evas_Coord x, Evas_Coord y)
{
Evas_Coord deltaX = priv->view.offset.current.x - priv->view.offset.old.x;
Evas_Coord deltaY = priv->view.offset.current.y - priv->view.offset.old.y;
INFO("ewkBackingStore=%p, offset: %+4d, %+4d (%+4d, %+4d)", priv->self, deltaX, deltaY, priv->view.offset.current.x, priv->view.offset.current.y);
if (!deltaX && !deltaY)
return;
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
long newCol = -priv->view.offset.current.x / tileWidth;
long stepX = priv->model.base.column - newCol;
long newRow = -priv->view.offset.current.y / tileHeight;
long stepY = priv->model.base.row - newRow;
priv->view.offset.old.x = priv->view.offset.current.x;
priv->view.offset.old.y = priv->view.offset.current.y;
evas_object_move(priv->contentsClipper, priv->view.offset.current.x + priv->view.x, priv->view.offset.current.y + priv->view.y);
if ((stepX < 0 && stepX <= -static_cast<long>(priv->view.columns))
|| (stepX > 0 && stepX >= static_cast<long>(priv->view.columns))
|| (stepY < 0 && stepY <= -static_cast<long>(priv->view.rows))
|| (stepY > 0 && stepY >= static_cast<long>(priv->view.rows))) {
priv->view.offset.base.x += deltaX - stepX * tileWidth;
priv->view.offset.base.y += deltaY - stepY * tileHeight;
_ewk_tiled_backing_store_view_refill(priv, priv->view.x, priv->view.y, stepX, stepY);
return;
}
priv->view.offset.base.x += deltaX;
priv->view.offset.base.y += deltaY;
if (stepY < 0)
_ewk_tiled_backing_store_view_wrap_up(priv, x, y, -stepY);
else if (stepY > 0)
_ewk_tiled_backing_store_view_wrap_down(priv, x, y, stepY);
if (stepX < 0)
_ewk_tiled_backing_store_view_wrap_left(priv, x, y, -stepX);
else if (stepX > 0)
_ewk_tiled_backing_store_view_wrap_right(priv, x, y, stepX);
_ewk_tiled_backing_store_view_pos_apply(priv, x, y);
}
static void _ewk_tiled_backing_store_smart_calculate_pos(Ewk_Tiled_Backing_Store_Data* priv, Evas_Coord x, Evas_Coord y)
{
_ewk_tiled_backing_store_view_pos_apply(priv, x, y);
priv->view.x = x;
priv->view.y = y;
evas_object_move(priv->contentsClipper, priv->view.offset.current.x + priv->view.x, priv->view.offset.current.y + priv->view.y);
}
static void _ewk_tiled_backing_store_fill_renderers(Ewk_Tiled_Backing_Store_Data* priv)
{
for (unsigned long i = 0; i < priv->view.rows; ++i) {
Eina_Inlist* list = priv->view.items[i];
unsigned long j = 0;
Ewk_Tiled_Backing_Store_Item* item;
EINA_INLIST_FOREACH(list, item)
_ewk_tiled_backing_store_item_fill(priv, item, j++, i);
}
}
static void _ewk_tiled_backing_store_smart_calculate(Evas_Object* ewkBackingStore)
{
Evas_Coord x, y, width, height;
evas_object_geometry_get(ewkBackingStore, &x, &y, &width, &height);
DBG("ewkBackingStore=%p at %d,%d + %dx%d", ewkBackingStore, x, y, width, height);
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
priv->changed.any = false;
ewk_tile_matrix_freeze(priv->model.matrix);
if (priv->changed.contentsSize)
ewk_tile_matrix_invalidate(priv->model.matrix);
if (!priv->render.suspend && (priv->changed.model || priv->changed.contentsSize)) {
unsigned long columns = priv->model.width / priv->view.tile.width + 1;
unsigned long rows = priv->model.height / priv->view.tile.height + 1;
priv->model.old.columns = priv->model.current.columns;
priv->model.old.rows = priv->model.current.rows;
priv->model.current.columns = columns;
priv->model.current.rows = rows;
if (priv->model.old.columns > columns)
columns = priv->model.old.columns;
if (priv->model.old.rows > rows)
rows = priv->model.old.rows;
ewk_tile_matrix_resize(priv->model.matrix, columns, rows);
}
if (priv->changed.position && (priv->view.x != x || priv->view.y != y)) {
_ewk_tiled_backing_store_smart_calculate_pos(priv, x, y);
priv->changed.position = false;
}
if (priv->changed.offset) {
_ewk_tiled_backing_store_smart_calculate_offset(priv, x, y);
priv->changed.offset = false;
}
if (priv->changed.size) {
_ewk_tiled_backing_store_smart_calculate_size(priv, width, height);
priv->changed.size = false;
}
if (!priv->render.suspend && (priv->changed.model || priv->changed.contentsSize)) {
_ewk_tiled_backing_store_fill_renderers(priv);
ewk_tile_matrix_resize(priv->model.matrix,
priv->model.current.columns,
priv->model.current.rows);
priv->changed.model = false;
evas_object_resize(priv->contentsClipper, priv->model.width, priv->model.height);
_ewk_tiled_backing_store_smart_calculate_offset_force(priv);
/* Make sure we do not miss any important repaint by
* repainting the whole viewport */
const Eina_Rectangle rect = { 0, 0, priv->model.width, priv->model.height };
ewk_tile_matrix_update(priv->model.matrix, &rect, priv->view.tile.zoom);
priv->changed.contentsSize = false;
}
ewk_tile_matrix_thaw(priv->model.matrix);
_ewk_tiled_backing_store_updates_process(priv);
if (priv->view.offset.base.x > 0
|| priv->view.offset.base.x <= - priv->view.tile.width
|| priv->view.offset.base.y > 0
|| priv->view.offset.base.y <= - priv->view.tile.height) {
ERR("incorrect base offset %+4d,%+4d, tile=%dx%d, current=%+4d,%+4d\n",
priv->view.offset.base.x, priv->view.offset.base.y,
priv->view.tile.width, priv->view.tile.height,
priv->view.offset.current.x, priv->view.offset.current.y);
}
}
Evas_Object* ewk_tiled_backing_store_add(Evas* canvas)
{
static Evas_Smart* smart = 0;
if (!smart) {
static Evas_Smart_Class sc =
EVAS_SMART_CLASS_INIT_NAME_VERSION("Ewk_Tiled_Backing_Store");
evas_object_smart_clipped_smart_set(&sc);
_parent_sc = sc;
sc.add = _ewk_tiled_backing_store_smart_add;
sc.del = _ewk_tiled_backing_store_smart_del;
sc.resize = _ewk_tiled_backing_store_smart_resize;
sc.move = _ewk_tiled_backing_store_smart_move;
sc.show = _ewk_tiled_backing_store_smart_show;
sc.hide = _ewk_tiled_backing_store_smart_hide;
sc.calculate = _ewk_tiled_backing_store_smart_calculate;
sc.member_add = _ewk_tiled_backing_store_smart_member_add;
sc.member_del = _ewk_tiled_backing_store_smart_member_del;
smart = evas_smart_class_new(&sc);
}
return evas_object_smart_add(canvas, smart);
}
void ewk_tiled_backing_store_render_cb_set(Evas_Object* ewkBackingStore, bool (*callback)(void* data, Ewk_Tile* tile, const Eina_Rectangle* area), const void* data)
{
EINA_SAFETY_ON_NULL_RETURN(callback);
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
priv->render.callback = callback;
priv->render.data = const_cast<void*>(data);
}
Ewk_Tile_Unused_Cache* ewk_tiled_backing_store_tile_unused_cache_get(const Evas_Object* ewkBackingStore)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, 0);
return ewk_tile_matrix_unused_cache_get(priv->model.matrix);
}
void ewk_tiled_backing_store_tile_unused_cache_set(Evas_Object* ewkBackingStore, Ewk_Tile_Unused_Cache* tileUnusedCache)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
if (ewk_tile_matrix_unused_cache_get(priv->model.matrix) == tileUnusedCache)
return;
_ewk_tiled_backing_store_model_matrix_create(priv, tileUnusedCache);
}
static bool _ewk_tiled_backing_store_scroll_full_offset_set_internal(Ewk_Tiled_Backing_Store_Data* priv, Evas_Coord x, Evas_Coord y)
{
/* TODO: check offset go out of bounds, clamp */
if (priv->render.disabled)
return false;
priv->view.offset.current.x = x;
priv->view.offset.current.y = y;
priv->changed.offset = true;
_ewk_tiled_backing_store_changed(priv);
return true;
}
bool ewk_tiled_backing_store_scroll_full_offset_set(Evas_Object* ewkBackingStore, Evas_Coord x, Evas_Coord y)
{
DBG("ewkBackingStore=%p, x=%d, y=%d", ewkBackingStore, x, y);
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, false);
if (x == priv->view.offset.current.x && y == priv->view.offset.current.y)
return true;
return _ewk_tiled_backing_store_scroll_full_offset_set_internal(priv, x, y);
}
bool ewk_tiled_backing_store_scroll_full_offset_add(Evas_Object* ewkBackingStore, Evas_Coord deltaX, Evas_Coord deltaY)
{
DBG("ewkBackingStore=%p, deltaX=%d, deltaY=%d", ewkBackingStore, deltaX, deltaY);
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, false);
if (!deltaX && !deltaY)
return true;
return _ewk_tiled_backing_store_scroll_full_offset_set_internal(priv, priv->view.offset.current.x + deltaX, priv->view.offset.current.y + deltaY);
}
static bool _ewk_tiled_backing_store_zoom_set_internal(Ewk_Tiled_Backing_Store_Data* priv, float* zoom, Evas_Coord currentX, Evas_Coord currentY, Evas_Coord* offsetX, Evas_Coord* offsetY)
{
*offsetX = priv->view.offset.current.x;
*offsetY = priv->view.offset.current.y;
if (fabsf(priv->view.tile.zoom - *zoom) < zoomStepMinimum) {
DBG("ignored as zoom difference is < %f: %f",
(double)zoomStepMinimum, fabsf(priv->view.tile.zoom - *zoom));
return true;
}
_ewk_tiled_backing_store_pre_render_request_flush(priv);
*zoom = ROUNDED_ZOOM(priv->view.tile.width, *zoom);
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
float scale = *zoom / priv->view.tile.zoom;
priv->view.tile.zoom = *zoom;
// todo: check currentX [0, w]...
priv->view.offset.zoomCenter.x = currentX;
priv->view.offset.zoomCenter.y = currentY;
unsigned long columns, rows;
ewk_tile_matrix_size_get(priv->model.matrix, &columns, &rows);
if (!ewk_tile_matrix_zoom_level_set(priv->model.matrix, *zoom))
ewk_tile_matrix_entry_new(priv->model.matrix, *zoom);
ewk_tile_matrix_resize(priv->model.matrix, columns, rows);
if (!priv->view.width || !priv->view.height) {
priv->view.offset.base.x = 0;
priv->view.offset.base.y = 0;
return true;
}
Evas_Coord newX = currentX + (priv->view.offset.current.x - currentX) * scale;
Evas_Coord newY = currentY + (priv->view.offset.current.y - currentY) * scale;
Evas_Coord modelWidth = priv->model.width * scale;
Evas_Coord modelHeight = priv->model.height * scale;
if (modelWidth < priv->view.width || newX >= 0)
newX = 0;
else if (-newX + priv->view.width >= modelWidth)
newX = -modelWidth + priv->view.width;
if (modelHeight < priv->view.height || newY >= 0)
newY = 0;
else if (-newY + priv->view.height >= modelHeight)
newY = -modelHeight + priv->view.height;
Evas_Coord baseX = newX % tileWidth;
Evas_Coord baseY = newY % tileHeight;
priv->model.base.column = -newX / tileWidth;
priv->model.base.row = -newY / tileHeight;
priv->changed.size = true;
priv->changed.model = true;
_ewk_tiled_backing_store_changed(priv);
priv->view.offset.current.x = newX;
priv->view.offset.current.y = newY;
priv->view.offset.base.x = baseX;
priv->view.offset.base.y = baseY;
priv->view.offset.old.x = priv->view.offset.current.x;
priv->view.offset.old.y = priv->view.offset.current.y;
*offsetX = priv->view.offset.current.x;
*offsetY = priv->view.offset.current.y;
evas_object_move(priv->contentsClipper, newX + priv->view.x, newY + priv->view.y);
_ewk_tiled_backing_store_fill_renderers(priv);
Evas_Coord tilePositionY = priv->view.offset.base.y + priv->view.y;
Evas_Coord baseTilePositionX = priv->view.x + priv->view.offset.base.x;
Eina_Inlist** it = priv->view.items;
Eina_Inlist** end = it + priv->view.rows;
for (; it < end; ++it) {
Evas_Coord tilePositionX = baseTilePositionX;
Eina_Inlist* lst = *it;
Ewk_Tiled_Backing_Store_Item* item;
EINA_INLIST_FOREACH(lst, item) {
_ewk_tiled_backing_store_item_move(item, tilePositionX, tilePositionY);
_ewk_tiled_backing_store_item_resize(item, tileWidth, tileHeight);
tilePositionX += tileWidth;
}
tilePositionY += tileHeight;
}
return true;
}
bool ewk_tiled_backing_store_zoom_set(Evas_Object* ewkBackingStore, float* zoom, Evas_Coord currentX, Evas_Coord currentY, Evas_Coord* offsetX, Evas_Coord* offsetY)
{
DBG("ewkBackingStore=%p, zoom=%f", ewkBackingStore, *zoom);
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, false);
return _ewk_tiled_backing_store_zoom_set_internal(priv, zoom, currentX, currentY, offsetX, offsetY);
}
bool ewk_tiled_backing_store_zoom_weak_set(Evas_Object* ewkBackingStore, float zoom, Evas_Coord currentX, Evas_Coord currentY)
{
DBG("ewkBackingStore=%p, zoom=%f", ewkBackingStore, zoom);
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, false);
if (!priv->view.width || !priv->view.height)
return false;
bool reCalculate = false;
float scale = zoom / priv->view.tile.zoom;
Evas_Coord tileWidth = TILE_SIZE_AT_ZOOM(priv->view.tile.width, scale);
scale = TILE_ZOOM_AT_SIZE(tileWidth, priv->view.tile.width);
Evas_Coord tileHeight = TILE_SIZE_AT_ZOOM(priv->view.tile.height, scale);
zoom = scale * priv->view.tile.zoom;
Evas_Coord modelWidth = priv->model.width * scale;
Evas_Coord modelHeight = priv->model.height * scale;
evas_object_resize(priv->contentsClipper, modelWidth, modelHeight);
unsigned long vrows = static_cast<unsigned long>(ceil(priv->view.height /static_cast<float>(tileHeight)) + 1);
unsigned long vcols = static_cast<unsigned long>(ceil(priv->view.width / static_cast<float>(tileWidth)) + 1);
Evas_Coord newX = currentX + (priv->view.offset.current.x - currentX) * scale;
Evas_Coord newY = currentY + (priv->view.offset.current.y - currentY) * scale;
Evas_Coord baseX = newX % tileWidth;
Evas_Coord baseY = newY % tileHeight;
unsigned long baseRow = -newY / tileHeight;
unsigned long baseColumn = -newX / tileWidth;
if (baseRow != priv->model.base.row || baseColumn != priv->model.base.column) {
priv->model.base.row = baseRow;
priv->model.base.column = baseColumn;
reCalculate = true;
}
if (vrows > priv->view.rows || vcols > priv->view.columns)
reCalculate = true;
if (reCalculate) {
Evas_Coord width, height;
evas_object_geometry_get(ewkBackingStore, 0, 0, &width, &height);
_ewk_tiled_backing_store_recalc_renderers(priv, width, height, tileWidth, tileHeight);
_ewk_tiled_backing_store_fill_renderers(priv);
_ewk_tiled_backing_store_updates_process(priv);
}
Evas_Coord baseTilePositionX = baseX + priv->view.x;
Evas_Coord tilePositionY = baseY + priv->view.y;
evas_object_move(priv->contentsClipper, newX + priv->view.x, newY + priv->view.y);
Eina_Inlist** it = priv->view.items;
Eina_Inlist** end = it + priv->view.rows;
for (; it < end; ++it) {
Evas_Coord tilePositionX = baseTilePositionX;
Eina_Inlist* list = *it;
Ewk_Tiled_Backing_Store_Item* item;
EINA_INLIST_FOREACH(list, item) {
_ewk_tiled_backing_store_item_move(item, tilePositionX, tilePositionY);
_ewk_tiled_backing_store_item_resize(item, tileWidth, tileHeight);
tilePositionX += tileWidth;
}
tilePositionY += tileHeight;
}
return true;
}
void ewk_tiled_backing_store_fix_offsets(Evas_Object* ewkBackingStore, Evas_Coord width, Evas_Coord height)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
Evas_Coord newX = priv->view.offset.current.x;
Evas_Coord newY = priv->view.offset.current.y;
Evas_Coord baseX = priv->view.offset.base.x;
Evas_Coord baseY = priv->view.offset.base.y;
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
if (-newX > width) {
newX = -width;
baseX = newX % tileWidth;
priv->model.base.column = -newX / tileWidth;
}
if (-newY > height) {
newY = -height;
baseY = newY % tileHeight;
priv->model.base.row = -newY / tileHeight;
}
if (baseX >= 0 || baseX <= -2 * priv->view.tile.width) {
baseX = newX % tileWidth;
priv->model.base.column = -newX / tileWidth;
}
if (baseY >= 0 || baseY <= -2 * priv->view.tile.height) {
baseY = newY % tileHeight;
priv->model.base.row = -newY / tileHeight;
}
priv->view.offset.current.x = newX;
priv->view.offset.current.y = newY;
priv->view.offset.old.x = newX;
priv->view.offset.old.y = newY;
priv->view.offset.base.x = baseX;
priv->view.offset.base.y = baseY;
evas_object_move(priv->contentsClipper, newX + priv->view.x, newY + priv->view.y);
Evas_Coord tilePositionY = priv->view.offset.base.y + priv->view.y;
Evas_Coord baseTilePositionX = priv->view.x + priv->view.offset.base.x;
Eina_Inlist** it = priv->view.items;
Eina_Inlist** end = it + priv->view.rows;
for (; it < end; ++it) {
Evas_Coord tilePositionX = baseTilePositionX;
Eina_Inlist* lst = *it;
Ewk_Tiled_Backing_Store_Item* item;
EINA_INLIST_FOREACH(lst, item) {
_ewk_tiled_backing_store_item_move(item, tilePositionX, tilePositionY);
_ewk_tiled_backing_store_item_resize(item, tileWidth, tileHeight);
tilePositionX += tileWidth;
}
tilePositionY += tileHeight;
}
}
void ewk_tiled_backing_store_zoom_weak_smooth_scale_set(Evas_Object* ewkBackingStore, bool smoothScale)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
Eina_Inlist** it = priv->view.items;
Eina_Inlist** end = it + priv->view.rows;
priv->view.tile.zoomWeakSmoothScale = smoothScale;
for (; it< end; ++it) {
Ewk_Tiled_Backing_Store_Item* item;
EINA_INLIST_FOREACH(*it, item)
if (item->tile)
_ewk_tiled_backing_store_item_smooth_scale_set(item, smoothScale);
}
}
void ewk_tiled_backing_store_alpha_set(Evas_Object* ewkBackingStore, bool hasAlpha)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
priv->view.tile.hasAlpha = hasAlpha;
}
bool ewk_tiled_backing_store_update(Evas_Object* ewkBackingStore, const Eina_Rectangle* update)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, false);
if (priv->render.disabled)
return false;
return ewk_tile_matrix_update(priv->model.matrix, update, priv->view.tile.zoom);
}
void ewk_tiled_backing_store_updates_process_pre_set(Evas_Object* ewkBackingStore, void* (*callback)(void* data, Evas_Object *ewkBackingStore), const void* data)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
priv->process.preCallback = callback;
priv->process.preData = const_cast<void*>(data);
}
void ewk_tiled_backing_store_updates_process_post_set(Evas_Object* ewkBackingStore, void* (*callback)(void* data, void* preData, Evas_Object *ewkBackingStore), const void* data)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
priv->process.postCallback = callback;
priv->process.postData = const_cast<void*>(data);
}
void ewk_tiled_backing_store_updates_process(Evas_Object* ewkBackingStore)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
_ewk_tiled_backing_store_updates_process(priv);
}
void ewk_tiled_backing_store_updates_clear(Evas_Object* ewkBackingStore)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
ewk_tile_matrix_updates_clear(priv->model.matrix);
}
void ewk_tiled_backing_store_contents_resize(Evas_Object* ewkBackingStore, Evas_Coord width, Evas_Coord height)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
if (width == priv->model.width && height == priv->model.height)
return;
priv->model.width = width;
priv->model.height = height;
priv->changed.contentsSize = true;
DBG("w,h=%d, %d", width, height);
_ewk_tiled_backing_store_changed(priv);
}
void ewk_tiled_backing_store_disabled_update_set(Evas_Object* ewkBackingStore, bool value)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
if (value != priv->render.disabled)
priv->render.disabled = value;
}
void ewk_tiled_backing_store_flush(Evas_Object* ewkBackingStore)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
priv->view.offset.current.x = 0;
priv->view.offset.current.y = 0;
priv->view.offset.old.x = 0;
priv->view.offset.old.y = 0;
priv->view.offset.base.x = 0;
priv->view.offset.base.y = 0;
priv->model.base.column = 0;
priv->model.base.row = 0;
priv->model.current.columns = 1;
priv->model.current.rows = 1;
priv->model.old.columns = 0;
priv->model.old.rows = 0;
priv->model.width = 0;
priv->model.height = 0;
priv->changed.size = true;
#ifdef DEBUG_MEM_LEAKS
printf("\nFLUSHED BACKING STORE, STATUS BEFORE DELETING TILE MATRIX:\n");
_ewk_tiled_backing_store_mem_dbg(priv);
#endif
_ewk_tiled_backing_store_pre_render_request_flush(priv);
_ewk_tiled_backing_store_tile_dissociate_all(priv);
Ewk_Tile_Unused_Cache* tileUnusedCache = ewk_tile_matrix_unused_cache_get(priv->model.matrix);
ewk_tile_unused_cache_clear(tileUnusedCache);
#ifdef DEBUG_MEM_LEAKS
printf("\nFLUSHED BACKING STORE, STATUS AFTER RECREATING TILE MATRIX:\n");
_ewk_tiled_backing_store_mem_dbg(priv);
#endif
}
bool ewk_tiled_backing_store_pre_render_tile_add(Evas_Object* ewkBackingStore, unsigned long column, unsigned long row, float zoom)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, false);
if (ewk_tile_matrix_tile_exact_exists(priv->model.matrix, column, row, zoom))
return false;
if (!_ewk_tiled_backing_store_pre_render_request_add(priv, column, row, zoom))
return false;
return true;
}
bool ewk_tiled_backing_store_pre_render_spiral_queue(Evas_Object* ewkBackingStore, Eina_Rectangle* viewRect, Eina_Rectangle* renderRect, int maxMemory, float zoom)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, false);
EINA_SAFETY_ON_NULL_RETURN_VAL(viewRect, false);
EINA_SAFETY_ON_NULL_RETURN_VAL(renderRect, false);
const int tileWidth = priv->view.tile.width;
const int tileHeight = priv->view.tile.height;
Eina_Tile_Grid_Slicer viewSlicer;
if (!eina_tile_grid_slicer_setup(&viewSlicer, viewRect->x, viewRect->y, viewRect->w, viewRect->h, tileWidth, tileHeight)) {
ERR("could not setup grid viewSlicer for %d,%d+%dx%d tile=%dx%d", viewRect->x, viewRect->y, viewRect->w, viewRect->h, tileWidth, tileHeight);
return false;
}
Eina_Tile_Grid_Slicer renderSlicer;
if (!eina_tile_grid_slicer_setup(&renderSlicer, renderRect->x, renderRect->y, renderRect->w, renderRect->h, tileWidth, tileHeight)) {
ERR("could not setup grid RenderSlicer for %d,%d+%dx%d tile=%dx%d", renderRect->y, renderRect->y, renderRect->w, renderRect->h, tileWidth, tileHeight);
return false;
}
// set limits of the loop.
int memoryLimits = maxMemory / (EWK_ARGB_BYTES_SIZE * tileWidth * tileHeight);
const unsigned long maxViewSideLength = std::max(viewSlicer.col2 - viewSlicer.col1, viewSlicer.row2 - viewSlicer.row1);
const unsigned long maxRenderSideLength = std::max(renderSlicer.col2 - renderSlicer.col1, renderSlicer.row2 - renderSlicer.row1);
const unsigned long maxLoopCount = maxViewSideLength + maxRenderSideLength;
// spire starts from the center of the view area.
unsigned long centerColumn = (viewSlicer.col1 + viewSlicer.col2) / 2;
unsigned long centerRow = (viewSlicer.row1 + viewSlicer.row2) / 2;
unsigned long step = 1;
const unsigned squareSide = 4;
for (unsigned loop = 0; loop < maxLoopCount; ++loop) {
for (unsigned long i = 1; i < step * squareSide + 1; ++i) {
if (memoryLimits <= 0)
goto memoryLimitsReached;
/*
this code means the loop runs like spiral. (i.g. left->down->right->up)
when it moves back to original place and then walk 1 tile left and up.
the loop keeps on doing this until it reaches max memory to draw tiles.
e.g. )
333333
322223
321123
321123
322223
333333
*/
if (i > 0 && i <= step)
++centerColumn; // move left.
else if (i > step && i <= step * 2)
++centerRow; // move down.
else if (i > step * 2 && i <= step * 3)
--centerColumn; // move right.
else if (i > step * 3 && i <= step * 4)
--centerRow; // move up.
else
ERR("ERROR : out of bounds\r\n");
// skip in view port area.
if (viewSlicer.col1 < centerColumn
&& viewSlicer.col2 > centerColumn
&& viewSlicer.row1 < centerRow
&& viewSlicer.row2 > centerRow)
continue;
if (renderSlicer.col1 <= centerColumn
&& renderSlicer.col2 >= centerColumn
&& renderSlicer.row1 <= centerRow
&& renderSlicer.row2 >= centerRow) {
if (!ewk_tiled_backing_store_pre_render_tile_add(ewkBackingStore, centerColumn, centerRow, zoom))
continue;
DBG("R>[%lu %lu] ", centerColumn, centerRow);
--memoryLimits;
}
}
--centerRow;
--centerColumn;
step += 2;
}
memoryLimitsReached:
_ewk_tiled_backing_store_item_process_idler_start(priv);
return true;
}
bool ewk_tiled_backing_store_pre_render_region(Evas_Object* ewkBackingStore, Evas_Coord x, Evas_Coord y, Evas_Coord width, Evas_Coord height, float zoom)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, false);
Evas_Coord tileWidth = priv->view.tile.width;
Evas_Coord tileHeight = priv->view.tile.height;
zoom = ROUNDED_ZOOM(priv->view.tile.width, zoom);
Eina_Tile_Grid_Slicer slicer;
memset(&slicer, 0, sizeof(Eina_Tile_Grid_Slicer));
if (!eina_tile_grid_slicer_setup(&slicer, x, y, width, height, tileWidth, tileHeight)) {
ERR("could not setup grid slicer for %d,%d+%dx%d tile=%dx%d",
x, y, width, height, tileWidth, tileHeight);
return false;
}
const Eina_Tile_Grid_Info* gridInfo;
while (eina_tile_grid_slicer_next(&slicer, &gridInfo)) {
const unsigned long column = gridInfo->col;
const unsigned long row = gridInfo->row;
if (!_ewk_tiled_backing_store_pre_render_request_add(priv, column, row, zoom))
break;
}
_ewk_tiled_backing_store_item_process_idler_start(priv);
Ewk_Tile_Unused_Cache* tileUnusedCache = ewk_tile_matrix_unused_cache_get(priv->model.matrix);
ewk_tile_unused_cache_lock_area(tileUnusedCache, x, y, width, height, zoom);
return true;
}
bool ewk_tiled_backing_store_pre_render_relative_radius(Evas_Object* ewkBackingStore, unsigned int n, float zoom)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, false);
INFO("priv->model.base.row =%ld, n=%u priv->view.rows=%lu", priv->model.base.row, n, priv->view.rows);
unsigned long startRow = priv->model.base.row - n;
unsigned long startCol = priv->model.base.column - n;
unsigned long endRow = std::min(priv->model.current.rows - 1, priv->model.base.row + priv->view.rows + n - 1);
unsigned long endCol = std::min(priv->model.current.columns - 1, priv->model.base.column + priv->view.columns + n - 1);
INFO("startRow=%lu, endRow=%lu, startCol=%lu, endCol=%lu", startRow, endRow, startCol, endCol);
zoom = ROUNDED_ZOOM(priv->view.tile.width, zoom);
for (unsigned long i = startRow; i <= endRow; ++i)
for (unsigned long j = startCol; j <= endCol; ++j)
if (!_ewk_tiled_backing_store_pre_render_request_add(priv, j, i, zoom))
goto start_processing;
start_processing:
_ewk_tiled_backing_store_item_process_idler_start(priv);
Ewk_Tile_Unused_Cache* tileUnusedCache = ewk_tile_matrix_unused_cache_get(priv->model.matrix);
unsigned long height = (endRow - startRow + 1) * TILE_SIZE_AT_ZOOM(priv->view.tile.height, zoom);
unsigned long width = (endCol - startCol + 1) * TILE_SIZE_AT_ZOOM(priv->view.tile.width, zoom);
ewk_tile_unused_cache_lock_area(tileUnusedCache,
startCol * TILE_SIZE_AT_ZOOM(priv->view.tile.width, zoom),
startRow * TILE_SIZE_AT_ZOOM(priv->view.tile.height, zoom), width, height, zoom);
return true;
}
void ewk_tiled_backing_store_pre_render_cancel(Evas_Object* ewkBackingStore)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv);
_ewk_tiled_backing_store_pre_render_request_clear(priv);
Ewk_Tile_Unused_Cache* tileUnusedCache = ewk_tile_matrix_unused_cache_get(priv->model.matrix);
ewk_tile_unused_cache_unlock_area(tileUnusedCache);
}
bool ewk_tiled_backing_store_disable_render(Evas_Object* ewkBackingStore)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, false);
return _ewk_tiled_backing_store_disable_render(priv);
}
bool ewk_tiled_backing_store_enable_render(Evas_Object* ewkBackingStore)
{
PRIV_DATA_GET_OR_RETURN(ewkBackingStore, priv, false);
_ewk_tiled_backing_store_changed(priv);
return _ewk_tiled_backing_store_enable_render(priv);
}
|