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

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

Issue 2493523003: cc: Remove unused proto conversion code. (Closed)
Patch Set: test 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/layers/picture_layer.cc ('k') | cc/layers/solid_color_scrollbar_layer.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 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 17 matching lines...) Expand all
28 #include "cc/test/skia_common.h" 28 #include "cc/test/skia_common.h"
29 #include "cc/test/stub_layer_tree_host_single_thread_client.h" 29 #include "cc/test/stub_layer_tree_host_single_thread_client.h"
30 #include "cc/test/test_task_graph_runner.h" 30 #include "cc/test/test_task_graph_runner.h"
31 #include "cc/trees/single_thread_proxy.h" 31 #include "cc/trees/single_thread_proxy.h"
32 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 #include "third_party/skia/include/core/SkRefCnt.h" 34 #include "third_party/skia/include/core/SkRefCnt.h"
35 35
36 namespace cc { 36 namespace cc {
37 37
38 class TestSerializationPictureLayer : public PictureLayer {
39 public:
40 static scoped_refptr<TestSerializationPictureLayer> Create(
41 const gfx::Size& recording_source_viewport) {
42 return make_scoped_refptr(new TestSerializationPictureLayer(
43 EmptyContentLayerClient::GetInstance(),
44 FakeRecordingSource::CreateFilledRecordingSource(
45 recording_source_viewport),
46 recording_source_viewport));
47 }
48
49 FakeRecordingSource* recording_source() {
50 return static_cast<FakeRecordingSource*>(recording_source_.get());
51 }
52
53 void set_invalidation(const Region& invalidation) {
54 last_updated_invalidation_ = invalidation;
55 }
56
57 void set_update_source_frame_number(int number) {
58 update_source_frame_number_ = number;
59 }
60
61 void set_is_mask(bool is_mask) { is_mask_ = is_mask; }
62
63 void set_nearest_neighbor(bool nearest_neighbor) {
64 picture_layer_inputs_.nearest_neighbor = nearest_neighbor;
65 }
66
67 void ValidateSerialization(
68 ImageSerializationProcessor* image_serialization_processor,
69 LayerTreeHostInProcess* host) {
70 std::vector<uint32_t> engine_picture_ids = GetPictureIds();
71 proto::LayerProperties proto;
72 LayerSpecificPropertiesToProto(&proto, false);
73
74 FakeEnginePictureCache* engine_picture_cache =
75 static_cast<FakeEnginePictureCache*>(host->engine_picture_cache());
76 EXPECT_THAT(engine_picture_ids,
77 testing::UnorderedElementsAreArray(
78 engine_picture_cache->GetAllUsedPictureIds()));
79
80 scoped_refptr<TestSerializationPictureLayer> layer =
81 TestSerializationPictureLayer::Create(recording_source_viewport_);
82 host->GetLayerTree()->SetRootLayer(layer);
83
84 layer->FromLayerSpecificPropertiesProto(proto);
85
86 FakeClientPictureCache* client_picture_cache =
87 static_cast<FakeClientPictureCache*>(host->client_picture_cache());
88 EXPECT_THAT(engine_picture_ids,
89 testing::UnorderedElementsAreArray(
90 client_picture_cache->GetAllUsedPictureIds()));
91
92 // Validate that the PictureLayer specific fields are properly set.
93 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source()));
94 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_);
95 EXPECT_EQ(is_mask_, layer->is_mask_);
96 EXPECT_EQ(picture_layer_inputs_.nearest_neighbor,
97 layer->picture_layer_inputs_.nearest_neighbor);
98 EXPECT_EQ(picture_layer_inputs_.recorded_viewport,
99 layer->picture_layer_inputs_.recorded_viewport);
100
101 // The DisplayItemLists are equal if they are both null or they are both not
102 // null and render to the same thing.
103 bool display_lists_equal = !picture_layer_inputs_.display_list &&
104 !layer->picture_layer_inputs_.display_list;
105 if (picture_layer_inputs_.display_list &&
106 layer->picture_layer_inputs_.display_list) {
107 display_lists_equal = AreDisplayListDrawingResultsSame(
108 picture_layer_inputs_.recorded_viewport,
109 picture_layer_inputs_.display_list.get(),
110 layer->picture_layer_inputs_.display_list.get());
111 }
112 EXPECT_TRUE(display_lists_equal);
113 }
114
115 std::vector<uint32_t> GetPictureIds() {
116 std::vector<uint32_t> ids;
117 const DisplayItemList* display_list =
118 picture_layer_inputs_.display_list.get();
119 if (!display_list)
120 return ids;
121
122 for (auto it = display_list->begin(); it != display_list->end(); ++it) {
123 sk_sp<const SkPicture> picture = it->GetPicture();
124 if (!picture)
125 continue;
126
127 ids.push_back(picture->uniqueID());
128 }
129 return ids;
130 }
131
132 private:
133 TestSerializationPictureLayer(ContentLayerClient* client,
134 std::unique_ptr<RecordingSource> source,
135 const gfx::Size& recording_source_viewport)
136 : PictureLayer(client, std::move(source)),
137 recording_source_viewport_(recording_source_viewport) {}
138 ~TestSerializationPictureLayer() override {}
139
140 gfx::Size recording_source_viewport_;
141
142 DISALLOW_COPY_AND_ASSIGN(TestSerializationPictureLayer);
143 };
144
145 namespace { 38 namespace {
146 39
147 TEST(PictureLayerTest, TestSetAllPropsSerializationDeserialization) {
148 FakeLayerTreeHostClient host_client;
149 TestTaskGraphRunner task_graph_runner;
150 LayerTreeSettings settings = LayerTreeSettingsForTesting();
151 std::unique_ptr<FakeImageSerializationProcessor>
152 fake_image_serialization_processor =
153 base::WrapUnique(new FakeImageSerializationProcessor);
154 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
155 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(
156 &host_client, &task_graph_runner, animation_host.get(), settings,
157 CompositorMode::SINGLE_THREADED,
158 fake_image_serialization_processor.get());
159 host->InitializePictureCacheForTesting();
160
161 gfx::Size recording_source_viewport(256, 256);
162 scoped_refptr<TestSerializationPictureLayer> layer =
163 TestSerializationPictureLayer::Create(recording_source_viewport);
164 host->GetLayerTree()->SetRootLayer(layer);
165
166 Region region(gfx::Rect(14, 15, 16, 17));
167 layer->set_invalidation(region);
168 layer->set_is_mask(true);
169 layer->set_nearest_neighbor(true);
170
171 layer->SetBounds(recording_source_viewport);
172 layer->set_update_source_frame_number(0);
173 layer->recording_source()->SetDisplayListUsesCachedPicture(false);
174 layer->recording_source()->add_draw_rect(
175 gfx::Rect(recording_source_viewport));
176 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true);
177 layer->recording_source()->Rerecord();
178 layer->ValidateSerialization(fake_image_serialization_processor.get(),
179 host.get());
180 }
181
182 TEST(PictureLayerTest, TestSerializationDeserialization) {
183 FakeLayerTreeHostClient host_client;
184 TestTaskGraphRunner task_graph_runner;
185 std::unique_ptr<FakeImageSerializationProcessor>
186 fake_image_serialization_processor =
187 base::WrapUnique(new FakeImageSerializationProcessor);
188 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
189 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(
190 &host_client, &task_graph_runner, animation_host.get(),
191 LayerTreeSettings(), CompositorMode::SINGLE_THREADED,
192 fake_image_serialization_processor.get());
193 host->InitializePictureCacheForTesting();
194
195 gfx::Size recording_source_viewport(256, 256);
196 scoped_refptr<TestSerializationPictureLayer> layer =
197 TestSerializationPictureLayer::Create(recording_source_viewport);
198 host->GetLayerTree()->SetRootLayer(layer);
199
200 layer->SetBounds(recording_source_viewport);
201 layer->set_update_source_frame_number(0);
202 layer->recording_source()->SetDisplayListUsesCachedPicture(false);
203 layer->recording_source()->add_draw_rect(
204 gfx::Rect(recording_source_viewport));
205 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true);
206 layer->recording_source()->Rerecord();
207 layer->ValidateSerialization(fake_image_serialization_processor.get(),
208 host.get());
209 }
210
211 TEST(PictureLayerTest, TestEmptySerializationDeserialization) {
212 std::unique_ptr<FakeImageSerializationProcessor>
213 fake_image_serialization_processor =
214 base::WrapUnique(new FakeImageSerializationProcessor);
215 FakeLayerTreeHostClient host_client;
216 TestTaskGraphRunner task_graph_runner;
217 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
218 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(
219 &host_client, &task_graph_runner, animation_host.get(),
220 LayerTreeSettings(), CompositorMode::SINGLE_THREADED,
221 fake_image_serialization_processor.get());
222 host->InitializePictureCacheForTesting();
223
224 gfx::Size recording_source_viewport(256, 256);
225 scoped_refptr<TestSerializationPictureLayer> layer =
226 TestSerializationPictureLayer::Create(recording_source_viewport);
227 host->GetLayerTree()->SetRootLayer(layer);
228 layer->ValidateSerialization(fake_image_serialization_processor.get(),
229 host.get());
230 }
231
232 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { 40 TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
233 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); 41 ContentLayerClient* client = EmptyContentLayerClient::GetInstance();
234 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); 42 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client);
235 layer->SetBounds(gfx::Size(10, 10)); 43 layer->SetBounds(gfx::Size(10, 10));
236 44
237 FakeLayerTreeHostClient host_client; 45 FakeLayerTreeHostClient host_client;
238 TestTaskGraphRunner task_graph_runner; 46 TestTaskGraphRunner task_graph_runner;
239 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); 47 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN);
240 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( 48 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(
241 &host_client, &task_graph_runner, animation_host.get()); 49 &host_client, &task_graph_runner, animation_host.get());
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 host2->Composite(base::TimeTicks::Now()); 358 host2->Composite(base::TimeTicks::Now());
551 EXPECT_EQ(3, layer->update_count()); 359 EXPECT_EQ(3, layer->update_count());
552 EXPECT_EQ(1, host2->SourceFrameNumber()); 360 EXPECT_EQ(1, host2->SourceFrameNumber());
553 361
554 animation_host->SetMutatorHostClient(nullptr); 362 animation_host->SetMutatorHostClient(nullptr);
555 animation_host2->SetMutatorHostClient(nullptr); 363 animation_host2->SetMutatorHostClient(nullptr);
556 } 364 }
557 365
558 } // namespace 366 } // namespace
559 } // namespace cc 367 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer.cc ('k') | cc/layers/solid_color_scrollbar_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698