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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 layer_tree_host_src_->overscroll_elasticity_layer_ = nullptr; | 347 layer_tree_host_src_->overscroll_elasticity_layer_ = nullptr; |
305 VerifySerializationAndDeserialization(); | 348 VerifySerializationAndDeserialization(); |
306 layer_tree_host_src_->page_scale_layer_ = nullptr; | 349 layer_tree_host_src_->page_scale_layer_ = nullptr; |
307 VerifySerializationAndDeserialization(); | 350 VerifySerializationAndDeserialization(); |
308 layer_tree_host_src_->inner_viewport_scroll_layer_ = nullptr; | 351 layer_tree_host_src_->inner_viewport_scroll_layer_ = nullptr; |
309 VerifySerializationAndDeserialization(); | 352 VerifySerializationAndDeserialization(); |
310 layer_tree_host_src_->outer_viewport_scroll_layer_ = nullptr; | 353 layer_tree_host_src_->outer_viewport_scroll_layer_ = nullptr; |
311 VerifySerializationAndDeserialization(); | 354 VerifySerializationAndDeserialization(); |
312 } | 355 } |
313 | 356 |
| 357 void RunPictureLayerMultipleSerializationsTest() { |
| 358 // Just fake setup a layer for both source and dest. |
| 359 scoped_refptr<Layer> root_layer_src = Layer::Create(); |
| 360 layer_tree_host_src_->SetRootLayer(root_layer_src); |
| 361 layer_tree_host_dst_->SetRootLayer(Layer::Create()); |
| 362 |
| 363 // Ensure that a PictureLayer work correctly for multiple rounds of |
| 364 // serialization and deserialization. |
| 365 scoped_refptr<FakePictureLayer> picture_layer_src = CreatePictureLayer(); |
| 366 root_layer_src->AddChild(picture_layer_src); |
| 367 picture_layer_src->SetBounds(gfx::Size(10, 10)); |
| 368 picture_layer_src->SetIsDrawable(true); |
| 369 picture_layer_src->SavePaintProperties(); |
| 370 picture_layer_src->Update(); |
| 371 picture_layer_src->SavePaintProperties(); |
| 372 VerifySerializationAndDeserialization(); |
| 373 ASSERT_EQ(1U, layer_tree_host_dst_->root_layer()->children().size()); |
| 374 PictureLayer* picture_layer_dst = reinterpret_cast<PictureLayer*>( |
| 375 layer_tree_host_dst_->root_layer()->child_at(0)); |
| 376 |
| 377 RecordingSource* recording_source_src = |
| 378 picture_layer_src->GetRecordingSourceForTesting(); |
| 379 RecordingSource* recording_source_dst = |
| 380 picture_layer_dst->GetRecordingSourceForTesting(); |
| 381 EXPECT_EQ(recording_source_src->GetSize(), recording_source_dst->GetSize()); |
| 382 // TODO(nyquist): Add support for inspecting SkPictures. |
| 383 |
| 384 VerifySerializationAndDeserialization(); |
| 385 } |
| 386 |
314 void RunAddAndRemoveNodeFromLayerTree() { | 387 void RunAddAndRemoveNodeFromLayerTree() { |
315 /* Testing serialization when the tree hierarchy changes like this: | 388 /* Testing serialization when the tree hierarchy changes like this: |
316 root root | 389 root root |
317 / \ / \ | 390 / \ / \ |
318 a b => a c | 391 a b => a c |
319 \ \ | 392 \ \ |
320 c d | 393 c d |
321 */ | 394 */ |
322 scoped_refptr<Layer> layer_src_root = Layer::Create(); | 395 scoped_refptr<Layer> layer_src_root = Layer::Create(); |
323 layer_tree_host_src_->SetRootLayer(layer_src_root); | 396 layer_tree_host_src_->SetRootLayer(layer_src_root); |
(...skipping 14 matching lines...) Expand all Loading... |
338 layer_src_c->RemoveFromParent(); | 411 layer_src_c->RemoveFromParent(); |
339 layer_src_b->RemoveFromParent(); | 412 layer_src_b->RemoveFromParent(); |
340 layer_src_root->AddChild(layer_src_c); | 413 layer_src_root->AddChild(layer_src_c); |
341 layer_src_c->AddChild(layer_src_d); | 414 layer_src_c->AddChild(layer_src_d); |
342 | 415 |
343 VerifySerializationAndDeserialization(); | 416 VerifySerializationAndDeserialization(); |
344 VerifyHostHasAllExpectedLayersInTree(layer_tree_host_dst_->root_layer()); | 417 VerifyHostHasAllExpectedLayersInTree(layer_tree_host_dst_->root_layer()); |
345 } | 418 } |
346 | 419 |
347 private: | 420 private: |
| 421 std::unique_ptr<ImageSerializationProcessor> image_serialization_processor_; |
| 422 |
348 TestTaskGraphRunner task_graph_runner_src_; | 423 TestTaskGraphRunner task_graph_runner_src_; |
349 FakeLayerTreeHostClient client_src_; | 424 FakeLayerTreeHostClient client_src_; |
350 std::unique_ptr<LayerTreeHost> layer_tree_host_src_; | 425 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_src_; |
351 | 426 |
352 TestTaskGraphRunner task_graph_runner_dst_; | 427 TestTaskGraphRunner task_graph_runner_dst_; |
353 FakeLayerTreeHostClient client_dst_; | 428 FakeLayerTreeHostClient client_dst_; |
354 std::unique_ptr<LayerTreeHost> layer_tree_host_dst_; | 429 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_dst_; |
355 }; | 430 }; |
356 | 431 |
357 TEST_F(LayerTreeHostSerializationTest, AllMembersChanged) { | 432 TEST_F(LayerTreeHostSerializationTest, AllMembersChanged) { |
358 RunAllMembersChangedTest(); | 433 RunAllMembersChangedTest(); |
359 } | 434 } |
360 | 435 |
361 TEST_F(LayerTreeHostSerializationTest, LayersChanged) { | 436 TEST_F(LayerTreeHostSerializationTest, LayersChanged) { |
362 RunLayersChangedTest(); | 437 RunLayersChangedTest(); |
363 } | 438 } |
364 | 439 |
365 TEST_F(LayerTreeHostSerializationTest, LayersChangedMultipleSerializations) { | 440 TEST_F(LayerTreeHostSerializationTest, LayersChangedMultipleSerializations) { |
366 RunLayersChangedMultipleSerializations(); | 441 RunLayersChangedMultipleSerializations(); |
367 } | 442 } |
368 | 443 |
369 TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) { | 444 TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) { |
370 RunAddAndRemoveNodeFromLayerTree(); | 445 RunAddAndRemoveNodeFromLayerTree(); |
371 } | 446 } |
372 | 447 |
| 448 TEST_F(LayerTreeHostSerializationTest, PictureLayerMultipleSerializations) { |
| 449 RunPictureLayerMultipleSerializationsTest(); |
| 450 } |
| 451 |
373 } // namespace cc | 452 } // namespace cc |
OLD | NEW |