Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: cc/blimp/compositor_state_deserializer_unittest.cc

Issue 2445093002: cc/blimp: Add synchronization for scroll/scale state. (Closed)
Patch Set: move application of deltas to push time. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/client_picture_cache.h"
10 #include "cc/blimp/compositor_proto_state.h" 10 #include "cc/blimp/compositor_proto_state.h"
11 #include "cc/blimp/compositor_state_deserializer_client.h"
12 #include "cc/blimp/layer_tree_host_remote.h" 11 #include "cc/blimp/layer_tree_host_remote.h"
13 #include "cc/layers/content_layer_client.h" 12 #include "cc/layers/content_layer_client.h"
14 #include "cc/layers/picture_layer.h" 13 #include "cc/layers/picture_layer.h"
15 #include "cc/layers/solid_color_scrollbar_layer.h" 14 #include "cc/layers/solid_color_scrollbar_layer.h"
16 #include "cc/playback/display_item_list.h" 15 #include "cc/playback/display_item_list.h"
17 #include "cc/playback/drawing_display_item.h" 16 #include "cc/playback/drawing_display_item.h"
18 #include "cc/proto/compositor_message.pb.h" 17 #include "cc/proto/compositor_message.pb.h"
19 #include "cc/test/fake_image_serialization_processor.h" 18 #include "cc/test/fake_image_serialization_processor.h"
20 #include "cc/test/fake_layer_tree_host.h" 19 #include "cc/test/fake_layer_tree_host.h"
21 #include "cc/test/fake_layer_tree_host_client.h" 20 #include "cc/test/fake_layer_tree_host_client.h"
22 #include "cc/test/fake_remote_compositor_bridge.h" 21 #include "cc/test/fake_remote_compositor_bridge.h"
23 #include "cc/test/remote_client_layer_factory.h" 22 #include "cc/test/remote_client_layer_factory.h"
24 #include "cc/test/skia_common.h" 23 #include "cc/test/skia_common.h"
25 #include "cc/test/stub_layer_tree_host_client.h" 24 #include "cc/test/stub_layer_tree_host_client.h"
25 #include "cc/test/stub_layer_tree_host_single_thread_client.h"
26 #include "cc/test/test_task_graph_runner.h" 26 #include "cc/test/test_task_graph_runner.h"
27 #include "cc/trees/layer_tree_host_common.h" 27 #include "cc/trees/layer_tree_host_common.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "third_party/skia/include/core/SkPictureRecorder.h" 29 #include "third_party/skia/include/core/SkPictureRecorder.h"
30 30
31 namespace cc { 31 namespace cc {
32 namespace { 32 namespace {
33 33
34 #define EXPECT_LAYERS_EQ(engine_layer_id, client_layer) \ 34 #define EXPECT_LAYERS_EQ(engine_layer_id, client_layer) \
35 EXPECT_EQ( \ 35 EXPECT_EQ( \
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 std::unique_ptr<CompositorProtoState> compositor_proto_state) override { 75 std::unique_ptr<CompositorProtoState> compositor_proto_state) override {
76 proto_frame_callback_.Run(std::move(compositor_proto_state)); 76 proto_frame_callback_.Run(std::move(compositor_proto_state));
77 } 77 }
78 78
79 private: 79 private:
80 ProtoFrameCallback proto_frame_callback_; 80 ProtoFrameCallback proto_frame_callback_;
81 }; 81 };
82 82
83 class CompositorStateDeserializerTest 83 class CompositorStateDeserializerTest
84 : public testing::Test, 84 : public testing::Test,
85 public CompositorStateDeserializerClient { 85 public CompositorStateDeserializerClient,
86 public FakeLayerTreeHostClient {
86 public: 87 public:
87 void SetUp() override { 88 void SetUp() override {
88 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner = 89 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner =
89 base::ThreadTaskRunnerHandle::Get(); 90 base::ThreadTaskRunnerHandle::Get();
90 91
91 // Engine side setup. 92 // Engine side setup.
92 LayerTreeHostRemote::InitParams params; 93 LayerTreeHostRemote::InitParams params;
93 params.client = &layer_tree_host_client_remote_; 94 params.client = &layer_tree_host_client_remote_;
94 params.main_task_runner = main_task_runner; 95 params.main_task_runner = main_task_runner;
95 params.animation_host = AnimationHost::CreateMainInstance(); 96 params.animation_host = AnimationHost::CreateMainInstance();
96 params.remote_compositor_bridge = 97 params.remote_compositor_bridge =
97 base::MakeUnique<RemoteCompositorBridgeForTest>( 98 base::MakeUnique<RemoteCompositorBridgeForTest>(
98 main_task_runner, 99 main_task_runner,
99 base::Bind( 100 base::Bind(
100 &CompositorStateDeserializerTest::ProcessCompositorStateUpdate, 101 &CompositorStateDeserializerTest::ProcessCompositorStateUpdate,
101 base::Unretained(this))); 102 base::Unretained(this)));
102 params.engine_picture_cache = 103 params.engine_picture_cache =
103 image_serialization_processor_.CreateEnginePictureCache(); 104 image_serialization_processor_.CreateEnginePictureCache();
104 LayerTreeSettings settings; 105 LayerTreeSettings settings;
105 params.settings = &settings; 106 params.settings = &settings;
106 107
107 layer_tree_host_remote_ = base::MakeUnique<LayerTreeHostRemote>(&params); 108 layer_tree_host_remote_ = base::MakeUnique<LayerTreeHostRemote>(&params);
108 109
109 // Client side setup. 110 // Client side setup.
110 layer_tree_host_in_process_ = FakeLayerTreeHost::Create( 111 layer_tree_host_in_process_ =
111 &layer_tree_host_client_client_, &task_graph_runner_); 112 FakeLayerTreeHost::Create(this, &task_graph_runner_);
112 std::unique_ptr<ClientPictureCache> client_picture_cache = 113 std::unique_ptr<ClientPictureCache> client_picture_cache =
113 image_serialization_processor_.CreateClientPictureCache(); 114 image_serialization_processor_.CreateClientPictureCache();
114 compositor_state_deserializer_ = 115 compositor_state_deserializer_ =
115 base::MakeUnique<CompositorStateDeserializer>( 116 base::MakeUnique<CompositorStateDeserializer>(
116 layer_tree_host_in_process_.get(), std::move(client_picture_cache), 117 layer_tree_host_in_process_.get(), std::move(client_picture_cache),
117 base::Bind(&CompositorStateDeserializerTest::LayerScrolled,
118 base::Unretained(this)),
119 this); 118 this);
120 } 119 }
121 120
122 void TearDown() override { 121 void TearDown() override {
123 layer_tree_host_remote_ = nullptr; 122 layer_tree_host_remote_ = nullptr;
124 compositor_state_deserializer_ = nullptr; 123 compositor_state_deserializer_ = nullptr;
125 layer_tree_host_in_process_ = nullptr; 124 layer_tree_host_in_process_ = nullptr;
126 } 125 }
127 126
128 void ProcessCompositorStateUpdate( 127 void ProcessCompositorStateUpdate(
129 std::unique_ptr<CompositorProtoState> compositor_proto_state) { 128 std::unique_ptr<CompositorProtoState> compositor_proto_state) {
130 // Immediately deserialize the state update. 129 // Immediately deserialize the state update.
131 compositor_state_deserializer_->DeserializeCompositorUpdate( 130 compositor_state_deserializer_->DeserializeCompositorUpdate(
132 compositor_proto_state->compositor_message->layer_tree_host()); 131 compositor_proto_state->compositor_message->layer_tree_host());
133 } 132 }
134 133
135 // CompositorStateDeserializer implementation. 134 // CompositorStateDeserializer implementation.
136 bool ShouldRetainClientScroll(int engine_layer_id, 135 void DidUpdateLocalState() override { client_state_dirty_ = true; }
137 const gfx::ScrollOffset& new_offset) override { 136
138 return should_retain_client_scroll_; 137 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
138 const gfx::Vector2dF& outer_delta,
139 const gfx::Vector2dF& elastic_overscroll_delta,
140 float page_scale,
141 float top_controls_delta) override {
142 compositor_state_deserializer_->ApplyViewportDeltas(
143 inner_delta, outer_delta, elastic_overscroll_delta, page_scale,
144 top_controls_delta);
139 } 145 }
140 bool ShouldRetainClientPageScale(float new_page_scale) override {
141 return should_retain_client_scale_;
142 }
143
144 void LayerScrolled(int engine_layer_id) {}
145 146
146 void VerifyTreesAreIdentical() { 147 void VerifyTreesAreIdentical() {
147 LayerTree* engine_layer_tree = layer_tree_host_remote_->GetLayerTree(); 148 LayerTree* engine_layer_tree = layer_tree_host_remote_->GetLayerTree();
148 LayerTree* client_layer_tree = layer_tree_host_in_process_->GetLayerTree(); 149 LayerTree* client_layer_tree = layer_tree_host_in_process_->GetLayerTree();
149 150
150 if (engine_layer_tree->root_layer()) { 151 if (engine_layer_tree->root_layer()) {
151 LayerTreeHostCommon::CallFunctionForEveryLayer( 152 LayerTreeHostCommon::CallFunctionForEveryLayer(
152 engine_layer_tree, [this](Layer* engine_layer) { 153 engine_layer_tree, [this](Layer* engine_layer) {
153 VerifyLayersAreIdentical( 154 VerifyLayersAreIdentical(
154 engine_layer, 155 engine_layer,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } 260 }
260 } 261 }
261 262
262 // Engine setup. 263 // Engine setup.
263 std::unique_ptr<LayerTreeHostRemote> layer_tree_host_remote_; 264 std::unique_ptr<LayerTreeHostRemote> layer_tree_host_remote_;
264 StubLayerTreeHostClient layer_tree_host_client_remote_; 265 StubLayerTreeHostClient layer_tree_host_client_remote_;
265 266
266 // Client setup. 267 // Client setup.
267 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_in_process_; 268 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_in_process_;
268 std::unique_ptr<CompositorStateDeserializer> compositor_state_deserializer_; 269 std::unique_ptr<CompositorStateDeserializer> compositor_state_deserializer_;
269 FakeLayerTreeHostClient layer_tree_host_client_client_;
270 TestTaskGraphRunner task_graph_runner_; 270 TestTaskGraphRunner task_graph_runner_;
271 StubLayerTreeHostSingleThreadClient single_thread_client_;
271 272
272 FakeImageSerializationProcessor image_serialization_processor_; 273 FakeImageSerializationProcessor image_serialization_processor_;
273 274
274 bool should_retain_client_scroll_ = false; 275 bool client_state_dirty_ = false;
275 bool should_retain_client_scale_ = false;
276 }; 276 };
277 277
278 TEST_F(CompositorStateDeserializerTest, BasicSync) { 278 TEST_F(CompositorStateDeserializerTest, BasicSync) {
279 // Set up a tree with a single node. 279 // Set up a tree with a single node.
280 scoped_refptr<Layer> root_layer = Layer::Create(); 280 scoped_refptr<Layer> root_layer = Layer::Create();
281 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer); 281 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer);
282 282
283 // Synchronize State and verify. 283 // Synchronize State and verify.
284 base::RunLoop().RunUntilIdle(); 284 base::RunLoop().RunUntilIdle();
285 VerifyTreesAreIdentical(); 285 VerifyTreesAreIdentical();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 layer_c->SetScrollParent(layer_b.get()); 351 layer_c->SetScrollParent(layer_b.get());
352 layer_c->SetScrollClipLayerId(root_layer->id()); 352 layer_c->SetScrollClipLayerId(root_layer->id());
353 layer_d->SetClipParent(layer_a.get()); 353 layer_d->SetClipParent(layer_a.get());
354 354
355 // Synchronize State and verify. 355 // Synchronize State and verify.
356 base::RunLoop().RunUntilIdle(); 356 base::RunLoop().RunUntilIdle();
357 VerifyTreesAreIdentical(); 357 VerifyTreesAreIdentical();
358 } 358 }
359 359
360 TEST_F(CompositorStateDeserializerTest, ReconcileScrollAndScale) { 360 TEST_F(CompositorStateDeserializerTest, ReconcileScrollAndScale) {
361 layer_tree_host_in_process_->InitializeSingleThreaded(
362 &single_thread_client_, base::ThreadTaskRunnerHandle::Get());
361 scoped_refptr<Layer> root_layer = Layer::Create(); 363 scoped_refptr<Layer> root_layer = Layer::Create();
362 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer); 364 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer);
363 365
364 // Set scroll offset. 366 // Set scroll offset.
365 scoped_refptr<Layer> scroll_layer = Layer::Create(); 367 scoped_refptr<Layer> scroll_layer = Layer::Create();
366 root_layer->AddChild(scroll_layer); 368 root_layer->AddChild(scroll_layer);
367 gfx::ScrollOffset engine_offset(4, 3); 369 gfx::ScrollOffset engine_offset(4, 3);
368 scroll_layer->SetScrollOffset(engine_offset); 370 scroll_layer->SetScrollOffset(engine_offset);
369 371
370 // Set page scale. 372 // Set page scale.
371 float engine_page_scale = 0.5f; 373 float engine_page_scale = 0.5f;
372 layer_tree_host_remote_->GetLayerTree()->SetPageScaleFactorAndLimits( 374 layer_tree_host_remote_->GetLayerTree()->SetPageScaleFactorAndLimits(
373 engine_page_scale, 1.0, 1.0); 375 engine_page_scale, 1.0, 1.0);
374 376
375 // Synchronize State and verify that the engine values are used. 377 // Synchronize State and verify that the engine values are used.
376 base::RunLoop().RunUntilIdle(); 378 base::RunLoop().RunUntilIdle();
377 VerifyTreesAreIdentical(); 379 VerifyTreesAreIdentical();
378 380 Layer* client_scroll_layer =
381 compositor_state_deserializer_->GetLayerForEngineId(scroll_layer->id());
379 EXPECT_EQ(engine_page_scale, 382 EXPECT_EQ(engine_page_scale,
380 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor()); 383 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor());
381 EXPECT_EQ(engine_offset, compositor_state_deserializer_ 384 EXPECT_EQ(engine_offset, client_scroll_layer->scroll_offset());
382 ->GetLayerForEngineId(scroll_layer->id())
383 ->scroll_offset());
384 385
385 // Now reset the scroll offset and page scale and force-retain the client 386 // Now send some updates from the impl thread.
386 // values. 387 ScrollAndScaleSet scroll_and_scale_set;
387 gfx::ScrollOffset new_engine_offset(2, 2); 388
389 gfx::ScrollOffset offset_from_impl_thread(10, 3);
390 LayerTreeHostCommon::ScrollUpdateInfo scroll_update;
391 scroll_update.layer_id = client_scroll_layer->id();
392 gfx::ScrollOffset delta =
393 offset_from_impl_thread - client_scroll_layer->scroll_offset();
394 scroll_update.scroll_delta = gfx::Vector2d(delta.x(), delta.y());
aelias_OOO_until_Jul13 2016/10/28 03:40:20 gfx::Vector2dF
Khushal 2016/10/28 04:11:17 cc still uses Vector2d for sending updates from im
aelias_OOO_until_Jul13 2016/10/29 02:35:53 That's a loose end we shouldn't propagate further,
Khushal 2016/10/31 21:02:01 Done.
395 scroll_and_scale_set.scrolls.push_back(scroll_update);
396
397 float page_scale_from_impl_side = 3.2f;
398 scroll_and_scale_set.page_scale_delta =
399 page_scale_from_impl_side /
400 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor();
401
402 layer_tree_host_in_process_->proxy()->SetNeedsCommit();
403 layer_tree_host_in_process_->ApplyScrollAndScale(&scroll_and_scale_set);
404
405 // The values on the client should have been forced to retain the original
406 // engine value.
407 EXPECT_EQ(engine_page_scale,
408 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor());
409 EXPECT_EQ(engine_offset, client_scroll_layer->scroll_offset());
410
411 // Now pull the deltas from the client onto the engine, this should result
412 // in an aborted commit.
413 proto::ClientStateUpdate client_state_update;
414 compositor_state_deserializer_->PullClientStateUpdate(&client_state_update);
415 layer_tree_host_remote_->ApplyStateUpdateFromClient(client_state_update);
416
417 // Inform the deserializer that the updates were applied on the engine.
418 // This should pre-emptively apply the deltas on the client.
419 compositor_state_deserializer_->DidApplyStateUpdatesOnEngine();
420 EXPECT_EQ(page_scale_from_impl_side,
421 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor());
422 EXPECT_EQ(offset_from_impl_thread, client_scroll_layer->scroll_offset());
423
424 // Now update the scroll offset on the engine, and ensure that the value is
425 // used on the client.
426 gfx::ScrollOffset new_engine_offset(10, 20);
388 scroll_layer->SetScrollOffset(new_engine_offset); 427 scroll_layer->SetScrollOffset(new_engine_offset);
389 float new_engine_page_scale = 0.8f;
390 layer_tree_host_remote_->GetLayerTree()->SetPageScaleFactorAndLimits(
391 new_engine_page_scale, 1.0, 1.0);
392 should_retain_client_scroll_ = true;
393 should_retain_client_scale_ = true;
394 428
395 // Synchronize State and verify that the client values are retained.
396 base::RunLoop().RunUntilIdle(); 429 base::RunLoop().RunUntilIdle();
397 VerifyTreesAreIdentical(); 430 VerifyTreesAreIdentical();
398 431 EXPECT_EQ(page_scale_from_impl_side,
399 EXPECT_EQ(engine_page_scale,
400 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor()); 432 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor());
401 EXPECT_EQ(engine_offset, compositor_state_deserializer_ 433 EXPECT_EQ(new_engine_offset, client_scroll_layer->scroll_offset());
402 ->GetLayerForEngineId(scroll_layer->id())
403 ->scroll_offset());
404 } 434 }
405 435
406 TEST_F(CompositorStateDeserializerTest, PropertyTreesAreIdentical) { 436 TEST_F(CompositorStateDeserializerTest, PropertyTreesAreIdentical) {
407 // Override the LayerFactory. This is necessary to ensure the layer ids 437 // Override the LayerFactory. This is necessary to ensure the layer ids
408 // tracked in PropertyTrees on the engine and client are identical. 438 // tracked in PropertyTrees on the engine and client are identical.
409 compositor_state_deserializer_->SetLayerFactoryForTesting( 439 compositor_state_deserializer_->SetLayerFactoryForTesting(
410 base::MakeUnique<RemoteClientLayerFactory>()); 440 base::MakeUnique<RemoteClientLayerFactory>());
411 441
412 scoped_refptr<Layer> root_layer = Layer::Create(); 442 scoped_refptr<Layer> root_layer = Layer::Create();
413 root_layer->SetBounds(gfx::Size(10, 10)); 443 root_layer->SetBounds(gfx::Size(10, 10));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 picture_layer2->id())); 591 picture_layer2->id()));
562 scoped_refptr<DisplayItemList> client_display_list2 = 592 scoped_refptr<DisplayItemList> client_display_list2 =
563 client_picture_layer2->client()->PaintContentsToDisplayList( 593 client_picture_layer2->client()->PaintContentsToDisplayList(
564 ContentLayerClient::PaintingControlSetting::PAINTING_BEHAVIOR_NORMAL); 594 ContentLayerClient::PaintingControlSetting::PAINTING_BEHAVIOR_NORMAL);
565 EXPECT_TRUE(AreDisplayListDrawingResultsSame( 595 EXPECT_TRUE(AreDisplayListDrawingResultsSame(
566 gfx::Rect(layer_size), display_list.get(), client_display_list2.get())); 596 gfx::Rect(layer_size), display_list.get(), client_display_list2.get()));
567 } 597 }
568 598
569 } // namespace 599 } // namespace
570 } // namespace cc 600 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698