| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "compositor_state_deserializer.h" | 5 #include "compositor_state_deserializer.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "cc/animation/animation_host.h" | 8 #include "cc/animation/animation_host.h" |
| 9 #include "cc/blimp/client_picture_cache.h" |
| 9 #include "cc/blimp/compositor_proto_state.h" | 10 #include "cc/blimp/compositor_proto_state.h" |
| 10 #include "cc/blimp/compositor_state_deserializer_client.h" | 11 #include "cc/blimp/compositor_state_deserializer_client.h" |
| 11 #include "cc/blimp/layer_tree_host_remote.h" | 12 #include "cc/blimp/layer_tree_host_remote.h" |
| 13 #include "cc/layers/content_layer_client.h" |
| 14 #include "cc/layers/picture_layer.h" |
| 15 #include "cc/layers/solid_color_scrollbar_layer.h" |
| 16 #include "cc/playback/display_item_list.h" |
| 17 #include "cc/playback/drawing_display_item.h" |
| 12 #include "cc/proto/compositor_message.pb.h" | 18 #include "cc/proto/compositor_message.pb.h" |
| 19 #include "cc/test/fake_image_serialization_processor.h" |
| 13 #include "cc/test/fake_layer_tree_host.h" | 20 #include "cc/test/fake_layer_tree_host.h" |
| 14 #include "cc/test/fake_layer_tree_host_client.h" | 21 #include "cc/test/fake_layer_tree_host_client.h" |
| 15 #include "cc/test/fake_remote_compositor_bridge.h" | 22 #include "cc/test/fake_remote_compositor_bridge.h" |
| 16 #include "cc/test/remote_client_layer_factory.h" | 23 #include "cc/test/remote_client_layer_factory.h" |
| 24 #include "cc/test/skia_common.h" |
| 17 #include "cc/test/stub_layer_tree_host_client.h" | 25 #include "cc/test/stub_layer_tree_host_client.h" |
| 18 #include "cc/test/test_task_graph_runner.h" | 26 #include "cc/test/test_task_graph_runner.h" |
| 19 #include "cc/trees/layer_tree_host_common.h" | 27 #include "cc/trees/layer_tree_host_common.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 21 | 30 |
| 22 namespace cc { | 31 namespace cc { |
| 23 namespace { | 32 namespace { |
| 24 | 33 |
| 25 #define EXPECT_LAYERS_EQ(engine_layer_id, client_layer) \ | 34 #define EXPECT_LAYERS_EQ(engine_layer_id, client_layer) \ |
| 26 EXPECT_EQ( \ | 35 EXPECT_EQ( \ |
| 27 compositor_state_deserializer_->GetLayerForEngineId(engine_layer_id), \ | 36 compositor_state_deserializer_->GetLayerForEngineId(engine_layer_id), \ |
| 28 client_layer); | 37 client_layer); |
| 29 | 38 |
| 39 class FakeContentLayerClient : public ContentLayerClient { |
| 40 public: |
| 41 FakeContentLayerClient(scoped_refptr<DisplayItemList> display_list, |
| 42 gfx::Rect recorded_viewport) |
| 43 : display_list_(std::move(display_list)), |
| 44 recorded_viewport_(recorded_viewport) {} |
| 45 ~FakeContentLayerClient() override {} |
| 46 |
| 47 // ContentLayerClient implementation. |
| 48 gfx::Rect PaintableRegion() override { return recorded_viewport_; } |
| 49 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 50 PaintingControlSetting painting_status) override { |
| 51 return display_list_; |
| 52 } |
| 53 bool FillsBoundsCompletely() const override { return false; } |
| 54 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } |
| 55 |
| 56 private: |
| 57 scoped_refptr<DisplayItemList> display_list_; |
| 58 gfx::Rect recorded_viewport_; |
| 59 }; |
| 60 |
| 30 class RemoteCompositorBridgeForTest : public FakeRemoteCompositorBridge { | 61 class RemoteCompositorBridgeForTest : public FakeRemoteCompositorBridge { |
| 31 public: | 62 public: |
| 32 using ProtoFrameCallback = base::Callback<void( | 63 using ProtoFrameCallback = base::Callback<void( |
| 33 std::unique_ptr<CompositorProtoState> compositor_proto_state)>; | 64 std::unique_ptr<CompositorProtoState> compositor_proto_state)>; |
| 34 | 65 |
| 35 RemoteCompositorBridgeForTest( | 66 RemoteCompositorBridgeForTest( |
| 36 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 67 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 37 ProtoFrameCallback proto_frame_callback) | 68 ProtoFrameCallback proto_frame_callback) |
| 38 : FakeRemoteCompositorBridge(main_task_runner), | 69 : FakeRemoteCompositorBridge(main_task_runner), |
| 39 proto_frame_callback_(proto_frame_callback) {} | 70 proto_frame_callback_(proto_frame_callback) {} |
| (...skipping 21 matching lines...) Expand all Loading... |
| 61 LayerTreeHostRemote::InitParams params; | 92 LayerTreeHostRemote::InitParams params; |
| 62 params.client = &layer_tree_host_client_remote_; | 93 params.client = &layer_tree_host_client_remote_; |
| 63 params.main_task_runner = main_task_runner; | 94 params.main_task_runner = main_task_runner; |
| 64 params.animation_host = AnimationHost::CreateMainInstance(); | 95 params.animation_host = AnimationHost::CreateMainInstance(); |
| 65 params.remote_compositor_bridge = | 96 params.remote_compositor_bridge = |
| 66 base::MakeUnique<RemoteCompositorBridgeForTest>( | 97 base::MakeUnique<RemoteCompositorBridgeForTest>( |
| 67 main_task_runner, | 98 main_task_runner, |
| 68 base::Bind( | 99 base::Bind( |
| 69 &CompositorStateDeserializerTest::ProcessCompositorStateUpdate, | 100 &CompositorStateDeserializerTest::ProcessCompositorStateUpdate, |
| 70 base::Unretained(this))); | 101 base::Unretained(this))); |
| 102 params.engine_picture_cache = |
| 103 image_serialization_processor_.CreateEnginePictureCache(); |
| 71 LayerTreeSettings settings; | 104 LayerTreeSettings settings; |
| 72 params.settings = &settings; | 105 params.settings = &settings; |
| 73 | 106 |
| 74 layer_tree_host_remote_ = base::MakeUnique<LayerTreeHostRemote>(¶ms); | 107 layer_tree_host_remote_ = base::MakeUnique<LayerTreeHostRemote>(¶ms); |
| 75 | 108 |
| 76 // Client side setup. | 109 // Client side setup. |
| 77 layer_tree_host_in_process_ = FakeLayerTreeHost::Create( | 110 layer_tree_host_in_process_ = FakeLayerTreeHost::Create( |
| 78 &layer_tree_host_client_client_, &task_graph_runner_); | 111 &layer_tree_host_client_client_, &task_graph_runner_); |
| 112 std::unique_ptr<ClientPictureCache> client_picture_cache = |
| 113 image_serialization_processor_.CreateClientPictureCache(); |
| 79 compositor_state_deserializer_ = | 114 compositor_state_deserializer_ = |
| 80 base::MakeUnique<CompositorStateDeserializer>( | 115 base::MakeUnique<CompositorStateDeserializer>( |
| 81 layer_tree_host_in_process_.get(), | 116 layer_tree_host_in_process_.get(), std::move(client_picture_cache), |
| 82 base::Bind(&CompositorStateDeserializerTest::LayerScrolled, | 117 base::Bind(&CompositorStateDeserializerTest::LayerScrolled, |
| 83 base::Unretained(this)), | 118 base::Unretained(this)), |
| 84 this); | 119 this); |
| 85 } | 120 } |
| 86 | 121 |
| 87 void TearDown() override { | 122 void TearDown() override { |
| 88 layer_tree_host_remote_ = nullptr; | 123 layer_tree_host_remote_ = nullptr; |
| 89 compositor_state_deserializer_ = nullptr; | 124 compositor_state_deserializer_ = nullptr; |
| 90 layer_tree_host_in_process_ = nullptr; | 125 layer_tree_host_in_process_ = nullptr; |
| 91 } | 126 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 // Engine setup. | 262 // Engine setup. |
| 228 std::unique_ptr<LayerTreeHostRemote> layer_tree_host_remote_; | 263 std::unique_ptr<LayerTreeHostRemote> layer_tree_host_remote_; |
| 229 StubLayerTreeHostClient layer_tree_host_client_remote_; | 264 StubLayerTreeHostClient layer_tree_host_client_remote_; |
| 230 | 265 |
| 231 // Client setup. | 266 // Client setup. |
| 232 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_in_process_; | 267 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_in_process_; |
| 233 std::unique_ptr<CompositorStateDeserializer> compositor_state_deserializer_; | 268 std::unique_ptr<CompositorStateDeserializer> compositor_state_deserializer_; |
| 234 FakeLayerTreeHostClient layer_tree_host_client_client_; | 269 FakeLayerTreeHostClient layer_tree_host_client_client_; |
| 235 TestTaskGraphRunner task_graph_runner_; | 270 TestTaskGraphRunner task_graph_runner_; |
| 236 | 271 |
| 272 FakeImageSerializationProcessor image_serialization_processor_; |
| 273 |
| 237 bool should_retain_client_scroll_ = false; | 274 bool should_retain_client_scroll_ = false; |
| 238 bool should_retain_client_scale_ = false; | 275 bool should_retain_client_scale_ = false; |
| 239 }; | 276 }; |
| 240 | 277 |
| 241 TEST_F(CompositorStateDeserializerTest, BasicSync) { | 278 TEST_F(CompositorStateDeserializerTest, BasicSync) { |
| 242 // Set up a tree with a single node. | 279 // Set up a tree with a single node. |
| 243 scoped_refptr<Layer> root_layer = Layer::Create(); | 280 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 244 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer); | 281 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer); |
| 245 | 282 |
| 246 // Synchronize State and verify. | 283 // Synchronize State and verify. |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 PropertyTrees* engine_property_trees = | 447 PropertyTrees* engine_property_trees = |
| 411 layer_tree_host_remote_->GetLayerTree()->property_trees(); | 448 layer_tree_host_remote_->GetLayerTree()->property_trees(); |
| 412 | 449 |
| 413 layer_tree_host_in_process_->BuildPropertyTreesForTesting(); | 450 layer_tree_host_in_process_->BuildPropertyTreesForTesting(); |
| 414 PropertyTrees* client_property_trees = | 451 PropertyTrees* client_property_trees = |
| 415 layer_tree_host_in_process_->property_trees(); | 452 layer_tree_host_in_process_->property_trees(); |
| 416 | 453 |
| 417 EXPECT_EQ(*engine_property_trees, *client_property_trees); | 454 EXPECT_EQ(*engine_property_trees, *client_property_trees); |
| 418 } | 455 } |
| 419 | 456 |
| 457 TEST_F(CompositorStateDeserializerTest, SolidColorScrollbarLayer) { |
| 458 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 459 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer); |
| 460 |
| 461 scoped_refptr<Layer> child_layer1 = Layer::Create(); |
| 462 root_layer->AddChild(child_layer1); |
| 463 scoped_refptr<SolidColorScrollbarLayer> scroll_layer1 = |
| 464 SolidColorScrollbarLayer::Create(ScrollbarOrientation::HORIZONTAL, 20, 5, |
| 465 true, 3); |
| 466 scroll_layer1->SetScrollLayer(child_layer1->id()); |
| 467 child_layer1->AddChild(scroll_layer1); |
| 468 |
| 469 scoped_refptr<SolidColorScrollbarLayer> scroll_layer2 = |
| 470 SolidColorScrollbarLayer::Create(ScrollbarOrientation::VERTICAL, 2, 9, |
| 471 false, 3); |
| 472 root_layer->AddChild(scroll_layer2); |
| 473 scoped_refptr<Layer> child_layer2 = Layer::Create(); |
| 474 scroll_layer2->AddChild(child_layer2); |
| 475 scroll_layer2->SetScrollLayer(child_layer2->id()); |
| 476 |
| 477 // Synchronize State and verify. |
| 478 base::RunLoop().RunUntilIdle(); |
| 479 VerifyTreesAreIdentical(); |
| 480 |
| 481 // Verify Scrollbar layers. |
| 482 SolidColorScrollbarLayer* client_scroll_layer1 = |
| 483 static_cast<SolidColorScrollbarLayer*>( |
| 484 compositor_state_deserializer_->GetLayerForEngineId( |
| 485 scroll_layer1->id())); |
| 486 EXPECT_EQ(client_scroll_layer1->ScrollLayerId(), |
| 487 compositor_state_deserializer_ |
| 488 ->GetLayerForEngineId(scroll_layer1->ScrollLayerId()) |
| 489 ->id()); |
| 490 EXPECT_EQ(client_scroll_layer1->orientation(), scroll_layer1->orientation()); |
| 491 |
| 492 SolidColorScrollbarLayer* client_scroll_layer2 = |
| 493 static_cast<SolidColorScrollbarLayer*>( |
| 494 compositor_state_deserializer_->GetLayerForEngineId( |
| 495 scroll_layer2->id())); |
| 496 EXPECT_EQ(client_scroll_layer2->ScrollLayerId(), |
| 497 compositor_state_deserializer_ |
| 498 ->GetLayerForEngineId(scroll_layer2->ScrollLayerId()) |
| 499 ->id()); |
| 500 EXPECT_EQ(client_scroll_layer2->orientation(), scroll_layer2->orientation()); |
| 501 } |
| 502 |
| 503 TEST_F(CompositorStateDeserializerTest, PictureLayer) { |
| 504 scoped_refptr<Layer> root_layer = Layer::Create(); |
| 505 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer); |
| 506 |
| 507 gfx::Size layer_size = gfx::Size(5, 5); |
| 508 |
| 509 gfx::PointF offset(2.f, 3.f); |
| 510 SkPictureRecorder recorder; |
| 511 sk_sp<SkCanvas> canvas; |
| 512 SkPaint red_paint; |
| 513 red_paint.setColor(SK_ColorRED); |
| 514 canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH( |
| 515 offset.x(), offset.y(), layer_size.width(), layer_size.height()))); |
| 516 canvas->translate(offset.x(), offset.y()); |
| 517 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint); |
| 518 sk_sp<SkPicture> test_picture = recorder.finishRecordingAsPicture(); |
| 519 |
| 520 DisplayItemListSettings settings; |
| 521 settings.use_cached_picture = false; |
| 522 scoped_refptr<DisplayItemList> display_list = |
| 523 DisplayItemList::Create(settings); |
| 524 const gfx::Rect visual_rect(0, 0, 42, 42); |
| 525 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>(visual_rect, |
| 526 test_picture); |
| 527 display_list->Finalize(); |
| 528 FakeContentLayerClient content_client(display_list, gfx::Rect(layer_size)); |
| 529 |
| 530 scoped_refptr<PictureLayer> picture_layer = |
| 531 PictureLayer::Create(&content_client); |
| 532 picture_layer->SetBounds(layer_size); |
| 533 root_layer->AddChild(picture_layer); |
| 534 |
| 535 // Synchronize State and verify. |
| 536 base::RunLoop().RunUntilIdle(); |
| 537 VerifyTreesAreIdentical(); |
| 538 |
| 539 // Verify PictureLayer. |
| 540 PictureLayer* client_picture_layer = static_cast<PictureLayer*>( |
| 541 compositor_state_deserializer_->GetLayerForEngineId(picture_layer->id())); |
| 542 scoped_refptr<DisplayItemList> client_display_list = |
| 543 client_picture_layer->client()->PaintContentsToDisplayList( |
| 544 ContentLayerClient::PaintingControlSetting::PAINTING_BEHAVIOR_NORMAL); |
| 545 EXPECT_TRUE(AreDisplayListDrawingResultsSame( |
| 546 gfx::Rect(layer_size), display_list.get(), client_display_list.get())); |
| 547 |
| 548 // Now attach new layer with the same DisplayList. |
| 549 scoped_refptr<PictureLayer> picture_layer2 = |
| 550 PictureLayer::Create(&content_client); |
| 551 picture_layer->SetBounds(layer_size); |
| 552 root_layer->AddChild(picture_layer2); |
| 553 |
| 554 // Synchronize State and verify. |
| 555 base::RunLoop().RunUntilIdle(); |
| 556 VerifyTreesAreIdentical(); |
| 557 |
| 558 // Verify PictureLayer2. |
| 559 PictureLayer* client_picture_layer2 = static_cast<PictureLayer*>( |
| 560 compositor_state_deserializer_->GetLayerForEngineId( |
| 561 picture_layer2->id())); |
| 562 scoped_refptr<DisplayItemList> client_display_list2 = |
| 563 client_picture_layer2->client()->PaintContentsToDisplayList( |
| 564 ContentLayerClient::PaintingControlSetting::PAINTING_BEHAVIOR_NORMAL); |
| 565 EXPECT_TRUE(AreDisplayListDrawingResultsSame( |
| 566 gfx::Rect(layer_size), display_list.get(), client_display_list2.get())); |
| 567 } |
| 568 |
| 420 } // namespace | 569 } // namespace |
| 421 } // namespace cc | 570 } // namespace cc |
| OLD | NEW |