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

Side by Side Diff: cc/resources/prioritized_resource_unittest.cc

Issue 609663003: cc: Remove use of PassAs() and constructor-casting with scoped_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cc-passas: PassAs-presubmit-warning Created 6 years, 2 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/resources/picture.cc ('k') | cc/resources/raster_worker_pool_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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/resources/prioritized_resource.h" 5 #include "cc/resources/prioritized_resource.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "cc/resources/prioritized_resource_manager.h" 9 #include "cc/resources/prioritized_resource_manager.h"
10 #include "cc/resources/resource.h" 10 #include "cc/resources/resource.h"
(...skipping 21 matching lines...) Expand all
32 shared_bitmap_manager_.get(), 32 shared_bitmap_manager_.get(),
33 NULL, 33 NULL,
34 0, 34 0,
35 false, 35 false,
36 1, 36 1,
37 false); 37 false);
38 } 38 }
39 39
40 virtual ~PrioritizedResourceTest() { 40 virtual ~PrioritizedResourceTest() {
41 DebugScopedSetImplThread impl_thread(&proxy_); 41 DebugScopedSetImplThread impl_thread(&proxy_);
42 resource_provider_.reset(); 42 resource_provider_ = nullptr;
43 } 43 }
44 44
45 size_t TexturesMemorySize(size_t texture_count) { 45 size_t TexturesMemorySize(size_t texture_count) {
46 return Resource::MemorySizeBytes(texture_size_, texture_format_) * 46 return Resource::MemorySizeBytes(texture_size_, texture_format_) *
47 texture_count; 47 texture_count;
48 } 48 }
49 49
50 scoped_ptr<PrioritizedResourceManager> CreateManager(size_t max_textures) { 50 scoped_ptr<PrioritizedResourceManager> CreateManager(size_t max_textures) {
51 scoped_ptr<PrioritizedResourceManager> manager = 51 scoped_ptr<PrioritizedResourceManager> manager =
52 PrioritizedResourceManager::Create(&proxy_); 52 PrioritizedResourceManager::Create(&proxy_);
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 { 270 {
271 DebugScopedSetImplThreadAndMainThreadBlocked 271 DebugScopedSetImplThreadAndMainThreadBlocked
272 impl_thread_and_main_thread_blocked(&proxy_); 272 impl_thread_and_main_thread_blocked(&proxy_);
273 resource_manager->ReduceMemory(resource_provider()); 273 resource_manager->ReduceMemory(resource_provider());
274 } 274 }
275 275
276 // 20 textures have backings allocated. 276 // 20 textures have backings allocated.
277 EXPECT_EQ(TexturesMemorySize(20), resource_manager->MemoryUseBytes()); 277 EXPECT_EQ(TexturesMemorySize(20), resource_manager->MemoryUseBytes());
278 278
279 // Destroy one texture, not enough is wasted to cause cleanup. 279 // Destroy one texture, not enough is wasted to cause cleanup.
280 textures[0] = scoped_ptr<PrioritizedResource>(); 280 textures[0] = nullptr;
281 PrioritizeTexturesAndBackings(resource_manager.get()); 281 PrioritizeTexturesAndBackings(resource_manager.get());
282 { 282 {
283 DebugScopedSetImplThreadAndMainThreadBlocked 283 DebugScopedSetImplThreadAndMainThreadBlocked
284 impl_thread_and_main_thread_blocked(&proxy_); 284 impl_thread_and_main_thread_blocked(&proxy_);
285 resource_manager->UpdateBackingsState(resource_provider()); 285 resource_manager->UpdateBackingsState(resource_provider());
286 resource_manager->ReduceWastedMemory(resource_provider()); 286 resource_manager->ReduceWastedMemory(resource_provider());
287 } 287 }
288 EXPECT_EQ(TexturesMemorySize(20), resource_manager->MemoryUseBytes()); 288 EXPECT_EQ(TexturesMemorySize(20), resource_manager->MemoryUseBytes());
289 289
290 // Destroy half the textures, leaving behind the backings. Now a cleanup 290 // Destroy half the textures, leaving behind the backings. Now a cleanup
291 // should happen. 291 // should happen.
292 for (size_t i = 0; i < kMaxTextures / 2; ++i) 292 for (size_t i = 0; i < kMaxTextures / 2; ++i)
293 textures[i] = scoped_ptr<PrioritizedResource>(); 293 textures[i] = nullptr;
294 PrioritizeTexturesAndBackings(resource_manager.get()); 294 PrioritizeTexturesAndBackings(resource_manager.get());
295 { 295 {
296 DebugScopedSetImplThreadAndMainThreadBlocked 296 DebugScopedSetImplThreadAndMainThreadBlocked
297 impl_thread_and_main_thread_blocked(&proxy_); 297 impl_thread_and_main_thread_blocked(&proxy_);
298 resource_manager->UpdateBackingsState(resource_provider()); 298 resource_manager->UpdateBackingsState(resource_provider());
299 resource_manager->ReduceWastedMemory(resource_provider()); 299 resource_manager->ReduceWastedMemory(resource_provider());
300 } 300 }
301 EXPECT_GT(TexturesMemorySize(20), resource_manager->MemoryUseBytes()); 301 EXPECT_GT(TexturesMemorySize(20), resource_manager->MemoryUseBytes());
302 302
303 DebugScopedSetImplThreadAndMainThreadBlocked 303 DebugScopedSetImplThreadAndMainThreadBlocked
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 ResourceProvider::ResourceIdArray to_send; 350 ResourceProvider::ResourceIdArray to_send;
351 TransferableResourceArray transferable; 351 TransferableResourceArray transferable;
352 for (size_t i = 0; i < kMaxTextures / 2; ++i) 352 for (size_t i = 0; i < kMaxTextures / 2; ++i)
353 to_send.push_back(textures[i]->resource_id()); 353 to_send.push_back(textures[i]->resource_id());
354 resource_provider_->PrepareSendToParent(to_send, &transferable); 354 resource_provider_->PrepareSendToParent(to_send, &transferable);
355 355
356 // Destroy half the textures, leaving behind the backings. The backings are 356 // Destroy half the textures, leaving behind the backings. The backings are
357 // sent to a parent compositor though, so they should not be considered wasted 357 // sent to a parent compositor though, so they should not be considered wasted
358 // and a cleanup should not happen. 358 // and a cleanup should not happen.
359 for (size_t i = 0; i < kMaxTextures / 2; ++i) 359 for (size_t i = 0; i < kMaxTextures / 2; ++i)
360 textures[i] = scoped_ptr<PrioritizedResource>(); 360 textures[i] = nullptr;
361 PrioritizeTexturesAndBackings(resource_manager.get()); 361 PrioritizeTexturesAndBackings(resource_manager.get());
362 { 362 {
363 DebugScopedSetImplThreadAndMainThreadBlocked 363 DebugScopedSetImplThreadAndMainThreadBlocked
364 impl_thread_and_main_thread_blocked(&proxy_); 364 impl_thread_and_main_thread_blocked(&proxy_);
365 resource_manager->UpdateBackingsState(resource_provider()); 365 resource_manager->UpdateBackingsState(resource_provider());
366 resource_manager->ReduceWastedMemory(resource_provider()); 366 resource_manager->ReduceWastedMemory(resource_provider());
367 } 367 }
368 EXPECT_EQ(TexturesMemorySize(20), resource_manager->MemoryUseBytes()); 368 EXPECT_EQ(TexturesMemorySize(20), resource_manager->MemoryUseBytes());
369 369
370 // Receive the textures back from the parent compositor. Now a cleanup should 370 // Receive the textures back from the parent compositor. Now a cleanup should
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 textures[4]->set_request_priority(100 + 4); 558 textures[4]->set_request_priority(100 + 4);
559 textures[5]->set_request_priority(100 + 5); 559 textures[5]->set_request_priority(100 + 5);
560 textures[6]->set_request_priority(100 + 4); 560 textures[6]->set_request_priority(100 + 4);
561 textures[7]->set_request_priority(100 + 5); 561 textures[7]->set_request_priority(100 + 5);
562 562
563 for (size_t i = 0; i < 8; ++i) 563 for (size_t i = 0; i < 8; ++i)
564 texture_resource_ids[i] = textures[i]->resource_id(); 564 texture_resource_ids[i] = textures[i]->resource_id();
565 565
566 // Drop all the textures. Now we have backings that can be recycled. 566 // Drop all the textures. Now we have backings that can be recycled.
567 for (size_t i = 0; i < 8; ++i) 567 for (size_t i = 0; i < 8; ++i)
568 textures[0].reset(); 568 textures[0] = nullptr;
569 PrioritizeTexturesAndBackings(resource_manager.get()); 569 PrioritizeTexturesAndBackings(resource_manager.get());
570 570
571 // The next commit finishes. 571 // The next commit finishes.
572 { 572 {
573 DebugScopedSetImplThreadAndMainThreadBlocked 573 DebugScopedSetImplThreadAndMainThreadBlocked
574 impl_thread_and_main_thread_blocked(&proxy_); 574 impl_thread_and_main_thread_blocked(&proxy_);
575 resource_manager->UpdateBackingsState(resource_provider()); 575 resource_manager->UpdateBackingsState(resource_provider());
576 } 576 }
577 577
578 // Evict four textures. It would be the last four again, except that 2 of them 578 // Evict four textures. It would be the last four again, except that 2 of them
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 PrioritizeTexturesAndBackings(resource_manager.get()); 721 PrioritizeTexturesAndBackings(resource_manager.get());
722 722
723 EXPECT_TRUE(ValidateTexture(texture.get(), false)); 723 EXPECT_TRUE(ValidateTexture(texture.get(), false));
724 EXPECT_TRUE(texture->can_acquire_backing_texture()); 724 EXPECT_TRUE(texture->can_acquire_backing_texture());
725 EXPECT_TRUE(texture->have_backing_texture()); 725 EXPECT_TRUE(texture->have_backing_texture());
726 { 726 {
727 DebugScopedSetImplThreadAndMainThreadBlocked 727 DebugScopedSetImplThreadAndMainThreadBlocked
728 impl_thread_and_main_thread_blocked(&proxy_); 728 impl_thread_and_main_thread_blocked(&proxy_);
729 resource_manager->ClearAllMemory(resource_provider()); 729 resource_manager->ClearAllMemory(resource_provider());
730 } 730 }
731 resource_manager.reset(); 731 resource_manager = nullptr;
732 732
733 EXPECT_FALSE(texture->can_acquire_backing_texture()); 733 EXPECT_FALSE(texture->can_acquire_backing_texture());
734 EXPECT_FALSE(texture->have_backing_texture()); 734 EXPECT_FALSE(texture->have_backing_texture());
735 } 735 }
736 736
737 TEST_F(PrioritizedResourceTest, TextureMovedToNewManager) { 737 TEST_F(PrioritizedResourceTest, TextureMovedToNewManager) {
738 scoped_ptr<PrioritizedResourceManager> resource_manager_one = 738 scoped_ptr<PrioritizedResourceManager> resource_manager_one =
739 CreateManager(1); 739 CreateManager(1);
740 scoped_ptr<PrioritizedResourceManager> resource_manager_two = 740 scoped_ptr<PrioritizedResourceManager> resource_manager_two =
741 CreateManager(1); 741 CreateManager(1);
742 scoped_ptr<PrioritizedResource> texture = 742 scoped_ptr<PrioritizedResource> texture =
743 resource_manager_one->CreateTexture(texture_size_, texture_format_); 743 resource_manager_one->CreateTexture(texture_size_, texture_format_);
744 744
745 // Texture is initially invalid, but it will become available. 745 // Texture is initially invalid, but it will become available.
746 EXPECT_FALSE(texture->have_backing_texture()); 746 EXPECT_FALSE(texture->have_backing_texture());
747 747
748 texture->set_request_priority(100); 748 texture->set_request_priority(100);
749 PrioritizeTexturesAndBackings(resource_manager_one.get()); 749 PrioritizeTexturesAndBackings(resource_manager_one.get());
750 750
751 EXPECT_TRUE(ValidateTexture(texture.get(), false)); 751 EXPECT_TRUE(ValidateTexture(texture.get(), false));
752 EXPECT_TRUE(texture->can_acquire_backing_texture()); 752 EXPECT_TRUE(texture->can_acquire_backing_texture());
753 EXPECT_TRUE(texture->have_backing_texture()); 753 EXPECT_TRUE(texture->have_backing_texture());
754 754
755 texture->SetTextureManager(NULL); 755 texture->SetTextureManager(NULL);
756 { 756 {
757 DebugScopedSetImplThreadAndMainThreadBlocked 757 DebugScopedSetImplThreadAndMainThreadBlocked
758 impl_thread_and_main_thread_blocked(&proxy_); 758 impl_thread_and_main_thread_blocked(&proxy_);
759 resource_manager_one->ClearAllMemory(resource_provider()); 759 resource_manager_one->ClearAllMemory(resource_provider());
760 } 760 }
761 resource_manager_one.reset(); 761 resource_manager_one = nullptr;
762 762
763 EXPECT_FALSE(texture->can_acquire_backing_texture()); 763 EXPECT_FALSE(texture->can_acquire_backing_texture());
764 EXPECT_FALSE(texture->have_backing_texture()); 764 EXPECT_FALSE(texture->have_backing_texture());
765 765
766 texture->SetTextureManager(resource_manager_two.get()); 766 texture->SetTextureManager(resource_manager_two.get());
767 767
768 PrioritizeTexturesAndBackings(resource_manager_two.get()); 768 PrioritizeTexturesAndBackings(resource_manager_two.get());
769 769
770 EXPECT_TRUE(ValidateTexture(texture.get(), false)); 770 EXPECT_TRUE(ValidateTexture(texture.get(), false));
771 EXPECT_TRUE(texture->can_acquire_backing_texture()); 771 EXPECT_TRUE(texture->can_acquire_backing_texture());
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 resource_manager->MemoryVisibleAndNearbyBytes()); 1108 resource_manager->MemoryVisibleAndNearbyBytes());
1109 } 1109 }
1110 1110
1111 DebugScopedSetImplThreadAndMainThreadBlocked 1111 DebugScopedSetImplThreadAndMainThreadBlocked
1112 impl_thread_and_main_thread_blocked(&proxy_); 1112 impl_thread_and_main_thread_blocked(&proxy_);
1113 resource_manager->ClearAllMemory(resource_provider()); 1113 resource_manager->ClearAllMemory(resource_provider());
1114 } 1114 }
1115 1115
1116 } // namespace 1116 } // namespace
1117 } // namespace cc 1117 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture.cc ('k') | cc/resources/raster_worker_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698