| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/resources/tile_bundle.h" | |
| 6 | |
| 7 #include <set> | |
| 8 | |
| 9 #include "cc/test/fake_picture_pile_impl.h" | |
| 10 #include "cc/test/fake_tile_manager.h" | |
| 11 #include "cc/test/fake_tile_manager_client.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace cc { | |
| 15 namespace { | |
| 16 | |
| 17 TEST(TileBundle, AddRemoveTile) { | |
| 18 FakeTileManagerClient tile_manager_client; | |
| 19 FakeTileManager tile_manager(&tile_manager_client); | |
| 20 scoped_refptr<PicturePileImpl> picture_pile = | |
| 21 FakePicturePileImpl::CreatePile(); | |
| 22 | |
| 23 scoped_refptr<Tile> tile = tile_manager.CreateTile(picture_pile.get(), | |
| 24 gfx::Size(256, 256), | |
| 25 gfx::Rect(), | |
| 26 gfx::Rect(), | |
| 27 1.0, | |
| 28 0, | |
| 29 0, | |
| 30 true); | |
| 31 scoped_refptr<TileBundle> bundle = tile_manager.CreateTileBundle(0, 0, 2, 2); | |
| 32 | |
| 33 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 0)); | |
| 34 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 1, 0)); | |
| 35 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 1)); | |
| 36 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 1, 1)); | |
| 37 EXPECT_TRUE(bundle->IsEmpty()); | |
| 38 | |
| 39 bundle->AddTileAt(ACTIVE_TREE, 0, 1, tile); | |
| 40 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 0)); | |
| 41 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 1, 0)); | |
| 42 EXPECT_TRUE(bundle->TileAt(ACTIVE_TREE, 0, 1)); | |
| 43 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 1, 1)); | |
| 44 EXPECT_FALSE(bundle->IsEmpty()); | |
| 45 | |
| 46 bundle->AddTileAt(ACTIVE_TREE, 1, 1, tile); | |
| 47 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 0)); | |
| 48 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 1, 0)); | |
| 49 EXPECT_TRUE(bundle->TileAt(ACTIVE_TREE, 0, 1)); | |
| 50 EXPECT_TRUE(bundle->TileAt(ACTIVE_TREE, 1, 1)); | |
| 51 EXPECT_FALSE(bundle->IsEmpty()); | |
| 52 | |
| 53 bundle->RemoveTileAt(ACTIVE_TREE, 0, 1); | |
| 54 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 0)); | |
| 55 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 1, 0)); | |
| 56 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 1)); | |
| 57 EXPECT_TRUE(bundle->TileAt(ACTIVE_TREE, 1, 1)); | |
| 58 EXPECT_FALSE(bundle->IsEmpty()); | |
| 59 | |
| 60 bundle->RemoveTileAt(ACTIVE_TREE, 0, 1); | |
| 61 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 0)); | |
| 62 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 1, 0)); | |
| 63 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 1)); | |
| 64 EXPECT_TRUE(bundle->TileAt(ACTIVE_TREE, 1, 1)); | |
| 65 EXPECT_FALSE(bundle->IsEmpty()); | |
| 66 | |
| 67 bundle->RemoveTileAt(ACTIVE_TREE, 1, 1); | |
| 68 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 0)); | |
| 69 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 1, 0)); | |
| 70 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 1)); | |
| 71 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 1, 1)); | |
| 72 EXPECT_TRUE(bundle->IsEmpty()); | |
| 73 } | |
| 74 | |
| 75 TEST(TileBundle, DidBecomeActiveSwapsTiles) { | |
| 76 FakeTileManagerClient tile_manager_client; | |
| 77 FakeTileManager tile_manager(&tile_manager_client); | |
| 78 scoped_refptr<PicturePileImpl> picture_pile = | |
| 79 FakePicturePileImpl::CreatePile(); | |
| 80 | |
| 81 scoped_refptr<Tile> tile = tile_manager.CreateTile(picture_pile.get(), | |
| 82 gfx::Size(256, 256), | |
| 83 gfx::Rect(), | |
| 84 gfx::Rect(), | |
| 85 1.0, | |
| 86 0, | |
| 87 0, | |
| 88 true); | |
| 89 scoped_refptr<Tile> other_tile = tile_manager.CreateTile(picture_pile.get(), | |
| 90 gfx::Size(256, 256), | |
| 91 gfx::Rect(), | |
| 92 gfx::Rect(), | |
| 93 1.0, | |
| 94 0, | |
| 95 0, | |
| 96 true); | |
| 97 | |
| 98 scoped_refptr<TileBundle> bundle = tile_manager.CreateTileBundle(0, 0, 2, 2); | |
| 99 bundle->AddTileAt(ACTIVE_TREE, 0, 0, tile); | |
| 100 bundle->AddTileAt(PENDING_TREE, 1, 1, other_tile); | |
| 101 | |
| 102 EXPECT_EQ(bundle->TileAt(ACTIVE_TREE, 0, 0), tile.get()); | |
| 103 EXPECT_EQ(bundle->TileAt(PENDING_TREE, 1, 1), other_tile.get()); | |
| 104 | |
| 105 bundle->DidBecomeActive(); | |
| 106 | |
| 107 EXPECT_EQ(bundle->TileAt(PENDING_TREE, 0, 0), tile.get()); | |
| 108 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 0)); | |
| 109 EXPECT_EQ(bundle->TileAt(ACTIVE_TREE, 1, 1), other_tile.get()); | |
| 110 EXPECT_FALSE(bundle->TileAt(PENDING_TREE, 1, 1)); | |
| 111 | |
| 112 bundle->SwapTilesIfRequired(); | |
| 113 | |
| 114 EXPECT_EQ(bundle->TileAt(PENDING_TREE, 0, 0), tile.get()); | |
| 115 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 0)); | |
| 116 EXPECT_EQ(bundle->TileAt(ACTIVE_TREE, 1, 1), other_tile.get()); | |
| 117 EXPECT_FALSE(bundle->TileAt(PENDING_TREE, 1, 1)); | |
| 118 } | |
| 119 | |
| 120 TEST(TileBundle, DidBecomeRecycledMarksTilesForSwap) { | |
| 121 FakeTileManagerClient tile_manager_client; | |
| 122 FakeTileManager tile_manager(&tile_manager_client); | |
| 123 scoped_refptr<PicturePileImpl> picture_pile = | |
| 124 FakePicturePileImpl::CreatePile(); | |
| 125 | |
| 126 scoped_refptr<Tile> tile = tile_manager.CreateTile(picture_pile.get(), | |
| 127 gfx::Size(256, 256), | |
| 128 gfx::Rect(), | |
| 129 gfx::Rect(), | |
| 130 1.0, | |
| 131 0, | |
| 132 0, | |
| 133 true); | |
| 134 scoped_refptr<Tile> other_tile = tile_manager.CreateTile(picture_pile.get(), | |
| 135 gfx::Size(256, 256), | |
| 136 gfx::Rect(), | |
| 137 gfx::Rect(), | |
| 138 1.0, | |
| 139 0, | |
| 140 0, | |
| 141 true); | |
| 142 | |
| 143 scoped_refptr<TileBundle> bundle = tile_manager.CreateTileBundle(0, 0, 2, 2); | |
| 144 bundle->AddTileAt(ACTIVE_TREE, 0, 0, tile); | |
| 145 bundle->AddTileAt(PENDING_TREE, 1, 1, other_tile); | |
| 146 | |
| 147 EXPECT_EQ(bundle->TileAt(ACTIVE_TREE, 0, 0), tile.get()); | |
| 148 EXPECT_EQ(bundle->TileAt(PENDING_TREE, 1, 1), other_tile.get()); | |
| 149 | |
| 150 bundle->DidBecomeRecycled(); | |
| 151 bundle->DidBecomeRecycled(); | |
| 152 | |
| 153 EXPECT_EQ(bundle->TileAt(ACTIVE_TREE, 0, 0), tile.get()); | |
| 154 EXPECT_FALSE(bundle->TileAt(PENDING_TREE, 0, 0)); | |
| 155 EXPECT_EQ(bundle->TileAt(PENDING_TREE, 1, 1), other_tile.get()); | |
| 156 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 1, 1)); | |
| 157 | |
| 158 bundle->DidBecomeRecycled(); | |
| 159 bundle->SwapTilesIfRequired(); | |
| 160 | |
| 161 EXPECT_EQ(bundle->TileAt(PENDING_TREE, 0, 0), tile.get()); | |
| 162 EXPECT_FALSE(bundle->TileAt(ACTIVE_TREE, 0, 0)); | |
| 163 EXPECT_EQ(bundle->TileAt(ACTIVE_TREE, 1, 1), other_tile.get()); | |
| 164 EXPECT_FALSE(bundle->TileAt(PENDING_TREE, 1, 1)); | |
| 165 } | |
| 166 | |
| 167 TEST(TileBundle, EmptyIterator) { | |
| 168 FakeTileManagerClient tile_manager_client; | |
| 169 FakeTileManager tile_manager(&tile_manager_client); | |
| 170 scoped_refptr<TileBundle> bundle = tile_manager.CreateTileBundle(0, 0, 2, 2); | |
| 171 | |
| 172 TileBundle::Iterator it(bundle.get()); | |
| 173 EXPECT_FALSE(it); | |
| 174 | |
| 175 TileBundle::Iterator active_it(bundle.get(), ACTIVE_TREE); | |
| 176 EXPECT_FALSE(active_it); | |
| 177 | |
| 178 TileBundle::Iterator pending_it(bundle.get(), PENDING_TREE); | |
| 179 EXPECT_FALSE(pending_it); | |
| 180 } | |
| 181 | |
| 182 TEST(TileBundle, NonEmptyIterator) { | |
| 183 FakeTileManagerClient tile_manager_client; | |
| 184 FakeTileManager tile_manager(&tile_manager_client); | |
| 185 scoped_refptr<PicturePileImpl> picture_pile = | |
| 186 FakePicturePileImpl::CreatePile(); | |
| 187 scoped_refptr<TileBundle> bundle = tile_manager.CreateTileBundle(0, 0, 2, 2); | |
| 188 | |
| 189 scoped_refptr<Tile> tile = tile_manager.CreateTile(picture_pile.get(), | |
| 190 gfx::Size(256, 256), | |
| 191 gfx::Rect(), | |
| 192 gfx::Rect(), | |
| 193 1.0, | |
| 194 0, | |
| 195 0, | |
| 196 true); | |
| 197 scoped_refptr<Tile> other_tile = tile_manager.CreateTile(picture_pile.get(), | |
| 198 gfx::Size(256, 256), | |
| 199 gfx::Rect(), | |
| 200 gfx::Rect(), | |
| 201 1.0, | |
| 202 0, | |
| 203 0, | |
| 204 true); | |
| 205 scoped_refptr<Tile> third_tile = tile_manager.CreateTile(picture_pile.get(), | |
| 206 gfx::Size(256, 256), | |
| 207 gfx::Rect(), | |
| 208 gfx::Rect(), | |
| 209 1.0, | |
| 210 0, | |
| 211 0, | |
| 212 true); | |
| 213 | |
| 214 bundle->AddTileAt(ACTIVE_TREE, 0, 0, tile); | |
| 215 bundle->AddTileAt(PENDING_TREE, 1, 1, other_tile); | |
| 216 bundle->AddTileAt(ACTIVE_TREE, 1, 1, third_tile); | |
| 217 | |
| 218 TileBundle::Iterator it(bundle.get()); | |
| 219 EXPECT_TRUE(it); | |
| 220 std::set<Tile*> tiles; | |
| 221 size_t count = 0; | |
| 222 while (it) { | |
| 223 tiles.insert(*it); | |
| 224 ++it; | |
| 225 ++count; | |
| 226 } | |
| 227 | |
| 228 EXPECT_EQ(count, tiles.size()); | |
| 229 EXPECT_TRUE(tiles.count(tile.get())); | |
| 230 EXPECT_TRUE(tiles.count(other_tile.get())); | |
| 231 EXPECT_TRUE(tiles.count(third_tile.get())); | |
| 232 | |
| 233 TileBundle::Iterator active_it(bundle.get(), ACTIVE_TREE); | |
| 234 EXPECT_TRUE(active_it); | |
| 235 count = 0; | |
| 236 tiles.clear(); | |
| 237 while (active_it) { | |
| 238 tiles.insert(*active_it); | |
| 239 ++active_it; | |
| 240 ++count; | |
| 241 } | |
| 242 | |
| 243 EXPECT_EQ(count, tiles.size()); | |
| 244 EXPECT_TRUE(tiles.count(tile.get())); | |
| 245 EXPECT_FALSE(tiles.count(other_tile.get())); | |
| 246 EXPECT_TRUE(tiles.count(third_tile.get())); | |
| 247 | |
| 248 TileBundle::Iterator pending_it(bundle.get(), PENDING_TREE); | |
| 249 EXPECT_TRUE(pending_it); | |
| 250 EXPECT_EQ(*pending_it, other_tile.get()); | |
| 251 ++pending_it; | |
| 252 EXPECT_FALSE(pending_it); | |
| 253 } | |
| 254 | |
| 255 | |
| 256 } // namespace | |
| 257 } // namespace cc | |
| OLD | NEW |