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