| 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 "cc/blimp/layer_tree_host_remote.h" | 5 #include "cc/blimp/layer_tree_host_remote.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 #include <unordered_set> |
| 9 |
| 7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 8 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "cc/animation/animation_host.h" | 13 #include "cc/animation/animation_host.h" |
| 11 #include "cc/layers/layer.h" | 14 #include "cc/layers/layer.h" |
| 12 #include "cc/output/begin_frame_args.h" | 15 #include "cc/output/begin_frame_args.h" |
| 16 #include "cc/proto/compositor_message.pb.h" |
| 13 #include "cc/test/fake_image_serialization_processor.h" | 17 #include "cc/test/fake_image_serialization_processor.h" |
| 14 #include "cc/test/fake_remote_compositor_bridge.h" | 18 #include "cc/test/fake_remote_compositor_bridge.h" |
| 15 #include "cc/test/stub_layer_tree_host_client.h" | 19 #include "cc/test/stub_layer_tree_host_client.h" |
| 16 #include "cc/trees/layer_tree_settings.h" | 20 #include "cc/trees/layer_tree_settings.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 23 |
| 20 using testing::InSequence; | 24 using testing::InSequence; |
| 21 using testing::Mock; | 25 using testing::Mock; |
| 22 using testing::StrictMock; | 26 using testing::StrictMock; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 41 public: | 45 public: |
| 42 UpdateTrackingRemoteCompositorBridge( | 46 UpdateTrackingRemoteCompositorBridge( |
| 43 scoped_refptr<base::SingleThreadTaskRunner> compositor_main_task_runner) | 47 scoped_refptr<base::SingleThreadTaskRunner> compositor_main_task_runner) |
| 44 : FakeRemoteCompositorBridge(std::move(compositor_main_task_runner)) {} | 48 : FakeRemoteCompositorBridge(std::move(compositor_main_task_runner)) {} |
| 45 | 49 |
| 46 ~UpdateTrackingRemoteCompositorBridge() override = default; | 50 ~UpdateTrackingRemoteCompositorBridge() override = default; |
| 47 | 51 |
| 48 void ProcessCompositorStateUpdate( | 52 void ProcessCompositorStateUpdate( |
| 49 std::unique_ptr<CompositorProtoState> compositor_proto_state) override { | 53 std::unique_ptr<CompositorProtoState> compositor_proto_state) override { |
| 50 num_updates_received_++; | 54 num_updates_received_++; |
| 55 compositor_proto_state_ = std::move(compositor_proto_state); |
| 51 }; | 56 }; |
| 52 | 57 |
| 53 bool SendUpdates(const std::unordered_map<int, gfx::ScrollOffset>& scroll_map, | 58 bool SendUpdates(const std::unordered_map<int, gfx::ScrollOffset>& scroll_map, |
| 54 float page_scale) { | 59 float page_scale) { |
| 55 return client_->ApplyScrollAndScaleUpdateFromClient(scroll_map, page_scale); | 60 return client_->ApplyScrollAndScaleUpdateFromClient(scroll_map, page_scale); |
| 56 } | 61 } |
| 57 | 62 |
| 58 int num_updates_received() const { return num_updates_received_; } | 63 int num_updates_received() const { return num_updates_received_; } |
| 59 | 64 |
| 65 CompositorProtoState* compositor_proto_state() { |
| 66 return compositor_proto_state_.get(); |
| 67 } |
| 68 |
| 60 private: | 69 private: |
| 61 int num_updates_received_ = 0; | 70 int num_updates_received_ = 0; |
| 71 std::unique_ptr<CompositorProtoState> compositor_proto_state_; |
| 62 }; | 72 }; |
| 63 | 73 |
| 64 class MockLayerTreeHostClient : public StubLayerTreeHostClient { | 74 class MockLayerTreeHostClient : public StubLayerTreeHostClient { |
| 65 public: | 75 public: |
| 66 MockLayerTreeHostClient() = default; | 76 MockLayerTreeHostClient() = default; |
| 67 ~MockLayerTreeHostClient() override = default; | 77 ~MockLayerTreeHostClient() override = default; |
| 68 | 78 |
| 69 void set_update_host_callback(base::Closure callback) { | 79 void set_update_host_callback(base::Closure callback) { |
| 70 update_host_callback_ = callback; | 80 update_host_callback_ = callback; |
| 71 } | 81 } |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 layer_tree_host_->SetNeedsCommit(); | 459 layer_tree_host_->SetNeedsCommit(); |
| 450 base::RunLoop().RunUntilIdle(); | 460 base::RunLoop().RunUntilIdle(); |
| 451 | 461 |
| 452 // Only the updated_layer should have been updated. | 462 // Only the updated_layer should have been updated. |
| 453 EXPECT_FALSE(non_drawable_layer->did_update()); | 463 EXPECT_FALSE(non_drawable_layer->did_update()); |
| 454 EXPECT_FALSE(empty_bound_layer->did_update()); | 464 EXPECT_FALSE(empty_bound_layer->did_update()); |
| 455 EXPECT_FALSE(transparent_layer->did_update()); | 465 EXPECT_FALSE(transparent_layer->did_update()); |
| 456 EXPECT_TRUE(updated_layer->did_update()); | 466 EXPECT_TRUE(updated_layer->did_update()); |
| 457 } | 467 } |
| 458 | 468 |
| 469 TEST_F(LayerTreeHostRemoteTest, OnlyPushPropertiesOnChangingLayers) { |
| 470 EXPECT_BEGIN_MAIN_FRAME_AND_COMMIT(mock_layer_tree_host_client_, 2); |
| 471 |
| 472 // Setup a tree with 3 nodes. |
| 473 scoped_refptr<Layer> child_layer = Layer::Create(); |
| 474 scoped_refptr<Layer> grandchild_layer = Layer::Create(); |
| 475 root_layer_->AddChild(child_layer); |
| 476 child_layer->AddChild(grandchild_layer); |
| 477 layer_tree_host_->SetNeedsCommit(); |
| 478 |
| 479 base::RunLoop().RunUntilIdle(); |
| 480 |
| 481 // Ensure the first proto contains all layer updates. |
| 482 EXPECT_EQ(1, remote_compositor_bridge_->num_updates_received()); |
| 483 CompositorProtoState* compositor_proto_state = |
| 484 remote_compositor_bridge_->compositor_proto_state(); |
| 485 const proto::LayerUpdate& layer_updates_first_commit = |
| 486 compositor_proto_state->compositor_message->layer_tree_host() |
| 487 .layer_updates(); |
| 488 |
| 489 std::unordered_set<int> layer_updates_id_set; |
| 490 for (int i = 0; i < layer_updates_first_commit.layers_size(); ++i) { |
| 491 layer_updates_id_set.insert(layer_updates_first_commit.layers(i).id()); |
| 492 } |
| 493 |
| 494 EXPECT_TRUE(layer_updates_id_set.find(root_layer_->id()) != |
| 495 layer_updates_id_set.end()); |
| 496 EXPECT_TRUE(layer_updates_id_set.find(child_layer->id()) != |
| 497 layer_updates_id_set.end()); |
| 498 EXPECT_TRUE(layer_updates_id_set.find(grandchild_layer->id()) != |
| 499 layer_updates_id_set.end()); |
| 500 EXPECT_EQ(3, layer_updates_first_commit.layers_size()); |
| 501 |
| 502 // Modify the |child_layer|, and run the second frame. |
| 503 child_layer->SetNeedsPushProperties(); |
| 504 layer_tree_host_->SetNeedsCommit(); |
| 505 base::RunLoop().RunUntilIdle(); |
| 506 |
| 507 // Ensure the second proto only contains |child_layer|. |
| 508 EXPECT_EQ(2, remote_compositor_bridge_->num_updates_received()); |
| 509 compositor_proto_state = remote_compositor_bridge_->compositor_proto_state(); |
| 510 DCHECK(compositor_proto_state); |
| 511 const proto::LayerUpdate& layer_updates_second_commit = |
| 512 compositor_proto_state->compositor_message->layer_tree_host() |
| 513 .layer_updates(); |
| 514 EXPECT_EQ(1, layer_updates_second_commit.layers_size()); |
| 515 EXPECT_EQ(child_layer->id(), layer_updates_second_commit.layers(0).id()); |
| 516 } |
| 517 |
| 459 } // namespace | 518 } // namespace |
| 460 } // namespace cc | 519 } // namespace cc |
| OLD | NEW |