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

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

Issue 2367953002: Implement OnMemoryStateChange for Various CC Classes (Closed)
Patch Set: feedback Created 4 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/resource_pool.cc ('k') | cc/tiles/gpu_image_decode_controller.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/resource_pool.h" 5 #include "cc/resources/resource_pool.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 gfx::Size size(100, 100); 328 gfx::Size size(100, 100);
329 Resource* resource = resource_pool_->ReuseResource(size, format, color_space); 329 Resource* resource = resource_pool_->ReuseResource(size, format, color_space);
330 EXPECT_EQ(nullptr, resource); 330 EXPECT_EQ(nullptr, resource);
331 size = gfx::Size(100, 99); 331 size = gfx::Size(100, 99);
332 resource = resource_pool_->ReuseResource(size, format, color_space); 332 resource = resource_pool_->ReuseResource(size, format, color_space);
333 EXPECT_NE(nullptr, resource); 333 EXPECT_NE(nullptr, resource);
334 ASSERT_EQ(nullptr, resource_pool_->ReuseResource(size, format, color_space)); 334 ASSERT_EQ(nullptr, resource_pool_->ReuseResource(size, format, color_space));
335 resource_pool_->ReleaseResource(resource); 335 resource_pool_->ReleaseResource(resource);
336 } 336 }
337 337
338 TEST_F(ResourcePoolTest, MemoryStateSuspended) {
339 // Limits high enough to not be hit by this test.
340 size_t bytes_limit = 10 * 1024 * 1024;
341 size_t count_limit = 100;
342 resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit);
343
344 gfx::Size size(100, 100);
345 ResourceFormat format = RGBA_8888;
346 gfx::ColorSpace color_space = gfx::ColorSpace::CreateSRGB();
347 Resource* resource =
348 resource_pool_->AcquireResource(size, format, color_space);
349
350 EXPECT_EQ(1u, resource_pool_->GetTotalResourceCountForTesting());
351 EXPECT_EQ(0u, resource_pool_->GetBusyResourceCountForTesting());
352
353 // Suspending should not impact an in-use resource.
354 resource_pool_->OnMemoryStateChange(base::MemoryState::SUSPENDED);
355 EXPECT_EQ(1u, resource_pool_->GetTotalResourceCountForTesting());
356 EXPECT_EQ(0u, resource_pool_->GetBusyResourceCountForTesting());
357 resource_pool_->OnMemoryStateChange(base::MemoryState::NORMAL);
358
359 // Release the resource making it busy.
360 resource_pool_->ReleaseResource(resource);
361 EXPECT_EQ(1u, resource_pool_->GetTotalResourceCountForTesting());
362 EXPECT_EQ(1u, resource_pool_->GetBusyResourceCountForTesting());
363
364 // Suspending should now free the busy resource.
365 resource_pool_->OnMemoryStateChange(base::MemoryState::SUSPENDED);
366 EXPECT_EQ(0u, resource_pool_->GetTotalResourceCountForTesting());
367 EXPECT_EQ(0u, resource_pool_->GetBusyResourceCountForTesting());
368 }
369
338 } // namespace cc 370 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_pool.cc ('k') | cc/tiles/gpu_image_decode_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698