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

Side by Side Diff: cc/trees/layer_tree_host_unittest_serialization.cc

Issue 1982893002: [blimp] Add SkPicture caching support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from vmpstr, including adding //cc/blimp Created 4 years, 5 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
« no previous file with comments | « cc/trees/layer_tree_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <memory>
8
9 #include "base/memory/ptr_util.h"
10 #include "cc/layers/empty_content_layer_client.h"
7 #include "cc/layers/heads_up_display_layer.h" 11 #include "cc/layers/heads_up_display_layer.h"
8 #include "cc/layers/layer.h" 12 #include "cc/layers/layer.h"
9 #include "cc/proto/layer.pb.h" 13 #include "cc/proto/layer.pb.h"
10 #include "cc/proto/layer_tree_host.pb.h" 14 #include "cc/proto/layer_tree_host.pb.h"
15 #include "cc/test/fake_image_serialization_processor.h"
11 #include "cc/test/fake_layer_tree_host.h" 16 #include "cc/test/fake_layer_tree_host.h"
12 #include "cc/test/fake_layer_tree_host_client.h" 17 #include "cc/test/fake_layer_tree_host_client.h"
18 #include "cc/test/fake_picture_layer.h"
19 #include "cc/test/fake_recording_source.h"
13 #include "cc/test/layer_tree_test.h" 20 #include "cc/test/layer_tree_test.h"
21 #include "cc/test/skia_common.h"
14 #include "cc/test/test_task_graph_runner.h" 22 #include "cc/test/test_task_graph_runner.h"
15 #include "cc/trees/layer_tree_settings.h" 23 #include "cc/trees/layer_tree_settings.h"
16 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/skia/include/core/SkColor.h" 25 #include "third_party/skia/include/core/SkColor.h"
18 #include "ui/gfx/geometry/point.h" 26 #include "ui/gfx/geometry/point.h"
19 #include "ui/gfx/geometry/size.h" 27 #include "ui/gfx/geometry/size.h"
20 #include "ui/gfx/geometry/vector2d_f.h" 28 #include "ui/gfx/geometry/vector2d_f.h"
21 29
22 namespace cc { 30 namespace cc {
23 31
32 namespace {
33 std::unique_ptr<FakeRecordingSource> CreateRecordingSource(
34 const gfx::Rect& viewport) {
35 gfx::Rect layer_rect(viewport.right(), viewport.bottom());
36 std::unique_ptr<FakeRecordingSource> recording_source =
37 FakeRecordingSource::CreateRecordingSource(viewport, layer_rect.size());
38 return recording_source;
39 }
40
41 scoped_refptr<FakePictureLayer> CreatePictureLayer() {
42 gfx::Rect recorded_viewport(0, 0, 256, 256);
43
44 std::unique_ptr<FakeRecordingSource> recording_source =
45 CreateRecordingSource(recorded_viewport);
46 recording_source->SetDisplayListUsesCachedPicture(false);
47
48 SkPaint simple_paint;
49 simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34));
50 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256),
51 simple_paint);
52 recording_source->SetGenerateDiscardableImagesMetadata(true);
53 recording_source->Rerecord();
54
55 ContentLayerClient* client = EmptyContentLayerClient::GetInstance();
56 return FakePictureLayer::CreateWithRecordingSource(
57 client, std::move(recording_source));
58 }
59 } // namespace
60
24 class LayerTreeHostSerializationTest : public testing::Test { 61 class LayerTreeHostSerializationTest : public testing::Test {
25 public: 62 public:
26 LayerTreeHostSerializationTest() 63 LayerTreeHostSerializationTest()
27 : client_src_(FakeLayerTreeHostClient::DIRECT_3D), 64 : image_serialization_processor_(
65 base::WrapUnique(new FakeImageSerializationProcessor)),
66 client_src_(FakeLayerTreeHostClient::DIRECT_3D),
28 client_dst_(FakeLayerTreeHostClient::DIRECT_3D) {} 67 client_dst_(FakeLayerTreeHostClient::DIRECT_3D) {}
29 68
30 protected: 69 protected:
31 void SetUp() override { 70 void SetUp() override {
32 layer_tree_host_src_ = 71 LayerTreeSettings settings;
33 FakeLayerTreeHost::Create(&client_src_, &task_graph_runner_src_); 72 layer_tree_host_src_ = FakeLayerTreeHost::Create(
34 layer_tree_host_dst_ = 73 &client_src_, &task_graph_runner_src_, settings,
35 FakeLayerTreeHost::Create(&client_dst_, &task_graph_runner_dst_); 74 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get());
75 layer_tree_host_dst_ = FakeLayerTreeHost::Create(
76 &client_dst_, &task_graph_runner_dst_, settings,
77 CompositorMode::SINGLE_THREADED, image_serialization_processor_.get());
78 layer_tree_host_src_->InitializePictureCacheForTesting();
79 layer_tree_host_dst_->InitializePictureCacheForTesting();
36 } 80 }
37 81
38 void TearDown() override { 82 void TearDown() override {
39 // Need to reset |in_paint_layer_contents_| to tear down. 83 // Need to reset |in_paint_layer_contents_| to tear down.
40 layer_tree_host_src_->in_paint_layer_contents_ = false; 84 layer_tree_host_src_->in_paint_layer_contents_ = false;
41 layer_tree_host_dst_->in_paint_layer_contents_ = false; 85 layer_tree_host_dst_->in_paint_layer_contents_ = false;
42 86
43 // Need to reset LayerTreeHost pointers before tear down. 87 // Need to reset LayerTreeHost pointers before tear down.
44 layer_tree_host_src_ = nullptr; 88 layer_tree_host_src_ = nullptr;
45 layer_tree_host_dst_ = nullptr; 89 layer_tree_host_dst_ = nullptr;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 layer_tree_host_src_->overscroll_elasticity_layer_ = nullptr; 348 layer_tree_host_src_->overscroll_elasticity_layer_ = nullptr;
305 VerifySerializationAndDeserialization(); 349 VerifySerializationAndDeserialization();
306 layer_tree_host_src_->page_scale_layer_ = nullptr; 350 layer_tree_host_src_->page_scale_layer_ = nullptr;
307 VerifySerializationAndDeserialization(); 351 VerifySerializationAndDeserialization();
308 layer_tree_host_src_->inner_viewport_scroll_layer_ = nullptr; 352 layer_tree_host_src_->inner_viewport_scroll_layer_ = nullptr;
309 VerifySerializationAndDeserialization(); 353 VerifySerializationAndDeserialization();
310 layer_tree_host_src_->outer_viewport_scroll_layer_ = nullptr; 354 layer_tree_host_src_->outer_viewport_scroll_layer_ = nullptr;
311 VerifySerializationAndDeserialization(); 355 VerifySerializationAndDeserialization();
312 } 356 }
313 357
358 void RunPictureLayerMultipleSerializationsTest() {
359 // Just fake setup a layer for both source and dest.
360 scoped_refptr<Layer> root_layer_src = Layer::Create();
361 layer_tree_host_src_->SetRootLayer(root_layer_src);
362 layer_tree_host_dst_->SetRootLayer(Layer::Create());
363
364 // Ensure that a PictureLayer work correctly for multiple rounds of
365 // serialization and deserialization.
366 scoped_refptr<FakePictureLayer> picture_layer_src = CreatePictureLayer();
367 root_layer_src->AddChild(picture_layer_src);
368 picture_layer_src->SetBounds(gfx::Size(10, 10));
369 picture_layer_src->SetIsDrawable(true);
370 picture_layer_src->SavePaintProperties();
371 picture_layer_src->Update();
372 picture_layer_src->SavePaintProperties();
373 VerifySerializationAndDeserialization();
374 ASSERT_EQ(1U, layer_tree_host_dst_->root_layer()->children().size());
375 PictureLayer* picture_layer_dst = reinterpret_cast<PictureLayer*>(
376 layer_tree_host_dst_->root_layer()->child_at(0));
377
378 RecordingSource* recording_source_src =
379 picture_layer_src->GetRecordingSourceForTesting();
380 RecordingSource* recording_source_dst =
381 picture_layer_dst->GetRecordingSourceForTesting();
382 EXPECT_EQ(recording_source_src->GetSize(), recording_source_dst->GetSize());
383 EXPECT_TRUE(AreDisplayListDrawingResultsSame(
384 gfx::Rect(recording_source_src->GetSize()),
385 recording_source_src->GetDisplayItemList(),
386 recording_source_dst->GetDisplayItemList()));
387
388 VerifySerializationAndDeserialization();
389 }
390
314 void RunAddAndRemoveNodeFromLayerTree() { 391 void RunAddAndRemoveNodeFromLayerTree() {
315 /* Testing serialization when the tree hierarchy changes like this: 392 /* Testing serialization when the tree hierarchy changes like this:
316 root root 393 root root
317 / \ / \ 394 / \ / \
318 a b => a c 395 a b => a c
319 \ \ 396 \ \
320 c d 397 c d
321 */ 398 */
322 scoped_refptr<Layer> layer_src_root = Layer::Create(); 399 scoped_refptr<Layer> layer_src_root = Layer::Create();
323 layer_tree_host_src_->SetRootLayer(layer_src_root); 400 layer_tree_host_src_->SetRootLayer(layer_src_root);
(...skipping 14 matching lines...) Expand all
338 layer_src_c->RemoveFromParent(); 415 layer_src_c->RemoveFromParent();
339 layer_src_b->RemoveFromParent(); 416 layer_src_b->RemoveFromParent();
340 layer_src_root->AddChild(layer_src_c); 417 layer_src_root->AddChild(layer_src_c);
341 layer_src_c->AddChild(layer_src_d); 418 layer_src_c->AddChild(layer_src_d);
342 419
343 VerifySerializationAndDeserialization(); 420 VerifySerializationAndDeserialization();
344 VerifyHostHasAllExpectedLayersInTree(layer_tree_host_dst_->root_layer()); 421 VerifyHostHasAllExpectedLayersInTree(layer_tree_host_dst_->root_layer());
345 } 422 }
346 423
347 private: 424 private:
425 std::unique_ptr<ImageSerializationProcessor> image_serialization_processor_;
426
348 TestTaskGraphRunner task_graph_runner_src_; 427 TestTaskGraphRunner task_graph_runner_src_;
349 FakeLayerTreeHostClient client_src_; 428 FakeLayerTreeHostClient client_src_;
350 std::unique_ptr<LayerTreeHost> layer_tree_host_src_; 429 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_src_;
351 430
352 TestTaskGraphRunner task_graph_runner_dst_; 431 TestTaskGraphRunner task_graph_runner_dst_;
353 FakeLayerTreeHostClient client_dst_; 432 FakeLayerTreeHostClient client_dst_;
354 std::unique_ptr<LayerTreeHost> layer_tree_host_dst_; 433 std::unique_ptr<FakeLayerTreeHost> layer_tree_host_dst_;
355 }; 434 };
356 435
357 TEST_F(LayerTreeHostSerializationTest, AllMembersChanged) { 436 TEST_F(LayerTreeHostSerializationTest, AllMembersChanged) {
358 RunAllMembersChangedTest(); 437 RunAllMembersChangedTest();
359 } 438 }
360 439
361 TEST_F(LayerTreeHostSerializationTest, LayersChanged) { 440 TEST_F(LayerTreeHostSerializationTest, LayersChanged) {
362 RunLayersChangedTest(); 441 RunLayersChangedTest();
363 } 442 }
364 443
365 TEST_F(LayerTreeHostSerializationTest, LayersChangedMultipleSerializations) { 444 TEST_F(LayerTreeHostSerializationTest, LayersChangedMultipleSerializations) {
366 RunLayersChangedMultipleSerializations(); 445 RunLayersChangedMultipleSerializations();
367 } 446 }
368 447
369 TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) { 448 TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) {
370 RunAddAndRemoveNodeFromLayerTree(); 449 RunAddAndRemoveNodeFromLayerTree();
371 } 450 }
372 451
452 TEST_F(LayerTreeHostSerializationTest, PictureLayerMultipleSerializations) {
453 RunPictureLayerMultipleSerializationsTest();
454 }
455
373 } // namespace cc 456 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698