| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 gfx::Transform inverse; | 28 gfx::Transform inverse; |
| 29 if (!transform.GetInverse(&inverse)) | 29 if (!transform.GetInverse(&inverse)) |
| 30 return gfx::Rect(); | 30 return gfx::Rect(); |
| 31 | 31 |
| 32 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( | 32 gfx::RectF viewport_in_layer_space = MathUtil::ProjectClippedRect( |
| 33 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); | 33 inverse, gfx::RectF(gfx::Point(0, 0), device_viewport)); |
| 34 return ToEnclosingRect(viewport_in_layer_space); | 34 return ToEnclosingRect(viewport_in_layer_space); |
| 35 } | 35 } |
| 36 | 36 |
| 37 static void UpdateAllTilePriorities(PictureLayerTilingSet* set, |
| 38 WhichTree tree, |
| 39 const gfx::Rect& visible_layer_rect, |
| 40 float layer_contents_scale, |
| 41 double current_frame_time_in_seconds) { |
| 42 for (size_t i = 0; i < set->num_tilings(); ++i) { |
| 43 set->tiling_at(i)->UpdateTilePriorities(tree, |
| 44 visible_layer_rect, |
| 45 layer_contents_scale, |
| 46 current_frame_time_in_seconds); |
| 47 } |
| 48 } |
| 49 |
| 37 class TestablePictureLayerTiling : public PictureLayerTiling { | 50 class TestablePictureLayerTiling : public PictureLayerTiling { |
| 38 public: | 51 public: |
| 39 using PictureLayerTiling::SetLiveTilesRect; | 52 using PictureLayerTiling::SetLiveTilesRect; |
| 40 using PictureLayerTiling::TileAt; | 53 using PictureLayerTiling::TileAt; |
| 41 | 54 |
| 42 static scoped_ptr<TestablePictureLayerTiling> Create( | 55 static scoped_ptr<TestablePictureLayerTiling> Create( |
| 43 float contents_scale, | 56 float contents_scale, |
| 44 const gfx::Size& layer_bounds, | 57 const gfx::Size& layer_bounds, |
| 45 PictureLayerTilingClient* client) { | 58 PictureLayerTilingClient* client) { |
| 46 return make_scoped_ptr(new TestablePictureLayerTiling( | 59 return make_scoped_ptr(new TestablePictureLayerTiling( |
| (...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 | 1177 |
| 1165 PictureLayerTilingSet active_set(&client_, layer_bounds); | 1178 PictureLayerTilingSet active_set(&client_, layer_bounds); |
| 1166 | 1179 |
| 1167 active_set.AddTiling(1.f); | 1180 active_set.AddTiling(1.f); |
| 1168 | 1181 |
| 1169 VerifyTiles(active_set.tiling_at(0), | 1182 VerifyTiles(active_set.tiling_at(0), |
| 1170 1.f, | 1183 1.f, |
| 1171 gfx::Rect(layer_bounds), | 1184 gfx::Rect(layer_bounds), |
| 1172 base::Bind(&TileExists, false)); | 1185 base::Bind(&TileExists, false)); |
| 1173 | 1186 |
| 1174 active_set.UpdateTilePriorities( | 1187 UpdateAllTilePriorities(&active_set, |
| 1175 PENDING_TREE, | 1188 PENDING_TREE, |
| 1176 gfx::Rect(layer_bounds), // visible content rect | 1189 gfx::Rect(layer_bounds), // visible content rect |
| 1177 1.f, // current contents scale | 1190 1.f, // current contents scale |
| 1178 1.0); // current frame time | 1191 1.0); // current frame time |
| 1179 | 1192 |
| 1180 // The active tiling has tiles now. | 1193 // The active tiling has tiles now. |
| 1181 VerifyTiles(active_set.tiling_at(0), | 1194 VerifyTiles(active_set.tiling_at(0), |
| 1182 1.f, | 1195 1.f, |
| 1183 gfx::Rect(layer_bounds), | 1196 gfx::Rect(layer_bounds), |
| 1184 base::Bind(&TileExists, true)); | 1197 base::Bind(&TileExists, true)); |
| 1185 | 1198 |
| 1186 // Add the same tilings to the pending set. | 1199 // Add the same tilings to the pending set. |
| 1187 PictureLayerTilingSet pending_set(&client_, layer_bounds); | 1200 PictureLayerTilingSet pending_set(&client_, layer_bounds); |
| 1188 Region invalidation; | 1201 Region invalidation; |
| 1189 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); | 1202 pending_set.SyncTilings(active_set, layer_bounds, invalidation, 0.f); |
| 1190 | 1203 |
| 1191 // The pending tiling starts with no tiles. | 1204 // The pending tiling starts with no tiles. |
| 1192 VerifyTiles(pending_set.tiling_at(0), | 1205 VerifyTiles(pending_set.tiling_at(0), |
| 1193 1.f, | 1206 1.f, |
| 1194 gfx::Rect(layer_bounds), | 1207 gfx::Rect(layer_bounds), |
| 1195 base::Bind(&TileExists, false)); | 1208 base::Bind(&TileExists, false)); |
| 1196 | 1209 |
| 1197 // UpdateTilePriorities on the pending tiling at the same frame time. The | 1210 // UpdateTilePriorities on the pending tiling at the same frame time. The |
| 1198 // pending tiling should get tiles. | 1211 // pending tiling should get tiles. |
| 1199 pending_set.UpdateTilePriorities( | 1212 UpdateAllTilePriorities(&pending_set, |
| 1200 PENDING_TREE, | 1213 PENDING_TREE, |
| 1201 gfx::Rect(layer_bounds), // visible content rect | 1214 gfx::Rect(layer_bounds), // visible content rect |
| 1202 1.f, // current contents scale | 1215 1.f, // current contents scale |
| 1203 1.0); // current frame time | 1216 1.0); // current frame time |
| 1204 | 1217 |
| 1205 VerifyTiles(pending_set.tiling_at(0), | 1218 VerifyTiles(pending_set.tiling_at(0), |
| 1206 1.f, | 1219 1.f, |
| 1207 gfx::Rect(layer_bounds), | 1220 gfx::Rect(layer_bounds), |
| 1208 base::Bind(&TileExists, true)); | 1221 base::Bind(&TileExists, true)); |
| 1209 } | 1222 } |
| 1210 | 1223 |
| 1211 TEST(UpdateTilePrioritiesTest, VisibleTiles) { | 1224 TEST(UpdateTilePrioritiesTest, VisibleTiles) { |
| 1212 // The TilePriority of visible tiles should have zero distance_to_visible | 1225 // The TilePriority of visible tiles should have zero distance_to_visible |
| 1213 // and time_to_visible. | 1226 // and time_to_visible. |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1736 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1749 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 1737 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1750 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1738 | 1751 |
| 1739 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); | 1752 priority = tiling->TileAt(1, 0)->priority(ACTIVE_TREE); |
| 1740 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); | 1753 EXPECT_FLOAT_EQ(0.f, priority.distance_to_visible); |
| 1741 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); | 1754 EXPECT_EQ(TilePriority::NOW, priority.priority_bin); |
| 1742 } | 1755 } |
| 1743 | 1756 |
| 1744 } // namespace | 1757 } // namespace |
| 1745 } // namespace cc | 1758 } // namespace cc |
| OLD | NEW |