|
27 | 27 | #include "LayerHierarchyTest.h" |
28 | 28 | #include "ui/GraphicTypes.h" |
29 | 29 |
|
| 30 | +#include <com_android_graphics_libgui_flags.h> |
30 | 31 | #include <com_android_graphics_surfaceflinger_flags.h> |
31 | 32 |
|
32 | 33 | #define UPDATE_AND_VERIFY(BUILDER, ...) \ |
@@ -1761,4 +1762,162 @@ TEST_F(LayerSnapshotTest, hideLayerWithNanMatrix) { |
1761 | 1762 | UPDATE_AND_VERIFY(mSnapshotBuilder, {2}); |
1762 | 1763 | EXPECT_TRUE(getSnapshot(1)->isHiddenByPolicy()); |
1763 | 1764 | } |
| 1765 | +TEST_F(LayerSnapshotTest, edgeExtensionPropagatesInHierarchy) { |
| 1766 | + if (!com::android::graphics::libgui::flags::edge_extension_shader()) { |
| 1767 | + GTEST_SKIP() << "Skipping test because edge_extension_shader is off"; |
| 1768 | + } |
| 1769 | + setCrop(1, Rect(0, 0, 20, 20)); |
| 1770 | + setBuffer(1221, |
| 1771 | + std::make_shared<renderengine::mock::FakeExternalTexture>(20 /* width */, |
| 1772 | + 20 /* height */, |
| 1773 | + 42ULL /* bufferId */, |
| 1774 | + HAL_PIXEL_FORMAT_RGBA_8888, |
| 1775 | + 0 /*usage*/)); |
| 1776 | + setEdgeExtensionEffect(12, LEFT); |
| 1777 | + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1778 | + |
| 1779 | + EXPECT_TRUE(getSnapshot({.id = 12})->edgeExtensionEffect.extendsEdge(LEFT)); |
| 1780 | + EXPECT_TRUE(getSnapshot({.id = 121})->edgeExtensionEffect.extendsEdge(LEFT)); |
| 1781 | + EXPECT_TRUE(getSnapshot({.id = 1221})->edgeExtensionEffect.extendsEdge(LEFT)); |
| 1782 | + |
| 1783 | + setEdgeExtensionEffect(12, RIGHT); |
| 1784 | + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1785 | + |
| 1786 | + EXPECT_TRUE(getSnapshot({.id = 12})->edgeExtensionEffect.extendsEdge(RIGHT)); |
| 1787 | + EXPECT_TRUE(getSnapshot({.id = 121})->edgeExtensionEffect.extendsEdge(RIGHT)); |
| 1788 | + EXPECT_TRUE(getSnapshot({.id = 1221})->edgeExtensionEffect.extendsEdge(RIGHT)); |
| 1789 | + |
| 1790 | + setEdgeExtensionEffect(12, TOP); |
| 1791 | + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1792 | + |
| 1793 | + EXPECT_TRUE(getSnapshot({.id = 12})->edgeExtensionEffect.extendsEdge(TOP)); |
| 1794 | + EXPECT_TRUE(getSnapshot({.id = 121})->edgeExtensionEffect.extendsEdge(TOP)); |
| 1795 | + EXPECT_TRUE(getSnapshot({.id = 1221})->edgeExtensionEffect.extendsEdge(TOP)); |
| 1796 | + |
| 1797 | + setEdgeExtensionEffect(12, BOTTOM); |
| 1798 | + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1799 | + |
| 1800 | + EXPECT_TRUE(getSnapshot({.id = 12})->edgeExtensionEffect.extendsEdge(BOTTOM)); |
| 1801 | + EXPECT_TRUE(getSnapshot({.id = 121})->edgeExtensionEffect.extendsEdge(BOTTOM)); |
| 1802 | + EXPECT_TRUE(getSnapshot({.id = 1221})->edgeExtensionEffect.extendsEdge(BOTTOM)); |
| 1803 | +} |
| 1804 | + |
| 1805 | +TEST_F(LayerSnapshotTest, leftEdgeExtensionIncreaseBoundSizeWithinCrop) { |
| 1806 | + // The left bound is extended when shifting to the right |
| 1807 | + if (!com::android::graphics::libgui::flags::edge_extension_shader()) { |
| 1808 | + GTEST_SKIP() << "Skipping test because edge_extension_shader is off"; |
| 1809 | + } |
| 1810 | + setCrop(1, Rect(0, 0, 20, 20)); |
| 1811 | + const int texSize = 10; |
| 1812 | + setBuffer(1221, |
| 1813 | + std::make_shared<renderengine::mock::FakeExternalTexture>(texSize /* width */, |
| 1814 | + texSize /* height*/, |
| 1815 | + 42ULL /* bufferId */, |
| 1816 | + HAL_PIXEL_FORMAT_RGBA_8888, |
| 1817 | + 0 /*usage*/)); |
| 1818 | + const float translation = 5.0; |
| 1819 | + setPosition(12, translation, 0); |
| 1820 | + setEdgeExtensionEffect(12, LEFT); |
| 1821 | + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1822 | + EXPECT_EQ(getSnapshot({.id = 1221})->transformedBounds.right, texSize + translation); |
| 1823 | + EXPECT_LT(getSnapshot({.id = 1221})->transformedBounds.left, translation); |
| 1824 | + EXPECT_GE(getSnapshot({.id = 1221})->transformedBounds.left, 0.0); |
| 1825 | +} |
| 1826 | + |
| 1827 | +TEST_F(LayerSnapshotTest, rightEdgeExtensionIncreaseBoundSizeWithinCrop) { |
| 1828 | + // The right bound is extended when shifting to the left |
| 1829 | + if (!com::android::graphics::libgui::flags::edge_extension_shader()) { |
| 1830 | + GTEST_SKIP() << "Skipping test because edge_extension_shader is off"; |
| 1831 | + } |
| 1832 | + const int crop = 20; |
| 1833 | + setCrop(1, Rect(0, 0, crop, crop)); |
| 1834 | + const int texSize = 10; |
| 1835 | + setBuffer(1221, |
| 1836 | + std::make_shared<renderengine::mock::FakeExternalTexture>(texSize /* width */, |
| 1837 | + texSize /* height*/, |
| 1838 | + 42ULL /* bufferId */, |
| 1839 | + HAL_PIXEL_FORMAT_RGBA_8888, |
| 1840 | + 0 /*usage*/)); |
| 1841 | + const float translation = -5.0; |
| 1842 | + setPosition(12, translation, 0); |
| 1843 | + setEdgeExtensionEffect(12, RIGHT); |
| 1844 | + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1845 | + EXPECT_EQ(getSnapshot({.id = 1221})->transformedBounds.left, 0); |
| 1846 | + EXPECT_GT(getSnapshot({.id = 1221})->transformedBounds.right, texSize + translation); |
| 1847 | + EXPECT_LE(getSnapshot({.id = 1221})->transformedBounds.right, (float)crop); |
| 1848 | +} |
| 1849 | + |
| 1850 | +TEST_F(LayerSnapshotTest, topEdgeExtensionIncreaseBoundSizeWithinCrop) { |
| 1851 | + // The top bound is extended when shifting to the bottom |
| 1852 | + if (!com::android::graphics::libgui::flags::edge_extension_shader()) { |
| 1853 | + GTEST_SKIP() << "Skipping test because edge_extension_shader is off"; |
| 1854 | + } |
| 1855 | + setCrop(1, Rect(0, 0, 20, 20)); |
| 1856 | + const int texSize = 10; |
| 1857 | + setBuffer(1221, |
| 1858 | + std::make_shared<renderengine::mock::FakeExternalTexture>(texSize /* width */, |
| 1859 | + texSize /* height*/, |
| 1860 | + 42ULL /* bufferId */, |
| 1861 | + HAL_PIXEL_FORMAT_RGBA_8888, |
| 1862 | + 0 /*usage*/)); |
| 1863 | + const float translation = 5.0; |
| 1864 | + setPosition(12, 0, translation); |
| 1865 | + setEdgeExtensionEffect(12, TOP); |
| 1866 | + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1867 | + EXPECT_EQ(getSnapshot({.id = 1221})->transformedBounds.bottom, texSize + translation); |
| 1868 | + EXPECT_LT(getSnapshot({.id = 1221})->transformedBounds.top, translation); |
| 1869 | + EXPECT_GE(getSnapshot({.id = 1221})->transformedBounds.top, 0.0); |
| 1870 | +} |
| 1871 | + |
| 1872 | +TEST_F(LayerSnapshotTest, bottomEdgeExtensionIncreaseBoundSizeWithinCrop) { |
| 1873 | + // The bottom bound is extended when shifting to the top |
| 1874 | + if (!com::android::graphics::libgui::flags::edge_extension_shader()) { |
| 1875 | + GTEST_SKIP() << "Skipping test because edge_extension_shader is off"; |
| 1876 | + } |
| 1877 | + const int crop = 20; |
| 1878 | + setCrop(1, Rect(0, 0, crop, crop)); |
| 1879 | + const int texSize = 10; |
| 1880 | + setBuffer(1221, |
| 1881 | + std::make_shared<renderengine::mock::FakeExternalTexture>(texSize /* width */, |
| 1882 | + texSize /* height*/, |
| 1883 | + 42ULL /* bufferId */, |
| 1884 | + HAL_PIXEL_FORMAT_RGBA_8888, |
| 1885 | + 0 /*usage*/)); |
| 1886 | + const float translation = -5.0; |
| 1887 | + setPosition(12, 0, translation); |
| 1888 | + setEdgeExtensionEffect(12, BOTTOM); |
| 1889 | + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1890 | + EXPECT_EQ(getSnapshot({.id = 1221})->transformedBounds.top, 0); |
| 1891 | + EXPECT_GT(getSnapshot({.id = 1221})->transformedBounds.bottom, texSize - translation); |
| 1892 | + EXPECT_LE(getSnapshot({.id = 1221})->transformedBounds.bottom, (float)crop); |
| 1893 | +} |
| 1894 | + |
| 1895 | +TEST_F(LayerSnapshotTest, multipleEdgeExtensionIncreaseBoundSizeWithinCrop) { |
| 1896 | + // The left bound is extended when shifting to the right |
| 1897 | + if (!com::android::graphics::libgui::flags::edge_extension_shader()) { |
| 1898 | + GTEST_SKIP() << "Skipping test because edge_extension_shader is off"; |
| 1899 | + } |
| 1900 | + const int crop = 20; |
| 1901 | + setCrop(1, Rect(0, 0, crop, crop)); |
| 1902 | + const int texSize = 10; |
| 1903 | + setBuffer(1221, |
| 1904 | + std::make_shared<renderengine::mock::FakeExternalTexture>(texSize /* width */, |
| 1905 | + texSize /* height*/, |
| 1906 | + 42ULL /* bufferId */, |
| 1907 | + HAL_PIXEL_FORMAT_RGBA_8888, |
| 1908 | + 0 /*usage*/)); |
| 1909 | + const float translation = 5.0; |
| 1910 | + setPosition(12, translation, translation); |
| 1911 | + setEdgeExtensionEffect(12, LEFT | RIGHT | TOP | BOTTOM); |
| 1912 | + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); |
| 1913 | + EXPECT_GT(getSnapshot({.id = 1221})->transformedBounds.right, texSize + translation); |
| 1914 | + EXPECT_LE(getSnapshot({.id = 1221})->transformedBounds.right, (float)crop); |
| 1915 | + EXPECT_LT(getSnapshot({.id = 1221})->transformedBounds.left, translation); |
| 1916 | + EXPECT_GE(getSnapshot({.id = 1221})->transformedBounds.left, 0.0); |
| 1917 | + EXPECT_GT(getSnapshot({.id = 1221})->transformedBounds.bottom, texSize + translation); |
| 1918 | + EXPECT_LE(getSnapshot({.id = 1221})->transformedBounds.bottom, (float)crop); |
| 1919 | + EXPECT_LT(getSnapshot({.id = 1221})->transformedBounds.top, translation); |
| 1920 | + EXPECT_GE(getSnapshot({.id = 1221})->transformedBounds.top, 0); |
| 1921 | +} |
| 1922 | + |
1764 | 1923 | } // namespace android::surfaceflinger::frontend |
0 commit comments