OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <memory> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "cc/layers/empty_content_layer_client.h" |
7 #include "cc/layers/heads_up_display_layer.h" | 11 #include "cc/layers/heads_up_display_layer.h" |
8 #include "cc/layers/layer.h" | 12 #include "cc/layers/layer.h" |
9 #include "cc/proto/layer.pb.h" | 13 #include "cc/proto/layer.pb.h" |
10 #include "cc/proto/layer_tree_host.pb.h" | 14 #include "cc/proto/layer_tree_host.pb.h" |
| 15 #include "cc/test/fake_image_serialization_processor.h" |
11 #include "cc/test/fake_layer_tree_host.h" | 16 #include "cc/test/fake_layer_tree_host.h" |
12 #include "cc/test/fake_layer_tree_host_client.h" | 17 #include "cc/test/fake_layer_tree_host_client.h" |
| 18 #include "cc/test/fake_picture_layer.h" |
| 19 #include "cc/test/fake_recording_source.h" |
13 #include "cc/test/layer_tree_test.h" | 20 #include "cc/test/layer_tree_test.h" |
14 #include "cc/test/test_task_graph_runner.h" | 21 #include "cc/test/test_task_graph_runner.h" |
15 #include "cc/trees/layer_tree_settings.h" | 22 #include "cc/trees/layer_tree_settings.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/skia/include/core/SkColor.h" | 24 #include "third_party/skia/include/core/SkColor.h" |
18 #include "ui/gfx/geometry/point.h" | 25 #include "ui/gfx/geometry/point.h" |
19 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
20 #include "ui/gfx/geometry/vector2d_f.h" | 27 #include "ui/gfx/geometry/vector2d_f.h" |
21 | 28 |
22 namespace cc { | 29 namespace cc { |
23 | 30 |
| 31 namespace { |
| 32 std::unique_ptr<FakeRecordingSource> CreateRecordingSource( |
| 33 const gfx::Rect& viewport) { |
| 34 gfx::Rect layer_rect(viewport.right(), viewport.bottom()); |
| 35 std::unique_ptr<FakeRecordingSource> recording_source = |
| 36 FakeRecordingSource::CreateRecordingSource(viewport, layer_rect.size()); |
| 37 return recording_source; |
| 38 } |
| 39 |
| 40 scoped_refptr<FakePictureLayer> CreatePictureLayer() { |
| 41 gfx::Rect recorded_viewport(0, 0, 256, 256); |
| 42 |
| 43 std::unique_ptr<FakeRecordingSource> recording_source = |
| 44 CreateRecordingSource(recorded_viewport); |
| 45 recording_source->SetDisplayListUsesCachedPicture(false); |
| 46 |
| 47 SkPaint simple_paint; |
| 48 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34)); |
| 49 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), |
| 50 simple_paint); |
| 51 recording_source->SetGenerateDiscardableImagesMetadata(true); |
| 52 recording_source->Rerecord(); |
| 53 |
| 54 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
| 55 return FakePictureLayer::CreateWithRecordingSource( |
| 56 client, std::move(recording_source)); |
| 57 } |
| 58 } // namespace |
| 59 |
24 class LayerTreeHostSerializationTest : public testing::Test { | 60 class LayerTreeHostSerializationTest : public testing::Test { |
25 public: | 61 public: |
26 LayerTreeHostSerializationTest() | 62 LayerTreeHostSerializationTest() |
27 : client_src_(FakeLayerTreeHostClient::DIRECT_3D), | 63 : image_serialization_processor_( |
| 64 base::WrapUnique(new FakeImageSerializationProcessor)), |
| 65 client_src_(FakeLayerTreeHostClient::DIRECT_3D), |
28 client_dst_(FakeLayerTreeHostClient::DIRECT_3D) {} | 66 client_dst_(FakeLayerTreeHostClient::DIRECT_3D) {} |
29 | 67 |
30 protected: | 68 protected: |
31 void SetUp() override { | 69 void SetUp() override { |
32 layer_tree_host_src_ = | 70 LayerTreeSettings settings; |
33 FakeLayerTreeHost::Create(&client_src_, &task_graph_runner_src_); | 71 layer_tree_host_src_ = FakeLayerTreeHost::Create( |
34 layer_tree_host_dst_ = | 72 &client_src_, &task_graph_runner_src_, settings, |
35 FakeLayerTreeHost::Create(&client_dst_, &task_graph_runner_dst_); | 73 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get()); |
| 74 layer_tree_host_dst_ = FakeLayerTreeHost::Create( |
| 75 &client_dst_, &task_graph_runner_dst_, settings, |
| 76 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get()); |
| 77 layer_tree_host_src_->InitializePictureCacheForTesting(); |
| 78 layer_tree_host_dst_->InitializePictureCacheForTesting(); |
36 } | 79 } |
37 | 80 |
38 void TearDown() override { | 81 void TearDown() override { |
39 // Need to reset |in_paint_layer_contents_| to tear down. | 82 // Need to reset |in_paint_layer_contents_| to tear down. |
40 layer_tree_host_src_->in_paint_layer_contents_ = false; | 83 layer_tree_host_src_->in_paint_layer_contents_ = false; |
41 layer_tree_host_dst_->in_paint_layer_contents_ = false; | 84 layer_tree_host_dst_->in_paint_layer_contents_ = false; |
42 | 85 |
43 // Need to reset LayerTreeHost pointers before tear down. | 86 // Need to reset LayerTreeHost pointers before tear down. |
44 layer_tree_host_src_ = nullptr; | 87 layer_tree_host_src_ = nullptr; |
45 layer_tree_host_dst_ = nullptr; | 88 layer_tree_host_dst_ = nullptr; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 layer_tree_host_src_->overscroll_elasticity_layer_ = nullptr; | 346 layer_tree_host_src_->overscroll_elasticity_layer_ = nullptr; |
304 VerifySerializationAndDeserialization(); | 347 VerifySerializationAndDeserialization(); |
305 layer_tree_host_src_->page_scale_layer_ = nullptr; | 348 layer_tree_host_src_->page_scale_layer_ = nullptr; |
306 VerifySerializationAndDeserialization(); | 349 VerifySerializationAndDeserialization(); |
307 layer_tree_host_src_->inner_viewport_scroll_layer_ = nullptr; | 350 layer_tree_host_src_->inner_viewport_scroll_layer_ = nullptr; |
308 VerifySerializationAndDeserialization(); | 351 VerifySerializationAndDeserialization(); |
309 layer_tree_host_src_->outer_viewport_scroll_layer_ = nullptr; | 352 layer_tree_host_src_->outer_viewport_scroll_layer_ = nullptr; |
310 VerifySerializationAndDeserialization(); | 353 VerifySerializationAndDeserialization(); |
311 } | 354 } |
312 | 355 |
| 356 void RunPictureLayerMultipleSerializationsTest() { |
| 357 // Just fake setup a layer for both source and dest. |
| 358 scoped_refptr<Layer> root_layer_src = Layer::Create(); |
| 359 layer_tree_host_src_->SetRootLayer(root_layer_src); |
| 360 layer_tree_host_dst_->SetRootLayer(Layer::Create()); |
| 361 |
| 362 // Ensure that a PictureLayer work correctly for multiple rounds of |
| 363 // serialization and deserialization. |
| 364 scoped_refptr<FakePictureLayer> picture_layer_src = CreatePictureLayer(); |
| 365 root_layer_src->AddChild(picture_layer_src); |
| 366 picture_layer_src->SetBounds(gfx::Size(10, 10)); |
| 367 picture_layer_src->SetIsDrawable(true); |
| 368 picture_layer_src->SavePaintProperties(); |
| 369 picture_layer_src->Update(); |
| 370 picture_layer_src->SavePaintProperties(); |
| 371 VerifySerializationAndDeserialization(); |
| 372 ASSERT_EQ(1U, layer_tree_host_dst_->root_layer()->children().size()); |
| 373 PictureLayer* picture_layer_dst = reinterpret_cast<PictureLayer*>( |
| 374 layer_tree_host_dst_->root_layer()->child_at(0)); |
| 375 |
| 376 RecordingSource* recording_source_src = |
| 377 picture_layer_src->GetRecordingSourceForTesting(); |
| 378 RecordingSource* recording_source_dst = |
| 379 picture_layer_dst->GetRecordingSourceForTesting(); |
| 380 EXPECT_EQ(recording_source_src->GetSize(), recording_source_dst->GetSize()); |
| 381 // TODO(nyquist): Add support for inspecting SkPictures. |
| 382 |
| 383 VerifySerializationAndDeserialization(); |
| 384 } |
| 385 |
313 void RunAddAndRemoveNodeFromLayerTree() { | 386 void RunAddAndRemoveNodeFromLayerTree() { |
314 /* Testing serialization when the tree hierarchy changes like this: | 387 /* Testing serialization when the tree hierarchy changes like this: |
315 root root | 388 root root |
316 / \ / \ | 389 / \ / \ |
317 a b => a c | 390 a b => a c |
318 \ \ | 391 \ \ |
319 c d | 392 c d |
320 */ | 393 */ |
321 scoped_refptr<Layer> layer_src_root = Layer::Create(); | 394 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
322 layer_tree_host_src_->SetRootLayer(layer_src_root); | 395 layer_tree_host_src_->SetRootLayer(layer_src_root); |
(...skipping 14 matching lines...) Expand all Loading... |
337 layer_src_c->RemoveFromParent(); | 410 layer_src_c->RemoveFromParent(); |
338 layer_src_b->RemoveFromParent(); | 411 layer_src_b->RemoveFromParent(); |
339 layer_src_root->AddChild(layer_src_c); | 412 layer_src_root->AddChild(layer_src_c); |
340 layer_src_c->AddChild(layer_src_d); | 413 layer_src_c->AddChild(layer_src_d); |
341 | 414 |
342 VerifySerializationAndDeserialization(); | 415 VerifySerializationAndDeserialization(); |
343 VerifyHostHasAllExpectedLayersInTree(layer_tree_host_dst_->root_layer()); | 416 VerifyHostHasAllExpectedLayersInTree(layer_tree_host_dst_->root_layer()); |
344 } | 417 } |
345 | 418 |
346 private: | 419 private: |
| 420 std::unique_ptr<ImageSerializationProcessor> image_serialization_processor_; |
| 421 |
347 TestTaskGraphRunner task_graph_runner_src_; | 422 TestTaskGraphRunner task_graph_runner_src_; |
348 FakeLayerTreeHostClient client_src_; | 423 FakeLayerTreeHostClient client_src_; |
349 std::unique_ptr<LayerTreeHost> layer_tree_host_src_; | 424 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_src_; |
350 | 425 |
351 TestTaskGraphRunner task_graph_runner_dst_; | 426 TestTaskGraphRunner task_graph_runner_dst_; |
352 FakeLayerTreeHostClient client_dst_; | 427 FakeLayerTreeHostClient client_dst_; |
353 std::unique_ptr<LayerTreeHost> layer_tree_host_dst_; | 428 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_dst_; |
354 }; | 429 }; |
355 | 430 |
356 TEST_F(LayerTreeHostSerializationTest, AllMembersChanged) { | 431 TEST_F(LayerTreeHostSerializationTest, AllMembersChanged) { |
357 RunAllMembersChangedTest(); | 432 RunAllMembersChangedTest(); |
358 } | 433 } |
359 | 434 |
360 TEST_F(LayerTreeHostSerializationTest, LayersChanged) { | 435 TEST_F(LayerTreeHostSerializationTest, LayersChanged) { |
361 RunLayersChangedTest(); | 436 RunLayersChangedTest(); |
362 } | 437 } |
363 | 438 |
364 TEST_F(LayerTreeHostSerializationTest, LayersChangedMultipleSerializations) { | 439 TEST_F(LayerTreeHostSerializationTest, LayersChangedMultipleSerializations) { |
365 RunLayersChangedMultipleSerializations(); | 440 RunLayersChangedMultipleSerializations(); |
366 } | 441 } |
367 | 442 |
368 TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) { | 443 TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) { |
369 RunAddAndRemoveNodeFromLayerTree(); | 444 RunAddAndRemoveNodeFromLayerTree(); |
370 } | 445 } |
371 | 446 |
| 447 TEST_F(LayerTreeHostSerializationTest, PictureLayerMultipleSerializations) { |
| 448 RunPictureLayerMultipleSerializationsTest(); |
| 449 } |
| 450 |
372 } // namespace cc | 451 } // namespace cc |
OLD | NEW |