OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 1941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 // This test performs the following: | 1952 // This test performs the following: |
1953 // Setup: | 1953 // Setup: |
1954 // - Two tilings, one active one recycled with all tiles shared. | 1954 // - Two tilings, one active one recycled with all tiles shared. |
1955 // Procedure: | 1955 // Procedure: |
1956 // - Viewport moves somewhere far away and active tiling clears tiles. | 1956 // - Viewport moves somewhere far away and active tiling clears tiles. |
1957 // - Viewport moves back and a new active tiling tile is created. | 1957 // - Viewport moves back and a new active tiling tile is created. |
1958 // Result: | 1958 // Result: |
1959 // - Recycle tiling does _not_ have the tile in the same location (thus it | 1959 // - Recycle tiling does _not_ have the tile in the same location (thus it |
1960 // will be shared next time a pending tiling is created). | 1960 // will be shared next time a pending tiling is created). |
1961 | 1961 |
1962 FakePictureLayerTilingClient client; | 1962 FakePictureLayerTilingClient active_client; |
1963 scoped_ptr<TestablePictureLayerTiling> tiling; | 1963 scoped_ptr<TestablePictureLayerTiling> active_tiling; |
1964 | 1964 |
1965 client.SetTileSize(gfx::Size(100, 100)); | 1965 active_client.SetTileSize(gfx::Size(100, 100)); |
1966 client.set_tree(ACTIVE_TREE); | 1966 active_client.set_tree(ACTIVE_TREE); |
1967 client.set_max_tiles_for_interest_area(10); | 1967 active_client.set_max_tiles_for_interest_area(10); |
1968 tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | 1968 active_tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
1969 gfx::Size(10000, 10000), | 1969 gfx::Size(10000, 10000), |
1970 &client); | 1970 &active_client); |
1971 // Create all tiles on this tiling. | 1971 // Create all tiles on this tiling. |
1972 tiling->UpdateTilePriorities(ACTIVE_TREE, | 1972 active_tiling->UpdateTilePriorities(ACTIVE_TREE, |
1973 gfx::Rect(0, 0, 100, 100), | |
1974 1.0f, | |
1975 1.0f, | |
1976 NULL, // occlusion tracker | |
1977 NULL, // render target | |
1978 gfx::Transform()); // draw transform | |
1979 | |
1980 FakePictureLayerTilingClient second_client; | |
1981 second_client.SetTileSize(gfx::Size(100, 100)); | |
1982 second_client.set_tree(PENDING_TREE); | |
1983 second_client.set_twin_tiling(tiling.get()); | |
1984 second_client.set_max_tiles_for_interest_area(10); | |
1985 | |
1986 scoped_ptr<TestablePictureLayerTiling> second_tiling; | |
1987 second_tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale | |
1988 gfx::Size(10000, 10000), | |
1989 &second_client); | |
1990 | |
1991 // Create all tiles on the second tiling. All tiles should be shared. | |
1992 second_tiling->UpdateTilePriorities(ACTIVE_TREE, | |
1993 gfx::Rect(0, 0, 100, 100), | 1973 gfx::Rect(0, 0, 100, 100), |
1994 1.0f, | 1974 1.0f, |
1995 1.0f, | 1975 1.0f, |
1996 NULL, // occlusion tracker | 1976 NULL, // occlusion tracker |
1997 NULL, // render target | 1977 NULL, // render target |
1998 gfx::Transform()); // draw transform | 1978 gfx::Transform()); // draw transform |
1999 | 1979 |
2000 // Verify that tiles exist and are shared. | 1980 FakePictureLayerTilingClient recycle_client; |
2001 ASSERT_TRUE(tiling->TileAt(0, 0)); | 1981 recycle_client.SetTileSize(gfx::Size(100, 100)); |
2002 ASSERT_EQ(tiling->TileAt(0, 0), second_tiling->TileAt(0, 0)); | 1982 recycle_client.set_tree(PENDING_TREE); |
| 1983 recycle_client.set_twin_tiling(active_tiling.get()); |
| 1984 recycle_client.set_max_tiles_for_interest_area(10); |
| 1985 |
| 1986 scoped_ptr<TestablePictureLayerTiling> recycle_tiling; |
| 1987 recycle_tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 1988 gfx::Size(10000, 10000), |
| 1989 &recycle_client); |
| 1990 |
| 1991 // Create all tiles on the second tiling. All tiles should be shared. |
| 1992 recycle_tiling->UpdateTilePriorities(PENDING_TREE, |
| 1993 gfx::Rect(0, 0, 100, 100), |
| 1994 1.0f, |
| 1995 1.0f, |
| 1996 NULL, // occlusion tracker |
| 1997 NULL, // render target |
| 1998 gfx::Transform()); // draw transform |
2003 | 1999 |
2004 // Set the second tiling as recycled. | 2000 // Set the second tiling as recycled. |
2005 client.set_twin_tiling(NULL); | 2001 active_client.set_twin_tiling(NULL); |
2006 client.set_recycled_twin_tiling(second_tiling.get()); | 2002 active_client.set_recycled_twin_tiling(recycle_tiling.get()); |
2007 second_client.set_twin_tiling(NULL); | 2003 recycle_client.set_twin_tiling(NULL); |
| 2004 |
| 2005 // Verify that tiles exist and are shared. |
| 2006 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
| 2007 EXPECT_TRUE(recycle_tiling->TileAt(0, 0)); |
| 2008 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); |
2008 | 2009 |
2009 // Move the viewport far away from the (0, 0) tile. | 2010 // Move the viewport far away from the (0, 0) tile. |
2010 tiling->UpdateTilePriorities(ACTIVE_TREE, | 2011 active_tiling->UpdateTilePriorities(ACTIVE_TREE, |
2011 gfx::Rect(9000, 9000, 100, 100), | 2012 gfx::Rect(9000, 9000, 100, 100), |
2012 1.0f, | 2013 1.0f, |
2013 2.0, | 2014 2.0, |
2014 NULL, // occlusion tracker | 2015 NULL, // occlusion tracker |
2015 NULL, // render target | 2016 NULL, // render target |
2016 gfx::Transform()); // draw transform | 2017 gfx::Transform()); // draw transform |
2017 // Ensure the tile was deleted. | 2018 // Ensure the tile was deleted on both tilings. |
2018 EXPECT_FALSE(tiling->TileAt(0, 0)); | 2019 EXPECT_FALSE(active_tiling->TileAt(0, 0)); |
| 2020 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); |
2019 | 2021 |
2020 // Move the viewport back to (0, 0) tile. | 2022 // Move the viewport back to (0, 0) tile. |
2021 tiling->UpdateTilePriorities(ACTIVE_TREE, | 2023 active_tiling->UpdateTilePriorities(ACTIVE_TREE, |
2022 gfx::Rect(0, 0, 100, 100), | 2024 gfx::Rect(0, 0, 100, 100), |
2023 1.0f, | 2025 1.0f, |
2024 3.0, | 2026 3.0, |
2025 NULL, // occlusion tracker | 2027 NULL, // occlusion tracker |
2026 NULL, // render target | 2028 NULL, // render target |
2027 gfx::Transform()); // draw transform | 2029 gfx::Transform()); // draw transform |
2028 | 2030 |
2029 // Ensure that we now have a tile here, but the recycle tiling does not. | 2031 // Ensure that we now have a tile here, but the recycle tiling does not. |
2030 EXPECT_TRUE(tiling->TileAt(0, 0)); | 2032 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
2031 EXPECT_FALSE(second_tiling->TileAt(0, 0)); | 2033 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); |
| 2034 } |
| 2035 |
| 2036 TEST(PictureLayerTilingTest, RecycledTilesClearedOnReset) { |
| 2037 FakePictureLayerTilingClient active_client; |
| 2038 scoped_ptr<TestablePictureLayerTiling> active_tiling; |
| 2039 |
| 2040 active_client.SetTileSize(gfx::Size(100, 100)); |
| 2041 active_client.set_tree(ACTIVE_TREE); |
| 2042 active_tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 2043 gfx::Size(100, 100), |
| 2044 &active_client); |
| 2045 // Create all tiles on this tiling. |
| 2046 active_tiling->UpdateTilePriorities(ACTIVE_TREE, |
| 2047 gfx::Rect(0, 0, 100, 100), |
| 2048 1.0f, |
| 2049 1.0f, |
| 2050 NULL, // occlusion tracker |
| 2051 NULL, // render target |
| 2052 gfx::Transform()); // draw transform |
| 2053 |
| 2054 FakePictureLayerTilingClient recycle_client; |
| 2055 recycle_client.SetTileSize(gfx::Size(100, 100)); |
| 2056 recycle_client.set_tree(PENDING_TREE); |
| 2057 recycle_client.set_twin_tiling(active_tiling.get()); |
| 2058 recycle_client.set_max_tiles_for_interest_area(10); |
| 2059 |
| 2060 scoped_ptr<TestablePictureLayerTiling> recycle_tiling; |
| 2061 recycle_tiling = TestablePictureLayerTiling::Create(1.0f, // contents_scale |
| 2062 gfx::Size(100, 100), |
| 2063 &recycle_client); |
| 2064 |
| 2065 // Create all tiles on the recycle tiling. All tiles should be shared. |
| 2066 recycle_tiling->UpdateTilePriorities(PENDING_TREE, |
| 2067 gfx::Rect(0, 0, 100, 100), |
| 2068 1.0f, |
| 2069 1.0f, |
| 2070 NULL, // occlusion tracker |
| 2071 NULL, // render target |
| 2072 gfx::Transform()); // draw transform |
| 2073 |
| 2074 // Set the second tiling as recycled. |
| 2075 active_client.set_twin_tiling(NULL); |
| 2076 active_client.set_recycled_twin_tiling(recycle_tiling.get()); |
| 2077 recycle_client.set_twin_tiling(NULL); |
| 2078 |
| 2079 // Verify that tiles exist and are shared. |
| 2080 EXPECT_TRUE(active_tiling->TileAt(0, 0)); |
| 2081 EXPECT_TRUE(recycle_tiling->TileAt(0, 0)); |
| 2082 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0)); |
| 2083 |
| 2084 // Reset the active tiling. The recycle tiles should be released too. |
| 2085 active_tiling->Reset(); |
| 2086 EXPECT_FALSE(active_tiling->TileAt(0, 0)); |
| 2087 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); |
2032 } | 2088 } |
2033 | 2089 |
2034 } // namespace | 2090 } // namespace |
2035 } // namespace cc | 2091 } // namespace cc |
OLD | NEW |