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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include "cc/test/fake_content_layer_client.h" | 7 #include "cc/test/fake_content_layer_client.h" |
8 #include "cc/test/fake_picture_layer.h" | 8 #include "cc/test/fake_picture_layer.h" |
9 #include "cc/test/fake_picture_layer_impl.h" | 9 #include "cc/test/fake_picture_layer_impl.h" |
10 #include "cc/test/layer_tree_test.h" | 10 #include "cc/test/layer_tree_test.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 void AfterTest() override {} | 184 void AfterTest() override {} |
185 | 185 |
186 gfx::Size tile_size_; | 186 gfx::Size tile_size_; |
187 FakeContentLayerClient client_; | 187 FakeContentLayerClient client_; |
188 scoped_refptr<FakePictureLayer> picture_; | 188 scoped_refptr<FakePictureLayer> picture_; |
189 }; | 189 }; |
190 | 190 |
191 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F( | 191 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F( |
192 LayerTreeHostPictureTestResizeViewportWithGpuRaster); | 192 LayerTreeHostPictureTestResizeViewportWithGpuRaster); |
193 | 193 |
| 194 class LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree |
| 195 : public LayerTreeHostPictureTest { |
| 196 void SetupTree() override { |
| 197 frame_ = 0; |
| 198 did_post_commit_ = false; |
| 199 |
| 200 scoped_refptr<Layer> root = Layer::Create(); |
| 201 root->SetBounds(gfx::Size(100, 100)); |
| 202 |
| 203 // The layer is big enough that the live tiles rect won't cover the full |
| 204 // layer. |
| 205 client_.set_fill_with_nonsolid_color(true); |
| 206 picture_ = FakePictureLayer::Create(&client_); |
| 207 picture_->SetBounds(gfx::Size(100, 100000)); |
| 208 root->AddChild(picture_); |
| 209 |
| 210 layer_tree_host()->SetRootLayer(root); |
| 211 LayerTreeHostPictureTest::SetupTree(); |
| 212 } |
| 213 |
| 214 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 215 |
| 216 void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| 217 LayerImpl* child = impl->active_tree()->root_layer()->children()[0]; |
| 218 FakePictureLayerImpl* picture_impl = |
| 219 static_cast<FakePictureLayerImpl*>(child); |
| 220 FakePictureLayerImpl* recycled_impl = static_cast<FakePictureLayerImpl*>( |
| 221 picture_impl->GetRecycledTwinLayer()); |
| 222 |
| 223 switch (++frame_) { |
| 224 case 1: { |
| 225 PictureLayerTiling* tiling = picture_impl->HighResTiling(); |
| 226 PictureLayerTiling* recycled_tiling = recycled_impl->HighResTiling(); |
| 227 int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y(); |
| 228 |
| 229 // There should be tiles at the top of the picture layer but not at the |
| 230 // bottom. |
| 231 EXPECT_TRUE(tiling->TileAt(0, 0)); |
| 232 EXPECT_FALSE(tiling->TileAt(0, num_tiles_y)); |
| 233 |
| 234 // The recycled tiling matches it. |
| 235 EXPECT_TRUE(recycled_tiling->TileAt(0, 0)); |
| 236 EXPECT_FALSE(recycled_tiling->TileAt(0, num_tiles_y)); |
| 237 |
| 238 // The live tiles rect matches on the recycled tree. |
| 239 EXPECT_EQ(tiling->live_tiles_rect(), |
| 240 recycled_tiling->live_tiles_rect()); |
| 241 |
| 242 // Make the bottom of the layer visible. |
| 243 picture_impl->SetPosition(gfx::PointF(0.f, -100000.f + 100.f)); |
| 244 impl->SetNeedsRedraw(); |
| 245 break; |
| 246 } |
| 247 case 2: { |
| 248 PictureLayerTiling* tiling = picture_impl->HighResTiling(); |
| 249 PictureLayerTiling* recycled_tiling = recycled_impl->HighResTiling(); |
| 250 |
| 251 // There not be tiles at the top of the layer now. |
| 252 EXPECT_FALSE(tiling->TileAt(0, 0)); |
| 253 |
| 254 // The recycled twin tiling should not have unshared tiles at the top |
| 255 // either. |
| 256 EXPECT_FALSE(recycled_tiling->TileAt(0, 0)); |
| 257 |
| 258 // The live tiles rect matches on the recycled tree. |
| 259 EXPECT_EQ(tiling->live_tiles_rect(), |
| 260 recycled_tiling->live_tiles_rect()); |
| 261 |
| 262 // Make the top of the layer visible again. |
| 263 picture_impl->SetPosition(gfx::PointF()); |
| 264 impl->SetNeedsRedraw(); |
| 265 break; |
| 266 } |
| 267 case 3: { |
| 268 PictureLayerTiling* tiling = picture_impl->HighResTiling(); |
| 269 PictureLayerTiling* recycled_tiling = recycled_impl->HighResTiling(); |
| 270 int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y(); |
| 271 |
| 272 // There should be tiles at the top of the picture layer again. |
| 273 EXPECT_TRUE(tiling->TileAt(0, 0)); |
| 274 EXPECT_FALSE(tiling->TileAt(0, num_tiles_y)); |
| 275 |
| 276 // The recycled tiling should also have tiles at the top. |
| 277 EXPECT_TRUE(recycled_tiling->TileAt(0, 0)); |
| 278 EXPECT_FALSE(recycled_tiling->TileAt(0, num_tiles_y)); |
| 279 |
| 280 // The live tiles rect matches on the recycled tree. |
| 281 EXPECT_EQ(tiling->live_tiles_rect(), |
| 282 recycled_tiling->live_tiles_rect()); |
| 283 |
| 284 // Make a new main frame without changing the picture layer at all, so |
| 285 // it won't need to update or push properties. |
| 286 did_post_commit_ = true; |
| 287 PostSetNeedsCommitToMainThread(); |
| 288 break; |
| 289 } |
| 290 } |
| 291 } |
| 292 |
| 293 void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 294 LayerImpl* child = impl->sync_tree()->root_layer()->children()[0]; |
| 295 FakePictureLayerImpl* picture_impl = |
| 296 static_cast<FakePictureLayerImpl*>(child); |
| 297 PictureLayerTiling* tiling = picture_impl->HighResTiling(); |
| 298 int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y(); |
| 299 |
| 300 // The pending layer should always have tiles at the top of it each commit. |
| 301 // The tile is part of the required for activation set so it should exist. |
| 302 EXPECT_TRUE(tiling->TileAt(0, 0)); |
| 303 EXPECT_FALSE(tiling->TileAt(0, num_tiles_y)); |
| 304 |
| 305 if (did_post_commit_) |
| 306 EndTest(); |
| 307 } |
| 308 |
| 309 void AfterTest() override {} |
| 310 |
| 311 int frame_; |
| 312 bool did_post_commit_; |
| 313 FakeContentLayerClient client_; |
| 314 scoped_refptr<FakePictureLayer> picture_; |
| 315 }; |
| 316 |
| 317 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F( |
| 318 LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree); |
| 319 |
194 } // namespace | 320 } // namespace |
195 } // namespace cc | 321 } // namespace cc |
OLD | NEW |