Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Side by Side Diff: cc/resources/picture_layer_tiling_unittest.cc

Issue 1051993002: cc: Remove tile sharing from tilings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
6
7 #include <limits> 5 #include <limits>
8 #include <set> 6 #include <set>
9 7
10 #include "cc/base/math_util.h" 8 #include "cc/base/math_util.h"
9 #include "cc/resources/picture_layer_tiling.h"
11 #include "cc/resources/picture_layer_tiling_set.h" 10 #include "cc/resources/picture_layer_tiling_set.h"
12 #include "cc/test/fake_output_surface.h" 11 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/fake_output_surface_client.h" 12 #include "cc/test/fake_output_surface_client.h"
14 #include "cc/test/fake_picture_layer_tiling_client.h" 13 #include "cc/test/fake_picture_layer_tiling_client.h"
15 #include "cc/test/fake_picture_pile_impl.h" 14 #include "cc/test/fake_picture_pile_impl.h"
16 #include "cc/test/test_context_provider.h" 15 #include "cc/test/test_context_provider.h"
17 #include "cc/test/test_shared_bitmap_manager.h" 16 #include "cc/test/test_shared_bitmap_manager.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/gfx/geometry/quad_f.h" 18 #include "ui/gfx/geometry/quad_f.h"
20 #include "ui/gfx/geometry/rect_conversions.h" 19 #include "ui/gfx/geometry/rect_conversions.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 float contents_scale, 81 float contents_scale,
83 const gfx::Size& layer_bounds) { 82 const gfx::Size& layer_bounds) {
84 client_.SetTileSize(tile_size); 83 client_.SetTileSize(tile_size);
85 client_.set_tree(PENDING_TREE); 84 client_.set_tree(PENDING_TREE);
86 scoped_refptr<FakePicturePileImpl> pile = 85 scoped_refptr<FakePicturePileImpl> pile =
87 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds); 86 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds);
88 tiling_ = TestablePictureLayerTiling::Create(contents_scale, pile, &client_, 87 tiling_ = TestablePictureLayerTiling::Create(contents_scale, pile, &client_,
89 LayerTreeSettings()); 88 LayerTreeSettings());
90 } 89 }
91 90
91 void InitializeActive(const gfx::Size& tile_size,
92 float contents_scale,
93 const gfx::Size& layer_bounds) {
94 client_.SetTileSize(tile_size);
95 client_.set_tree(ACTIVE_TREE);
96 scoped_refptr<FakePicturePileImpl> pile =
97 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(layer_bounds);
98 tiling_ = TestablePictureLayerTiling::Create(contents_scale, pile, &client_,
99 LayerTreeSettings());
100 }
101
92 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) { 102 void SetLiveRectAndVerifyTiles(const gfx::Rect& live_tiles_rect) {
93 tiling_->SetLiveTilesRect(live_tiles_rect); 103 tiling_->SetLiveTilesRect(live_tiles_rect);
94 104
95 std::vector<Tile*> tiles = tiling_->AllTilesForTesting(); 105 std::vector<Tile*> tiles = tiling_->AllTilesForTesting();
96 for (std::vector<Tile*>::iterator iter = tiles.begin(); 106 for (std::vector<Tile*>::iterator iter = tiles.begin();
97 iter != tiles.end(); 107 iter != tiles.end();
98 ++iter) { 108 ++iter) {
99 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect())); 109 EXPECT_TRUE(live_tiles_rect.Intersects((*iter)->content_rect()));
100 } 110 }
101 } 111 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 192
183 private: 193 private:
184 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest); 194 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingIteratorTest);
185 }; 195 };
186 196
187 TEST_F(PictureLayerTilingIteratorTest, ResizeDeletesTiles) { 197 TEST_F(PictureLayerTilingIteratorTest, ResizeDeletesTiles) {
188 // Verifies that a resize with invalidation for newly exposed pixels will 198 // Verifies that a resize with invalidation for newly exposed pixels will
189 // deletes tiles that intersect that invalidation. 199 // deletes tiles that intersect that invalidation.
190 gfx::Size tile_size(100, 100); 200 gfx::Size tile_size(100, 100);
191 gfx::Size original_layer_size(10, 10); 201 gfx::Size original_layer_size(10, 10);
192 Initialize(tile_size, 1.f, original_layer_size); 202 InitializeActive(tile_size, 1.f, original_layer_size);
193 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); 203 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size));
194 204
195 // Tiling only has one tile, since its total size is less than one. 205 // Tiling only has one tile, since its total size is less than one.
196 EXPECT_TRUE(tiling_->TileAt(0, 0)); 206 EXPECT_TRUE(tiling_->TileAt(0, 0));
197 207
198 // Stop creating tiles so that any invalidations are left as holes. 208 // Stop creating tiles so that any invalidations are left as holes.
199 gfx::Size new_layer_size(200, 200); 209 gfx::Size new_layer_size(200, 200);
200 scoped_refptr<FakePicturePileImpl> pile = 210 scoped_refptr<FakePicturePileImpl> pile =
201 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(new_layer_size); 211 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(new_layer_size);
202 212
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 for (int j = 0; j < 4; ++j) 408 for (int j = 0; j < 4; ++j)
399 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j; 409 EXPECT_TRUE(tiling_->TileAt(i, j)) << i << "," << j;
400 } 410 }
401 } 411 }
402 412
403 TEST_F(PictureLayerTilingIteratorTest, ResizeOverBorderPixelsDeletesTiles) { 413 TEST_F(PictureLayerTilingIteratorTest, ResizeOverBorderPixelsDeletesTiles) {
404 // Verifies that a resize with invalidation for newly exposed pixels will 414 // Verifies that a resize with invalidation for newly exposed pixels will
405 // deletes tiles that intersect that invalidation. 415 // deletes tiles that intersect that invalidation.
406 gfx::Size tile_size(100, 100); 416 gfx::Size tile_size(100, 100);
407 gfx::Size original_layer_size(99, 99); 417 gfx::Size original_layer_size(99, 99);
408 Initialize(tile_size, 1.f, original_layer_size); 418 InitializeActive(tile_size, 1.f, original_layer_size);
409 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size)); 419 SetLiveRectAndVerifyTiles(gfx::Rect(original_layer_size));
410 420
411 // Tiling only has one tile, since its total size is less than one. 421 // Tiling only has one tile, since its total size is less than one.
412 EXPECT_TRUE(tiling_->TileAt(0, 0)); 422 EXPECT_TRUE(tiling_->TileAt(0, 0));
413 423
414 // Stop creating tiles so that any invalidations are left as holes. 424 // Stop creating tiles so that any invalidations are left as holes.
415 scoped_refptr<FakePicturePileImpl> pile = 425 scoped_refptr<FakePicturePileImpl> pile =
416 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize( 426 FakePicturePileImpl::CreateEmptyPileWithDefaultTileSize(
417 gfx::Size(200, 200)); 427 gfx::Size(200, 200));
418 tiling_->SetRasterSourceAndResize(pile); 428 tiling_->SetRasterSourceAndResize(pile);
(...skipping 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1878 1888
1879 // Create all tiles on the second tiling. All tiles should be shared. 1889 // Create all tiles on the second tiling. All tiles should be shared.
1880 recycle_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 1890 recycle_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f,
1881 1.0f, Occlusion()); 1891 1.0f, Occlusion());
1882 1892
1883 // Set the second tiling as recycled. 1893 // Set the second tiling as recycled.
1884 active_client.set_twin_tiling(NULL); 1894 active_client.set_twin_tiling(NULL);
1885 active_client.set_recycled_twin_tiling(recycle_tiling.get()); 1895 active_client.set_recycled_twin_tiling(recycle_tiling.get());
1886 recycle_client.set_twin_tiling(NULL); 1896 recycle_client.set_twin_tiling(NULL);
1887 1897
1888 // Verify that tiles exist and are shared.
1889 EXPECT_TRUE(active_tiling->TileAt(0, 0)); 1898 EXPECT_TRUE(active_tiling->TileAt(0, 0));
1890 EXPECT_TRUE(recycle_tiling->TileAt(0, 0)); 1899 EXPECT_FALSE(recycle_tiling->TileAt(0, 0));
1891 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0));
1892 1900
1893 // Move the viewport far away from the (0, 0) tile. 1901 // Move the viewport far away from the (0, 0) tile.
1894 active_tiling->ComputeTilePriorityRects(gfx::Rect(9000, 9000, 100, 100), 1.0f, 1902 active_tiling->ComputeTilePriorityRects(gfx::Rect(9000, 9000, 100, 100), 1.0f,
1895 2.0, Occlusion()); 1903 2.0, Occlusion());
1896 // Ensure the tile was deleted on both tilings. 1904 // Ensure the tile was deleted.
1897 EXPECT_FALSE(active_tiling->TileAt(0, 0)); 1905 EXPECT_FALSE(active_tiling->TileAt(0, 0));
1898 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); 1906 EXPECT_FALSE(recycle_tiling->TileAt(0, 0));
1899 1907
1900 // Move the viewport back to (0, 0) tile. 1908 // Move the viewport back to (0, 0) tile.
1901 active_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 3.0, 1909 active_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 3.0,
1902 Occlusion()); 1910 Occlusion());
1903 1911
1904 // Ensure that we now have a tile here on both tilings again. 1912 // Ensure that we now have a tile here on both active.
1905 EXPECT_TRUE(active_tiling->TileAt(0, 0)); 1913 EXPECT_TRUE(active_tiling->TileAt(0, 0));
1906 EXPECT_TRUE(recycle_tiling->TileAt(0, 0)); 1914 EXPECT_FALSE(recycle_tiling->TileAt(0, 0));
1907 } 1915 }
1908 1916
1909 TEST(PictureLayerTilingTest, RecycledTilesClearedOnReset) { 1917 TEST(PictureLayerTilingTest, RecycledTilesClearedOnReset) {
1910 FakePictureLayerTilingClient active_client; 1918 FakePictureLayerTilingClient active_client;
1911 active_client.SetTileSize(gfx::Size(100, 100)); 1919 active_client.SetTileSize(gfx::Size(100, 100));
1912 active_client.set_tree(ACTIVE_TREE); 1920 active_client.set_tree(ACTIVE_TREE);
1913 1921
1914 scoped_refptr<FakePicturePileImpl> pile = 1922 scoped_refptr<FakePicturePileImpl> pile =
1915 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize( 1923 FakePicturePileImpl::CreateFilledPileWithDefaultTileSize(
1916 gfx::Size(100, 100)); 1924 gfx::Size(100, 100));
(...skipping 19 matching lines...) Expand all
1936 1944
1937 // Create all tiles on the recycle tiling. All tiles should be shared. 1945 // Create all tiles on the recycle tiling. All tiles should be shared.
1938 recycle_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f, 1946 recycle_tiling->ComputeTilePriorityRects(gfx::Rect(0, 0, 100, 100), 1.0f,
1939 1.0f, Occlusion()); 1947 1.0f, Occlusion());
1940 1948
1941 // Set the second tiling as recycled. 1949 // Set the second tiling as recycled.
1942 active_client.set_twin_tiling(NULL); 1950 active_client.set_twin_tiling(NULL);
1943 active_client.set_recycled_twin_tiling(recycle_tiling.get()); 1951 active_client.set_recycled_twin_tiling(recycle_tiling.get());
1944 recycle_client.set_twin_tiling(NULL); 1952 recycle_client.set_twin_tiling(NULL);
1945 1953
1946 // Verify that tiles exist and are shared.
1947 EXPECT_TRUE(active_tiling->TileAt(0, 0)); 1954 EXPECT_TRUE(active_tiling->TileAt(0, 0));
1948 EXPECT_TRUE(recycle_tiling->TileAt(0, 0)); 1955 EXPECT_FALSE(recycle_tiling->TileAt(0, 0));
1949 EXPECT_EQ(active_tiling->TileAt(0, 0), recycle_tiling->TileAt(0, 0));
1950 1956
1951 // Reset the active tiling. The recycle tiles should be released too. 1957 // Reset the active tiling. The recycle tiles should be released too.
1952 active_tiling->Reset(); 1958 active_tiling->Reset();
1953 EXPECT_FALSE(active_tiling->TileAt(0, 0)); 1959 EXPECT_FALSE(active_tiling->TileAt(0, 0));
1954 EXPECT_FALSE(recycle_tiling->TileAt(0, 0)); 1960 EXPECT_FALSE(recycle_tiling->TileAt(0, 0));
1955 } 1961 }
1956 1962
1957 TEST_F(PictureLayerTilingIteratorTest, ResizeTilesAndUpdateToCurrent) { 1963 TEST_F(PictureLayerTilingIteratorTest, ResizeTilesAndUpdateToCurrent) {
1958 // The tiling has four rows and three columns. 1964 // The tiling has four rows and three columns.
1959 Initialize(gfx::Size(150, 100), 1.f, gfx::Size(250, 150)); 1965 Initialize(gfx::Size(150, 100), 1.f, gfx::Size(250, 150));
(...skipping 16 matching lines...) Expand all
1976 tiling_->SetRasterSourceAndResize(pile); 1982 tiling_->SetRasterSourceAndResize(pile);
1977 1983
1978 // Tile size in the tiling should be resized to 250x200. 1984 // Tile size in the tiling should be resized to 250x200.
1979 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width()); 1985 EXPECT_EQ(250, tiling_->TilingDataForTesting().max_texture_size().width());
1980 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height()); 1986 EXPECT_EQ(200, tiling_->TilingDataForTesting().max_texture_size().height());
1981 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size()); 1987 EXPECT_EQ(0u, tiling_->AllRefTilesForTesting().size());
1982 } 1988 }
1983 1989
1984 } // namespace 1990 } // namespace
1985 } // namespace cc 1991 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698