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

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

Issue 2445093002: cc/blimp: Add synchronization for scroll/scale state. (Closed)
Patch Set: test compile 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
« no previous file with comments | « cc/blimp/compositor_state_deserializer_client.h ('k') | cc/blimp/layer_tree_host_remote.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
21 #include "cc/test/fake_proxy.h"
22 #include "cc/test/fake_remote_compositor_bridge.h" 22 #include "cc/test/fake_remote_compositor_bridge.h"
23 #include "cc/test/remote_client_layer_factory.h" 23 #include "cc/test/remote_client_layer_factory.h"
24 #include "cc/test/skia_common.h" 24 #include "cc/test/skia_common.h"
25 #include "cc/test/stub_layer_tree_host_client.h" 25 #include "cc/test/stub_layer_tree_host_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( \
36 compositor_state_deserializer_->GetLayerForEngineId(engine_layer_id), \ 36 compositor_state_deserializer_->GetLayerForEngineId(engine_layer_id), \
37 client_layer); 37 client_layer);
38 38
39 class ProxyForCommitRequest : public FakeProxy {
40 public:
41 bool CommitRequested() const override { return true; }
42 };
43
39 class FakeContentLayerClient : public ContentLayerClient { 44 class FakeContentLayerClient : public ContentLayerClient {
40 public: 45 public:
41 FakeContentLayerClient(scoped_refptr<DisplayItemList> display_list, 46 FakeContentLayerClient(scoped_refptr<DisplayItemList> display_list,
42 gfx::Rect recorded_viewport) 47 gfx::Rect recorded_viewport)
43 : display_list_(std::move(display_list)), 48 : display_list_(std::move(display_list)),
44 recorded_viewport_(recorded_viewport) {} 49 recorded_viewport_(recorded_viewport) {}
45 ~FakeContentLayerClient() override {} 50 ~FakeContentLayerClient() override {}
46 51
47 // ContentLayerClient implementation. 52 // ContentLayerClient implementation.
48 gfx::Rect PaintableRegion() override { return recorded_viewport_; } 53 gfx::Rect PaintableRegion() override { return recorded_viewport_; }
(...skipping 26 matching lines...) Expand all
75 std::unique_ptr<CompositorProtoState> compositor_proto_state) override { 80 std::unique_ptr<CompositorProtoState> compositor_proto_state) override {
76 proto_frame_callback_.Run(std::move(compositor_proto_state)); 81 proto_frame_callback_.Run(std::move(compositor_proto_state));
77 } 82 }
78 83
79 private: 84 private:
80 ProtoFrameCallback proto_frame_callback_; 85 ProtoFrameCallback proto_frame_callback_;
81 }; 86 };
82 87
83 class CompositorStateDeserializerTest 88 class CompositorStateDeserializerTest
84 : public testing::Test, 89 : public testing::Test,
85 public CompositorStateDeserializerClient { 90 public CompositorStateDeserializerClient,
91 public FakeLayerTreeHostClient {
86 public: 92 public:
87 void SetUp() override { 93 void SetUp() override {
88 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner = 94 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner =
89 base::ThreadTaskRunnerHandle::Get(); 95 base::ThreadTaskRunnerHandle::Get();
90 96
91 // Engine side setup. 97 // Engine side setup.
92 LayerTreeHostRemote::InitParams params; 98 LayerTreeHostRemote::InitParams params;
93 params.client = &layer_tree_host_client_remote_; 99 params.client = &layer_tree_host_client_remote_;
94 params.main_task_runner = main_task_runner; 100 params.main_task_runner = main_task_runner;
95 params.animation_host = AnimationHost::CreateMainInstance(); 101 params.animation_host = AnimationHost::CreateMainInstance();
96 params.remote_compositor_bridge = 102 params.remote_compositor_bridge =
97 base::MakeUnique<RemoteCompositorBridgeForTest>( 103 base::MakeUnique<RemoteCompositorBridgeForTest>(
98 main_task_runner, 104 main_task_runner,
99 base::Bind( 105 base::Bind(
100 &CompositorStateDeserializerTest::ProcessCompositorStateUpdate, 106 &CompositorStateDeserializerTest::ProcessCompositorStateUpdate,
101 base::Unretained(this))); 107 base::Unretained(this)));
102 params.engine_picture_cache = 108 params.engine_picture_cache =
103 image_serialization_processor_.CreateEnginePictureCache(); 109 image_serialization_processor_.CreateEnginePictureCache();
104 LayerTreeSettings settings; 110 LayerTreeSettings settings;
105 params.settings = &settings; 111 params.settings = &settings;
106 112
107 layer_tree_host_remote_ = base::MakeUnique<LayerTreeHostRemote>(&params); 113 layer_tree_host_remote_ = base::MakeUnique<LayerTreeHostRemote>(&params);
108 114
109 // Client side setup. 115 // Client side setup.
110 layer_tree_host_in_process_ = FakeLayerTreeHost::Create( 116 layer_tree_host_in_process_ = FakeLayerTreeHost::Create(
111 &layer_tree_host_client_client_, &task_graph_runner_); 117 this, &task_graph_runner_, settings, CompositorMode::THREADED);
118 layer_tree_host_in_process_->InitializeForTesting(
119 TaskRunnerProvider::Create(base::ThreadTaskRunnerHandle::Get(),
120 base::ThreadTaskRunnerHandle::Get()),
121 base::MakeUnique<ProxyForCommitRequest>());
112 std::unique_ptr<ClientPictureCache> client_picture_cache = 122 std::unique_ptr<ClientPictureCache> client_picture_cache =
113 image_serialization_processor_.CreateClientPictureCache(); 123 image_serialization_processor_.CreateClientPictureCache();
114 compositor_state_deserializer_ = 124 compositor_state_deserializer_ =
115 base::MakeUnique<CompositorStateDeserializer>( 125 base::MakeUnique<CompositorStateDeserializer>(
116 layer_tree_host_in_process_.get(), std::move(client_picture_cache), 126 layer_tree_host_in_process_.get(), std::move(client_picture_cache),
117 base::Bind(&CompositorStateDeserializerTest::LayerScrolled,
118 base::Unretained(this)),
119 this); 127 this);
120 } 128 }
121 129
122 void TearDown() override { 130 void TearDown() override {
123 layer_tree_host_remote_ = nullptr; 131 layer_tree_host_remote_ = nullptr;
124 compositor_state_deserializer_ = nullptr; 132 compositor_state_deserializer_ = nullptr;
125 layer_tree_host_in_process_ = nullptr; 133 layer_tree_host_in_process_ = nullptr;
126 } 134 }
127 135
128 void ProcessCompositorStateUpdate( 136 void ProcessCompositorStateUpdate(
129 std::unique_ptr<CompositorProtoState> compositor_proto_state) { 137 std::unique_ptr<CompositorProtoState> compositor_proto_state) {
130 // Immediately deserialize the state update. 138 // Immediately deserialize the state update.
131 compositor_state_deserializer_->DeserializeCompositorUpdate( 139 compositor_state_deserializer_->DeserializeCompositorUpdate(
132 compositor_proto_state->compositor_message->layer_tree_host()); 140 compositor_proto_state->compositor_message->layer_tree_host());
133 } 141 }
134 142
135 // CompositorStateDeserializer implementation. 143 // CompositorStateDeserializer implementation.
136 bool ShouldRetainClientScroll(int engine_layer_id, 144 void DidUpdateLocalState() override { client_state_dirty_ = true; }
137 const gfx::ScrollOffset& new_offset) override { 145
138 return should_retain_client_scroll_; 146 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
147 const gfx::Vector2dF& outer_delta,
148 const gfx::Vector2dF& elastic_overscroll_delta,
149 float page_scale,
150 float top_controls_delta) override {
151 compositor_state_deserializer_->ApplyViewportDeltas(
152 inner_delta, outer_delta, elastic_overscroll_delta, page_scale,
153 top_controls_delta);
139 } 154 }
140 bool ShouldRetainClientPageScale(float new_page_scale) override {
141 return should_retain_client_scale_;
142 }
143
144 void LayerScrolled(int engine_layer_id) {}
145 155
146 void VerifyTreesAreIdentical() { 156 void VerifyTreesAreIdentical() {
147 LayerTree* engine_layer_tree = layer_tree_host_remote_->GetLayerTree(); 157 LayerTree* engine_layer_tree = layer_tree_host_remote_->GetLayerTree();
148 LayerTree* client_layer_tree = layer_tree_host_in_process_->GetLayerTree(); 158 LayerTree* client_layer_tree = layer_tree_host_in_process_->GetLayerTree();
149 159
150 if (engine_layer_tree->root_layer()) { 160 if (engine_layer_tree->root_layer()) {
151 LayerTreeHostCommon::CallFunctionForEveryLayer( 161 LayerTreeHostCommon::CallFunctionForEveryLayer(
152 engine_layer_tree, [this](Layer* engine_layer) { 162 engine_layer_tree, [this](Layer* engine_layer) {
153 VerifyLayersAreIdentical( 163 VerifyLayersAreIdentical(
154 engine_layer, 164 engine_layer,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } 269 }
260 } 270 }
261 271
262 // Engine setup. 272 // Engine setup.
263 std::unique_ptr<LayerTreeHostRemote> layer_tree_host_remote_; 273 std::unique_ptr<LayerTreeHostRemote> layer_tree_host_remote_;
264 StubLayerTreeHostClient layer_tree_host_client_remote_; 274 StubLayerTreeHostClient layer_tree_host_client_remote_;
265 275
266 // Client setup. 276 // Client setup.
267 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_in_process_; 277 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_in_process_;
268 std::unique_ptr<CompositorStateDeserializer> compositor_state_deserializer_; 278 std::unique_ptr<CompositorStateDeserializer> compositor_state_deserializer_;
269 FakeLayerTreeHostClient layer_tree_host_client_client_;
270 TestTaskGraphRunner task_graph_runner_; 279 TestTaskGraphRunner task_graph_runner_;
271 280
272 FakeImageSerializationProcessor image_serialization_processor_; 281 FakeImageSerializationProcessor image_serialization_processor_;
273 282
274 bool should_retain_client_scroll_ = false; 283 bool client_state_dirty_ = false;
275 bool should_retain_client_scale_ = false;
276 }; 284 };
277 285
278 TEST_F(CompositorStateDeserializerTest, BasicSync) { 286 TEST_F(CompositorStateDeserializerTest, BasicSync) {
279 // Set up a tree with a single node. 287 // Set up a tree with a single node.
280 scoped_refptr<Layer> root_layer = Layer::Create(); 288 scoped_refptr<Layer> root_layer = Layer::Create();
281 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer); 289 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer);
282 290
283 // Synchronize State and verify. 291 // Synchronize State and verify.
284 base::RunLoop().RunUntilIdle(); 292 base::RunLoop().RunUntilIdle();
285 VerifyTreesAreIdentical(); 293 VerifyTreesAreIdentical();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 scroll_layer->SetScrollOffset(engine_offset); 376 scroll_layer->SetScrollOffset(engine_offset);
369 377
370 // Set page scale. 378 // Set page scale.
371 float engine_page_scale = 0.5f; 379 float engine_page_scale = 0.5f;
372 layer_tree_host_remote_->GetLayerTree()->SetPageScaleFactorAndLimits( 380 layer_tree_host_remote_->GetLayerTree()->SetPageScaleFactorAndLimits(
373 engine_page_scale, 1.0, 1.0); 381 engine_page_scale, 1.0, 1.0);
374 382
375 // Synchronize State and verify that the engine values are used. 383 // Synchronize State and verify that the engine values are used.
376 base::RunLoop().RunUntilIdle(); 384 base::RunLoop().RunUntilIdle();
377 VerifyTreesAreIdentical(); 385 VerifyTreesAreIdentical();
378 386 Layer* client_scroll_layer =
387 compositor_state_deserializer_->GetLayerForEngineId(scroll_layer->id());
379 EXPECT_EQ(engine_page_scale, 388 EXPECT_EQ(engine_page_scale,
380 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor()); 389 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor());
381 EXPECT_EQ(engine_offset, compositor_state_deserializer_ 390 EXPECT_EQ(engine_offset, client_scroll_layer->scroll_offset());
382 ->GetLayerForEngineId(scroll_layer->id())
383 ->scroll_offset());
384 391
385 // Now reset the scroll offset and page scale and force-retain the client 392 // Now send some updates from the impl thread.
386 // values. 393 ScrollAndScaleSet scroll_and_scale_set;
387 gfx::ScrollOffset new_engine_offset(2, 2); 394
395 gfx::ScrollOffset offset_from_impl_thread(10, 3);
396 gfx::ScrollOffset scroll_delta =
397 offset_from_impl_thread - client_scroll_layer->scroll_offset();
398 LayerTreeHostCommon::ScrollUpdateInfo scroll_update;
399 scroll_update.layer_id = client_scroll_layer->id();
400 scroll_update.scroll_delta = gfx::ScrollOffsetToFlooredVector2d(scroll_delta);
401 scroll_and_scale_set.scrolls.push_back(scroll_update);
402
403 float page_scale_from_impl_side = 3.2f;
404 float page_scale_delta =
405 page_scale_from_impl_side /
406 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor();
407 scroll_and_scale_set.page_scale_delta = page_scale_delta;
408
409 layer_tree_host_in_process_->ApplyScrollAndScale(&scroll_and_scale_set);
410
411 // The values on the client should have been forced to retain the original
412 // engine value.
413 EXPECT_EQ(engine_page_scale,
414 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor());
415 EXPECT_EQ(engine_offset, client_scroll_layer->scroll_offset());
416
417 // Now pull the deltas from the client onto the engine, this should result
418 // in an aborted commit.
419 proto::ClientStateUpdate client_state_update;
420 compositor_state_deserializer_->PullClientStateUpdate(&client_state_update);
421
422 // Send the reflected main frame state to the client layer tree host.
423 compositor_state_deserializer_->SendUnappliedDeltasToLayerTreeHost();
424 const ReflectedMainFrameState* reflected_state =
425 layer_tree_host_in_process_->reflected_main_frame_state_for_testing();
426 EXPECT_EQ(reflected_state->scrolls.size(), 1u);
427 EXPECT_EQ(reflected_state->scrolls[0].layer_id, client_scroll_layer->id());
428 EXPECT_EQ(reflected_state->scrolls[0].scroll_delta,
429 gfx::ScrollOffsetToVector2dF(scroll_delta));
430 EXPECT_EQ(reflected_state->page_scale_delta, page_scale_delta);
431
432 layer_tree_host_remote_->ApplyStateUpdateFromClient(client_state_update);
433
434 // Inform the deserializer that the updates were applied on the engine.
435 // This should pre-emptively apply the deltas on the client.
436 compositor_state_deserializer_->DidApplyStateUpdatesOnEngine();
437 EXPECT_EQ(page_scale_from_impl_side,
438 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor());
439 EXPECT_EQ(offset_from_impl_thread, client_scroll_layer->scroll_offset());
440
441 // Now update the scroll offset on the engine, and ensure that the value is
442 // used on the client.
443 gfx::ScrollOffset new_engine_offset(10, 20);
388 scroll_layer->SetScrollOffset(new_engine_offset); 444 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 445
395 // Synchronize State and verify that the client values are retained.
396 base::RunLoop().RunUntilIdle(); 446 base::RunLoop().RunUntilIdle();
397 VerifyTreesAreIdentical(); 447 VerifyTreesAreIdentical();
398 448 EXPECT_EQ(page_scale_from_impl_side,
399 EXPECT_EQ(engine_page_scale,
400 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor()); 449 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor());
401 EXPECT_EQ(engine_offset, compositor_state_deserializer_ 450 EXPECT_EQ(new_engine_offset, client_scroll_layer->scroll_offset());
402 ->GetLayerForEngineId(scroll_layer->id())
403 ->scroll_offset());
404 } 451 }
405 452
406 TEST_F(CompositorStateDeserializerTest, PropertyTreesAreIdentical) { 453 TEST_F(CompositorStateDeserializerTest, PropertyTreesAreIdentical) {
407 // Override the LayerFactory. This is necessary to ensure the layer ids 454 // Override the LayerFactory. This is necessary to ensure the layer ids
408 // tracked in PropertyTrees on the engine and client are identical. 455 // tracked in PropertyTrees on the engine and client are identical.
409 compositor_state_deserializer_->SetLayerFactoryForTesting( 456 compositor_state_deserializer_->SetLayerFactoryForTesting(
410 base::MakeUnique<RemoteClientLayerFactory>()); 457 base::MakeUnique<RemoteClientLayerFactory>());
411 458
412 scoped_refptr<Layer> root_layer = Layer::Create(); 459 scoped_refptr<Layer> root_layer = Layer::Create();
413 root_layer->SetBounds(gfx::Size(10, 10)); 460 root_layer->SetBounds(gfx::Size(10, 10));
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 picture_layer2->id())); 612 picture_layer2->id()));
566 scoped_refptr<DisplayItemList> client_display_list2 = 613 scoped_refptr<DisplayItemList> client_display_list2 =
567 client_picture_layer2->client()->PaintContentsToDisplayList( 614 client_picture_layer2->client()->PaintContentsToDisplayList(
568 ContentLayerClient::PaintingControlSetting::PAINTING_BEHAVIOR_NORMAL); 615 ContentLayerClient::PaintingControlSetting::PAINTING_BEHAVIOR_NORMAL);
569 EXPECT_TRUE(AreDisplayListDrawingResultsSame( 616 EXPECT_TRUE(AreDisplayListDrawingResultsSame(
570 gfx::Rect(layer_size), display_list.get(), client_display_list2.get())); 617 gfx::Rect(layer_size), display_list.get(), client_display_list2.get()));
571 } 618 }
572 619
573 } // namespace 620 } // namespace
574 } // namespace cc 621 } // namespace cc
OLDNEW
« no previous file with comments | « cc/blimp/compositor_state_deserializer_client.h ('k') | cc/blimp/layer_tree_host_remote.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698