Home | History | Annotate | Download | only in resources
      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
      3 // found in the LICENSE file.
      4 
      5 #include "cc/resources/picture_layer_tiling_set.h"
      6 
      7 #include <map>
      8 #include <vector>
      9 
     10 #include "cc/resources/resource_pool.h"
     11 #include "cc/resources/resource_provider.h"
     12 #include "cc/test/fake_output_surface.h"
     13 #include "cc/test/fake_output_surface_client.h"
     14 #include "cc/test/fake_picture_layer_tiling_client.h"
     15 #include "cc/test/fake_tile_manager_client.h"
     16 #include "cc/test/test_shared_bitmap_manager.h"
     17 #include "testing/gtest/include/gtest/gtest.h"
     18 #include "ui/gfx/size_conversions.h"
     19 
     20 namespace cc {
     21 namespace {
     22 
     23 TEST(PictureLayerTilingSetTest, NoResources) {
     24   FakePictureLayerTilingClient client;
     25   gfx::Size layer_bounds(1000, 800);
     26   PictureLayerTilingSet set(&client, layer_bounds);
     27   client.SetTileSize(gfx::Size(256, 256));
     28 
     29   set.AddTiling(1.0);
     30   set.AddTiling(1.5);
     31   set.AddTiling(2.0);
     32 
     33   float contents_scale = 2.0;
     34   gfx::Size content_bounds(
     35       gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)));
     36   gfx::Rect content_rect(content_bounds);
     37 
     38   Region remaining(content_rect);
     39   PictureLayerTilingSet::CoverageIterator iter(
     40       &set,
     41       contents_scale,
     42       content_rect,
     43       contents_scale);
     44   for (; iter; ++iter) {
     45     gfx::Rect geometry_rect = iter.geometry_rect();
     46     EXPECT_TRUE(content_rect.Contains(geometry_rect));
     47     ASSERT_TRUE(remaining.Contains(geometry_rect));
     48     remaining.Subtract(geometry_rect);
     49 
     50     // No tiles have resources, so no iter represents a real tile.
     51     EXPECT_FALSE(*iter);
     52   }
     53   EXPECT_TRUE(remaining.IsEmpty());
     54 }
     55 
     56 TEST(PictureLayerTilingSetTest, TilingRange) {
     57   FakePictureLayerTilingClient client;
     58   gfx::Size layer_bounds(10, 10);
     59   PictureLayerTilingSet::TilingRange higher_than_high_res_range(0, 0);
     60   PictureLayerTilingSet::TilingRange high_res_range(0, 0);
     61   PictureLayerTilingSet::TilingRange between_high_and_low_res_range(0, 0);
     62   PictureLayerTilingSet::TilingRange low_res_range(0, 0);
     63   PictureLayerTilingSet::TilingRange lower_than_low_res_range(0, 0);
     64   PictureLayerTiling* high_res_tiling;
     65   PictureLayerTiling* low_res_tiling;
     66 
     67   PictureLayerTilingSet set(&client, layer_bounds);
     68   set.AddTiling(2.0);
     69   high_res_tiling = set.AddTiling(1.0);
     70   high_res_tiling->set_resolution(HIGH_RESOLUTION);
     71   set.AddTiling(0.5);
     72   low_res_tiling = set.AddTiling(0.25);
     73   low_res_tiling->set_resolution(LOW_RESOLUTION);
     74   set.AddTiling(0.125);
     75 
     76   higher_than_high_res_range =
     77       set.GetTilingRange(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
     78   EXPECT_EQ(0u, higher_than_high_res_range.start);
     79   EXPECT_EQ(1u, higher_than_high_res_range.end);
     80 
     81   high_res_range = set.GetTilingRange(PictureLayerTilingSet::HIGH_RES);
     82   EXPECT_EQ(1u, high_res_range.start);
     83   EXPECT_EQ(2u, high_res_range.end);
     84 
     85   between_high_and_low_res_range =
     86       set.GetTilingRange(PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
     87   EXPECT_EQ(2u, between_high_and_low_res_range.start);
     88   EXPECT_EQ(3u, between_high_and_low_res_range.end);
     89 
     90   low_res_range = set.GetTilingRange(PictureLayerTilingSet::LOW_RES);
     91   EXPECT_EQ(3u, low_res_range.start);
     92   EXPECT_EQ(4u, low_res_range.end);
     93 
     94   lower_than_low_res_range =
     95       set.GetTilingRange(PictureLayerTilingSet::LOWER_THAN_LOW_RES);
     96   EXPECT_EQ(4u, lower_than_low_res_range.start);
     97   EXPECT_EQ(5u, lower_than_low_res_range.end);
     98 
     99   PictureLayerTilingSet set_without_low_res(&client, layer_bounds);
    100   set_without_low_res.AddTiling(2.0);
    101   high_res_tiling = set_without_low_res.AddTiling(1.0);
    102   high_res_tiling->set_resolution(HIGH_RESOLUTION);
    103   set_without_low_res.AddTiling(0.5);
    104   set_without_low_res.AddTiling(0.25);
    105 
    106   higher_than_high_res_range = set_without_low_res.GetTilingRange(
    107       PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
    108   EXPECT_EQ(0u, higher_than_high_res_range.start);
    109   EXPECT_EQ(1u, higher_than_high_res_range.end);
    110 
    111   high_res_range =
    112       set_without_low_res.GetTilingRange(PictureLayerTilingSet::HIGH_RES);
    113   EXPECT_EQ(1u, high_res_range.start);
    114   EXPECT_EQ(2u, high_res_range.end);
    115 
    116   between_high_and_low_res_range = set_without_low_res.GetTilingRange(
    117       PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
    118   EXPECT_EQ(2u, between_high_and_low_res_range.start);
    119   EXPECT_EQ(4u, between_high_and_low_res_range.end);
    120 
    121   low_res_range =
    122       set_without_low_res.GetTilingRange(PictureLayerTilingSet::LOW_RES);
    123   EXPECT_EQ(0u, low_res_range.end - low_res_range.start);
    124 
    125   lower_than_low_res_range = set_without_low_res.GetTilingRange(
    126       PictureLayerTilingSet::LOWER_THAN_LOW_RES);
    127   EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
    128 
    129   PictureLayerTilingSet set_with_only_high_and_low_res(&client, layer_bounds);
    130   high_res_tiling = set_with_only_high_and_low_res.AddTiling(1.0);
    131   high_res_tiling->set_resolution(HIGH_RESOLUTION);
    132   low_res_tiling = set_with_only_high_and_low_res.AddTiling(0.5);
    133   low_res_tiling->set_resolution(LOW_RESOLUTION);
    134 
    135   higher_than_high_res_range = set_with_only_high_and_low_res.GetTilingRange(
    136       PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
    137   EXPECT_EQ(0u,
    138             higher_than_high_res_range.end - higher_than_high_res_range.start);
    139 
    140   high_res_range = set_with_only_high_and_low_res.GetTilingRange(
    141       PictureLayerTilingSet::HIGH_RES);
    142   EXPECT_EQ(0u, high_res_range.start);
    143   EXPECT_EQ(1u, high_res_range.end);
    144 
    145   between_high_and_low_res_range =
    146       set_with_only_high_and_low_res.GetTilingRange(
    147           PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
    148   EXPECT_EQ(0u,
    149             between_high_and_low_res_range.end -
    150                 between_high_and_low_res_range.start);
    151 
    152   low_res_range = set_with_only_high_and_low_res.GetTilingRange(
    153       PictureLayerTilingSet::LOW_RES);
    154   EXPECT_EQ(1u, low_res_range.start);
    155   EXPECT_EQ(2u, low_res_range.end);
    156 
    157   lower_than_low_res_range = set_with_only_high_and_low_res.GetTilingRange(
    158       PictureLayerTilingSet::LOWER_THAN_LOW_RES);
    159   EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
    160 
    161   PictureLayerTilingSet set_with_only_high_res(&client, layer_bounds);
    162   high_res_tiling = set_with_only_high_res.AddTiling(1.0);
    163   high_res_tiling->set_resolution(HIGH_RESOLUTION);
    164 
    165   higher_than_high_res_range = set_with_only_high_res.GetTilingRange(
    166       PictureLayerTilingSet::HIGHER_THAN_HIGH_RES);
    167   EXPECT_EQ(0u,
    168             higher_than_high_res_range.end - higher_than_high_res_range.start);
    169 
    170   high_res_range =
    171       set_with_only_high_res.GetTilingRange(PictureLayerTilingSet::HIGH_RES);
    172   EXPECT_EQ(0u, high_res_range.start);
    173   EXPECT_EQ(1u, high_res_range.end);
    174 
    175   between_high_and_low_res_range = set_with_only_high_res.GetTilingRange(
    176       PictureLayerTilingSet::BETWEEN_HIGH_AND_LOW_RES);
    177   EXPECT_EQ(0u,
    178             between_high_and_low_res_range.end -
    179                 between_high_and_low_res_range.start);
    180 
    181   low_res_range =
    182       set_with_only_high_res.GetTilingRange(PictureLayerTilingSet::LOW_RES);
    183   EXPECT_EQ(0u, low_res_range.end - low_res_range.start);
    184 
    185   lower_than_low_res_range = set_with_only_high_res.GetTilingRange(
    186       PictureLayerTilingSet::LOWER_THAN_LOW_RES);
    187   EXPECT_EQ(0u, lower_than_low_res_range.end - lower_than_low_res_range.start);
    188 }
    189 
    190 class PictureLayerTilingSetTestWithResources : public testing::Test {
    191  public:
    192   void runTest(
    193       int num_tilings,
    194       float min_scale,
    195       float scale_increment,
    196       float ideal_contents_scale,
    197       float expected_scale) {
    198     FakeOutputSurfaceClient output_surface_client;
    199     scoped_ptr<FakeOutputSurface> output_surface =
    200         FakeOutputSurface::Create3d();
    201     CHECK(output_surface->BindToClient(&output_surface_client));
    202 
    203     scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
    204         new TestSharedBitmapManager());
    205     scoped_ptr<ResourceProvider> resource_provider =
    206         ResourceProvider::Create(output_surface.get(),
    207                                  shared_bitmap_manager.get(),
    208                                  NULL,
    209                                  0,
    210                                  false,
    211                                  1,
    212                                  false);
    213 
    214     FakePictureLayerTilingClient client(resource_provider.get());
    215     client.SetTileSize(gfx::Size(256, 256));
    216     client.set_tree(PENDING_TREE);
    217     gfx::Size layer_bounds(1000, 800);
    218     PictureLayerTilingSet set(&client, layer_bounds);
    219 
    220     float scale = min_scale;
    221     for (int i = 0; i < num_tilings; ++i, scale += scale_increment) {
    222       PictureLayerTiling* tiling = set.AddTiling(scale);
    223       tiling->CreateAllTilesForTesting();
    224       std::vector<Tile*> tiles = tiling->AllTilesForTesting();
    225       client.tile_manager()->InitializeTilesWithResourcesForTesting(tiles);
    226     }
    227 
    228     float max_contents_scale = scale;
    229     gfx::Size content_bounds(
    230         gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, max_contents_scale)));
    231     gfx::Rect content_rect(content_bounds);
    232 
    233     Region remaining(content_rect);
    234     PictureLayerTilingSet::CoverageIterator iter(
    235         &set,
    236         max_contents_scale,
    237         content_rect,
    238         ideal_contents_scale);
    239     for (; iter; ++iter) {
    240       gfx::Rect geometry_rect = iter.geometry_rect();
    241       EXPECT_TRUE(content_rect.Contains(geometry_rect));
    242       ASSERT_TRUE(remaining.Contains(geometry_rect));
    243       remaining.Subtract(geometry_rect);
    244 
    245       float scale = iter.CurrentTiling()->contents_scale();
    246       EXPECT_EQ(expected_scale, scale);
    247 
    248       if (num_tilings)
    249         EXPECT_TRUE(*iter);
    250       else
    251         EXPECT_FALSE(*iter);
    252     }
    253     EXPECT_TRUE(remaining.IsEmpty());
    254   }
    255 };
    256 
    257 TEST_F(PictureLayerTilingSetTestWithResources, NoTilings) {
    258   runTest(0, 0.f, 0.f, 2.f, 0.f);
    259 }
    260 TEST_F(PictureLayerTilingSetTestWithResources, OneTiling_Smaller) {
    261   runTest(1, 1.f, 0.f, 2.f, 1.f);
    262 }
    263 TEST_F(PictureLayerTilingSetTestWithResources, OneTiling_Larger) {
    264   runTest(1, 3.f, 0.f, 2.f, 3.f);
    265 }
    266 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_Smaller) {
    267   runTest(2, 1.f, 1.f, 3.f, 2.f);
    268 }
    269 
    270 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_SmallerEqual) {
    271   runTest(2, 1.f, 1.f, 2.f, 2.f);
    272 }
    273 
    274 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_LargerEqual) {
    275   runTest(2, 1.f, 1.f, 1.f, 1.f);
    276 }
    277 
    278 TEST_F(PictureLayerTilingSetTestWithResources, TwoTilings_Larger) {
    279   runTest(2, 2.f, 8.f, 1.f, 2.f);
    280 }
    281 
    282 TEST_F(PictureLayerTilingSetTestWithResources, ManyTilings_Equal) {
    283   runTest(10, 1.f, 1.f, 5.f, 5.f);
    284 }
    285 
    286 TEST_F(PictureLayerTilingSetTestWithResources, ManyTilings_NotEqual) {
    287   runTest(10, 1.f, 1.f, 4.5f, 5.f);
    288 }
    289 
    290 class PictureLayerTilingSetSyncTest : public testing::Test {
    291  public:
    292   PictureLayerTilingSetSyncTest()
    293       : tile_size_(gfx::Size(10, 10)),
    294         source_bounds_(gfx::Size(30, 20)),
    295         target_bounds_(gfx::Size(30, 30)) {
    296     source_client_.SetTileSize(tile_size_);
    297     source_client_.set_tree(PENDING_TREE);
    298     target_client_.SetTileSize(tile_size_);
    299     target_client_.set_tree(PENDING_TREE);
    300     source_.reset(new PictureLayerTilingSet(&source_client_, source_bounds_));
    301     target_.reset(new PictureLayerTilingSet(&target_client_, target_bounds_));
    302   }
    303 
    304   // Sync from source to target.
    305   void SyncTilings(const gfx::Size& new_bounds,
    306                    const Region& invalidation,
    307                    float minimum_scale) {
    308     for (size_t i = 0; i < source_->num_tilings(); ++i)
    309       source_->tiling_at(i)->CreateAllTilesForTesting();
    310     for (size_t i = 0; i < target_->num_tilings(); ++i)
    311       target_->tiling_at(i)->CreateAllTilesForTesting();
    312 
    313     target_->SyncTilings(
    314         *source_.get(), new_bounds, invalidation, minimum_scale);
    315   }
    316   void SyncTilings(const gfx::Size& new_bounds) {
    317     Region invalidation;
    318     SyncTilings(new_bounds, invalidation, 0.f);
    319   }
    320   void SyncTilings(const gfx::Size& new_bounds, const Region& invalidation) {
    321     SyncTilings(new_bounds, invalidation, 0.f);
    322   }
    323   void SyncTilings(const gfx::Size& new_bounds, float minimum_scale) {
    324     Region invalidation;
    325     SyncTilings(new_bounds, invalidation, minimum_scale);
    326   }
    327 
    328   void VerifyTargetEqualsSource(const gfx::Size& new_bounds) {
    329     ASSERT_FALSE(new_bounds.IsEmpty());
    330     EXPECT_EQ(target_->num_tilings(), source_->num_tilings());
    331     EXPECT_EQ(target_->layer_bounds().ToString(), new_bounds.ToString());
    332 
    333     for (size_t i = 0; i < target_->num_tilings(); ++i) {
    334       ASSERT_GT(source_->num_tilings(), i);
    335       const PictureLayerTiling* source_tiling = source_->tiling_at(i);
    336       const PictureLayerTiling* target_tiling = target_->tiling_at(i);
    337       EXPECT_EQ(target_tiling->layer_bounds().ToString(),
    338                 new_bounds.ToString());
    339       EXPECT_EQ(source_tiling->contents_scale(),
    340                 target_tiling->contents_scale());
    341     }
    342 
    343     EXPECT_EQ(source_->client(), &source_client_);
    344     EXPECT_EQ(target_->client(), &target_client_);
    345     ValidateTargetTilingSet();
    346   }
    347 
    348   void ValidateTargetTilingSet() {
    349     // Tilings should be sorted largest to smallest.
    350     if (target_->num_tilings() > 0) {
    351       float last_scale = target_->tiling_at(0)->contents_scale();
    352       for (size_t i = 1; i < target_->num_tilings(); ++i) {
    353         const PictureLayerTiling* target_tiling = target_->tiling_at(i);
    354         EXPECT_LT(target_tiling->contents_scale(), last_scale);
    355         last_scale = target_tiling->contents_scale();
    356       }
    357     }
    358 
    359     for (size_t i = 0; i < target_->num_tilings(); ++i)
    360       ValidateTiling(target_->tiling_at(i), target_client_.GetPile());
    361   }
    362 
    363   void ValidateTiling(const PictureLayerTiling* tiling,
    364                       const PicturePileImpl* pile) {
    365     if (tiling->tiling_size().IsEmpty()) {
    366       EXPECT_TRUE(tiling->live_tiles_rect().IsEmpty());
    367     } else if (!tiling->live_tiles_rect().IsEmpty()) {
    368       gfx::Rect tiling_rect(tiling->tiling_size());
    369       EXPECT_TRUE(tiling_rect.Contains(tiling->live_tiles_rect()));
    370     }
    371 
    372     std::vector<Tile*> tiles = tiling->AllTilesForTesting();
    373     for (size_t i = 0; i < tiles.size(); ++i) {
    374       const Tile* tile = tiles[i];
    375       ASSERT_TRUE(!!tile);
    376       EXPECT_EQ(tile->picture_pile(), pile);
    377       EXPECT_TRUE(tile->content_rect().Intersects(tiling->live_tiles_rect()))
    378           << "All tiles must be inside the live tiles rect."
    379           << " Tile rect: " << tile->content_rect().ToString()
    380           << " Live rect: " << tiling->live_tiles_rect().ToString()
    381           << " Scale: " << tiling->contents_scale();
    382     }
    383 
    384     for (PictureLayerTiling::CoverageIterator iter(
    385              tiling, tiling->contents_scale(), tiling->live_tiles_rect());
    386          iter;
    387          ++iter) {
    388       EXPECT_TRUE(*iter) << "The live tiles rect must be full.";
    389     }
    390   }
    391 
    392   gfx::Size tile_size_;
    393 
    394   FakePictureLayerTilingClient source_client_;
    395   gfx::Size source_bounds_;
    396   scoped_ptr<PictureLayerTilingSet> source_;
    397 
    398   FakePictureLayerTilingClient target_client_;
    399   gfx::Size target_bounds_;
    400   scoped_ptr<PictureLayerTilingSet> target_;
    401 };
    402 
    403 TEST_F(PictureLayerTilingSetSyncTest, EmptyBounds) {
    404   float source_scales[] = {1.f, 1.2f};
    405   for (size_t i = 0; i < arraysize(source_scales); ++i)
    406     source_->AddTiling(source_scales[i]);
    407 
    408   gfx::Size new_bounds;
    409   SyncTilings(new_bounds);
    410   EXPECT_EQ(target_->num_tilings(), 0u);
    411   EXPECT_EQ(target_->layer_bounds().ToString(), new_bounds.ToString());
    412 }
    413 
    414 TEST_F(PictureLayerTilingSetSyncTest, AllNew) {
    415   float source_scales[] = {0.5f, 1.f, 1.2f};
    416   for (size_t i = 0; i < arraysize(source_scales); ++i)
    417     source_->AddTiling(source_scales[i]);
    418   float target_scales[] = {0.75f, 1.4f, 3.f};
    419   for (size_t i = 0; i < arraysize(target_scales); ++i)
    420     target_->AddTiling(target_scales[i]);
    421 
    422   gfx::Size new_bounds(15, 40);
    423   SyncTilings(new_bounds);
    424   VerifyTargetEqualsSource(new_bounds);
    425 }
    426 
    427 Tile* FindTileAtOrigin(PictureLayerTiling* tiling) {
    428   std::vector<Tile*> tiles = tiling->AllTilesForTesting();
    429   for (size_t i = 0; i < tiles.size(); ++i) {
    430     if (tiles[i]->content_rect().origin() == gfx::Point())
    431       return tiles[i];
    432   }
    433   return NULL;
    434 }
    435 
    436 TEST_F(PictureLayerTilingSetSyncTest, KeepExisting) {
    437   float source_scales[] = {0.7f, 1.f, 1.1f, 2.f};
    438   for (size_t i = 0; i < arraysize(source_scales); ++i)
    439     source_->AddTiling(source_scales[i]);
    440   float target_scales[] = {0.5f, 1.f, 2.f};
    441   for (size_t i = 0; i < arraysize(target_scales); ++i)
    442     target_->AddTiling(target_scales[i]);
    443 
    444   PictureLayerTiling* tiling1 = source_->TilingAtScale(1.f);
    445   ASSERT_TRUE(tiling1);
    446   tiling1->CreateAllTilesForTesting();
    447   EXPECT_EQ(tiling1->contents_scale(), 1.f);
    448   Tile* tile1 = FindTileAtOrigin(tiling1);
    449   ASSERT_TRUE(tile1);
    450 
    451   PictureLayerTiling* tiling2 = source_->TilingAtScale(2.f);
    452   tiling2->CreateAllTilesForTesting();
    453   ASSERT_TRUE(tiling2);
    454   EXPECT_EQ(tiling2->contents_scale(), 2.f);
    455   Tile* tile2 = FindTileAtOrigin(tiling2);
    456   ASSERT_TRUE(tile2);
    457 
    458   gfx::Size new_bounds(15, 40);
    459   SyncTilings(new_bounds);
    460   VerifyTargetEqualsSource(new_bounds);
    461 
    462   EXPECT_EQ(tiling1, source_->TilingAtScale(1.f));
    463   EXPECT_EQ(tile1, FindTileAtOrigin(tiling1));
    464   EXPECT_FALSE(tiling1->live_tiles_rect().IsEmpty());
    465 
    466   EXPECT_EQ(tiling2, source_->TilingAtScale(2.f));
    467   EXPECT_EQ(tile2, FindTileAtOrigin(tiling2));
    468   EXPECT_FALSE(tiling2->live_tiles_rect().IsEmpty());
    469 }
    470 
    471 TEST_F(PictureLayerTilingSetSyncTest, EmptySet) {
    472   float target_scales[] = {0.2f, 1.f};
    473   for (size_t i = 0; i < arraysize(target_scales); ++i)
    474     target_->AddTiling(target_scales[i]);
    475 
    476   gfx::Size new_bounds(15, 40);
    477   SyncTilings(new_bounds);
    478   VerifyTargetEqualsSource(new_bounds);
    479 }
    480 
    481 TEST_F(PictureLayerTilingSetSyncTest, MinimumScale) {
    482   float source_scales[] = {0.7f, 1.f, 1.1f, 2.f};
    483   for (size_t i = 0; i < arraysize(source_scales); ++i)
    484     source_->AddTiling(source_scales[i]);
    485   float target_scales[] = {0.5f, 0.7f, 1.f, 1.1f, 2.f};
    486   for (size_t i = 0; i < arraysize(target_scales); ++i)
    487     target_->AddTiling(target_scales[i]);
    488 
    489   gfx::Size new_bounds(15, 40);
    490   float minimum_scale = 1.5f;
    491   SyncTilings(new_bounds, minimum_scale);
    492 
    493   EXPECT_EQ(target_->num_tilings(), 1u);
    494   EXPECT_EQ(target_->tiling_at(0)->contents_scale(), 2.f);
    495   ValidateTargetTilingSet();
    496 }
    497 
    498 TEST_F(PictureLayerTilingSetSyncTest, Invalidation) {
    499   source_->AddTiling(2.f);
    500   target_->AddTiling(2.f);
    501   target_->tiling_at(0)->CreateAllTilesForTesting();
    502 
    503   Region layer_invalidation;
    504   layer_invalidation.Union(gfx::Rect(0, 0, 1, 1));
    505   layer_invalidation.Union(gfx::Rect(0, 15, 1, 1));
    506   // Out of bounds layer_invalidation.
    507   layer_invalidation.Union(gfx::Rect(100, 100, 1, 1));
    508 
    509   Region content_invalidation;
    510   for (Region::Iterator iter(layer_invalidation); iter.has_rect();
    511        iter.next()) {
    512     gfx::Rect content_rect = gfx::ScaleToEnclosingRect(iter.rect(), 2.f);
    513     content_invalidation.Union(content_rect);
    514   }
    515 
    516   std::vector<Tile*> old_tiles = target_->tiling_at(0)->AllTilesForTesting();
    517   std::map<gfx::Point, scoped_refptr<Tile> > old_tile_map;
    518   for (size_t i = 0; i < old_tiles.size(); ++i)
    519     old_tile_map[old_tiles[i]->content_rect().origin()] = old_tiles[i];
    520 
    521   SyncTilings(target_bounds_, layer_invalidation);
    522   VerifyTargetEqualsSource(target_bounds_);
    523 
    524   std::vector<Tile*> new_tiles = target_->tiling_at(0)->AllTilesForTesting();
    525   for (size_t i = 0; i < new_tiles.size(); ++i) {
    526     const Tile* tile = new_tiles[i];
    527     std::map<gfx::Point, scoped_refptr<Tile> >::iterator find =
    528         old_tile_map.find(tile->content_rect().origin());
    529     if (content_invalidation.Intersects(tile->content_rect()))
    530       EXPECT_NE(tile, find->second.get());
    531     else
    532       EXPECT_EQ(tile, find->second.get());
    533   }
    534 }
    535 
    536 TEST_F(PictureLayerTilingSetSyncTest, TileSizeChange) {
    537   source_->AddTiling(1.f);
    538   target_->AddTiling(1.f);
    539 
    540   target_->tiling_at(0)->CreateAllTilesForTesting();
    541   std::vector<Tile*> original_tiles =
    542       target_->tiling_at(0)->AllTilesForTesting();
    543   EXPECT_GT(original_tiles.size(), 0u);
    544   gfx::Size new_tile_size(100, 100);
    545   target_client_.SetTileSize(new_tile_size);
    546   EXPECT_NE(target_->tiling_at(0)->tile_size().ToString(),
    547             new_tile_size.ToString());
    548 
    549   gfx::Size new_bounds(15, 40);
    550   SyncTilings(new_bounds);
    551   VerifyTargetEqualsSource(new_bounds);
    552 
    553   EXPECT_EQ(target_->tiling_at(0)->tile_size().ToString(),
    554             new_tile_size.ToString());
    555 
    556   // All old tiles should not be present in new tiles.
    557   std::vector<Tile*> new_tiles = target_->tiling_at(0)->AllTilesForTesting();
    558   for (size_t i = 0; i < original_tiles.size(); ++i) {
    559     std::vector<Tile*>::iterator find =
    560         std::find(new_tiles.begin(), new_tiles.end(), original_tiles[i]);
    561     EXPECT_TRUE(find == new_tiles.end());
    562   }
    563 }
    564 
    565 }  // namespace
    566 }  // namespace cc
    567