| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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/test/fake_picture_pile.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "cc/test/fake_picture_pile_impl.h" | |
| 10 #include "cc/trees/layer_tree_settings.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace cc { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 scoped_ptr<FakePicturePile> CreatePile(const gfx::Size& tile_size, | |
| 18 const gfx::Size& layer_bounds, | |
| 19 bool is_filled) { | |
| 20 scoped_ptr<FakePicturePile> pile( | |
| 21 new FakePicturePile(LayerTreeSettings().minimum_contents_scale, | |
| 22 LayerTreeSettings().default_tile_grid_size)); | |
| 23 pile->tiling().SetBorderTexels(0); | |
| 24 pile->tiling().SetTilingSize(layer_bounds); | |
| 25 pile->tiling().SetMaxTextureSize(tile_size); | |
| 26 pile->SetRecordedViewport(is_filled ? gfx::Rect(layer_bounds) : gfx::Rect()); | |
| 27 pile->SetHasAnyRecordings(is_filled); | |
| 28 if (is_filled) { | |
| 29 for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) { | |
| 30 for (int y = 0; y < pile->tiling().num_tiles_y(); ++y) | |
| 31 pile->AddRecordingAt(x, y); | |
| 32 } | |
| 33 } | |
| 34 return pile; | |
| 35 } | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 scoped_ptr<FakePicturePile> FakePicturePile::CreateFilledPile( | |
| 40 const gfx::Size& tile_size, | |
| 41 const gfx::Size& layer_bounds) { | |
| 42 bool is_filled = true; | |
| 43 return CreatePile(tile_size, layer_bounds, is_filled); | |
| 44 } | |
| 45 | |
| 46 scoped_ptr<FakePicturePile> FakePicturePile::CreateEmptyPile( | |
| 47 const gfx::Size& tile_size, | |
| 48 const gfx::Size& layer_bounds) { | |
| 49 bool is_filled = false; | |
| 50 return CreatePile(tile_size, layer_bounds, is_filled); | |
| 51 } | |
| 52 | |
| 53 scoped_refptr<RasterSource> FakePicturePile::CreateRasterSource( | |
| 54 bool can_use_lcd_text) const { | |
| 55 return FakePicturePileImpl::CreateFromPile(this, playback_allowed_event_); | |
| 56 } | |
| 57 | |
| 58 void FakePicturePile::AddRecordingAt(int x, int y) { | |
| 59 EXPECT_GE(x, 0); | |
| 60 EXPECT_GE(y, 0); | |
| 61 EXPECT_LT(x, tiling_.num_tiles_x()); | |
| 62 EXPECT_LT(y, tiling_.num_tiles_y()); | |
| 63 | |
| 64 if (HasRecordingAt(x, y)) | |
| 65 return; | |
| 66 gfx::Rect bounds(tiling().TileBounds(x, y)); | |
| 67 bounds.Inset(-buffer_pixels(), -buffer_pixels()); | |
| 68 | |
| 69 scoped_refptr<Picture> picture( | |
| 70 Picture::Create(bounds, &client_, tile_grid_size_, gather_images_, | |
| 71 RecordingSource::RECORD_NORMALLY)); | |
| 72 picture_map_[std::pair<int, int>(x, y)] = picture; | |
| 73 EXPECT_TRUE(HasRecordingAt(x, y)); | |
| 74 | |
| 75 has_any_recordings_ = true; | |
| 76 } | |
| 77 | |
| 78 void FakePicturePile::RemoveRecordingAt(int x, int y) { | |
| 79 EXPECT_GE(x, 0); | |
| 80 EXPECT_GE(y, 0); | |
| 81 EXPECT_LT(x, tiling_.num_tiles_x()); | |
| 82 EXPECT_LT(y, tiling_.num_tiles_y()); | |
| 83 | |
| 84 if (!HasRecordingAt(x, y)) | |
| 85 return; | |
| 86 picture_map_.erase(std::pair<int, int>(x, y)); | |
| 87 EXPECT_FALSE(HasRecordingAt(x, y)); | |
| 88 } | |
| 89 | |
| 90 bool FakePicturePile::HasRecordingAt(int x, int y) const { | |
| 91 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); | |
| 92 return found != picture_map_.end(); | |
| 93 } | |
| 94 | |
| 95 void FakePicturePile::Rerecord() { | |
| 96 for (int y = 0; y < num_tiles_y(); ++y) { | |
| 97 for (int x = 0; x < num_tiles_x(); ++x) { | |
| 98 RemoveRecordingAt(x, y); | |
| 99 AddRecordingAt(x, y); | |
| 100 } | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 } // namespace cc | |
| OLD | NEW |