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 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <tuple>
#include "base/containers/contains.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_trace_processor.h"
#include "components/input/features.h"
#include "components/viz/common/constants.h"
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "components/viz/service/frame_sinks/compositor_frame_sink_support.h"
#include "components/viz/service/gl/mock_gpu_service_impl.h"
#include "components/viz/service/input/mock_input_manager.h"
#include "components/viz/service/input/render_input_router_iterator_impl.h"
#include "components/viz/service/surfaces/surface.h"
#include "components/viz/service/surfaces/surface_manager.h"
#include "components/viz/test/begin_frame_source_test.h"
#include "components/viz/test/compositor_frame_helpers.h"
#include "components/viz/test/fake_external_begin_frame_source.h"
#include "components/viz/test/fake_surface_observer.h"
#include "components/viz/test/mock_compositor_frame_sink_client.h"
#include "components/viz/test/mock_display_client.h"
#include "components/viz/test/test_output_surface_provider.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/perfetto/include/perfetto/tracing/tracing.h"
namespace viz {
namespace {
constexpr FrameSinkId kFrameSinkIdRoot(1, 1);
constexpr FrameSinkId kFrameSinkIdRoot2(2, 2);
constexpr FrameSinkId kFrameSinkIdA(2, 1);
constexpr FrameSinkId kFrameSinkIdB(3, 1);
constexpr FrameSinkId kFrameSinkIdC(4, 1);
constexpr FrameSinkId kFrameSinkIdD(5, 1);
constexpr FrameSinkId kFrameSinkIdE(6, 1);
constexpr FrameSinkId kFrameSinkIdF(7, 1);
// Holds the four interface objects needed to create a RootCompositorFrameSink.
struct RootCompositorFrameSinkData {
mojom::RootCompositorFrameSinkParamsPtr BuildParams(
const FrameSinkId& frame_sink_id) {
auto params = mojom::RootCompositorFrameSinkParams::New();
params->frame_sink_id = frame_sink_id;
params->widget = gpu::kNullSurfaceHandle;
params->compositor_frame_sink =
compositor_frame_sink.BindNewEndpointAndPassReceiver();
params->compositor_frame_sink_client =
compositor_frame_sink_client.BindInterfaceRemote();
params->display_private = display_private.BindNewEndpointAndPassReceiver();
params->display_client = display_client.BindRemote();
return params;
}
mojo::AssociatedRemote<mojom::CompositorFrameSink> compositor_frame_sink;
MockCompositorFrameSinkClient compositor_frame_sink_client;
mojo::AssociatedRemote<mojom::DisplayPrivate> display_private;
MockDisplayClient display_client;
};
} // namespace
class FrameSinkManagerTest : public testing::Test {
public:
FrameSinkManagerTest() {
FrameSinkManagerImpl::InitParams init_params(&output_surface_provider_);
init_params.gpu_service = &gpu_service_;
manager_ = std::make_unique<FrameSinkManagerImpl>(std::move(init_params));
surface_observer_ =
std::make_unique<FakeSurfaceObserver>(manager_->surface_manager());
}
~FrameSinkManagerTest() override = default;
RootCompositorFrameSinkImpl* GetRootCompositorFrameSinkImpl() {
auto it = manager_->root_sink_map_.find(kFrameSinkIdRoot);
return it == manager_->root_sink_map_.end() ? nullptr : it->second.get();
}
std::unique_ptr<CompositorFrameSinkSupport> CreateCompositorFrameSinkSupport(
const FrameSinkId& frame_sink_id) {
return std::make_unique<CompositorFrameSinkSupport>(nullptr, manager_.get(),
frame_sink_id, false);
}
const BeginFrameSource* GetBeginFrameSource(
const std::unique_ptr<CompositorFrameSinkSupport>& support) {
return support->begin_frame_source_;
}
void ExpireAllTemporaryReferencesAndGarbageCollect() {
manager_->surface_manager()->ExpireOldTemporaryReferences();
manager_->surface_manager()->ExpireOldTemporaryReferences();
manager_->surface_manager()->GarbageCollectSurfaces();
}
// Checks if a [Root]CompositorFrameSinkImpl exists for |frame_sink_id|.
bool CompositorFrameSinkExists(const FrameSinkId& frame_sink_id) {
return base::Contains(manager_->sink_map_, frame_sink_id) ||
base::Contains(manager_->root_sink_map_, frame_sink_id);
}
CompositorFrameSinkSupport* GetFrameSinkSupport(const FrameSinkId& id) {
return manager_->support_map_.find(id)->second;
}
bool InputManagerExists() { return manager_->GetInputManager(); }
MockInputManager* GetMockInputManager() {
return static_cast<MockInputManager*>(manager_->GetInputManager());
}
CapturableFrameSink* FindCapturableFrameSink(const FrameSinkId& id) {
return manager_->FindCapturableFrameSink(VideoCaptureTarget(id));
}
// Verifies the frame sinks with provided id in |ids| are throttled at
// |interval|.
void VerifyThrottling(base::TimeDelta interval,
const std::vector<FrameSinkId>& ids) {
for (auto& id : ids) {
EXPECT_EQ(interval, manager_->support_map_[id]->begin_frame_interval_);
}
}
// Creates a CompositorFrameSinkImpl.
void CreateCompositorFrameSink(
const FrameSinkId& frame_sink_id,
input::mojom::RenderInputRouterConfigPtr config) {
MockCompositorFrameSinkClient compositor_frame_sink_client;
mojo::Remote<mojom::CompositorFrameSink> compositor_frame_sink;
manager_->CreateCompositorFrameSink(
frame_sink_id, /*bundle_id=*/std::nullopt,
compositor_frame_sink.BindNewPipeAndPassReceiver(),
compositor_frame_sink_client.BindInterfaceRemote(), std::move(config));
EXPECT_TRUE(CompositorFrameSinkExists(frame_sink_id));
}
input::mojom::RenderInputRouterConfigPtr CreateRIRConfig(
const base::UnguessableToken& grouping_id) {
auto config = input::mojom::RenderInputRouterConfig::New();
mojo::PendingReceiver<blink::mojom::RenderInputRouterClient>
rir_client_receiver;
config->rir_client = rir_client_receiver.InitWithNewPipeAndPassRemote();
config->grouping_id = grouping_id;
return config;
}
base::flat_set<FrameSinkId> GetEmbeddedRenderInputRouters(
const FrameSinkId& frame_sink_id) {
auto rir_iterator =
GetMockInputManager()->GetEmbeddedRenderInputRouters(frame_sink_id);
return static_cast<RenderInputRouterIteratorImpl*>(rir_iterator.get())
->GetRenderInputRoutersForTesting();
}
// testing::Test implementation.
void SetUp() override {
manager_->SetInputManagerForTesting(
std::make_unique<MockInputManager>(manager_.get()));
}
// testing::Test implementation.
void TearDown() override {
// Make sure that all FrameSinkSourceMappings have been deleted.
EXPECT_TRUE(manager_->frame_sink_source_map_.empty());
// Make sure test cleans up all [Root]CompositorFrameSinkImpls.
EXPECT_TRUE(manager_->support_map_.empty());
// Make sure test has invalidated all registered FrameSinkIds.
EXPECT_TRUE(manager_->frame_sink_data_.empty());
}
protected:
DebugRendererSettings debug_settings_;
TestOutputSurfaceProvider output_surface_provider_;
std::unique_ptr<FrameSinkManagerImpl> manager_;
std::unique_ptr<FakeSurfaceObserver> surface_observer_;
base::test::ScopedFeatureList scoped_feature_list_;
private:
MockGpuServiceImpl gpu_service_;
};
TEST_F(FrameSinkManagerTest, CreateRootCompositorFrameSink) {
manager_->RegisterFrameSinkId(kFrameSinkIdRoot, true /* report_activation */);
// Create a RootCompositorFrameSinkImpl.
RootCompositorFrameSinkData root_data;
manager_->CreateRootCompositorFrameSink(
root_data.BuildParams(kFrameSinkIdRoot));
EXPECT_TRUE(CompositorFrameSinkExists(kFrameSinkIdRoot));
// Invalidating should destroy the RootCompositorFrameSinkImpl.
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot);
EXPECT_FALSE(CompositorFrameSinkExists(kFrameSinkIdRoot));
}
TEST_F(FrameSinkManagerTest, InputManagerCreation) {
ASSERT_FALSE(input::InputUtils::IsTransferInputToVizSupported());
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
// Create a CompositorFrameSinkImpl.
CreateCompositorFrameSink(kFrameSinkIdA,
/* render_input_router_config= */ nullptr);
// InputManager is not created since IsTransferInputToVizSupported() returns
// false.
EXPECT_FALSE(InputManagerExists());
// Invalidating should destroy the CompositorFrameSinkImpl.
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
}
TEST_F(FrameSinkManagerTest, CreateCompositorFrameSink) {
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
// Create a CompositorFrameSinkImpl.
CreateCompositorFrameSink(kFrameSinkIdA,
/* render_input_router_config= */ nullptr);
// Invalidating should destroy the CompositorFrameSinkImpl.
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
EXPECT_FALSE(CompositorFrameSinkExists(kFrameSinkIdA));
}
TEST_F(FrameSinkManagerTest, CompositorFrameSinkConnectionLost) {
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
// Create a CompositorFrameSinkImpl.
MockCompositorFrameSinkClient compositor_frame_sink_client;
mojo::Remote<mojom::CompositorFrameSink> compositor_frame_sink;
manager_->CreateCompositorFrameSink(
kFrameSinkIdA, /*bundle_id=*/std::nullopt,
compositor_frame_sink.BindNewPipeAndPassReceiver(),
compositor_frame_sink_client.BindInterfaceRemote(),
/* render_input_router_config= */ nullptr);
EXPECT_TRUE(CompositorFrameSinkExists(kFrameSinkIdA));
// Close the connection from the renderer.
compositor_frame_sink.reset();
// Closing the connection will destroy the CompositorFrameSinkImpl along with
// the mojom::CompositorFrameSinkClient binding.
base::RunLoop run_loop;
compositor_frame_sink_client.set_disconnect_handler(run_loop.QuitClosure());
run_loop.Run();
// Check that the CompositorFrameSinkImpl was destroyed.
EXPECT_FALSE(CompositorFrameSinkExists(kFrameSinkIdA));
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
}
TEST_F(FrameSinkManagerTest, SingleClients) {
auto client = CreateCompositorFrameSinkSupport(FrameSinkId(1, 1));
auto other_client = CreateCompositorFrameSinkSupport(FrameSinkId(2, 2));
StubBeginFrameSource source;
EXPECT_EQ(nullptr, GetBeginFrameSource(client));
EXPECT_EQ(nullptr, GetBeginFrameSource(other_client));
// Test setting unsetting BFS
manager_->RegisterBeginFrameSource(&source, client->frame_sink_id());
EXPECT_EQ(&source, GetBeginFrameSource(client));
EXPECT_EQ(nullptr, GetBeginFrameSource(other_client));
manager_->UnregisterBeginFrameSource(&source);
EXPECT_EQ(nullptr, GetBeginFrameSource(client));
EXPECT_EQ(nullptr, GetBeginFrameSource(other_client));
// Set BFS for other namespace
manager_->RegisterBeginFrameSource(&source, other_client->frame_sink_id());
EXPECT_EQ(&source, GetBeginFrameSource(other_client));
EXPECT_EQ(nullptr, GetBeginFrameSource(client));
manager_->UnregisterBeginFrameSource(&source);
EXPECT_EQ(nullptr, GetBeginFrameSource(client));
EXPECT_EQ(nullptr, GetBeginFrameSource(other_client));
// Re-set BFS for original
manager_->RegisterBeginFrameSource(&source, client->frame_sink_id());
EXPECT_EQ(&source, GetBeginFrameSource(client));
manager_->UnregisterBeginFrameSource(&source);
EXPECT_EQ(nullptr, GetBeginFrameSource(client));
}
// This test verifies that a client is still connected to the BeginFrameSource
// after restart.
TEST_F(FrameSinkManagerTest, ClientRestart) {
auto client = CreateCompositorFrameSinkSupport(kFrameSinkIdRoot);
StubBeginFrameSource source;
manager_->RegisterBeginFrameSource(&source, kFrameSinkIdRoot);
EXPECT_EQ(&source, GetBeginFrameSource(client));
client.reset();
// |client| is reconnected with |source| after being recreated..
client = CreateCompositorFrameSinkSupport(kFrameSinkIdRoot);
EXPECT_EQ(&source, GetBeginFrameSource(client));
manager_->UnregisterBeginFrameSource(&source);
EXPECT_EQ(nullptr, GetBeginFrameSource(client));
}
TEST_F(FrameSinkManagerTest, MultipleDisplays) {
StubBeginFrameSource root1_source;
StubBeginFrameSource root2_source;
// root1 -> A -> B
// root2 -> C
auto root1 = CreateCompositorFrameSinkSupport(FrameSinkId(1, 1));
auto root2 = CreateCompositorFrameSinkSupport(FrameSinkId(2, 2));
auto client_a = CreateCompositorFrameSinkSupport(FrameSinkId(3, 3));
auto client_b = CreateCompositorFrameSinkSupport(FrameSinkId(4, 4));
auto client_c = CreateCompositorFrameSinkSupport(FrameSinkId(5, 5));
manager_->RegisterBeginFrameSource(&root1_source, root1->frame_sink_id());
manager_->RegisterBeginFrameSource(&root2_source, root2->frame_sink_id());
EXPECT_EQ(GetBeginFrameSource(root1), &root1_source);
EXPECT_EQ(GetBeginFrameSource(root2), &root2_source);
// Set up initial hierarchy.
manager_->RegisterFrameSinkHierarchy(root1->frame_sink_id(),
client_a->frame_sink_id());
EXPECT_EQ(GetBeginFrameSource(client_a), GetBeginFrameSource(root1));
manager_->RegisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
EXPECT_EQ(GetBeginFrameSource(client_b), GetBeginFrameSource(root1));
manager_->RegisterFrameSinkHierarchy(root2->frame_sink_id(),
client_c->frame_sink_id());
EXPECT_EQ(GetBeginFrameSource(client_c), GetBeginFrameSource(root2));
// Attach A into root2's subtree, like a window moving across displays.
// root1 -> A -> B
// root2 -> C -> A -> B
manager_->RegisterFrameSinkHierarchy(client_c->frame_sink_id(),
client_a->frame_sink_id());
// With the heuristic of just keeping existing BFS in the face of multiple,
// no client sources should change.
EXPECT_EQ(GetBeginFrameSource(client_a), GetBeginFrameSource(root1));
EXPECT_EQ(GetBeginFrameSource(client_b), GetBeginFrameSource(root1));
EXPECT_EQ(GetBeginFrameSource(client_c), GetBeginFrameSource(root2));
// Detach A from root1-> A and B should now be updated to root2->
manager_->UnregisterFrameSinkHierarchy(root1->frame_sink_id(),
client_a->frame_sink_id());
EXPECT_EQ(GetBeginFrameSource(client_a), GetBeginFrameSource(root2));
EXPECT_EQ(GetBeginFrameSource(client_b), GetBeginFrameSource(root2));
EXPECT_EQ(GetBeginFrameSource(client_c), GetBeginFrameSource(root2));
// Detach root1 from BFS. root1 should now have no source.
manager_->UnregisterBeginFrameSource(&root1_source);
EXPECT_EQ(nullptr, GetBeginFrameSource(root1));
EXPECT_NE(nullptr, GetBeginFrameSource(root2));
// Detach root2 from BFS.
manager_->UnregisterBeginFrameSource(&root2_source);
EXPECT_EQ(nullptr, GetBeginFrameSource(client_a));
EXPECT_EQ(nullptr, GetBeginFrameSource(client_b));
EXPECT_EQ(nullptr, GetBeginFrameSource(client_c));
EXPECT_EQ(nullptr, GetBeginFrameSource(root2));
// Cleanup hierarchy.
manager_->UnregisterFrameSinkHierarchy(root2->frame_sink_id(),
client_c->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_c->frame_sink_id(),
client_a->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
}
TEST_F(FrameSinkManagerTest, FrameSinkParentChildRelationship) {
// Create 2 RootCompositorFrameSinks.
RootCompositorFrameSinkData root_data1;
manager_->CreateRootCompositorFrameSink(
root_data1.BuildParams(kFrameSinkIdRoot));
EXPECT_TRUE(CompositorFrameSinkExists(kFrameSinkIdRoot));
RootCompositorFrameSinkData root_data2;
manager_->CreateRootCompositorFrameSink(
root_data2.BuildParams(kFrameSinkIdRoot2));
EXPECT_TRUE(CompositorFrameSinkExists(kFrameSinkIdRoot2));
auto* root1 = GetFrameSinkSupport(kFrameSinkIdRoot);
auto* root2 = GetFrameSinkSupport(kFrameSinkIdRoot2);
auto client_a = CreateCompositorFrameSinkSupport(FrameSinkId(3, 3));
auto client_b = CreateCompositorFrameSinkSupport(FrameSinkId(4, 4));
auto client_c = CreateCompositorFrameSinkSupport(FrameSinkId(5, 5));
auto client_d = CreateCompositorFrameSinkSupport(FrameSinkId(6, 6));
auto client_e = CreateCompositorFrameSinkSupport(FrameSinkId(7, 7));
// Set up initial hierarchy.
// root1 -> A -> B -> C
// + -> D
// root2 -> E
manager_->RegisterFrameSinkHierarchy(root1->frame_sink_id(),
client_a->frame_sink_id());
EXPECT_EQ(manager_->GetOldestParentByChildFrameId(client_a->frame_sink_id()),
root1->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
EXPECT_EQ(manager_->GetOldestParentByChildFrameId(client_b->frame_sink_id()),
client_a->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(client_b->frame_sink_id(),
client_c->frame_sink_id());
EXPECT_EQ(manager_->GetOldestParentByChildFrameId(client_c->frame_sink_id()),
client_b->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(client_b->frame_sink_id(),
client_d->frame_sink_id());
EXPECT_EQ(manager_->GetOldestParentByChildFrameId(client_d->frame_sink_id()),
client_b->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(root2->frame_sink_id(),
client_e->frame_sink_id());
EXPECT_EQ(manager_->GetOldestParentByChildFrameId(client_e->frame_sink_id()),
root2->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_a->frame_sink_id()),
root1->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_b->frame_sink_id()),
root1->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_c->frame_sink_id()),
root1->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_d->frame_sink_id()),
root1->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_e->frame_sink_id()),
root2->frame_sink_id());
// Attach A into root2's subtree, like a window moving across displays.
// root1 -> A -> B -> C
// + -> D
// root2 -> E -> A -> B -> C
// + -> D
manager_->RegisterFrameSinkHierarchy(client_e->frame_sink_id(),
client_a->frame_sink_id());
// With the heuristic of just keeping existing parent in the face of multiple,
// no client's corresponding RootCompositorFrameSink should change.
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_a->frame_sink_id()),
root1->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_b->frame_sink_id()),
root1->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_c->frame_sink_id()),
root1->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_d->frame_sink_id()),
root1->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_e->frame_sink_id()),
root2->frame_sink_id());
// Detach A from root1.
manager_->UnregisterFrameSinkHierarchy(root1->frame_sink_id(),
client_a->frame_sink_id());
// root1
// root2 -> E -> A -> B -> C
// + -> D
EXPECT_EQ(manager_->GetOldestParentByChildFrameId(client_a->frame_sink_id()),
client_e->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_a->frame_sink_id()),
root2->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_b->frame_sink_id()),
root2->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_c->frame_sink_id()),
root2->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_d->frame_sink_id()),
root2->frame_sink_id());
EXPECT_EQ(
manager_->GetOldestRootCompositorFrameSinkId(client_e->frame_sink_id()),
root2->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(root2->frame_sink_id(),
client_e->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_e->frame_sink_id(),
client_a->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_b->frame_sink_id(),
client_d->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_b->frame_sink_id(),
client_c->frame_sink_id());
// Delete RootCompositorFrameSinks.
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot);
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot2);
}
// This test verifies that a BeginFrameSource path to the root from a
// FrameSinkId is preserved even if that FrameSinkId has no children
// and does not have a corresponding CompositorFrameSinkSupport.
TEST_F(FrameSinkManagerTest, ParentWithoutClientRetained) {
StubBeginFrameSource root_source;
auto root = CreateCompositorFrameSinkSupport(kFrameSinkIdRoot);
auto client_b = CreateCompositorFrameSinkSupport(kFrameSinkIdB);
auto client_c = CreateCompositorFrameSinkSupport(kFrameSinkIdC);
manager_->RegisterBeginFrameSource(&root_source, root->frame_sink_id());
EXPECT_EQ(&root_source, GetBeginFrameSource(root));
// Set up initial hierarchy: root -> A -> B.
// Note that A does not have a CompositorFrameSinkSupport.
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
// The root's BeginFrameSource should propagate to B.
EXPECT_EQ(GetBeginFrameSource(root), GetBeginFrameSource(client_b));
// Unregister B, and attach C to A: root -> A -> C
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
EXPECT_EQ(nullptr, GetBeginFrameSource(client_b));
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdC);
// The root's BeginFrameSource should propagate to C.
EXPECT_EQ(GetBeginFrameSource(root), GetBeginFrameSource(client_c));
manager_->UnregisterBeginFrameSource(&root_source);
EXPECT_EQ(nullptr, GetBeginFrameSource(root));
EXPECT_EQ(nullptr, GetBeginFrameSource(client_c));
// Unregister all registered hierarchy.
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdC);
}
// This test sets up the same hierarchy as ParentWithoutClientRetained.
// However, this unit test registers the BeginFrameSource AFTER C
// has been attached to A. This test verifies that the BeginFrameSource
// propagates all the way to C.
TEST_F(FrameSinkManagerTest,
ParentWithoutClientRetained_LateBeginFrameRegistration) {
StubBeginFrameSource root_source;
auto root = CreateCompositorFrameSinkSupport(kFrameSinkIdRoot);
auto client_b = CreateCompositorFrameSinkSupport(kFrameSinkIdB);
auto client_c = CreateCompositorFrameSinkSupport(kFrameSinkIdC);
// Set up initial hierarchy: root -> A -> B.
// Note that A does not have a CompositorFrameSinkSupport.
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
// The root does not yet have a BeginFrameSource so client B should not have
// one either.
EXPECT_EQ(nullptr, GetBeginFrameSource(client_b));
// Unregister B, and attach C to A: root -> A -> C
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdC);
// Registering a BeginFrameSource at the root should propagate it to C.
manager_->RegisterBeginFrameSource(&root_source, root->frame_sink_id());
// The root's BeginFrameSource should propagate to C.
EXPECT_EQ(&root_source, GetBeginFrameSource(root));
EXPECT_EQ(GetBeginFrameSource(root), GetBeginFrameSource(client_c));
manager_->UnregisterBeginFrameSource(&root_source);
EXPECT_EQ(nullptr, GetBeginFrameSource(root));
EXPECT_EQ(nullptr, GetBeginFrameSource(client_c));
// Unregister all registered hierarchy.
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdC);
}
// Verifies that the SurfaceIds passed to EvictSurfaces will be destroyed in the
// next garbage collection.
TEST_F(FrameSinkManagerTest, EvictSurfaces) {
ParentLocalSurfaceIdAllocator allocator1;
ParentLocalSurfaceIdAllocator allocator2;
allocator1.GenerateId();
LocalSurfaceId local_surface_id1 = allocator1.GetCurrentLocalSurfaceId();
allocator2.GenerateId();
LocalSurfaceId local_surface_id2 = allocator2.GetCurrentLocalSurfaceId();
SurfaceId surface_id1(kFrameSinkIdA, local_surface_id1);
SurfaceId surface_id2(kFrameSinkIdB, local_surface_id2);
// Create two frame sinks. Each create a surface.
auto sink1 = CreateCompositorFrameSinkSupport(kFrameSinkIdA);
auto sink2 = CreateCompositorFrameSinkSupport(kFrameSinkIdB);
sink1->SubmitCompositorFrame(local_surface_id1, MakeDefaultCompositorFrame());
sink2->SubmitCompositorFrame(local_surface_id2, MakeDefaultCompositorFrame());
// |surface_id1| and |surface_id2| should remain alive after garbage
// collection because they're not marked for destruction.
ExpireAllTemporaryReferencesAndGarbageCollect();
EXPECT_TRUE(manager_->surface_manager()->GetSurfaceForId(surface_id1));
EXPECT_TRUE(manager_->surface_manager()->GetSurfaceForId(surface_id2));
// Call EvictSurfaces. Now the garbage collector can destroy the surfaces.
manager_->EvictSurfaces({surface_id1, surface_id2});
// Garbage collection is synchronous.
EXPECT_FALSE(manager_->surface_manager()->GetSurfaceForId(surface_id1));
EXPECT_FALSE(manager_->surface_manager()->GetSurfaceForId(surface_id1));
}
// Verify that setting debug label works and that debug labels are cleared when
// FrameSinkId is invalidated.
TEST_F(FrameSinkManagerTest, DebugLabel) {
const std::string label = "Test Label";
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
manager_->SetFrameSinkDebugLabel(kFrameSinkIdA, label);
EXPECT_EQ(label, manager_->GetFrameSinkDebugLabel(kFrameSinkIdA));
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
EXPECT_EQ("", manager_->GetFrameSinkDebugLabel(kFrameSinkIdA));
}
// Verifies the the begin frames are throttled properly for the requested frame
// sinks and their children.
TEST_F(FrameSinkManagerTest, Throttle) {
// root -> A -> B
// -> C -> D
auto root = CreateCompositorFrameSinkSupport(kFrameSinkIdRoot);
auto client_a = CreateCompositorFrameSinkSupport(kFrameSinkIdA);
auto client_b = CreateCompositorFrameSinkSupport(kFrameSinkIdB);
auto client_c = CreateCompositorFrameSinkSupport(kFrameSinkIdC);
auto client_d = CreateCompositorFrameSinkSupport(kFrameSinkIdD);
// Set up the hierarchy.
manager_->RegisterFrameSinkHierarchy(root->frame_sink_id(),
client_a->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(root->frame_sink_id(),
client_c->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(client_c->frame_sink_id(),
client_d->frame_sink_id());
constexpr base::TimeDelta interval = base::Hertz(20);
std::vector<FrameSinkId> ids{kFrameSinkIdRoot, kFrameSinkIdA, kFrameSinkIdB,
kFrameSinkIdC, kFrameSinkIdD};
// By default, a CompositorFrameSinkSupport shouldn't have its
// |begin_frame_interval| set.
VerifyThrottling(base::TimeDelta(), ids);
manager_->Throttle({kFrameSinkIdRoot}, interval);
VerifyThrottling(interval, ids);
manager_->Throttle({}, base::TimeDelta());
VerifyThrottling(base::TimeDelta(), ids);
manager_->Throttle({kFrameSinkIdB, kFrameSinkIdC}, interval);
VerifyThrottling(interval, {kFrameSinkIdB, kFrameSinkIdC, kFrameSinkIdD});
VerifyThrottling(base::TimeDelta(), {kFrameSinkIdA, kFrameSinkIdRoot});
manager_->Throttle({}, base::TimeDelta());
VerifyThrottling(base::TimeDelta(), ids);
manager_->UnregisterFrameSinkHierarchy(root->frame_sink_id(),
client_a->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(root->frame_sink_id(),
client_c->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_c->frame_sink_id(),
client_d->frame_sink_id());
}
TEST_F(FrameSinkManagerTest, GlobalThrottle) {
// root -> A -> B
// -> C -> D
auto root = CreateCompositorFrameSinkSupport(kFrameSinkIdRoot);
auto client_a = CreateCompositorFrameSinkSupport(kFrameSinkIdA);
auto client_b = CreateCompositorFrameSinkSupport(kFrameSinkIdB);
auto client_c = CreateCompositorFrameSinkSupport(kFrameSinkIdC);
auto client_d = CreateCompositorFrameSinkSupport(kFrameSinkIdD);
// Set up the hierarchy.
manager_->RegisterFrameSinkHierarchy(root->frame_sink_id(),
client_a->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(root->frame_sink_id(),
client_c->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(client_c->frame_sink_id(),
client_d->frame_sink_id());
constexpr base::TimeDelta global_interval = base::Hertz(30);
constexpr base::TimeDelta interval = base::Hertz(20);
std::vector<FrameSinkId> ids{kFrameSinkIdRoot, kFrameSinkIdA, kFrameSinkIdB,
kFrameSinkIdC, kFrameSinkIdD};
// By default, a CompositorFrameSinkSupport shouldn't have its
// |begin_frame_interval| set.
VerifyThrottling(base::TimeDelta(), ids);
// Starting global throttling should throttle the entire hierarchy.
manager_->StartThrottlingAllFrameSinks(global_interval);
VerifyThrottling(global_interval, ids);
// Throttling more aggressively on top of global throttling should further
// throttle the specified frame sink hierarchy, but preserve global throttling
// on the unaffected framesinks.
manager_->Throttle({kFrameSinkIdC}, interval);
VerifyThrottling(global_interval,
{kFrameSinkIdRoot, kFrameSinkIdA, kFrameSinkIdB});
VerifyThrottling(interval, {kFrameSinkIdC, kFrameSinkIdD});
// Attempting to per-sink throttle to an interval shorter than the global
// throttling should still throttle all frame sinks to the global interval.
manager_->Throttle({kFrameSinkIdA}, base::Hertz(40));
VerifyThrottling(global_interval, ids);
// Add a new branch to the hierarchy. These new frame sinks should be globally
// throttled immediately. root -> A -> B
// -> C -> D
// -> E -> F
auto client_e = CreateCompositorFrameSinkSupport(kFrameSinkIdE);
auto client_f = CreateCompositorFrameSinkSupport(kFrameSinkIdF);
manager_->RegisterFrameSinkHierarchy(root->frame_sink_id(),
client_e->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(client_e->frame_sink_id(),
client_f->frame_sink_id());
VerifyThrottling(
global_interval,
{kFrameSinkIdRoot, kFrameSinkIdA, kFrameSinkIdB, kFrameSinkIdC,
kFrameSinkIdD, kFrameSinkIdE, kFrameSinkIdF});
// Disabling global throttling should revert back to only the up-to-date
// per-frame sink throttling.
manager_->StopThrottlingAllFrameSinks();
VerifyThrottling(base::Hertz(40), {kFrameSinkIdA, kFrameSinkIdB});
manager_->UnregisterFrameSinkHierarchy(root->frame_sink_id(),
client_a->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(root->frame_sink_id(),
client_c->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_c->frame_sink_id(),
client_d->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(root->frame_sink_id(),
client_e->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_e->frame_sink_id(),
client_f->frame_sink_id());
}
// Verifies if a frame sink is being captured, it should not be throttled.
TEST_F(FrameSinkManagerTest, NoThrottleOnFrameSinksBeingCaptured) {
// root -> A -> B -> C
auto root = CreateCompositorFrameSinkSupport(kFrameSinkIdRoot);
auto client_a = CreateCompositorFrameSinkSupport(kFrameSinkIdA);
auto client_b = CreateCompositorFrameSinkSupport(kFrameSinkIdB);
auto client_c = CreateCompositorFrameSinkSupport(kFrameSinkIdC);
// Set up the hierarchy.
manager_->RegisterFrameSinkHierarchy(root->frame_sink_id(),
client_a->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(client_b->frame_sink_id(),
client_c->frame_sink_id());
constexpr base::TimeDelta interval = base::Hertz(20);
std::vector<FrameSinkId> ids{kFrameSinkIdRoot, kFrameSinkIdA, kFrameSinkIdB,
kFrameSinkIdC};
// By default, a CompositorFrameSinkSupport shouldn't have its
// |begin_frame_interval| set.
VerifyThrottling(base::TimeDelta(), ids);
// Throttle all frame sinks.
manager_->Throttle({kFrameSinkIdRoot}, interval);
VerifyThrottling(interval, ids);
// Start capturing frame sink B.
CapturableFrameSink* capturable_frame_sink =
FindCapturableFrameSink(kFrameSinkIdB);
capturable_frame_sink->OnClientCaptureStarted();
// Throttling should be stopped on frame sink B and its child C, but not
// affected on root frame sink and frame sink A.
VerifyThrottling(interval, {kFrameSinkIdRoot, kFrameSinkIdA});
VerifyThrottling(base::TimeDelta(), {kFrameSinkIdB, kFrameSinkIdC});
// Explicitly request to throttle all frame sinks. This would not affect B or
// C while B is still being captured.
manager_->Throttle(ids, interval);
VerifyThrottling(interval, {kFrameSinkIdRoot, kFrameSinkIdA});
VerifyThrottling(base::TimeDelta(), {kFrameSinkIdB, kFrameSinkIdC});
// Stop capturing.
capturable_frame_sink->OnClientCaptureStopped();
// Now the throttling state should be the same as before capturing started,
// i.e. all frame sinks will now be throttled.
VerifyThrottling(interval, ids);
manager_->Throttle({}, base::TimeDelta());
VerifyThrottling(base::TimeDelta(), ids);
manager_->UnregisterFrameSinkHierarchy(root->frame_sink_id(),
client_a->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_b->frame_sink_id(),
client_c->frame_sink_id());
}
// Verifies if throttling on frame sinks is updated properly when hierarchy
// changes.
TEST_F(FrameSinkManagerTest, ThrottleUponHierarchyChange) {
// root -> A -> B
auto root = CreateCompositorFrameSinkSupport(kFrameSinkIdRoot);
auto client_a = CreateCompositorFrameSinkSupport(kFrameSinkIdA);
auto client_b = CreateCompositorFrameSinkSupport(kFrameSinkIdB);
// Set up the hierarchy.
manager_->RegisterFrameSinkHierarchy(root->frame_sink_id(),
client_a->frame_sink_id());
manager_->RegisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
constexpr base::TimeDelta interval = base::Hertz(20);
std::vector<FrameSinkId> ids{kFrameSinkIdRoot, kFrameSinkIdA, kFrameSinkIdB};
// Throttle the root frame sink.
manager_->Throttle({kFrameSinkIdRoot}, interval);
// All frame sinks should now be throttled.
VerifyThrottling(interval, ids);
// Unparent A from root. Root should remain throttled while A and B should be
// unthrottled.
manager_->UnregisterFrameSinkHierarchy(root->frame_sink_id(),
client_a->frame_sink_id());
VerifyThrottling(interval, {kFrameSinkIdRoot});
VerifyThrottling(base::TimeDelta(), {kFrameSinkIdA, kFrameSinkIdB});
// Reparent A to root. Both A and B should now be throttled along with root.
manager_->RegisterFrameSinkHierarchy(root->frame_sink_id(),
client_a->frame_sink_id());
VerifyThrottling(interval, ids);
// Unthrottle all frame sinks.
manager_->Throttle({}, base::TimeDelta());
VerifyThrottling(base::TimeDelta(), ids);
manager_->UnregisterFrameSinkHierarchy(root->frame_sink_id(),
client_a->frame_sink_id());
manager_->UnregisterFrameSinkHierarchy(client_a->frame_sink_id(),
client_b->frame_sink_id());
}
TEST_F(FrameSinkManagerTest, EvictRootSurfaceId) {
manager_->RegisterFrameSinkId(kFrameSinkIdRoot, true /* report_activation */);
// Create a RootCompositorFrameSinkImpl.
RootCompositorFrameSinkData root_data;
manager_->CreateRootCompositorFrameSink(
root_data.BuildParams(kFrameSinkIdRoot));
GetRootCompositorFrameSinkImpl()->Resize(gfx::Size(20, 20));
ParentLocalSurfaceIdAllocator allocator;
allocator.GenerateId();
const LocalSurfaceId local_surface_id = allocator.GetCurrentLocalSurfaceId();
const SurfaceId surface_id(kFrameSinkIdRoot, local_surface_id);
GetRootCompositorFrameSinkImpl()->SubmitCompositorFrame(
local_surface_id, MakeDefaultCompositorFrame(), std::nullopt, 0);
EXPECT_EQ(surface_id, GetRootCompositorFrameSinkImpl()->CurrentSurfaceId());
manager_->EvictSurfaces({surface_id});
EXPECT_FALSE(GetRootCompositorFrameSinkImpl()->CurrentSurfaceId().is_valid());
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot);
}
TEST_F(FrameSinkManagerTest, EvictNewerRootSurfaceId) {
manager_->RegisterFrameSinkId(kFrameSinkIdRoot, true /* report_activation */);
// Create a RootCompositorFrameSinkImpl.
RootCompositorFrameSinkData root_data;
manager_->CreateRootCompositorFrameSink(
root_data.BuildParams(kFrameSinkIdRoot));
GetRootCompositorFrameSinkImpl()->Resize(gfx::Size(20, 20));
ParentLocalSurfaceIdAllocator allocator;
allocator.GenerateId();
const LocalSurfaceId local_surface_id = allocator.GetCurrentLocalSurfaceId();
const SurfaceId surface_id(kFrameSinkIdRoot, local_surface_id);
GetRootCompositorFrameSinkImpl()->SubmitCompositorFrame(
local_surface_id, MakeDefaultCompositorFrame(), std::nullopt, 0);
EXPECT_EQ(surface_id, GetRootCompositorFrameSinkImpl()->CurrentSurfaceId());
allocator.GenerateId();
const LocalSurfaceId next_local_surface_id =
allocator.GetCurrentLocalSurfaceId();
manager_->EvictSurfaces({{kFrameSinkIdRoot, next_local_surface_id}});
EXPECT_FALSE(GetRootCompositorFrameSinkImpl()->CurrentSurfaceId().is_valid());
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot);
}
TEST_F(FrameSinkManagerTest, SubmitCompositorFrameWithEvictedSurfaceId) {
manager_->RegisterFrameSinkId(kFrameSinkIdRoot, true /* report_activation */);
// Create a RootCompositorFrameSinkImpl.
RootCompositorFrameSinkData root_data;
manager_->CreateRootCompositorFrameSink(
root_data.BuildParams(kFrameSinkIdRoot));
GetRootCompositorFrameSinkImpl()->Resize(gfx::Size(20, 20));
ParentLocalSurfaceIdAllocator allocator;
allocator.GenerateId();
const LocalSurfaceId local_surface_id = allocator.GetCurrentLocalSurfaceId();
const SurfaceId surface_id(kFrameSinkIdRoot, local_surface_id);
allocator.GenerateId();
const LocalSurfaceId local_surface_id2 = allocator.GetCurrentLocalSurfaceId();
const SurfaceId surface_id2(kFrameSinkIdRoot, local_surface_id2);
GetRootCompositorFrameSinkImpl()->SubmitCompositorFrame(
local_surface_id, MakeDefaultCompositorFrame(), std::nullopt, 0);
EXPECT_EQ(surface_id, GetRootCompositorFrameSinkImpl()->CurrentSurfaceId());
manager_->EvictSurfaces({surface_id, surface_id2});
EXPECT_FALSE(GetRootCompositorFrameSinkImpl()->CurrentSurfaceId().is_valid());
GetRootCompositorFrameSinkImpl()->SubmitCompositorFrame(
local_surface_id2, MakeDefaultCompositorFrame(), std::nullopt, 0);
// Even though `surface_id2` was just submitted, Display should not reference
// it because it was evicted.
EXPECT_NE(surface_id2, GetRootCompositorFrameSinkImpl()->CurrentSurfaceId());
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot);
}
// Test that `FrameSinkManagerImpl::DiscardPendingCopyOfOutputRequests`
// relocates the exact `PendingCopyOutputRequest`s to the target surfaces.
TEST_F(FrameSinkManagerTest,
CopyOutputRequestPreservedAfterDiscardPendingCopyOfOutputRequests) {
StubBeginFrameSource source;
manager_->RegisterBeginFrameSource(&source, kFrameSinkIdA);
// Create a CompositorFrameSinkImpl.
CreateCompositorFrameSink(kFrameSinkIdA,
/* render_input_router_config= */ nullptr);
ParentLocalSurfaceIdAllocator allocator;
allocator.GenerateId();
const auto id1 = allocator.GetCurrentLocalSurfaceId();
const auto surface_id1 = SurfaceId(kFrameSinkIdA, id1);
manager_->GetFrameSinkForId(kFrameSinkIdA)
->SubmitCompositorFrame(id1, MakeDefaultCompositorFrame());
auto* surface1 = manager_->surface_manager()->GetSurfaceForId(surface_id1);
ASSERT_TRUE(surface1);
auto request = std::make_unique<CopyOutputRequest>(
CopyOutputRequest::ResultFormat::RGBA,
CopyOutputRequest::ResultDestination::kSystemMemory,
base::BindOnce([](std::unique_ptr<CopyOutputResult> result) {}));
auto* request_ptr = request.get();
manager_->RequestCopyOfOutput(surface_id1, std::move(request),
/*capture_exact_surface_id=*/true);
manager_->DiscardPendingCopyOfOutputRequests(&source);
ASSERT_TRUE(surface_observer_->IsSurfaceDamaged(surface_id1));
// `request` is emplaced at the end of the root RenderPass.
const auto& preserved_request = *(
surface1->GetActiveFrame().render_pass_list.back()->copy_requests.back());
// Expect the identical `CopyOutputRequest`.
ASSERT_EQ(&preserved_request, request_ptr);
// For `manager_->CreateCompositorFrameSink`.
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
// For `manager_->RegisterBeginFrameSource`.
manager_->UnregisterBeginFrameSource(&source);
}
// Submit an exact copy request while there is no frame sink. Such request can
// only be picked up by the specified surface.
TEST_F(FrameSinkManagerTest, ExactCopyOutputRequestTakenBySurfaceRightAway) {
StubBeginFrameSource source;
manager_->RegisterBeginFrameSource(&source, kFrameSinkIdA);
// Create a CompositorFrameSinkImpl.
CreateCompositorFrameSink(kFrameSinkIdA,
/* render_input_router_config= */ nullptr);
ParentLocalSurfaceIdAllocator allocator;
allocator.GenerateId();
const auto id1 = allocator.GetCurrentLocalSurfaceId();
const auto surface_id1 = SurfaceId(kFrameSinkIdA, id1);
manager_->GetFrameSinkForId(kFrameSinkIdA)
->SubmitCompositorFrame(id1, MakeDefaultCompositorFrame());
auto* surface1 = manager_->surface_manager()->GetSurfaceForId(surface_id1);
ASSERT_TRUE(surface1);
// Invalidate the frame sink after we create the surface. This makes sure
// the exact request can only be taken by the exact surface, instead of being
// queued in the `CompositorFrameSinkSupport`.
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
auto request = std::make_unique<CopyOutputRequest>(
CopyOutputRequest::ResultFormat::RGBA,
CopyOutputRequest::ResultDestination::kSystemMemory,
base::BindOnce([](std::unique_ptr<CopyOutputResult> result) {}));
auto* request_ptr = request.get();
manager_->RequestCopyOfOutput(surface_id1, std::move(request),
/*capture_exact_surface_id=*/true);
ASSERT_TRUE(surface_observer_->IsSurfaceDamaged(surface_id1));
// `request` is emplaced at the end of the root RenderPass.
const auto& preserved_request = *(
surface1->GetActiveFrame().render_pass_list.back()->copy_requests.back());
// Expect the identical `CopyOutputRequest`.
ASSERT_EQ(&preserved_request, request_ptr);
// Already de-registered `kFrameSinkIdA`.
// For `manager_->RegisterBeginFrameSource`.
manager_->UnregisterBeginFrameSource(&source);
}
// Submit an exact copy request while there is no specified surface. Such
// request will be queued in the `CompositorFrameSinkSupport`, just like the
// non-exact requests.
TEST_F(FrameSinkManagerTest,
ExactCopyOutputRequestQueuedInCompositorFrameSinkSupport) {
StubBeginFrameSource source;
manager_->RegisterBeginFrameSource(&source, kFrameSinkIdA);
// Create a CompositorFrameSinkImpl.
CreateCompositorFrameSink(kFrameSinkIdA,
/* render_input_router_config= */ nullptr);
ParentLocalSurfaceIdAllocator allocator;
allocator.GenerateId();
const auto id1 = allocator.GetCurrentLocalSurfaceId();
const auto surface_id1 = SurfaceId(kFrameSinkIdA, id1);
// Submit the request.
auto request = std::make_unique<CopyOutputRequest>(
CopyOutputRequest::ResultFormat::RGBA,
CopyOutputRequest::ResultDestination::kSystemMemory,
base::BindOnce([](std::unique_ptr<CopyOutputResult> result) {}));
auto* request_ptr = request.get();
manager_->RequestCopyOfOutput(surface_id1, std::move(request),
/*capture_exact_surface_id=*/true);
// Won't be marked because the surface does not exist.
ASSERT_FALSE(surface_observer_->IsSurfaceDamaged(surface_id1));
auto* cfss = manager_->GetFrameSinkForId(kFrameSinkIdA);
ASSERT_TRUE(cfss);
// Since this is an exact request, it can only be taken by the matching
// `LocalSurfaceId`.
auto requests = cfss->TakeCopyOutputRequests(id1);
ASSERT_EQ(requests.size(), 1u);
ASSERT_EQ(requests[0].copy_output_request.get(), request_ptr);
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
manager_->UnregisterBeginFrameSource(&source);
}
#if BUILDFLAG(IS_ANDROID)
class AndroidFrameSinkManagerTest : public FrameSinkManagerTest,
public ::testing::WithParamInterface<bool> {
public:
AndroidFrameSinkManagerTest() {
scoped_feature_list_.InitWithFeatureState(input::features::kInputOnViz,
/* enabled= */ GetParam());
}
bool ExpectedInputManagerCreation() {
return input::InputUtils::IsTransferInputToVizSupported();
}
bool IsRenderInputRouterSupportChildFrame(const FrameSinkId& frame_sink_id) {
auto* mock_input_manager = GetMockInputManager();
EXPECT_TRUE(mock_input_manager);
auto* support = mock_input_manager->GetSupportForFrameSink(frame_sink_id);
EXPECT_TRUE(support);
return support->IsRenderInputRouterSupportChildFrame();
}
private:
base::test::TracingEnvironment tracing_environment_;
};
TEST_P(AndroidFrameSinkManagerTest, InputManagerCreation) {
EXPECT_EQ(InputManagerExists(), ExpectedInputManagerCreation());
}
TEST_P(AndroidFrameSinkManagerTest, RenderInputRouterLifecycle) {
EXPECT_EQ(InputManagerExists(), ExpectedInputManagerCreation());
base::test::TestTraceProcessor ttp;
ttp.StartTrace("viz");
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
// Create a grouping id.
base::UnguessableToken grouping_id = base::UnguessableToken::Create();
// Create a CompositorFrameSinkImpl.
CreateCompositorFrameSink(kFrameSinkIdA, CreateRIRConfig(grouping_id));
if (InputManagerExists()) {
EXPECT_TRUE(GetMockInputManager()->RIRExistsForFrameSinkId(kFrameSinkIdA));
}
// Invalidating should destroy the CompositorFrameSinkImpl.
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
EXPECT_FALSE(CompositorFrameSinkExists(kFrameSinkIdA));
if (InputManagerExists()) {
EXPECT_FALSE(GetMockInputManager()->RIRExistsForFrameSinkId(kFrameSinkIdA));
}
absl::Status status = ttp.StopAndParseTrace();
EXPECT_TRUE(status.ok()) << status.message();
std::string query = R"(
SELECT COUNT(*) AS cnt,
EXTRACT_ARG(arg_set_id, 'debug.config_is_null') as config_is_null,
EXTRACT_ARG(arg_set_id, 'debug.frame_sink_id.frame_sink_client_id')
as client_id,
EXTRACT_ARG(arg_set_id, 'debug.frame_sink_id.frame_sink_id') as sink_id
FROM slice
WHERE slice.name = 'InputManager::OnCreateCompositorFrameSink'
)";
auto result = ttp.RunQuery(query);
EXPECT_TRUE(result.has_value());
// `result.value()` would look something like this: {{"cnt", "config_is_null",
// "client_id", "sink_id"}, {"<num>", "<boolean>" "<clientId>", "<sinkId>"}}.
EXPECT_EQ(result.value().size(), 2u);
EXPECT_EQ(result.value()[1].size(), 4u);
if (input::InputUtils::IsTransferInputToVizSupported()) {
// Checks if `InputManger::OnCreateCompositorFrameSink` was called for
// kFrameSinkIdA.
EXPECT_THAT(
result.value(),
testing::ElementsAre(
testing::ElementsAre("cnt", "config_is_null", "client_id",
"sink_id"),
testing::ElementsAre(
"1", "0", base::NumberToString(kFrameSinkIdA.client_id()),
base::NumberToString(kFrameSinkIdA.sink_id()))));
} else {
EXPECT_EQ(result.value()[1][0], "0");
}
std::string query2 = R"(
SELECT COUNT(*) AS cnt,
EXTRACT_ARG(arg_set_id, 'debug.frame_sink_id.frame_sink_client_id')
as client_id,
EXTRACT_ARG(arg_set_id, 'debug.frame_sink_id.frame_sink_id') as sink_id
FROM slice
WHERE slice.name = 'InputManager::OnDestroyedCompositorFrameSink'
)";
auto result2 = ttp.RunQuery(query2);
EXPECT_TRUE(result2.has_value());
if (input::InputUtils::IsTransferInputToVizSupported()) {
EXPECT_THAT(result2.value(),
testing::ElementsAre(
testing::ElementsAre("cnt", "client_id", "sink_id"),
testing::ElementsAre(
"1", base::NumberToString(kFrameSinkIdA.client_id()),
base::NumberToString(kFrameSinkIdA.sink_id()))));
} else {
EXPECT_EQ(result2.value()[1][0], "0");
}
}
TEST_P(AndroidFrameSinkManagerTest,
RenderInputRouterLifecycleNonLayerFrameSink) {
EXPECT_EQ(InputManagerExists(), ExpectedInputManagerCreation());
base::test::TestTraceProcessor ttp;
ttp.StartTrace("viz");
// Register a non layer tree frame sink.
manager_->RegisterFrameSinkId(kFrameSinkIdB, true /* report_activation */);
CreateCompositorFrameSink(kFrameSinkIdB,
/* render_input_router_config= */ nullptr);
if (InputManagerExists()) {
// RIR should not be created for non layer tree frame sink.
EXPECT_FALSE(GetMockInputManager()->RIRExistsForFrameSinkId(kFrameSinkIdB));
}
// Invalidating should destroy the CompositorFrameSinkImpl.
manager_->InvalidateFrameSinkId(kFrameSinkIdB);
EXPECT_FALSE(CompositorFrameSinkExists(kFrameSinkIdB));
if (InputManagerExists()) {
EXPECT_FALSE(GetMockInputManager()->RIRExistsForFrameSinkId(kFrameSinkIdB));
}
absl::Status status = ttp.StopAndParseTrace();
EXPECT_TRUE(status.ok()) << status.message();
std::string query = R"(
SELECT COUNT(*) AS cnt,
EXTRACT_ARG(arg_set_id, 'debug.config_is_null') as config_is_null,
EXTRACT_ARG(arg_set_id, 'debug.frame_sink_id.frame_sink_client_id')
as client_id,
EXTRACT_ARG(arg_set_id, 'debug.frame_sink_id.frame_sink_id') as sink_id
FROM slice
WHERE slice.name = 'InputManager::OnCreateCompositorFrameSink'
)";
auto result = ttp.RunQuery(query);
EXPECT_TRUE(result.has_value());
// `result.value()` would look something like this: {{"cnt", "config_is_null",
// "client_id", "sink_id"}, {"<num>", "<boolean>" "<clientId>", "<sinkId>"}}.
EXPECT_EQ(result.value().size(), 2u);
EXPECT_EQ(result.value()[1].size(), 4u);
if (input::InputUtils::IsTransferInputToVizSupported()) {
EXPECT_THAT(
result.value(),
testing::ElementsAre(
testing::ElementsAre("cnt", "config_is_null", "client_id",
"sink_id"),
testing::ElementsAre(
"1", "1", base::NumberToString(kFrameSinkIdB.client_id()),
base::NumberToString(kFrameSinkIdB.sink_id()))));
} else {
EXPECT_EQ(result.value()[1][0], "0");
}
}
TEST_P(AndroidFrameSinkManagerTest, RWHIERLifecycleDiffWebContents) {
const bool expected_creation =
input::InputUtils::IsTransferInputToVizSupported();
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
base::UnguessableToken grouping_id_1 = base::UnguessableToken::Create();
base::UnguessableToken grouping_id_2 = base::UnguessableToken::Create();
// Create a CompositorFrameSinkImpl.
CreateCompositorFrameSink(kFrameSinkIdA, CreateRIRConfig(grouping_id_1));
EXPECT_EQ(InputManagerExists(), expected_creation);
manager_->RegisterFrameSinkId(kFrameSinkIdB, true /* report_activation */);
// Create another CompositorFrameSinkImpl for a different WebContent.
CreateCompositorFrameSink(kFrameSinkIdB, CreateRIRConfig(grouping_id_2));
EXPECT_EQ(InputManagerExists(), expected_creation);
auto* mock_input_manager = GetMockInputManager();
if (expected_creation) {
EXPECT_EQ(mock_input_manager->GetRenderInputRouterMapSize(), 2);
EXPECT_EQ(mock_input_manager->GetInputEventRouterMapSize(), 2);
}
// Invalidating should destroy the CompositorFrameSinkImpl.
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
EXPECT_FALSE(CompositorFrameSinkExists(kFrameSinkIdA));
if (expected_creation) {
EXPECT_EQ(mock_input_manager->GetRenderInputRouterMapSize(), 1);
EXPECT_EQ(mock_input_manager->GetInputEventRouterMapSize(), 1);
}
manager_->InvalidateFrameSinkId(kFrameSinkIdB);
EXPECT_FALSE(CompositorFrameSinkExists(kFrameSinkIdB));
if (expected_creation) {
EXPECT_EQ(mock_input_manager->GetRenderInputRouterMapSize(), 0);
EXPECT_EQ(mock_input_manager->GetInputEventRouterMapSize(), 0);
}
}
TEST_P(AndroidFrameSinkManagerTest, RWHIERLifecycleSameWebContents) {
const bool expected_creation =
input::InputUtils::IsTransferInputToVizSupported();
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
base::UnguessableToken grouping_id = base::UnguessableToken::Create();
// Create a CompositorFrameSinkImpl.
CreateCompositorFrameSink(kFrameSinkIdA, CreateRIRConfig(grouping_id));
EXPECT_EQ(InputManagerExists(), expected_creation);
manager_->RegisterFrameSinkId(kFrameSinkIdB, true /* report_activation */);
// Create another CompositorFrameSinkImpl for the same WebContent.
CreateCompositorFrameSink(kFrameSinkIdB, CreateRIRConfig(grouping_id));
EXPECT_EQ(InputManagerExists(), expected_creation);
auto* mock_input_manager = GetMockInputManager();
if (expected_creation) {
EXPECT_EQ(mock_input_manager->GetRenderInputRouterMapSize(), 2);
EXPECT_EQ(mock_input_manager->GetInputEventRouterMapSize(), 1);
}
// Invalidating should destroy the CompositorFrameSinkImpl.
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
EXPECT_FALSE(CompositorFrameSinkExists(kFrameSinkIdA));
if (expected_creation) {
EXPECT_EQ(mock_input_manager->GetRenderInputRouterMapSize(), 1);
EXPECT_EQ(mock_input_manager->GetInputEventRouterMapSize(), 1);
}
manager_->InvalidateFrameSinkId(kFrameSinkIdB);
EXPECT_FALSE(CompositorFrameSinkExists(kFrameSinkIdB));
if (expected_creation) {
EXPECT_EQ(mock_input_manager->GetRenderInputRouterMapSize(), 0);
EXPECT_EQ(mock_input_manager->GetInputEventRouterMapSize(), 0);
}
}
TEST_P(AndroidFrameSinkManagerTest, VizRIRDelegateLifecycle) {
base::test::TestTraceProcessor ttp;
ttp.StartTrace("viz, input");
const bool expected_creation =
input::InputUtils::IsTransferInputToVizSupported();
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
base::UnguessableToken grouping_id = base::UnguessableToken::Create();
// Create a CompositorFrameSinkImpl.
CreateCompositorFrameSink(kFrameSinkIdA, CreateRIRConfig(grouping_id));
EXPECT_EQ(InputManagerExists(), expected_creation);
EXPECT_EQ(InputManagerExists(), ExpectedInputManagerCreation());
// Invalidating should destroy the CompositorFrameSinkImpl.
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
EXPECT_FALSE(CompositorFrameSinkExists(kFrameSinkIdA));
absl::Status status = ttp.StopAndParseTrace();
EXPECT_TRUE(status.ok()) << status.message();
std::string query = R"(
SELECT name
FROM slice
WHERE
(
name = 'RenderInputRouter::RenderInputRouter'
OR
name = 'RenderInputRouter::~RenderInputRouter'
OR
name = 'RenderInputRouterDelegateImpl::RenderInputRouterDelegateImpl'
OR
name = 'RenderInputRouterDelegateImpl::~RenderInputRouterDelegateImpl'
)
ORDER BY ts ASC
)";
auto result = ttp.RunQuery(query);
EXPECT_TRUE(result.has_value());
// `result.value()` would look something like this: {{"name"},
// {"<name1>"}, {"<name2>"}, {"<name3>"}, {"<name4>"}}.
if (input::InputUtils::IsTransferInputToVizSupported()) {
EXPECT_EQ(result.value().size(), 5u);
EXPECT_EQ(result.value()[1].size(), 1u);
EXPECT_THAT(
result.value(),
testing::ElementsAre(
testing::ElementsAre("name"),
testing::ElementsAre("RenderInputRouterDelegateImpl::"
"RenderInputRouterDelegateImpl"),
testing::ElementsAre("RenderInputRouter::RenderInputRouter"),
testing::ElementsAre("RenderInputRouter::~RenderInputRouter"),
testing::ElementsAre("RenderInputRouterDelegateImpl::~"
"RenderInputRouterDelegateImpl")));
} else {
EXPECT_EQ(result.value()[0][0], "name");
}
}
TEST_P(AndroidFrameSinkManagerTest, VizRenderInputRouterSupportBaseLifecycle) {
base::test::TestTraceProcessor ttp;
ttp.StartTrace("viz, input");
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
// Create a grouping id.
base::UnguessableToken grouping_id = base::UnguessableToken::Create();
// Create a CompositorFrameSinkImpl.
CreateCompositorFrameSink(kFrameSinkIdA, CreateRIRConfig(grouping_id));
EXPECT_EQ(InputManagerExists(), ExpectedInputManagerCreation());
// Invalidating should destroy the CompositorFrameSinkImpl.
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
EXPECT_FALSE(CompositorFrameSinkExists(kFrameSinkIdA));
absl::Status status = ttp.StopAndParseTrace();
ASSERT_TRUE(status.ok()) << status.message();
std::string query = R"(
SELECT name
FROM slice
WHERE
(
name = 'RenderInputRouter::RenderInputRouter'
OR
name = 'RenderInputRouter::~RenderInputRouter'
OR
name = 'RenderInputRouterSupportBase::RenderInputRouterSupportBase'
OR
name = 'RenderInputRouterSupportBase::~RenderInputRouterSupportBase'
)
ORDER BY ts ASC
)";
auto result = ttp.RunQuery(query);
ASSERT_TRUE(result.has_value());
// `result.value()` would look something like this: {{"name"},
// {"<name1>"}, {"<name2>"}, {"<name3>"}, {"<name4>"}}.
if (input::InputUtils::IsTransferInputToVizSupported()) {
EXPECT_THAT(
result.value(),
testing::ElementsAre(
testing::ElementsAre("name"),
testing::ElementsAre("RenderInputRouter::RenderInputRouter"),
testing::ElementsAre(
"RenderInputRouterSupportBase::RenderInputRouterSupportBase"),
testing::ElementsAre(
"RenderInputRouterSupportBase::~RenderInputRouterSupportBase"),
testing::ElementsAre("RenderInputRouter::~RenderInputRouter")));
} else {
EXPECT_EQ(result.value()[0][0], "name");
}
}
TEST_P(AndroidFrameSinkManagerTest, RenderInputRouterSupportTraversals) {
const bool expected_creation =
input::InputUtils::IsTransferInputToVizSupported();
if (!expected_creation) {
return;
}
base::UnguessableToken grouping_id = base::UnguessableToken::Create();
RootCompositorFrameSinkData root_data1;
manager_->CreateRootCompositorFrameSink(
root_data1.BuildParams(kFrameSinkIdRoot));
EXPECT_TRUE(CompositorFrameSinkExists(kFrameSinkIdRoot));
RootCompositorFrameSinkData root_data2;
manager_->CreateRootCompositorFrameSink(
root_data2.BuildParams(kFrameSinkIdRoot2));
EXPECT_TRUE(CompositorFrameSinkExists(kFrameSinkIdRoot2));
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
manager_->RegisterFrameSinkId(kFrameSinkIdB, true /* report_activation */);
manager_->RegisterFrameSinkId(kFrameSinkIdC, true /* report_activation */);
manager_->RegisterFrameSinkId(kFrameSinkIdD, true /* report_activation */);
manager_->RegisterFrameSinkId(kFrameSinkIdE, true /* report_activation */);
// Create CompositorFrameSinkImpl's.
CreateCompositorFrameSink(kFrameSinkIdA, CreateRIRConfig(grouping_id));
CreateCompositorFrameSink(kFrameSinkIdB, CreateRIRConfig(grouping_id));
CreateCompositorFrameSink(kFrameSinkIdC, CreateRIRConfig(grouping_id));
CreateCompositorFrameSink(kFrameSinkIdD, CreateRIRConfig(grouping_id));
CreateCompositorFrameSink(kFrameSinkIdE, CreateRIRConfig(grouping_id));
// Set up initial hierarchy.
// root1 -> A -> B -> C
// + -> D
// root2 -> E
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdRoot2, kFrameSinkIdE);
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
EXPECT_EQ(
GetMockInputManager()->GetParentRenderInputRouterSupport(kFrameSinkIdB),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdA));
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdC);
EXPECT_EQ(
GetMockInputManager()->GetParentRenderInputRouterSupport(kFrameSinkIdC),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdB));
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdD);
EXPECT_EQ(
GetMockInputManager()->GetParentRenderInputRouterSupport(kFrameSinkIdD),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdB));
EXPECT_EQ(
GetMockInputManager()->GetRootRenderInputRouterSupport(kFrameSinkIdB),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdA));
EXPECT_EQ(
GetMockInputManager()->GetRootRenderInputRouterSupport(kFrameSinkIdC),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdA));
EXPECT_EQ(
GetMockInputManager()->GetRootRenderInputRouterSupport(kFrameSinkIdD),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdA));
// Attach A into root2's subtree, like a window moving across displays.
// root1 -> A -> B -> C
// + -> D
// root2 -> E -> A -> B -> C
// + -> D
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdE, kFrameSinkIdA);
// With the heuristic of just keeping existing parent in the face of multiple,
// no client's corresponding RootCompositorFrameSink should change.
EXPECT_EQ(
GetMockInputManager()->GetRootRenderInputRouterSupport(kFrameSinkIdB),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdA));
EXPECT_EQ(
GetMockInputManager()->GetRootRenderInputRouterSupport(kFrameSinkIdC),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdA));
EXPECT_EQ(
GetMockInputManager()->GetRootRenderInputRouterSupport(kFrameSinkIdD),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdA));
// Detach A from root1.
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
// root1
// root2 -> E -> A -> B -> C
// + -> D
EXPECT_EQ(
GetMockInputManager()->GetRootRenderInputRouterSupport(kFrameSinkIdB),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdE));
EXPECT_EQ(
GetMockInputManager()->GetRootRenderInputRouterSupport(kFrameSinkIdC),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdE));
EXPECT_EQ(
GetMockInputManager()->GetRootRenderInputRouterSupport(kFrameSinkIdD),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdE));
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdRoot2, kFrameSinkIdE);
// root1
// root2
// E -> A -> B -> C
// + -> D
EXPECT_EQ(
GetMockInputManager()->GetRootRenderInputRouterSupport(kFrameSinkIdD),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdE));
EXPECT_EQ(
GetMockInputManager()->GetRootRenderInputRouterSupport(kFrameSinkIdA),
GetMockInputManager()->GetSupportForFrameSink(kFrameSinkIdE));
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdD);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdC);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdE, kFrameSinkIdA);
// Delete RootCompositorFrameSinks.
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot);
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot2);
// Invalidating should destroy the CompositorFrameSinkImpl's.
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
manager_->InvalidateFrameSinkId(kFrameSinkIdB);
manager_->InvalidateFrameSinkId(kFrameSinkIdC);
manager_->InvalidateFrameSinkId(kFrameSinkIdD);
manager_->InvalidateFrameSinkId(kFrameSinkIdE);
}
TEST_P(AndroidFrameSinkManagerTest, EmbeddedRenderInputRouters) {
const bool expected_creation =
input::InputUtils::IsTransferInputToVizSupported();
if (!expected_creation) {
return;
}
base::UnguessableToken grouping_id = base::UnguessableToken::Create();
RootCompositorFrameSinkData root_data1;
manager_->CreateRootCompositorFrameSink(
root_data1.BuildParams(kFrameSinkIdRoot));
EXPECT_TRUE(CompositorFrameSinkExists(kFrameSinkIdRoot));
RootCompositorFrameSinkData root_data2;
manager_->CreateRootCompositorFrameSink(
root_data2.BuildParams(kFrameSinkIdRoot2));
EXPECT_TRUE(CompositorFrameSinkExists(kFrameSinkIdRoot2));
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
manager_->RegisterFrameSinkId(kFrameSinkIdB, true /* report_activation */);
manager_->RegisterFrameSinkId(kFrameSinkIdC, true /* report_activation */);
manager_->RegisterFrameSinkId(kFrameSinkIdD, true /* report_activation */);
manager_->RegisterFrameSinkId(kFrameSinkIdE, true /* report_activation */);
// Create CompositorFrameSinkImpl's.
CreateCompositorFrameSink(kFrameSinkIdA, CreateRIRConfig(grouping_id));
CreateCompositorFrameSink(kFrameSinkIdB, CreateRIRConfig(grouping_id));
CreateCompositorFrameSink(kFrameSinkIdC, CreateRIRConfig(grouping_id));
CreateCompositorFrameSink(kFrameSinkIdD, CreateRIRConfig(grouping_id));
CreateCompositorFrameSink(kFrameSinkIdE, CreateRIRConfig(grouping_id));
// Set up initial hierarchy.
// root1 -> A -> B -> C
// + -> D
// root2 -> E
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdRoot2, kFrameSinkIdE);
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdC);
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdD);
EXPECT_THAT(
GetEmbeddedRenderInputRouters(kFrameSinkIdA),
testing::ContainerEq(base::flat_set<FrameSinkId>({kFrameSinkIdB})));
EXPECT_THAT(GetEmbeddedRenderInputRouters(kFrameSinkIdB),
testing::ContainerEq(
base::flat_set<FrameSinkId>({kFrameSinkIdC, kFrameSinkIdD})));
EXPECT_THAT(GetEmbeddedRenderInputRouters(kFrameSinkIdC),
testing::ContainerEq(base::flat_set<FrameSinkId>({})));
// Attach A into root2's subtree, like a window moving across displays.
// root1 -> A -> B -> C
// + -> D
// root2 -> E -> A -> B -> C
// + -> D
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdE, kFrameSinkIdA);
// Detach A from root1.
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
// root1
// root2 -> E -> A -> B -> C
// + -> D
EXPECT_THAT(
GetEmbeddedRenderInputRouters(kFrameSinkIdE),
testing::ContainerEq(base::flat_set<FrameSinkId>({kFrameSinkIdA})));
EXPECT_THAT(
GetEmbeddedRenderInputRouters(kFrameSinkIdA),
testing::ContainerEq(base::flat_set<FrameSinkId>({kFrameSinkIdB})));
EXPECT_THAT(GetEmbeddedRenderInputRouters(kFrameSinkIdB),
testing::ContainerEq(
base::flat_set<FrameSinkId>({kFrameSinkIdC, kFrameSinkIdD})));
EXPECT_THAT(
GetEmbeddedRenderInputRouters(kFrameSinkIdRoot2),
testing::ContainerEq(base::flat_set<FrameSinkId>({kFrameSinkIdE})));
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdRoot2, kFrameSinkIdE);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdD);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdC);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdE, kFrameSinkIdA);
// Delete RootCompositorFrameSinks.
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot);
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot2);
// Invalidating should destroy the CompositorFrameSinkImpl's.
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
manager_->InvalidateFrameSinkId(kFrameSinkIdB);
manager_->InvalidateFrameSinkId(kFrameSinkIdC);
manager_->InvalidateFrameSinkId(kFrameSinkIdD);
manager_->InvalidateFrameSinkId(kFrameSinkIdE);
}
TEST_P(AndroidFrameSinkManagerTest, ReconstructsRenderInputRouterSupports) {
const bool expected_creation =
input::InputUtils::IsTransferInputToVizSupported();
if (!expected_creation) {
return;
}
base::UnguessableToken grouping_id = base::UnguessableToken::Create();
RootCompositorFrameSinkData root_data1;
manager_->CreateRootCompositorFrameSink(
root_data1.BuildParams(kFrameSinkIdRoot));
EXPECT_TRUE(CompositorFrameSinkExists(kFrameSinkIdRoot));
RootCompositorFrameSinkData root_data2;
manager_->CreateRootCompositorFrameSink(
root_data2.BuildParams(kFrameSinkIdRoot2));
EXPECT_TRUE(CompositorFrameSinkExists(kFrameSinkIdRoot2));
manager_->RegisterFrameSinkId(kFrameSinkIdA, true /* report_activation */);
manager_->RegisterFrameSinkId(kFrameSinkIdB, true /* report_activation */);
// Create CompositorFrameSinkImpl's.
CreateCompositorFrameSink(kFrameSinkIdA, CreateRIRConfig(grouping_id));
CreateCompositorFrameSink(kFrameSinkIdB, CreateRIRConfig(grouping_id));
CreateCompositorFrameSink(kFrameSinkIdC, CreateRIRConfig(grouping_id));
EXPECT_TRUE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdA));
EXPECT_TRUE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdB));
EXPECT_TRUE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdC));
// root1 -> A
// -> C
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdC);
// root2 -> B
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdRoot2, kFrameSinkIdB);
// RenderInputRouterSupport is reconstructed as non-child support.
EXPECT_FALSE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdA));
EXPECT_FALSE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdB));
EXPECT_FALSE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdC));
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdA);
// `A` has multiple parents, nothing should have happened until the number of
// parents go back to 1.
EXPECT_FALSE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdA));
// root1 -> C
// root2 -> B -> A
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
// `A` becomes a child support.
EXPECT_TRUE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdA));
// root1
// root2 -> B -> A
// -> C
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdC);
EXPECT_FALSE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdC));
// C becomes a child support.
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdC);
EXPECT_TRUE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdC));
// root1 -> A
// root2 -> B -> C
// Move A back under root 1
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
// `A` stays as a child support since it has multiple parents.
EXPECT_TRUE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdA));
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdA);
EXPECT_FALSE(IsRenderInputRouterSupportChildFrame(kFrameSinkIdA));
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdRoot2, kFrameSinkIdB);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdC);
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot);
manager_->InvalidateFrameSinkId(kFrameSinkIdRoot2);
manager_->InvalidateFrameSinkId(kFrameSinkIdA);
manager_->InvalidateFrameSinkId(kFrameSinkIdB);
manager_->InvalidateFrameSinkId(kFrameSinkIdC);
}
INSTANTIATE_TEST_SUITE_P(All,
AndroidFrameSinkManagerTest,
::testing::Bool(),
[](auto& info) {
return info.param ? "InputOnViz_Enabled"
: "InputOnViz_Disabled";
});
#endif // BUILDFLAG(IS_ANDROID)
namespace {
enum RegisterOrder { REGISTER_HIERARCHY_FIRST, REGISTER_CLIENTS_FIRST };
enum UnregisterOrder { UNREGISTER_HIERARCHY_FIRST, UNREGISTER_CLIENTS_FIRST };
enum BFSOrder { BFS_FIRST, BFS_SECOND, BFS_THIRD };
static const RegisterOrder kRegisterOrderList[] = {REGISTER_HIERARCHY_FIRST,
REGISTER_CLIENTS_FIRST};
static const UnregisterOrder kUnregisterOrderList[] = {
UNREGISTER_HIERARCHY_FIRST, UNREGISTER_CLIENTS_FIRST};
static const BFSOrder kBFSOrderList[] = {BFS_FIRST, BFS_SECOND, BFS_THIRD};
} // namespace
// In practice, registering and unregistering both parent/child relationships
// and CompositorFrameSinkSupports can happen in any ordering with respect to
// each other. These following tests verify that all the data structures
// are properly set up and cleaned up under the four permutations of orderings
// of this nesting.
class FrameSinkManagerOrderingTest : public FrameSinkManagerTest {
public:
FrameSinkManagerOrderingTest()
: hierarchy_registered_(false),
clients_registered_(false),
bfs_registered_(false) {
AssertCorrectBFSState();
}
~FrameSinkManagerOrderingTest() override {
EXPECT_FALSE(hierarchy_registered_);
EXPECT_FALSE(clients_registered_);
EXPECT_FALSE(bfs_registered_);
AssertCorrectBFSState();
}
void RegisterHierarchy() {
DCHECK(!hierarchy_registered_);
hierarchy_registered_ = true;
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
manager_->RegisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdC);
AssertCorrectBFSState();
}
void UnregisterHierarchy() {
DCHECK(hierarchy_registered_);
hierarchy_registered_ = false;
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
manager_->UnregisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdC);
AssertCorrectBFSState();
}
void RegisterClients() {
DCHECK(!clients_registered_);
clients_registered_ = true;
client_a_ = CreateCompositorFrameSinkSupport(kFrameSinkIdA);
client_b_ = CreateCompositorFrameSinkSupport(kFrameSinkIdB);
client_c_ = CreateCompositorFrameSinkSupport(kFrameSinkIdC);
AssertCorrectBFSState();
}
void UnregisterClients() {
DCHECK(clients_registered_);
clients_registered_ = false;
client_a_.reset();
client_b_.reset();
client_c_.reset();
AssertCorrectBFSState();
}
void RegisterBFS() {
DCHECK(!bfs_registered_);
bfs_registered_ = true;
manager_->RegisterBeginFrameSource(&source_, kFrameSinkIdA);
AssertCorrectBFSState();
}
void UnregisterBFS() {
DCHECK(bfs_registered_);
bfs_registered_ = false;
manager_->UnregisterBeginFrameSource(&source_);
AssertCorrectBFSState();
}
void AssertEmptyBFS() {
EXPECT_EQ(nullptr, GetBeginFrameSource(client_a_));
EXPECT_EQ(nullptr, GetBeginFrameSource(client_b_));
EXPECT_EQ(nullptr, GetBeginFrameSource(client_c_));
}
void AssertAllValidBFS() {
EXPECT_EQ(&source_, GetBeginFrameSource(client_a_));
EXPECT_EQ(&source_, GetBeginFrameSource(client_b_));
EXPECT_EQ(&source_, GetBeginFrameSource(client_c_));
}
protected:
void AssertCorrectBFSState() {
if (!clients_registered_)
return;
if (!bfs_registered_) {
AssertEmptyBFS();
return;
}
if (!hierarchy_registered_) {
// A valid but not attached to anything.
EXPECT_EQ(&source_, GetBeginFrameSource(client_a_));
EXPECT_EQ(nullptr, GetBeginFrameSource(client_b_));
EXPECT_EQ(nullptr, GetBeginFrameSource(client_c_));
return;
}
AssertAllValidBFS();
}
StubBeginFrameSource source_;
// A -> B -> C hierarchy, with A always having the BFS.
std::unique_ptr<CompositorFrameSinkSupport> client_a_;
std::unique_ptr<CompositorFrameSinkSupport> client_b_;
std::unique_ptr<CompositorFrameSinkSupport> client_c_;
bool hierarchy_registered_;
bool clients_registered_;
bool bfs_registered_;
};
class FrameSinkManagerOrderingParamTest
: public FrameSinkManagerOrderingTest,
public ::testing::WithParamInterface<
std::tuple<RegisterOrder, UnregisterOrder, BFSOrder>> {};
TEST_P(FrameSinkManagerOrderingParamTest, Ordering) {
// Test the four permutations of client/hierarchy setting/unsetting and test
// each place the BFS can be added and removed. The BFS and the
// client/hierarchy are less related, so BFS is tested independently instead
// of every permutation of BFS setting and unsetting.
// The register/unregister functions themselves test most of the state.
RegisterOrder register_order = std::get<0>(GetParam());
UnregisterOrder unregister_order = std::get<1>(GetParam());
BFSOrder bfs_order = std::get<2>(GetParam());
// Attach everything up in the specified order.
if (bfs_order == BFS_FIRST)
RegisterBFS();
if (register_order == REGISTER_HIERARCHY_FIRST)
RegisterHierarchy();
else
RegisterClients();
if (bfs_order == BFS_SECOND)
RegisterBFS();
if (register_order == REGISTER_HIERARCHY_FIRST)
RegisterClients();
else
RegisterHierarchy();
if (bfs_order == BFS_THIRD)
RegisterBFS();
// Everything hooked up, so should be valid.
AssertAllValidBFS();
// Detach everything in the specified order.
if (bfs_order == BFS_THIRD)
UnregisterBFS();
if (unregister_order == UNREGISTER_HIERARCHY_FIRST)
UnregisterHierarchy();
else
UnregisterClients();
if (bfs_order == BFS_SECOND)
UnregisterBFS();
if (unregister_order == UNREGISTER_HIERARCHY_FIRST)
UnregisterClients();
else
UnregisterHierarchy();
if (bfs_order == BFS_FIRST)
UnregisterBFS();
}
INSTANTIATE_TEST_SUITE_P(
FrameSinkManagerOrderingParamTestInstantiation,
FrameSinkManagerOrderingParamTest,
::testing::Combine(::testing::ValuesIn(kRegisterOrderList),
::testing::ValuesIn(kUnregisterOrderList),
::testing::ValuesIn(kBFSOrderList)));
} // namespace viz
|