| 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_set.h" | 5 #include "cc/resources/picture_layer_tiling_set.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "cc/resources/resource_pool.h" | 10 #include "cc/resources/resource_pool.h" |
| 11 #include "cc/resources/resource_provider.h" | 11 #include "cc/resources/resource_provider.h" |
| 12 #include "cc/test/fake_output_surface.h" | 12 #include "cc/test/fake_output_surface.h" |
| 13 #include "cc/test/fake_output_surface_client.h" | 13 #include "cc/test/fake_output_surface_client.h" |
| 14 #include "cc/test/fake_picture_layer_tiling_client.h" | 14 #include "cc/test/fake_picture_layer_tiling_client.h" |
| 15 #include "cc/test/fake_tile_manager.h" |
| 15 #include "cc/test/fake_tile_manager_client.h" | 16 #include "cc/test/fake_tile_manager_client.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/gfx/size_conversions.h" | 18 #include "ui/gfx/size_conversions.h" |
| 18 | 19 |
| 19 namespace cc { | 20 namespace cc { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 TEST(PictureLayerTilingSetTest, NoResources) { | 23 TEST(PictureLayerTilingSetTest, NoResources) { |
| 23 FakePictureLayerTilingClient client; | 24 FakePictureLayerTilingClient client; |
| 24 gfx::Size layer_bounds(1000, 800); | 25 gfx::Size layer_bounds(1000, 800); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 146 } |
| 146 | 147 |
| 147 class PictureLayerTilingSetSyncTest : public testing::Test { | 148 class PictureLayerTilingSetSyncTest : public testing::Test { |
| 148 public: | 149 public: |
| 149 PictureLayerTilingSetSyncTest() | 150 PictureLayerTilingSetSyncTest() |
| 150 : tile_size_(gfx::Size(10, 10)), | 151 : tile_size_(gfx::Size(10, 10)), |
| 151 source_bounds_(gfx::Size(30, 20)), | 152 source_bounds_(gfx::Size(30, 20)), |
| 152 target_bounds_(gfx::Size(30, 30)) { | 153 target_bounds_(gfx::Size(30, 30)) { |
| 153 source_client_.SetTileSize(tile_size_); | 154 source_client_.SetTileSize(tile_size_); |
| 154 target_client_.SetTileSize(tile_size_); | 155 target_client_.SetTileSize(tile_size_); |
| 156 |
| 157 output_surface_ = FakeOutputSurface::Create3d(); |
| 158 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 159 resource_provider_ = |
| 160 ResourceProvider::Create(output_surface_.get(), NULL, 0, false, 1); |
| 161 tile_manager_ = make_scoped_ptr( |
| 162 new FakeTileManager(&tile_manager_client_, resource_provider_.get())); |
| 163 source_client_.set_tile_manager(tile_manager_.get()); |
| 164 target_client_.set_tile_manager(tile_manager_.get()); |
| 165 |
| 155 source_.reset(new PictureLayerTilingSet(&source_client_, source_bounds_)); | 166 source_.reset(new PictureLayerTilingSet(&source_client_, source_bounds_)); |
| 156 target_.reset(new PictureLayerTilingSet(&target_client_, target_bounds_)); | 167 target_.reset(new PictureLayerTilingSet(&target_client_, target_bounds_)); |
| 157 } | 168 } |
| 158 | 169 |
| 170 ~PictureLayerTilingSetSyncTest() { |
| 171 tile_manager_.reset(NULL); |
| 172 resource_provider_.reset(NULL); |
| 173 } |
| 174 |
| 159 // Sync from source to target. | 175 // Sync from source to target. |
| 160 void SyncTilings(gfx::Size new_bounds, | 176 void SyncTilings(gfx::Size new_bounds, |
| 161 const Region& invalidation, | 177 const Region& invalidation, |
| 162 float minimum_scale) { | 178 float minimum_scale) { |
| 163 for (size_t i = 0; i < source_->num_tilings(); ++i) | 179 for (size_t i = 0; i < source_->num_tilings(); ++i) |
| 164 source_->tiling_at(i)->CreateAllTilesForTesting(); | 180 source_->tiling_at(i)->CreateAllTilesForTesting(); |
| 165 for (size_t i = 0; i < target_->num_tilings(); ++i) | 181 for (size_t i = 0; i < target_->num_tilings(); ++i) |
| 166 target_->tiling_at(i)->CreateAllTilesForTesting(); | 182 target_->tiling_at(i)->CreateAllTilesForTesting(); |
| 167 | 183 |
| 168 target_->SyncTilings( | 184 target_->SyncTilings( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 257 |
| 242 gfx::Size tile_size_; | 258 gfx::Size tile_size_; |
| 243 | 259 |
| 244 FakePictureLayerTilingClient source_client_; | 260 FakePictureLayerTilingClient source_client_; |
| 245 gfx::Size source_bounds_; | 261 gfx::Size source_bounds_; |
| 246 scoped_ptr<PictureLayerTilingSet> source_; | 262 scoped_ptr<PictureLayerTilingSet> source_; |
| 247 | 263 |
| 248 FakePictureLayerTilingClient target_client_; | 264 FakePictureLayerTilingClient target_client_; |
| 249 gfx::Size target_bounds_; | 265 gfx::Size target_bounds_; |
| 250 scoped_ptr<PictureLayerTilingSet> target_; | 266 scoped_ptr<PictureLayerTilingSet> target_; |
| 267 |
| 268 FakeTileManagerClient tile_manager_client_; |
| 269 scoped_ptr<FakeTileManager> tile_manager_; |
| 270 scoped_ptr<ResourceProvider> resource_provider_; |
| 271 scoped_ptr<FakeOutputSurface> output_surface_; |
| 272 FakeOutputSurfaceClient output_surface_client_; |
| 251 }; | 273 }; |
| 252 | 274 |
| 253 TEST_F(PictureLayerTilingSetSyncTest, EmptyBounds) { | 275 TEST_F(PictureLayerTilingSetSyncTest, EmptyBounds) { |
| 254 float source_scales[] = {1.f, 1.2f}; | 276 float source_scales[] = {1.f, 1.2f}; |
| 255 for (size_t i = 0; i < arraysize(source_scales); ++i) | 277 for (size_t i = 0; i < arraysize(source_scales); ++i) |
| 256 source_->AddTiling(source_scales[i]); | 278 source_->AddTiling(source_scales[i]); |
| 257 | 279 |
| 258 gfx::Size new_bounds; | 280 gfx::Size new_bounds; |
| 259 SyncTilings(new_bounds); | 281 SyncTilings(new_bounds); |
| 260 EXPECT_EQ(target_->num_tilings(), 0u); | 282 EXPECT_EQ(target_->num_tilings(), 0u); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 std::vector<Tile*> new_tiles = target_->tiling_at(0)->AllTilesForTesting(); | 429 std::vector<Tile*> new_tiles = target_->tiling_at(0)->AllTilesForTesting(); |
| 408 for (size_t i = 0; i < original_tiles.size(); ++i) { | 430 for (size_t i = 0; i < original_tiles.size(); ++i) { |
| 409 std::vector<Tile*>::iterator find = | 431 std::vector<Tile*>::iterator find = |
| 410 std::find(new_tiles.begin(), new_tiles.end(), original_tiles[i]); | 432 std::find(new_tiles.begin(), new_tiles.end(), original_tiles[i]); |
| 411 EXPECT_TRUE(find == new_tiles.end()); | 433 EXPECT_TRUE(find == new_tiles.end()); |
| 412 } | 434 } |
| 413 } | 435 } |
| 414 | 436 |
| 415 } // namespace | 437 } // namespace |
| 416 } // namespace cc | 438 } // namespace cc |
| OLD | NEW |