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 "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace cc { | |
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 | |
52 scoped_refptr<RasterSource> FakePicturePile::CreateRasterSource( | |
53 bool can_use_lcd_text) const { | |
54 return FakePicturePileImpl::CreateFromPile(this, playback_allowed_event_); | |
55 } | |
56 | |
57 void FakePicturePile::AddRecordingAt(int x, int y) { | |
58 EXPECT_GE(x, 0); | |
59 EXPECT_GE(y, 0); | |
60 EXPECT_LT(x, tiling_.num_tiles_x()); | |
61 EXPECT_LT(y, tiling_.num_tiles_y()); | |
62 | |
63 if (HasRecordingAt(x, y)) | |
64 return; | |
65 gfx::Rect bounds(tiling().TileBounds(x, y)); | |
66 bounds.Inset(-buffer_pixels(), -buffer_pixels()); | |
67 | |
68 scoped_refptr<Picture> picture( | |
69 Picture::Create(bounds, &client_, tile_grid_size_, true, | |
70 RecordingSource::RECORD_NORMALLY)); | |
71 picture_map_[std::pair<int, int>(x, y)].SetPicture(picture); | |
72 EXPECT_TRUE(HasRecordingAt(x, y)); | |
73 | |
74 has_any_recordings_ = true; | |
75 } | |
76 | |
77 void FakePicturePile::RemoveRecordingAt(int x, int y) { | |
78 EXPECT_GE(x, 0); | |
79 EXPECT_GE(y, 0); | |
80 EXPECT_LT(x, tiling_.num_tiles_x()); | |
81 EXPECT_LT(y, tiling_.num_tiles_y()); | |
82 | |
83 if (!HasRecordingAt(x, y)) | |
84 return; | |
85 picture_map_.erase(std::pair<int, int>(x, y)); | |
86 EXPECT_FALSE(HasRecordingAt(x, y)); | |
87 } | |
88 | |
89 bool FakePicturePile::HasRecordingAt(int x, int y) const { | |
90 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); | |
91 if (found == picture_map_.end()) | |
92 return false; | |
93 return !!found->second.GetPicture(); | |
94 } | |
95 | |
96 void FakePicturePile::RerecordPile() { | |
97 for (int y = 0; y < num_tiles_y(); ++y) { | |
98 for (int x = 0; x < num_tiles_x(); ++x) { | |
99 RemoveRecordingAt(x, y); | |
100 AddRecordingAt(x, y); | |
101 } | |
102 } | |
103 } | |
104 | |
105 } // namespace cc | |
OLD | NEW |