OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_impl.h" | 5 #include "cc/test/fake_picture_pile_impl.h" |
6 | 6 |
| 7 #include <algorithm> |
7 #include <limits> | 8 #include <limits> |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
| 11 #include "cc/resources/picture_pile.h" |
| 12 #include "cc/test/fake_picture_pile.h" |
10 #include "cc/test/impl_side_painting_settings.h" | 13 #include "cc/test/impl_side_painting_settings.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
12 | 15 |
13 namespace cc { | 16 namespace cc { |
14 | 17 |
15 FakePicturePileImpl::FakePicturePileImpl() {} | 18 FakePicturePileImpl::FakePicturePileImpl() {} |
16 | 19 |
| 20 FakePicturePileImpl::FakePicturePileImpl(const PicturePile* other) |
| 21 : PicturePileImpl(other), |
| 22 tile_grid_info_(other->GetTileGridInfoForTesting()) { |
| 23 } |
| 24 |
17 FakePicturePileImpl::~FakePicturePileImpl() {} | 25 FakePicturePileImpl::~FakePicturePileImpl() {} |
18 | 26 |
19 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile( | 27 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile( |
20 const gfx::Size& tile_size, | 28 const gfx::Size& tile_size, |
21 const gfx::Size& layer_bounds) { | 29 const gfx::Size& layer_bounds) { |
22 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); | 30 FakePicturePile pile; |
23 pile->tiling().SetTilingSize(layer_bounds); | 31 pile.tiling().SetTilingSize(layer_bounds); |
24 pile->tiling().SetMaxTextureSize(tile_size); | 32 pile.tiling().SetMaxTextureSize(tile_size); |
25 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); | 33 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); |
26 pile->recorded_viewport_ = gfx::Rect(layer_bounds); | 34 pile.SetRecordedViewport(gfx::Rect(layer_bounds)); |
27 pile->has_any_recordings_ = true; | 35 pile.SetHasAnyRecordings(true); |
28 for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) { | 36 |
29 for (int y = 0; y < pile->tiling().num_tiles_y(); ++y) | 37 auto pile_impl = make_scoped_refptr(new FakePicturePileImpl(&pile)); |
30 pile->AddRecordingAt(x, y); | 38 for (int x = 0; x < pile_impl->tiling().num_tiles_x(); ++x) { |
| 39 for (int y = 0; y < pile_impl->tiling().num_tiles_y(); ++y) |
| 40 pile_impl->AddRecordingAt(x, y); |
31 } | 41 } |
32 return pile; | 42 return pile_impl; |
33 } | 43 } |
34 | 44 |
35 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile( | 45 scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile( |
36 const gfx::Size& tile_size, | 46 const gfx::Size& tile_size, |
37 const gfx::Size& layer_bounds) { | 47 const gfx::Size& layer_bounds) { |
38 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); | 48 FakePicturePile pile; |
39 pile->tiling().SetTilingSize(layer_bounds); | 49 pile.tiling().SetTilingSize(layer_bounds); |
40 pile->tiling().SetMaxTextureSize(tile_size); | 50 pile.tiling().SetMaxTextureSize(tile_size); |
41 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); | 51 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); |
42 pile->recorded_viewport_ = gfx::Rect(); | 52 pile.SetRecordedViewport(gfx::Rect()); |
43 pile->has_any_recordings_ = false; | 53 pile.SetHasAnyRecordings(false); |
44 return pile; | 54 return make_scoped_refptr(new FakePicturePileImpl(&pile)); |
45 } | 55 } |
46 | 56 |
47 scoped_refptr<FakePicturePileImpl> | 57 scoped_refptr<FakePicturePileImpl> |
48 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( | 58 FakePicturePileImpl::CreateEmptyPileThatThinksItHasRecordings( |
49 const gfx::Size& tile_size, | 59 const gfx::Size& tile_size, |
50 const gfx::Size& layer_bounds) { | 60 const gfx::Size& layer_bounds) { |
51 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); | 61 FakePicturePile pile; |
52 pile->tiling().SetTilingSize(layer_bounds); | 62 pile.tiling().SetTilingSize(layer_bounds); |
53 pile->tiling().SetMaxTextureSize(tile_size); | 63 pile.tiling().SetMaxTextureSize(tile_size); |
54 pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); | 64 pile.SetTileGridSize(ImplSidePaintingSettings().default_tile_grid_size); |
55 // This simulates a false positive for this flag. | 65 // This simulates a false positive for this flag. |
56 pile->recorded_viewport_ = gfx::Rect(); | 66 pile.SetRecordedViewport(gfx::Rect()); |
57 pile->has_any_recordings_ = true; | 67 pile.SetHasAnyRecordings(true); |
58 return pile; | 68 return make_scoped_refptr(new FakePicturePileImpl(&pile)); |
59 } | 69 } |
60 | 70 |
61 scoped_refptr<FakePicturePileImpl> | 71 scoped_refptr<FakePicturePileImpl> |
62 FakePicturePileImpl::CreateInfiniteFilledPile() { | 72 FakePicturePileImpl::CreateInfiniteFilledPile() { |
63 scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl()); | 73 FakePicturePile pile; |
64 gfx::Size size(std::numeric_limits<int>::max(), | 74 gfx::Size size(std::numeric_limits<int>::max(), |
65 std::numeric_limits<int>::max()); | 75 std::numeric_limits<int>::max()); |
66 pile->tiling().SetTilingSize(size); | 76 pile.tiling().SetTilingSize(size); |
67 pile->tiling().SetMaxTextureSize(size); | 77 pile.tiling().SetMaxTextureSize(size); |
68 pile->SetTileGridSize(size); | 78 pile.SetTileGridSize(size); |
69 pile->recorded_viewport_ = gfx::Rect(size); | 79 pile.SetRecordedViewport(gfx::Rect(size)); |
70 pile->has_any_recordings_ = true; | 80 pile.SetHasAnyRecordings(true); |
71 pile->AddRecordingAt(0, 0); | 81 |
72 return pile; | 82 auto pile_impl = make_scoped_refptr(new FakePicturePileImpl(&pile)); |
| 83 pile_impl->AddRecordingAt(0, 0); |
| 84 return pile_impl; |
73 } | 85 } |
74 | 86 |
75 void FakePicturePileImpl::AddRecordingAt(int x, int y) { | 87 void FakePicturePileImpl::AddRecordingAt(int x, int y) { |
76 EXPECT_GE(x, 0); | 88 EXPECT_GE(x, 0); |
77 EXPECT_GE(y, 0); | 89 EXPECT_GE(y, 0); |
78 EXPECT_LT(x, tiling_.num_tiles_x()); | 90 EXPECT_LT(x, tiling_.num_tiles_x()); |
79 EXPECT_LT(y, tiling_.num_tiles_y()); | 91 EXPECT_LT(y, tiling_.num_tiles_y()); |
80 | 92 |
81 if (HasRecordingAt(x, y)) | 93 if (HasRecordingAt(x, y)) |
82 return; | 94 return; |
(...skipping 13 matching lines...) Expand all Loading... |
96 EXPECT_GE(y, 0); | 108 EXPECT_GE(y, 0); |
97 EXPECT_LT(x, tiling_.num_tiles_x()); | 109 EXPECT_LT(x, tiling_.num_tiles_x()); |
98 EXPECT_LT(y, tiling_.num_tiles_y()); | 110 EXPECT_LT(y, tiling_.num_tiles_y()); |
99 | 111 |
100 if (!HasRecordingAt(x, y)) | 112 if (!HasRecordingAt(x, y)) |
101 return; | 113 return; |
102 picture_map_.erase(std::pair<int, int>(x, y)); | 114 picture_map_.erase(std::pair<int, int>(x, y)); |
103 EXPECT_FALSE(HasRecordingAt(x, y)); | 115 EXPECT_FALSE(HasRecordingAt(x, y)); |
104 } | 116 } |
105 | 117 |
| 118 bool FakePicturePileImpl::HasRecordingAt(int x, int y) const { |
| 119 PictureMap::const_iterator found = picture_map_.find(PictureMapKey(x, y)); |
| 120 if (found == picture_map_.end()) |
| 121 return false; |
| 122 return !!found->second.GetPicture(); |
| 123 } |
| 124 |
106 void FakePicturePileImpl::RerecordPile() { | 125 void FakePicturePileImpl::RerecordPile() { |
107 for (int y = 0; y < num_tiles_y(); ++y) { | 126 for (int y = 0; y < num_tiles_y(); ++y) { |
108 for (int x = 0; x < num_tiles_x(); ++x) { | 127 for (int x = 0; x < num_tiles_x(); ++x) { |
109 RemoveRecordingAt(x, y); | 128 RemoveRecordingAt(x, y); |
110 AddRecordingAt(x, y); | 129 AddRecordingAt(x, y); |
111 } | 130 } |
112 } | 131 } |
113 } | 132 } |
114 | 133 |
| 134 void FakePicturePileImpl::SetMinContentsScale(float min_contents_scale) { |
| 135 if (min_contents_scale_ == min_contents_scale) |
| 136 return; |
| 137 |
| 138 // Picture contents are played back scaled. When the final contents scale is |
| 139 // less than 1 (i.e. low res), then multiple recorded pixels will be used |
| 140 // to raster one final pixel. To avoid splitting a final pixel across |
| 141 // pictures (which would result in incorrect rasterization due to blending), a |
| 142 // buffer margin is added so that any picture can be snapped to integral |
| 143 // final pixels. |
| 144 // |
| 145 // For example, if a 1/4 contents scale is used, then that would be 3 buffer |
| 146 // pixels, since that's the minimum number of pixels to add so that resulting |
| 147 // content can be snapped to a four pixel aligned grid. |
| 148 int buffer_pixels = static_cast<int>(ceil(1 / min_contents_scale) - 1); |
| 149 buffer_pixels = std::max(0, buffer_pixels); |
| 150 SetBufferPixels(buffer_pixels); |
| 151 min_contents_scale_ = min_contents_scale; |
| 152 } |
| 153 |
| 154 void FakePicturePileImpl::SetBufferPixels(int new_buffer_pixels) { |
| 155 if (new_buffer_pixels == buffer_pixels()) |
| 156 return; |
| 157 |
| 158 Clear(); |
| 159 tiling_.SetBorderTexels(new_buffer_pixels); |
| 160 } |
| 161 |
| 162 void FakePicturePileImpl::Clear() { |
| 163 picture_map_.clear(); |
| 164 recorded_viewport_ = gfx::Rect(); |
| 165 } |
| 166 |
115 } // namespace cc | 167 } // namespace cc |
OLD | NEW |