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

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

Issue 2397843003: cc/blimp: Add (de)-serialization for PictureLayer and ScrollbarLayer. (Closed)
Patch Set: Created 4 years, 2 months 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/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
34 bool ArePicturesIdentical(SkPicture* picture1, SkPicture* picture2) {
35 LOG(ERROR) << "picture1 stuff: " << picture1->approximateOpCount();
36 LOG(ERROR) << "picture2 stuff: " << picture2->approximateOpCount();
37 // Serialize the pictures and compare to check that they are identical.
38 sk_sp<SkData> picture_data1 = picture1->serialize();
39 sk_sp<SkData> picture_data2 = picture2->serialize();
40 return picture_data1->equals(picture_data2.get());
41 }
42
25 #define EXPECT_LAYERS_EQ(engine_layer_id, client_layer) \ 43 #define EXPECT_LAYERS_EQ(engine_layer_id, client_layer) \
26 EXPECT_EQ( \ 44 EXPECT_EQ( \
27 compositor_state_deserializer_->GetLayerForEngineId(engine_layer_id), \ 45 compositor_state_deserializer_->GetLayerForEngineId(engine_layer_id), \
28 client_layer); 46 client_layer);
29 47
48 class FakeContentLayerClient : public ContentLayerClient {
49 public:
50 FakeContentLayerClient(scoped_refptr<DisplayItemList> display_list,
51 gfx::Rect recorded_viewport)
52 : display_list_(std::move(display_list)),
53 recorded_viewport_(recorded_viewport) {}
54 ~FakeContentLayerClient() override {}
55
56 // ContentLayerClient implementation.
57 gfx::Rect PaintableRegion() override { return recorded_viewport_; }
58 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
59 PaintingControlSetting painting_status) override {
60 return display_list_;
61 }
62 bool FillsBoundsCompletely() const override { return false; }
63 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
64
65 private:
66 scoped_refptr<DisplayItemList> display_list_;
67 gfx::Rect recorded_viewport_;
68 };
69
30 class RemoteCompositorBridgeForTest : public FakeRemoteCompositorBridge { 70 class RemoteCompositorBridgeForTest : public FakeRemoteCompositorBridge {
31 public: 71 public:
32 using ProtoFrameCallback = base::Callback<void( 72 using ProtoFrameCallback = base::Callback<void(
33 std::unique_ptr<CompositorProtoState> compositor_proto_state)>; 73 std::unique_ptr<CompositorProtoState> compositor_proto_state)>;
34 74
35 RemoteCompositorBridgeForTest( 75 RemoteCompositorBridgeForTest(
36 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 76 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
37 ProtoFrameCallback proto_frame_callback) 77 ProtoFrameCallback proto_frame_callback)
38 : FakeRemoteCompositorBridge(main_task_runner), 78 : FakeRemoteCompositorBridge(main_task_runner),
39 proto_frame_callback_(proto_frame_callback) {} 79 proto_frame_callback_(proto_frame_callback) {}
(...skipping 21 matching lines...) Expand all
61 LayerTreeHostRemote::InitParams params; 101 LayerTreeHostRemote::InitParams params;
62 params.client = &layer_tree_host_client_remote_; 102 params.client = &layer_tree_host_client_remote_;
63 params.main_task_runner = main_task_runner; 103 params.main_task_runner = main_task_runner;
64 params.animation_host = AnimationHost::CreateMainInstance(); 104 params.animation_host = AnimationHost::CreateMainInstance();
65 params.remote_compositor_bridge = 105 params.remote_compositor_bridge =
66 base::MakeUnique<RemoteCompositorBridgeForTest>( 106 base::MakeUnique<RemoteCompositorBridgeForTest>(
67 main_task_runner, 107 main_task_runner,
68 base::Bind( 108 base::Bind(
69 &CompositorStateDeserializerTest::ProcessCompositorStateUpdate, 109 &CompositorStateDeserializerTest::ProcessCompositorStateUpdate,
70 base::Unretained(this))); 110 base::Unretained(this)));
111 params.engine_picture_cache =
112 image_serialization_processor_.CreateEnginePictureCache();
71 LayerTreeSettings settings; 113 LayerTreeSettings settings;
72 params.settings = &settings; 114 params.settings = &settings;
73 115
74 layer_tree_host_remote_ = base::MakeUnique<LayerTreeHostRemote>(&params); 116 layer_tree_host_remote_ = base::MakeUnique<LayerTreeHostRemote>(&params);
75 117
76 // Client side setup. 118 // Client side setup.
77 layer_tree_host_in_process_ = FakeLayerTreeHost::Create( 119 layer_tree_host_in_process_ = FakeLayerTreeHost::Create(
78 &layer_tree_host_client_client_, &task_graph_runner_); 120 &layer_tree_host_client_client_, &task_graph_runner_);
121 std::unique_ptr<ClientPictureCache> client_picture_cache =
122 image_serialization_processor_.CreateClientPictureCache();
79 compositor_state_deserializer_ = 123 compositor_state_deserializer_ =
80 base::MakeUnique<CompositorStateDeserializer>( 124 base::MakeUnique<CompositorStateDeserializer>(
81 layer_tree_host_in_process_.get(), 125 layer_tree_host_in_process_.get(), std::move(client_picture_cache),
82 base::Bind(&CompositorStateDeserializerTest::LayerScrolled, 126 base::Bind(&CompositorStateDeserializerTest::LayerScrolled,
83 base::Unretained(this)), 127 base::Unretained(this)),
84 this); 128 this);
85 } 129 }
86 130
87 void TearDown() override { 131 void TearDown() override {
88 layer_tree_host_remote_ = nullptr; 132 layer_tree_host_remote_ = nullptr;
89 compositor_state_deserializer_ = nullptr; 133 compositor_state_deserializer_ = nullptr;
90 layer_tree_host_in_process_ = nullptr; 134 layer_tree_host_in_process_ = nullptr;
91 } 135 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 EXPECT_EQ(client_layer->clip_parent(), nullptr); 259 EXPECT_EQ(client_layer->clip_parent(), nullptr);
216 } 260 }
217 261
218 // Scroll-clip layer. 262 // Scroll-clip layer.
219 if (engine_layer->scroll_clip_layer()) { 263 if (engine_layer->scroll_clip_layer()) {
220 int scroll_clip_id = engine_layer->scroll_clip_layer()->id(); 264 int scroll_clip_id = engine_layer->scroll_clip_layer()->id();
221 EXPECT_LAYERS_EQ(scroll_clip_id, client_layer->scroll_clip_layer()); 265 EXPECT_LAYERS_EQ(scroll_clip_id, client_layer->scroll_clip_layer());
222 } else { 266 } else {
223 EXPECT_EQ(client_layer->scroll_clip_layer(), nullptr); 267 EXPECT_EQ(client_layer->scroll_clip_layer(), nullptr);
224 } 268 }
269
270 // Picture layer result.
271 sk_sp<SkPicture> engine_picture = engine_layer->GetPicture();
272 sk_sp<SkPicture> client_picture = client_layer->GetPicture();
273 if (engine_picture) {
274 EXPECT_NE(client_picture, nullptr);
275 } else {
276 EXPECT_EQ(client_picture, nullptr);
277 }
225 } 278 }
226 279
227 // Engine setup. 280 // Engine setup.
228 std::unique_ptr<LayerTreeHostRemote> layer_tree_host_remote_; 281 std::unique_ptr<LayerTreeHostRemote> layer_tree_host_remote_;
229 StubLayerTreeHostClient layer_tree_host_client_remote_; 282 StubLayerTreeHostClient layer_tree_host_client_remote_;
230 283
231 // Client setup. 284 // Client setup.
232 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_in_process_; 285 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_in_process_;
233 std::unique_ptr<CompositorStateDeserializer> compositor_state_deserializer_; 286 std::unique_ptr<CompositorStateDeserializer> compositor_state_deserializer_;
234 FakeLayerTreeHostClient layer_tree_host_client_client_; 287 FakeLayerTreeHostClient layer_tree_host_client_client_;
235 TestTaskGraphRunner task_graph_runner_; 288 TestTaskGraphRunner task_graph_runner_;
236 289
290 FakeImageSerializationProcessor image_serialization_processor_;
291
237 bool should_retain_client_scroll_ = false; 292 bool should_retain_client_scroll_ = false;
238 bool should_retain_client_scale_ = false; 293 bool should_retain_client_scale_ = false;
239 }; 294 };
240 295
241 TEST_F(CompositorStateDeserializerTest, BasicSync) { 296 TEST_F(CompositorStateDeserializerTest, BasicSync) {
242 // Set up a tree with a single node. 297 // Set up a tree with a single node.
243 scoped_refptr<Layer> root_layer = Layer::Create(); 298 scoped_refptr<Layer> root_layer = Layer::Create();
244 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer); 299 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer);
245 300
246 // Synchronize State and verify. 301 // Synchronize State and verify.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 PropertyTrees* engine_property_trees = 465 PropertyTrees* engine_property_trees =
411 layer_tree_host_remote_->GetLayerTree()->property_trees(); 466 layer_tree_host_remote_->GetLayerTree()->property_trees();
412 467
413 layer_tree_host_in_process_->BuildPropertyTreesForTesting(); 468 layer_tree_host_in_process_->BuildPropertyTreesForTesting();
414 PropertyTrees* client_property_trees = 469 PropertyTrees* client_property_trees =
415 layer_tree_host_in_process_->property_trees(); 470 layer_tree_host_in_process_->property_trees();
416 471
417 EXPECT_EQ(*engine_property_trees, *client_property_trees); 472 EXPECT_EQ(*engine_property_trees, *client_property_trees);
418 } 473 }
419 474
475 TEST_F(CompositorStateDeserializerTest, SolidColorScrollbarLayer) {
476 scoped_refptr<Layer> root_layer = Layer::Create();
477 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer);
478
479 scoped_refptr<Layer> child_layer1 = Layer::Create();
480 root_layer->AddChild(child_layer1);
481 scoped_refptr<SolidColorScrollbarLayer> scroll_layer1 =
482 SolidColorScrollbarLayer::Create(ScrollbarOrientation::HORIZONTAL, 20, 5,
483 true, 3);
484 scroll_layer1->SetScrollLayer(child_layer1->id());
485 child_layer1->AddChild(scroll_layer1);
486
487 scoped_refptr<SolidColorScrollbarLayer> scroll_layer2 =
488 SolidColorScrollbarLayer::Create(ScrollbarOrientation::VERTICAL, 2, 9,
489 false, 3);
490 root_layer->AddChild(scroll_layer2);
491 scoped_refptr<Layer> child_layer2 = Layer::Create();
492 scroll_layer2->AddChild(child_layer2);
493 scroll_layer2->SetScrollLayer(child_layer2->id());
494
495 // Synchronize State and verify.
496 base::RunLoop().RunUntilIdle();
497 VerifyTreesAreIdentical();
498
499 // Verify Scrollbar layers.
500 SolidColorScrollbarLayer* client_scroll_layer1 =
501 static_cast<SolidColorScrollbarLayer*>(
502 compositor_state_deserializer_->GetLayerForEngineId(
503 scroll_layer1->id()));
504 EXPECT_EQ(client_scroll_layer1->ScrollLayerId(),
505 compositor_state_deserializer_->GetClientIdFromEngineId(
506 scroll_layer1->ScrollLayerId()));
507 EXPECT_EQ(client_scroll_layer1->orientation(), scroll_layer1->orientation());
508
509 SolidColorScrollbarLayer* client_scroll_layer2 =
510 static_cast<SolidColorScrollbarLayer*>(
511 compositor_state_deserializer_->GetLayerForEngineId(
512 scroll_layer2->id()));
513 EXPECT_EQ(client_scroll_layer2->ScrollLayerId(),
514 compositor_state_deserializer_->GetClientIdFromEngineId(
515 scroll_layer2->ScrollLayerId()));
516 EXPECT_EQ(client_scroll_layer2->orientation(), scroll_layer2->orientation());
517 }
518
519 TEST_F(CompositorStateDeserializerTest, PictureLayer) {
520 scoped_refptr<Layer> root_layer = Layer::Create();
521 layer_tree_host_remote_->GetLayerTree()->SetRootLayer(root_layer);
522
523 gfx::Size layer_size = gfx::Size(5, 5);
524
525 gfx::PointF offset(2.f, 3.f);
526 SkPictureRecorder recorder;
527 sk_sp<SkCanvas> canvas;
528 SkPaint red_paint;
529 red_paint.setColor(SK_ColorRED);
530 canvas = sk_ref_sp(recorder.beginRecording(SkRect::MakeXYWH(
531 offset.x(), offset.y(), layer_size.width(), layer_size.height())));
532 canvas->translate(offset.x(), offset.y());
533 canvas->drawRectCoords(0.f, 0.f, 4.f, 4.f, red_paint);
534 sk_sp<SkPicture> test_picture = recorder.finishRecordingAsPicture();
535
536 DisplayItemListSettings settings;
537 settings.use_cached_picture = false;
538 scoped_refptr<DisplayItemList> display_list =
539 DisplayItemList::Create(settings);
540 const gfx::Rect visual_rect(0, 0, 42, 42);
541 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>(visual_rect,
542 test_picture);
543 display_list->Finalize();
544 FakeContentLayerClient content_client(display_list, gfx::Rect(layer_size));
545
546 scoped_refptr<PictureLayer> picture_layer =
547 PictureLayer::Create(&content_client);
548 picture_layer->SetBounds(layer_size);
549 root_layer->AddChild(picture_layer);
550
551 // Synchronize State and verify.
552 base::RunLoop().RunUntilIdle();
553 VerifyTreesAreIdentical();
554
555 // Verify PictureLayer.
556 PictureLayer* client_picture_layer = static_cast<PictureLayer*>(
557 compositor_state_deserializer_->GetLayerForEngineId(picture_layer->id()));
558 scoped_refptr<DisplayItemList> client_display_list =
559 client_picture_layer->client()->PaintContentsToDisplayList(
560 ContentLayerClient::PaintingControlSetting::PAINTING_BEHAVIOR_NORMAL);
561 AreDisplayListDrawingResultsSame(gfx::Rect(layer_size), display_list.get(),
562 client_display_list.get());
563
564 // Now attach new layer with the same DisplayList.
565 scoped_refptr<PictureLayer> picture_layer2 =
566 PictureLayer::Create(&content_client);
567 picture_layer->SetBounds(layer_size);
568 root_layer->AddChild(picture_layer2);
569
570 // Synchronize State and verify.
571 base::RunLoop().RunUntilIdle();
572 VerifyTreesAreIdentical();
573
574 // Verify PictureLayer2.
575 PictureLayer* client_picture_layer2 = static_cast<PictureLayer*>(
576 compositor_state_deserializer_->GetLayerForEngineId(
577 picture_layer2->id()));
578 scoped_refptr<DisplayItemList> client_display_list2 =
579 client_picture_layer2->client()->PaintContentsToDisplayList(
580 ContentLayerClient::PaintingControlSetting::PAINTING_BEHAVIOR_NORMAL);
581 AreDisplayListDrawingResultsSame(gfx::Rect(layer_size), display_list.get(),
582 client_display_list2.get());
583 }
584
420 } // namespace 585 } // namespace
421 } // namespace cc 586 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698