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

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

Issue 2183403002: cc: Move data to LayerTree from LayerTreeHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@layer_tree_change
Patch Set: remove unused test file. Created 4 years, 4 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 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 LayerSpecificPropertiesToProto(&proto); 73 LayerSpecificPropertiesToProto(&proto);
74 74
75 FakeEnginePictureCache* engine_picture_cache = 75 FakeEnginePictureCache* engine_picture_cache =
76 static_cast<FakeEnginePictureCache*>(host->engine_picture_cache()); 76 static_cast<FakeEnginePictureCache*>(host->engine_picture_cache());
77 EXPECT_THAT(engine_picture_ids, 77 EXPECT_THAT(engine_picture_ids,
78 testing::UnorderedElementsAreArray( 78 testing::UnorderedElementsAreArray(
79 engine_picture_cache->GetAllUsedPictureIds())); 79 engine_picture_cache->GetAllUsedPictureIds()));
80 80
81 scoped_refptr<TestSerializationPictureLayer> layer = 81 scoped_refptr<TestSerializationPictureLayer> layer =
82 TestSerializationPictureLayer::Create(recording_source_viewport_); 82 TestSerializationPictureLayer::Create(recording_source_viewport_);
83 host->SetRootLayer(layer); 83 host->GetLayerTree()->SetRootLayer(layer);
84 84
85 layer->FromLayerSpecificPropertiesProto(proto); 85 layer->FromLayerSpecificPropertiesProto(proto);
86 86
87 FakeClientPictureCache* client_picture_cache = 87 FakeClientPictureCache* client_picture_cache =
88 static_cast<FakeClientPictureCache*>(host->client_picture_cache()); 88 static_cast<FakeClientPictureCache*>(host->client_picture_cache());
89 EXPECT_THAT(engine_picture_ids, 89 EXPECT_THAT(engine_picture_ids,
90 testing::UnorderedElementsAreArray( 90 testing::UnorderedElementsAreArray(
91 client_picture_cache->GetAllUsedPictureIds())); 91 client_picture_cache->GetAllUsedPictureIds()));
92 92
93 // Validate that the PictureLayer specific fields are properly set. 93 // Validate that the PictureLayer specific fields are properly set.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 base::WrapUnique(new FakeImageSerializationProcessor); 154 base::WrapUnique(new FakeImageSerializationProcessor);
155 std::unique_ptr<FakeLayerTreeHost> host = 155 std::unique_ptr<FakeLayerTreeHost> host =
156 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, 156 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings,
157 CompositorMode::SINGLE_THREADED, 157 CompositorMode::SINGLE_THREADED,
158 fake_image_serialization_processor.get()); 158 fake_image_serialization_processor.get());
159 host->InitializePictureCacheForTesting(); 159 host->InitializePictureCacheForTesting();
160 160
161 gfx::Size recording_source_viewport(256, 256); 161 gfx::Size recording_source_viewport(256, 256);
162 scoped_refptr<TestSerializationPictureLayer> layer = 162 scoped_refptr<TestSerializationPictureLayer> layer =
163 TestSerializationPictureLayer::Create(recording_source_viewport); 163 TestSerializationPictureLayer::Create(recording_source_viewport);
164 host->SetRootLayer(layer); 164 host->GetLayerTree()->SetRootLayer(layer);
165 165
166 Region region(gfx::Rect(14, 15, 16, 17)); 166 Region region(gfx::Rect(14, 15, 16, 17));
167 layer->set_invalidation(region); 167 layer->set_invalidation(region);
168 layer->set_is_mask(true); 168 layer->set_is_mask(true);
169 layer->set_nearest_neighbor(true); 169 layer->set_nearest_neighbor(true);
170 170
171 layer->SetBounds(recording_source_viewport); 171 layer->SetBounds(recording_source_viewport);
172 layer->set_update_source_frame_number(0); 172 layer->set_update_source_frame_number(0);
173 layer->recording_source()->SetDisplayListUsesCachedPicture(false); 173 layer->recording_source()->SetDisplayListUsesCachedPicture(false);
174 layer->recording_source()->add_draw_rect( 174 layer->recording_source()->add_draw_rect(
(...skipping 12 matching lines...) Expand all
187 base::WrapUnique(new FakeImageSerializationProcessor); 187 base::WrapUnique(new FakeImageSerializationProcessor);
188 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( 188 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(
189 &host_client, &task_graph_runner, LayerTreeSettings(), 189 &host_client, &task_graph_runner, LayerTreeSettings(),
190 CompositorMode::SINGLE_THREADED, 190 CompositorMode::SINGLE_THREADED,
191 fake_image_serialization_processor.get()); 191 fake_image_serialization_processor.get());
192 host->InitializePictureCacheForTesting(); 192 host->InitializePictureCacheForTesting();
193 193
194 gfx::Size recording_source_viewport(256, 256); 194 gfx::Size recording_source_viewport(256, 256);
195 scoped_refptr<TestSerializationPictureLayer> layer = 195 scoped_refptr<TestSerializationPictureLayer> layer =
196 TestSerializationPictureLayer::Create(recording_source_viewport); 196 TestSerializationPictureLayer::Create(recording_source_viewport);
197 host->SetRootLayer(layer); 197 host->GetLayerTree()->SetRootLayer(layer);
198 198
199 layer->SetBounds(recording_source_viewport); 199 layer->SetBounds(recording_source_viewport);
200 layer->set_update_source_frame_number(0); 200 layer->set_update_source_frame_number(0);
201 layer->recording_source()->SetDisplayListUsesCachedPicture(false); 201 layer->recording_source()->SetDisplayListUsesCachedPicture(false);
202 layer->recording_source()->add_draw_rect( 202 layer->recording_source()->add_draw_rect(
203 gfx::Rect(recording_source_viewport)); 203 gfx::Rect(recording_source_viewport));
204 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); 204 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true);
205 layer->recording_source()->Rerecord(); 205 layer->recording_source()->Rerecord();
206 layer->ValidateSerialization(fake_image_serialization_processor.get(), 206 layer->ValidateSerialization(fake_image_serialization_processor.get(),
207 host.get()); 207 host.get());
208 } 208 }
209 209
210 TEST(PictureLayerTest, TestEmptySerializationDeserialization) { 210 TEST(PictureLayerTest, TestEmptySerializationDeserialization) {
211 std::unique_ptr<FakeImageSerializationProcessor> 211 std::unique_ptr<FakeImageSerializationProcessor>
212 fake_image_serialization_processor = 212 fake_image_serialization_processor =
213 base::WrapUnique(new FakeImageSerializationProcessor); 213 base::WrapUnique(new FakeImageSerializationProcessor);
214 FakeLayerTreeHostClient host_client; 214 FakeLayerTreeHostClient host_client;
215 TestTaskGraphRunner task_graph_runner; 215 TestTaskGraphRunner task_graph_runner;
216 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( 216 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(
217 &host_client, &task_graph_runner, LayerTreeSettings(), 217 &host_client, &task_graph_runner, LayerTreeSettings(),
218 CompositorMode::SINGLE_THREADED, 218 CompositorMode::SINGLE_THREADED,
219 fake_image_serialization_processor.get()); 219 fake_image_serialization_processor.get());
220 host->InitializePictureCacheForTesting(); 220 host->InitializePictureCacheForTesting();
221 221
222 gfx::Size recording_source_viewport(256, 256); 222 gfx::Size recording_source_viewport(256, 256);
223 scoped_refptr<TestSerializationPictureLayer> layer = 223 scoped_refptr<TestSerializationPictureLayer> layer =
224 TestSerializationPictureLayer::Create(recording_source_viewport); 224 TestSerializationPictureLayer::Create(recording_source_viewport);
225 host->SetRootLayer(layer); 225 host->GetLayerTree()->SetRootLayer(layer);
226 layer->ValidateSerialization(fake_image_serialization_processor.get(), 226 layer->ValidateSerialization(fake_image_serialization_processor.get(),
227 host.get()); 227 host.get());
228 } 228 }
229 229
230 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { 230 TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
231 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); 231 ContentLayerClient* client = EmptyContentLayerClient::GetInstance();
232 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); 232 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client);
233 layer->SetBounds(gfx::Size(10, 10)); 233 layer->SetBounds(gfx::Size(10, 10));
234 234
235 FakeLayerTreeHostClient host_client; 235 FakeLayerTreeHostClient host_client;
236 TestTaskGraphRunner task_graph_runner; 236 TestTaskGraphRunner task_graph_runner;
237 std::unique_ptr<FakeLayerTreeHost> host = 237 std::unique_ptr<FakeLayerTreeHost> host =
238 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); 238 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
239 host->SetRootLayer(layer); 239 host->GetLayerTree()->SetRootLayer(layer);
240 layer->SetIsDrawable(true); 240 layer->SetIsDrawable(true);
241 layer->SavePaintProperties(); 241 layer->SavePaintProperties();
242 layer->Update(); 242 layer->Update();
243 243
244 EXPECT_EQ(0, host->source_frame_number()); 244 EXPECT_EQ(0, host->source_frame_number());
245 host->CommitComplete(); 245 host->CommitComplete();
246 EXPECT_EQ(1, host->source_frame_number()); 246 EXPECT_EQ(1, host->source_frame_number());
247 247
248 layer->SetBounds(gfx::Size(0, 0)); 248 layer->SetBounds(gfx::Size(0, 0));
249 layer->SavePaintProperties(); 249 layer->SavePaintProperties();
(...skipping 24 matching lines...) Expand all
274 gfx::Size layer_size(50, 50); 274 gfx::Size layer_size(50, 50);
275 FakeContentLayerClient client; 275 FakeContentLayerClient client;
276 client.set_bounds(layer_size); 276 client.set_bounds(layer_size);
277 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); 277 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
278 layer->SetBounds(gfx::Size(50, 50)); 278 layer->SetBounds(gfx::Size(50, 50));
279 279
280 FakeLayerTreeHostClient host_client; 280 FakeLayerTreeHostClient host_client;
281 TestTaskGraphRunner task_graph_runner; 281 TestTaskGraphRunner task_graph_runner;
282 std::unique_ptr<FakeLayerTreeHost> host = 282 std::unique_ptr<FakeLayerTreeHost> host =
283 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); 283 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
284 host->SetRootLayer(layer); 284 host->GetLayerTree()->SetRootLayer(layer);
285 layer->SetIsDrawable(true); 285 layer->SetIsDrawable(true);
286 layer->SavePaintProperties(); 286 layer->SavePaintProperties();
287 287
288 gfx::Rect invalidation_bounds(layer_size); 288 gfx::Rect invalidation_bounds(layer_size);
289 289
290 // The important two lines are the following: 290 // The important two lines are the following:
291 layer->SetNeedsDisplayRect(invalidation_bounds); 291 layer->SetNeedsDisplayRect(invalidation_bounds);
292 layer->Update(); 292 layer->Update();
293 293
294 host->CommitComplete(); 294 host->CommitComplete();
(...skipping 24 matching lines...) Expand all
319 gfx::Size layer_size(50, 50); 319 gfx::Size layer_size(50, 50);
320 FakeContentLayerClient client; 320 FakeContentLayerClient client;
321 client.set_bounds(layer_size); 321 client.set_bounds(layer_size);
322 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); 322 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
323 layer->SetBounds(gfx::Size(50, 50)); 323 layer->SetBounds(gfx::Size(50, 50));
324 324
325 FakeLayerTreeHostClient host_client; 325 FakeLayerTreeHostClient host_client;
326 TestTaskGraphRunner task_graph_runner; 326 TestTaskGraphRunner task_graph_runner;
327 std::unique_ptr<FakeLayerTreeHost> host = 327 std::unique_ptr<FakeLayerTreeHost> host =
328 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); 328 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
329 host->SetRootLayer(layer); 329 host->GetLayerTree()->SetRootLayer(layer);
330 layer->SetIsDrawable(true); 330 layer->SetIsDrawable(true);
331 layer->SavePaintProperties(); 331 layer->SavePaintProperties();
332 332
333 gfx::Rect invalidation_bounds(layer_size); 333 gfx::Rect invalidation_bounds(layer_size);
334 334
335 // The important line is the following (note that we do not call Update): 335 // The important line is the following (note that we do not call Update):
336 layer->SetNeedsDisplayRect(invalidation_bounds); 336 layer->SetNeedsDisplayRect(invalidation_bounds);
337 337
338 host->CommitComplete(); 338 host->CommitComplete();
339 FakeImplTaskRunnerProvider impl_task_runner_provider; 339 FakeImplTaskRunnerProvider impl_task_runner_provider;
(...skipping 24 matching lines...) Expand all
364 client.set_bounds(layer_size); 364 client.set_bounds(layer_size);
365 client.add_draw_image(CreateDiscardableImage(layer_size), gfx::Point(), 365 client.add_draw_image(CreateDiscardableImage(layer_size), gfx::Point(),
366 SkPaint()); 366 SkPaint());
367 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); 367 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
368 layer->SetBounds(gfx::Size(10, 10)); 368 layer->SetBounds(gfx::Size(10, 10));
369 369
370 FakeLayerTreeHostClient host_client; 370 FakeLayerTreeHostClient host_client;
371 TestTaskGraphRunner task_graph_runner; 371 TestTaskGraphRunner task_graph_runner;
372 std::unique_ptr<FakeLayerTreeHost> host = 372 std::unique_ptr<FakeLayerTreeHost> host =
373 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); 373 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
374 host->SetRootLayer(layer); 374 host->GetLayerTree()->SetRootLayer(layer);
375 layer->SetIsDrawable(true); 375 layer->SetIsDrawable(true);
376 layer->SavePaintProperties(); 376 layer->SavePaintProperties();
377 layer->Update(); 377 layer->Update();
378 378
379 EXPECT_EQ(0, host->source_frame_number()); 379 EXPECT_EQ(0, host->source_frame_number());
380 host->CommitComplete(); 380 host->CommitComplete();
381 EXPECT_EQ(1, host->source_frame_number()); 381 EXPECT_EQ(1, host->source_frame_number());
382 382
383 layer->SavePaintProperties(); 383 layer->SavePaintProperties();
384 layer->Update(); 384 layer->Update();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 446
447 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); 447 ContentLayerClient* client = EmptyContentLayerClient::GetInstance();
448 scoped_refptr<FakePictureLayer> layer = 448 scoped_refptr<FakePictureLayer> layer =
449 FakePictureLayer::CreateWithRecordingSource( 449 FakePictureLayer::CreateWithRecordingSource(
450 client, std::move(recording_source_owned)); 450 client, std::move(recording_source_owned));
451 451
452 FakeLayerTreeHostClient host_client; 452 FakeLayerTreeHostClient host_client;
453 TestTaskGraphRunner task_graph_runner; 453 TestTaskGraphRunner task_graph_runner;
454 std::unique_ptr<FakeLayerTreeHost> host = 454 std::unique_ptr<FakeLayerTreeHost> host =
455 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); 455 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
456 host->SetRootLayer(layer); 456 host->GetLayerTree()->SetRootLayer(layer);
457 457
458 // Update layers to initialize the recording source. 458 // Update layers to initialize the recording source.
459 gfx::Size layer_bounds(200, 200); 459 gfx::Size layer_bounds(200, 200);
460 gfx::Rect layer_rect(layer_bounds); 460 gfx::Rect layer_rect(layer_bounds);
461 Region invalidation(layer_rect); 461 Region invalidation(layer_rect);
462 462
463 gfx::Rect new_recorded_viewport = client->PaintableRegion(); 463 gfx::Rect new_recorded_viewport = client->PaintableRegion();
464 scoped_refptr<DisplayItemList> display_list = 464 scoped_refptr<DisplayItemList> display_list =
465 client->PaintContentsToDisplayList( 465 client->PaintContentsToDisplayList(
466 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); 466 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 params2.main_task_runner = base::ThreadTaskRunnerHandle::Get(); 518 params2.main_task_runner = base::ThreadTaskRunnerHandle::Get();
519 params2.client = &host_client2; 519 params2.client = &host_client2;
520 params2.animation_host = 520 params2.animation_host =
521 AnimationHost::CreateForTesting(ThreadInstance::MAIN); 521 AnimationHost::CreateForTesting(ThreadInstance::MAIN);
522 std::unique_ptr<LayerTreeHost> host2 = 522 std::unique_ptr<LayerTreeHost> host2 =
523 LayerTreeHost::CreateSingleThreaded(&single_thread_client, &params2); 523 LayerTreeHost::CreateSingleThreaded(&single_thread_client, &params2);
524 host2->SetVisible(true); 524 host2->SetVisible(true);
525 host_client2.SetLayerTreeHost(host2.get()); 525 host_client2.SetLayerTreeHost(host2.get());
526 526
527 // The PictureLayer is put in one LayerTreeHost. 527 // The PictureLayer is put in one LayerTreeHost.
528 host1->SetRootLayer(layer); 528 host1->GetLayerTree()->SetRootLayer(layer);
529 // Do a main frame, record the picture layers. 529 // Do a main frame, record the picture layers.
530 EXPECT_EQ(0, layer->update_count()); 530 EXPECT_EQ(0, layer->update_count());
531 layer->SetNeedsDisplay(); 531 layer->SetNeedsDisplay();
532 host1->Composite(base::TimeTicks::Now()); 532 host1->Composite(base::TimeTicks::Now());
533 EXPECT_EQ(1, layer->update_count()); 533 EXPECT_EQ(1, layer->update_count());
534 EXPECT_EQ(1, host1->source_frame_number()); 534 EXPECT_EQ(1, host1->source_frame_number());
535 535
536 // The source frame number in |host1| is now higher than host2. 536 // The source frame number in |host1| is now higher than host2.
537 layer->SetNeedsDisplay(); 537 layer->SetNeedsDisplay();
538 host1->Composite(base::TimeTicks::Now()); 538 host1->Composite(base::TimeTicks::Now());
539 EXPECT_EQ(2, layer->update_count()); 539 EXPECT_EQ(2, layer->update_count());
540 EXPECT_EQ(2, host1->source_frame_number()); 540 EXPECT_EQ(2, host1->source_frame_number());
541 541
542 // Then moved to another LayerTreeHost. 542 // Then moved to another LayerTreeHost.
543 host1->SetRootLayer(nullptr); 543 host1->GetLayerTree()->SetRootLayer(nullptr);
544 host2->SetRootLayer(layer); 544 host2->GetLayerTree()->SetRootLayer(layer);
545 545
546 // Do a main frame, record the picture layers. The frame number has changed 546 // Do a main frame, record the picture layers. The frame number has changed
547 // non-monotonically. 547 // non-monotonically.
548 layer->SetNeedsDisplay(); 548 layer->SetNeedsDisplay();
549 host2->Composite(base::TimeTicks::Now()); 549 host2->Composite(base::TimeTicks::Now());
550 EXPECT_EQ(3, layer->update_count()); 550 EXPECT_EQ(3, layer->update_count());
551 EXPECT_EQ(1, host2->source_frame_number()); 551 EXPECT_EQ(1, host2->source_frame_number());
552 } 552 }
553 553
554 } // namespace 554 } // namespace
555 } // namespace cc 555 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698