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

Side by Side Diff: cc/layers/picture_layer_unittest.cc

Issue 1527863002: Serialize PictureLayer properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed tests Created 5 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/layers/picture_layer.h" 5 #include "cc/layers/picture_layer.h"
6 6
7 #include "base/thread_task_runner_handle.h" 7 #include "base/thread_task_runner_handle.h"
8 #include "cc/layers/content_layer_client.h" 8 #include "cc/layers/content_layer_client.h"
9 #include "cc/layers/empty_content_layer_client.h"
9 #include "cc/layers/layer_settings.h" 10 #include "cc/layers/layer_settings.h"
10 #include "cc/layers/picture_layer_impl.h" 11 #include "cc/layers/picture_layer_impl.h"
11 #include "cc/playback/display_item_list_settings.h" 12 #include "cc/playback/display_item_list_settings.h"
13 #include "cc/proto/layer.pb.h"
12 #include "cc/test/fake_display_list_recording_source.h" 14 #include "cc/test/fake_display_list_recording_source.h"
13 #include "cc/test/fake_layer_tree_host.h" 15 #include "cc/test/fake_layer_tree_host.h"
14 #include "cc/test/fake_picture_layer.h" 16 #include "cc/test/fake_picture_layer.h"
15 #include "cc/test/fake_picture_layer_impl.h" 17 #include "cc/test/fake_picture_layer_impl.h"
16 #include "cc/test/fake_proxy.h" 18 #include "cc/test/fake_proxy.h"
17 #include "cc/test/layer_tree_settings_for_testing.h" 19 #include "cc/test/layer_tree_settings_for_testing.h"
18 #include "cc/test/test_shared_bitmap_manager.h" 20 #include "cc/test/test_shared_bitmap_manager.h"
19 #include "cc/test/test_task_graph_runner.h" 21 #include "cc/test/test_task_graph_runner.h"
20 #include "cc/trees/single_thread_proxy.h" 22 #include "cc/trees/single_thread_proxy.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
22 24
23 namespace cc { 25 namespace cc {
26
27 class TestSerializationPictureLayer : public PictureLayer {
28 public:
29 static scoped_refptr<TestSerializationPictureLayer> Create(
30 const gfx::Size& recording_source_viewport) {
31 return make_scoped_refptr(new TestSerializationPictureLayer(
32 LayerSettings(), EmptyContentLayerClient::GetInstance(),
33 FakeDisplayListRecordingSource::CreateFilledRecordingSource(
34 recording_source_viewport),
35 recording_source_viewport));
36 }
37
38 FakeDisplayListRecordingSource* recording_source() {
39 return static_cast<FakeDisplayListRecordingSource*>(
40 recording_source_.get());
41 }
42
43 void set_invalidation(const Region& invalidation) {
44 *invalidation_.region() = invalidation;
45 }
46
47 void set_last_updated_visible_layer_rect(const gfx::Rect& rect) {
48 last_updated_visible_layer_rect_ = rect;
49 }
50
51 void set_update_source_frame_number(int number) {
52 update_source_frame_number_ = number;
53 }
54
55 void set_is_mask(bool is_mask) { is_mask_ = is_mask; }
56
57 void set_nearest_neighbor(bool nearest_neighbor) {
58 nearest_neighbor_ = nearest_neighbor;
59 }
60
61 void ValidateSerialization() {
62 proto::LayerProperties proto;
63 LayerSpecificPropertiesToProto(&proto);
64
65 scoped_refptr<TestSerializationPictureLayer> layer =
66 TestSerializationPictureLayer::Create(recording_source_viewport_);
67 layer->FromLayerSpecificPropertiesProto(proto);
68
69 // Validate that the PictureLayer specific fields are properly set.
70 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source()));
71 EXPECT_EQ(last_updated_visible_layer_rect_,
72 layer->last_updated_visible_layer_rect_);
73 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_);
74 EXPECT_EQ(is_mask_, layer->is_mask_);
75 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_);
76 }
77
78 private:
79 TestSerializationPictureLayer(const LayerSettings& settings,
80 ContentLayerClient* client,
81 scoped_ptr<DisplayListRecordingSource> source,
82 const gfx::Size& recording_source_viewport)
83 : PictureLayer(settings, client, std::move(source)),
84 recording_source_viewport_(recording_source_viewport) {}
85 ~TestSerializationPictureLayer() override {}
86
87 gfx::Size recording_source_viewport_;
88
89 DISALLOW_COPY_AND_ASSIGN(TestSerializationPictureLayer);
90 };
91
24 namespace { 92 namespace {
25 93
26 class MockContentLayerClient : public ContentLayerClient { 94 TEST(PictureLayerTest, TestSetAllPropsSerializationDeserialization) {
27 public: 95 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
28 gfx::Rect PaintableRegion() override { return gfx::Rect(); } 96 TestTaskGraphRunner task_graph_runner;
29 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( 97 scoped_ptr<FakeLayerTreeHost> host =
30 PaintingControlSetting picture_control) override { 98 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
31 return DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings()); 99
32 } 100 gfx::Size recording_source_viewport(256, 256);
33 bool FillsBoundsCompletely() const override { return false; }; 101 scoped_refptr<TestSerializationPictureLayer> layer =
34 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } 102 TestSerializationPictureLayer::Create(recording_source_viewport);
35 }; 103 host->SetRootLayer(layer);
104
105 Region region(gfx::Rect(14, 15, 16, 17));
106 layer->set_invalidation(region);
107 layer->set_last_updated_visible_layer_rect(gfx::Rect(5, 6, 7, 8));
108 layer->set_is_mask(true);
109 layer->set_nearest_neighbor(true);
110
111 layer->SetBounds(recording_source_viewport);
112 layer->set_update_source_frame_number(0);
113 layer->recording_source()->SetDisplayListUsesCachedPicture(false);
114 layer->recording_source()->add_draw_rect(
115 gfx::Rect(recording_source_viewport));
116 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true);
117 layer->recording_source()->Rerecord();
118 layer->ValidateSerialization();
119 }
120
121 TEST(PictureLayerTest, TestSerializationDeserialization) {
122 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
123 TestTaskGraphRunner task_graph_runner;
124 scoped_ptr<FakeLayerTreeHost> host =
125 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
126
127 gfx::Size recording_source_viewport(256, 256);
128 scoped_refptr<TestSerializationPictureLayer> layer =
129 TestSerializationPictureLayer::Create(recording_source_viewport);
130 host->SetRootLayer(layer);
131
132 layer->SetBounds(recording_source_viewport);
133 layer->set_update_source_frame_number(0);
134 layer->recording_source()->SetDisplayListUsesCachedPicture(false);
135 layer->recording_source()->add_draw_rect(
136 gfx::Rect(recording_source_viewport));
137 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true);
138 layer->recording_source()->Rerecord();
139 layer->ValidateSerialization();
140 }
141
142 TEST(PictureLayerTest, TestEmptySerializationDeserialization) {
143 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
144 TestTaskGraphRunner task_graph_runner;
145 scoped_ptr<FakeLayerTreeHost> host =
146 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
147
148 gfx::Size recording_source_viewport(256, 256);
149 scoped_refptr<TestSerializationPictureLayer> layer =
150 TestSerializationPictureLayer::Create(recording_source_viewport);
151 host->SetRootLayer(layer);
152 layer->ValidateSerialization();
153 }
36 154
37 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { 155 TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
38 MockContentLayerClient client; 156 ContentLayerClient* client = EmptyContentLayerClient::GetInstance();
39 scoped_refptr<PictureLayer> layer = 157 scoped_refptr<PictureLayer> layer =
40 PictureLayer::Create(LayerSettings(), &client); 158 PictureLayer::Create(LayerSettings(), client);
41 layer->SetBounds(gfx::Size(10, 10)); 159 layer->SetBounds(gfx::Size(10, 10));
42 160
43 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 161 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
44 TestTaskGraphRunner task_graph_runner; 162 TestTaskGraphRunner task_graph_runner;
45 scoped_ptr<FakeLayerTreeHost> host = 163 scoped_ptr<FakeLayerTreeHost> host =
46 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); 164 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
47 host->SetRootLayer(layer); 165 host->SetRootLayer(layer);
48 layer->SetIsDrawable(true); 166 layer->SetIsDrawable(true);
49 layer->SavePaintProperties(); 167 layer->SavePaintProperties();
50 layer->Update(); 168 layer->Update();
(...skipping 23 matching lines...) Expand all
74 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize()); 192 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize());
75 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings()); 193 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings());
76 } 194 }
77 195
78 TEST(PictureLayerTest, SuitableForGpuRasterization) { 196 TEST(PictureLayerTest, SuitableForGpuRasterization) {
79 scoped_ptr<FakeDisplayListRecordingSource> recording_source_owned( 197 scoped_ptr<FakeDisplayListRecordingSource> recording_source_owned(
80 new FakeDisplayListRecordingSource); 198 new FakeDisplayListRecordingSource);
81 FakeDisplayListRecordingSource* recording_source = 199 FakeDisplayListRecordingSource* recording_source =
82 recording_source_owned.get(); 200 recording_source_owned.get();
83 201
84 MockContentLayerClient client; 202 ContentLayerClient* client = EmptyContentLayerClient::GetInstance();
85 scoped_refptr<FakePictureLayer> layer = 203 scoped_refptr<FakePictureLayer> layer =
86 FakePictureLayer::CreateWithRecordingSource( 204 FakePictureLayer::CreateWithRecordingSource(
87 LayerSettings(), &client, std::move(recording_source_owned)); 205 LayerSettings(), client, std::move(recording_source_owned));
88 206
89 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 207 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
90 TestTaskGraphRunner task_graph_runner; 208 TestTaskGraphRunner task_graph_runner;
91 scoped_ptr<FakeLayerTreeHost> host = 209 scoped_ptr<FakeLayerTreeHost> host =
92 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); 210 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
93 host->SetRootLayer(layer); 211 host->SetRootLayer(layer);
94 212
95 // Update layers to initialize the recording source. 213 // Update layers to initialize the recording source.
96 gfx::Size layer_bounds(200, 200); 214 gfx::Size layer_bounds(200, 200);
97 gfx::Rect layer_rect(layer_bounds); 215 gfx::Rect layer_rect(layer_bounds);
98 Region invalidation(layer_rect); 216 Region invalidation(layer_rect);
99 recording_source->UpdateAndExpandInvalidation( 217 recording_source->UpdateAndExpandInvalidation(
100 &client, &invalidation, layer_bounds, layer_rect, 1, 218 client, &invalidation, layer_bounds, layer_rect, 1,
101 DisplayListRecordingSource::RECORD_NORMALLY); 219 DisplayListRecordingSource::RECORD_NORMALLY);
102 220
103 // Layer is suitable for gpu rasterization by default. 221 // Layer is suitable for gpu rasterization by default.
104 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization()); 222 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization());
105 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); 223 EXPECT_TRUE(layer->IsSuitableForGpuRasterization());
106 224
107 // Veto gpu rasterization. 225 // Veto gpu rasterization.
108 recording_source->SetUnsuitableForGpuRasterization(); 226 recording_source->SetUnsuitableForGpuRasterization();
109 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization()); 227 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization());
110 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); 228 EXPECT_FALSE(layer->IsSuitableForGpuRasterization());
111 } 229 }
112 230
113 // PicturePile uses the source frame number as a unit for measuring invalidation 231 // PicturePile uses the source frame number as a unit for measuring invalidation
114 // frequency. When a pile moves between compositors, the frame number increases 232 // frequency. When a pile moves between compositors, the frame number increases
115 // non-monotonically. This executes that code path under this scenario allowing 233 // non-monotonically. This executes that code path under this scenario allowing
116 // for the code to verify correctness with DCHECKs. 234 // for the code to verify correctness with DCHECKs.
117 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { 235 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) {
118 LayerTreeSettingsForTesting settings; 236 LayerTreeSettingsForTesting settings;
119 settings.single_thread_proxy_scheduler = false; 237 settings.single_thread_proxy_scheduler = false;
120 settings.use_zero_copy = true; 238 settings.use_zero_copy = true;
121 239
122 FakeLayerTreeHostClient host_client1(FakeLayerTreeHostClient::DIRECT_3D); 240 FakeLayerTreeHostClient host_client1(FakeLayerTreeHostClient::DIRECT_3D);
123 FakeLayerTreeHostClient host_client2(FakeLayerTreeHostClient::DIRECT_3D); 241 FakeLayerTreeHostClient host_client2(FakeLayerTreeHostClient::DIRECT_3D);
124 TestSharedBitmapManager shared_bitmap_manager; 242 TestSharedBitmapManager shared_bitmap_manager;
125 TestTaskGraphRunner task_graph_runner; 243 TestTaskGraphRunner task_graph_runner;
126 244
127 MockContentLayerClient client; 245 ContentLayerClient* client = EmptyContentLayerClient::GetInstance();
128 scoped_refptr<FakePictureLayer> layer = 246 scoped_refptr<FakePictureLayer> layer =
129 FakePictureLayer::Create(LayerSettings(), &client); 247 FakePictureLayer::Create(LayerSettings(), client);
130 248
131 LayerTreeHost::InitParams params; 249 LayerTreeHost::InitParams params;
132 params.client = &host_client1; 250 params.client = &host_client1;
133 params.shared_bitmap_manager = &shared_bitmap_manager; 251 params.shared_bitmap_manager = &shared_bitmap_manager;
134 params.settings = &settings; 252 params.settings = &settings;
135 params.task_graph_runner = &task_graph_runner; 253 params.task_graph_runner = &task_graph_runner;
136 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); 254 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
137 scoped_ptr<LayerTreeHost> host1 = 255 scoped_ptr<LayerTreeHost> host1 =
138 LayerTreeHost::CreateSingleThreaded(&host_client1, &params); 256 LayerTreeHost::CreateSingleThreaded(&host_client1, &params);
139 host1->SetVisible(true); 257 host1->SetVisible(true);
(...skipping 27 matching lines...) Expand all
167 // Do a main frame, record the picture layers. The frame number has changed 285 // Do a main frame, record the picture layers. The frame number has changed
168 // non-monotonically. 286 // non-monotonically.
169 layer->SetNeedsDisplay(); 287 layer->SetNeedsDisplay();
170 host2->Composite(base::TimeTicks::Now()); 288 host2->Composite(base::TimeTicks::Now());
171 EXPECT_EQ(3, layer->update_count()); 289 EXPECT_EQ(3, layer->update_count());
172 EXPECT_EQ(1, host2->source_frame_number()); 290 EXPECT_EQ(1, host2->source_frame_number());
173 } 291 }
174 292
175 } // namespace 293 } // namespace
176 } // namespace cc 294 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698