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

Side by Side Diff: cc/surfaces/surface_factory_unittest.cc

Issue 1866203004: Convert //cc from scoped_ptr to std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptrcc: rebase Created 4 years, 8 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/surfaces/surface_factory.cc ('k') | cc/surfaces/surface_hittest_unittest.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/surfaces/surface_factory.h" 5 #include "cc/surfaces/surface_factory.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 factory_->Create(surface_id_); 62 factory_->Create(surface_id_);
63 } 63 }
64 64
65 ~SurfaceFactoryTest() override { 65 ~SurfaceFactoryTest() override {
66 if (!surface_id_.is_null()) 66 if (!surface_id_.is_null())
67 factory_->Destroy(surface_id_); 67 factory_->Destroy(surface_id_);
68 } 68 }
69 69
70 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, 70 void SubmitCompositorFrameWithResources(ResourceId* resource_ids,
71 size_t num_resource_ids) { 71 size_t num_resource_ids) {
72 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 72 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
73 for (size_t i = 0u; i < num_resource_ids; ++i) { 73 for (size_t i = 0u; i < num_resource_ids; ++i) {
74 TransferableResource resource; 74 TransferableResource resource;
75 resource.id = resource_ids[i]; 75 resource.id = resource_ids[i];
76 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 76 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
77 frame_data->resource_list.push_back(resource); 77 frame_data->resource_list.push_back(resource);
78 } 78 }
79 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 79 std::unique_ptr<CompositorFrame> frame(new CompositorFrame);
80 frame->delegated_frame_data = std::move(frame_data); 80 frame->delegated_frame_data = std::move(frame_data);
81 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), 81 factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
82 SurfaceFactory::DrawCallback()); 82 SurfaceFactory::DrawCallback());
83 } 83 }
84 84
85 void UnrefResources(ResourceId* ids_to_unref, 85 void UnrefResources(ResourceId* ids_to_unref,
86 int* counts_to_unref, 86 int* counts_to_unref,
87 size_t num_ids_to_unref) { 87 size_t num_ids_to_unref) {
88 ReturnedResourceArray unref_array; 88 ReturnedResourceArray unref_array;
89 for (size_t i = 0; i < num_ids_to_unref; ++i) { 89 for (size_t i = 0; i < num_ids_to_unref; ++i) {
(...skipping 21 matching lines...) Expand all
111 111
112 void RefCurrentFrameResources() { 112 void RefCurrentFrameResources() {
113 Surface* surface = manager_.GetSurfaceForId(surface_id_); 113 Surface* surface = manager_.GetSurfaceForId(surface_id_);
114 factory_->RefResources( 114 factory_->RefResources(
115 surface->GetEligibleFrame()->delegated_frame_data->resource_list); 115 surface->GetEligibleFrame()->delegated_frame_data->resource_list);
116 } 116 }
117 117
118 protected: 118 protected:
119 SurfaceManager manager_; 119 SurfaceManager manager_;
120 TestSurfaceFactoryClient client_; 120 TestSurfaceFactoryClient client_;
121 scoped_ptr<SurfaceFactory> factory_; 121 std::unique_ptr<SurfaceFactory> factory_;
122 SurfaceId surface_id_; 122 SurfaceId surface_id_;
123 }; 123 };
124 124
125 // Tests submitting a frame with resources followed by one with no resources 125 // Tests submitting a frame with resources followed by one with no resources
126 // with no resource provider action in between. 126 // with no resource provider action in between.
127 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimple) { 127 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimple) {
128 ResourceId first_frame_ids[] = {1, 2, 3}; 128 ResourceId first_frame_ids[] = {1, 2, 3};
129 SubmitCompositorFrameWithResources(first_frame_ids, 129 SubmitCompositorFrameWithResources(first_frame_ids,
130 arraysize(first_frame_ids)); 130 arraysize(first_frame_ids));
131 131
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 arraysize(expected_returned_counts)); 387 arraysize(expected_returned_counts));
388 } 388 }
389 } 389 }
390 390
391 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { 391 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
392 SurfaceId surface_id(6); 392 SurfaceId surface_id(6);
393 factory_->Create(surface_id); 393 factory_->Create(surface_id);
394 Surface* surface = manager_.GetSurfaceForId(surface_id); 394 Surface* surface = manager_.GetSurfaceForId(surface_id);
395 ASSERT_NE(nullptr, surface); 395 ASSERT_NE(nullptr, surface);
396 EXPECT_EQ(2, surface->frame_index()); 396 EXPECT_EQ(2, surface->frame_index());
397 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 397 std::unique_ptr<CompositorFrame> frame(new CompositorFrame);
398 frame->delegated_frame_data.reset(new DelegatedFrameData); 398 frame->delegated_frame_data.reset(new DelegatedFrameData);
399 399
400 factory_->SubmitCompositorFrame(surface_id, std::move(frame), 400 factory_->SubmitCompositorFrame(surface_id, std::move(frame),
401 SurfaceFactory::DrawCallback()); 401 SurfaceFactory::DrawCallback());
402 EXPECT_EQ(2, surface->frame_index()); 402 EXPECT_EQ(2, surface->frame_index());
403 factory_->Destroy(surface_id); 403 factory_->Destroy(surface_id);
404 } 404 }
405 405
406 void DrawCallback(uint32_t* execute_count, 406 void DrawCallback(uint32_t* execute_count,
407 SurfaceDrawStatus* result, 407 SurfaceDrawStatus* result,
408 SurfaceDrawStatus drawn) { 408 SurfaceDrawStatus drawn) {
409 *execute_count += 1; 409 *execute_count += 1;
410 *result = drawn; 410 *result = drawn;
411 } 411 }
412 412
413 // Tests doing a DestroyAll before shutting down the factory; 413 // Tests doing a DestroyAll before shutting down the factory;
414 TEST_F(SurfaceFactoryTest, DestroyAll) { 414 TEST_F(SurfaceFactoryTest, DestroyAll) {
415 SurfaceId id(7); 415 SurfaceId id(7);
416 factory_->Create(id); 416 factory_->Create(id);
417 417
418 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 418 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
419 TransferableResource resource; 419 TransferableResource resource;
420 resource.id = 1; 420 resource.id = 1;
421 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 421 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
422 frame_data->resource_list.push_back(resource); 422 frame_data->resource_list.push_back(resource);
423 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 423 std::unique_ptr<CompositorFrame> frame(new CompositorFrame);
424 frame->delegated_frame_data = std::move(frame_data); 424 frame->delegated_frame_data = std::move(frame_data);
425 uint32_t execute_count = 0; 425 uint32_t execute_count = 0;
426 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; 426 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED;
427 427
428 factory_->SubmitCompositorFrame( 428 factory_->SubmitCompositorFrame(
429 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn)); 429 id, std::move(frame), base::Bind(&DrawCallback, &execute_count, &drawn));
430 430
431 surface_id_ = SurfaceId(); 431 surface_id_ = SurfaceId();
432 factory_->DestroyAll(); 432 factory_->DestroyAll();
433 EXPECT_EQ(1u, execute_count); 433 EXPECT_EQ(1u, execute_count);
434 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); 434 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn);
435 } 435 }
436 436
437 TEST_F(SurfaceFactoryTest, DestroySequence) { 437 TEST_F(SurfaceFactoryTest, DestroySequence) {
438 SurfaceId id2(5); 438 SurfaceId id2(5);
439 factory_->Create(id2); 439 factory_->Create(id2);
440 440
441 manager_.RegisterSurfaceIdNamespace(0); 441 manager_.RegisterSurfaceIdNamespace(0);
442 442
443 // Check that waiting before the sequence is satisfied works. 443 // Check that waiting before the sequence is satisfied works.
444 manager_.GetSurfaceForId(id2) 444 manager_.GetSurfaceForId(id2)
445 ->AddDestructionDependency(SurfaceSequence(0, 4)); 445 ->AddDestructionDependency(SurfaceSequence(0, 4));
446 factory_->Destroy(id2); 446 factory_->Destroy(id2);
447 447
448 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 448 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
449 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 449 std::unique_ptr<CompositorFrame> frame(new CompositorFrame);
450 frame->metadata.satisfies_sequences.push_back(6); 450 frame->metadata.satisfies_sequences.push_back(6);
451 frame->metadata.satisfies_sequences.push_back(4); 451 frame->metadata.satisfies_sequences.push_back(4);
452 frame->delegated_frame_data = std::move(frame_data); 452 frame->delegated_frame_data = std::move(frame_data);
453 DCHECK(manager_.GetSurfaceForId(id2)); 453 DCHECK(manager_.GetSurfaceForId(id2));
454 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), 454 factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
455 SurfaceFactory::DrawCallback()); 455 SurfaceFactory::DrawCallback());
456 DCHECK(!manager_.GetSurfaceForId(id2)); 456 DCHECK(!manager_.GetSurfaceForId(id2));
457 457
458 // Check that waiting after the sequence is satisfied works. 458 // Check that waiting after the sequence is satisfied works.
459 factory_->Create(id2); 459 factory_->Create(id2);
(...skipping 30 matching lines...) Expand all
490 SurfaceId id2(5); 490 SurfaceId id2(5);
491 factory_->Create(id2); 491 factory_->Create(id2);
492 492
493 manager_.RegisterSurfaceIdNamespace(0); 493 manager_.RegisterSurfaceIdNamespace(0);
494 494
495 manager_.GetSurfaceForId(id2) 495 manager_.GetSurfaceForId(id2)
496 ->AddDestructionDependency(SurfaceSequence(0, 4)); 496 ->AddDestructionDependency(SurfaceSequence(0, 4));
497 497
498 // Give id2 a frame that references surface_id_. 498 // Give id2 a frame that references surface_id_.
499 { 499 {
500 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); 500 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
501 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 501 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
502 frame_data->render_pass_list.push_back(std::move(render_pass)); 502 frame_data->render_pass_list.push_back(std::move(render_pass));
503 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 503 std::unique_ptr<CompositorFrame> frame(new CompositorFrame);
504 frame->metadata.referenced_surfaces.push_back(surface_id_); 504 frame->metadata.referenced_surfaces.push_back(surface_id_);
505 frame->delegated_frame_data = std::move(frame_data); 505 frame->delegated_frame_data = std::move(frame_data);
506 factory_->SubmitCompositorFrame(id2, std::move(frame), 506 factory_->SubmitCompositorFrame(id2, std::move(frame),
507 SurfaceFactory::DrawCallback()); 507 SurfaceFactory::DrawCallback());
508 } 508 }
509 factory_->Destroy(id2); 509 factory_->Destroy(id2);
510 510
511 // Give surface_id_ a frame that references id2. 511 // Give surface_id_ a frame that references id2.
512 { 512 {
513 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); 513 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
514 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 514 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
515 frame_data->render_pass_list.push_back(std::move(render_pass)); 515 frame_data->render_pass_list.push_back(std::move(render_pass));
516 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 516 std::unique_ptr<CompositorFrame> frame(new CompositorFrame);
517 frame->metadata.referenced_surfaces.push_back(id2); 517 frame->metadata.referenced_surfaces.push_back(id2);
518 frame->delegated_frame_data = std::move(frame_data); 518 frame->delegated_frame_data = std::move(frame_data);
519 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), 519 factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
520 SurfaceFactory::DrawCallback()); 520 SurfaceFactory::DrawCallback());
521 } 521 }
522 factory_->Destroy(surface_id_); 522 factory_->Destroy(surface_id_);
523 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); 523 EXPECT_TRUE(manager_.GetSurfaceForId(id2));
524 // surface_id_ should be retained by reference from id2. 524 // surface_id_ should be retained by reference from id2.
525 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id_)); 525 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id_));
526 526
527 // Satisfy last destruction dependency for id2. 527 // Satisfy last destruction dependency for id2.
528 std::vector<uint32_t> to_satisfy; 528 std::vector<uint32_t> to_satisfy;
529 to_satisfy.push_back(4); 529 to_satisfy.push_back(4);
530 manager_.DidSatisfySequences(0, &to_satisfy); 530 manager_.DidSatisfySequences(0, &to_satisfy);
531 531
532 // id2 and surface_id_ are in a reference cycle that has no surface 532 // id2 and surface_id_ are in a reference cycle that has no surface
533 // sequences holding on to it, so they should be destroyed. 533 // sequences holding on to it, so they should be destroyed.
534 EXPECT_TRUE(!manager_.GetSurfaceForId(id2)); 534 EXPECT_TRUE(!manager_.GetSurfaceForId(id2));
535 EXPECT_TRUE(!manager_.GetSurfaceForId(surface_id_)); 535 EXPECT_TRUE(!manager_.GetSurfaceForId(surface_id_));
536 536
537 surface_id_ = SurfaceId(); 537 surface_id_ = SurfaceId();
538 } 538 }
539 539
540 void CopyRequestTestCallback(bool* called, 540 void CopyRequestTestCallback(bool* called,
541 scoped_ptr<CopyOutputResult> result) { 541 std::unique_ptr<CopyOutputResult> result) {
542 *called = true; 542 *called = true;
543 } 543 }
544 544
545 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { 545 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) {
546 { 546 {
547 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); 547 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
548 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 548 std::unique_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
549 frame_data->render_pass_list.push_back(std::move(render_pass)); 549 frame_data->render_pass_list.push_back(std::move(render_pass));
550 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 550 std::unique_ptr<CompositorFrame> frame(new CompositorFrame);
551 frame->metadata.referenced_surfaces.push_back(surface_id_); 551 frame->metadata.referenced_surfaces.push_back(surface_id_);
552 frame->delegated_frame_data = std::move(frame_data); 552 frame->delegated_frame_data = std::move(frame_data);
553 factory_->SubmitCompositorFrame(surface_id_, std::move(frame), 553 factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
554 SurfaceFactory::DrawCallback()); 554 SurfaceFactory::DrawCallback());
555 } 555 }
556 void* source1 = &source1; 556 void* source1 = &source1;
557 void* source2 = &source2; 557 void* source2 = &source2;
558 558
559 bool called1 = false; 559 bool called1 = false;
560 scoped_ptr<CopyOutputRequest> request; 560 std::unique_ptr<CopyOutputRequest> request;
561 request = CopyOutputRequest::CreateRequest( 561 request = CopyOutputRequest::CreateRequest(
562 base::Bind(&CopyRequestTestCallback, &called1)); 562 base::Bind(&CopyRequestTestCallback, &called1));
563 request->set_source(source1); 563 request->set_source(source1);
564 564
565 factory_->RequestCopyOfSurface(surface_id_, std::move(request)); 565 factory_->RequestCopyOfSurface(surface_id_, std::move(request));
566 EXPECT_FALSE(called1); 566 EXPECT_FALSE(called1);
567 567
568 bool called2 = false; 568 bool called2 = false;
569 request = CopyOutputRequest::CreateRequest( 569 request = CopyOutputRequest::CreateRequest(
570 base::Bind(&CopyRequestTestCallback, &called2)); 570 base::Bind(&CopyRequestTestCallback, &called2));
(...skipping 17 matching lines...) Expand all
588 588
589 factory_->Destroy(surface_id_); 589 factory_->Destroy(surface_id_);
590 surface_id_ = SurfaceId(); 590 surface_id_ = SurfaceId();
591 EXPECT_TRUE(called1); 591 EXPECT_TRUE(called1);
592 EXPECT_TRUE(called2); 592 EXPECT_TRUE(called2);
593 EXPECT_TRUE(called3); 593 EXPECT_TRUE(called3);
594 } 594 }
595 595
596 } // namespace 596 } // namespace
597 } // namespace cc 597 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_factory.cc ('k') | cc/surfaces/surface_hittest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698