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

Unified Diff: cc/resources/resource_pool_unittest.cc

Issue 1293873005: Expire resources in ResourcePool after non-use (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@re-use
Patch Set: Fix unit test Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/resources/resource_pool.cc ('k') | cc/test/fake_picture_layer_tiling_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/resource_pool_unittest.cc
diff --git a/cc/resources/resource_pool_unittest.cc b/cc/resources/resource_pool_unittest.cc
index f55c9b379be766af1fb253eae21a0761b3cccac3..bde9d748b7e9f72218312ed9aa494b668bd4192e 100644
--- a/cc/resources/resource_pool_unittest.cc
+++ b/cc/resources/resource_pool_unittest.cc
@@ -4,6 +4,8 @@
#include "cc/resources/resource_pool.h"
+#include "base/run_loop.h"
+#include "base/thread_task_runner_handle.h"
#include "cc/resources/resource_util.h"
#include "cc/resources/scoped_resource.h"
#include "cc/test/fake_output_surface.h"
@@ -23,8 +25,9 @@ class ResourcePoolTest : public testing::Test {
shared_bitmap_manager_.reset(new TestSharedBitmapManager());
resource_provider_ = FakeResourceProvider::Create(
output_surface_.get(), shared_bitmap_manager_.get());
- resource_pool_ =
- ResourcePool::Create(resource_provider_.get(), GL_TEXTURE_2D);
+ task_runner_ = base::ThreadTaskRunnerHandle::Get();
+ resource_pool_ = ResourcePool::Create(resource_provider_.get(),
+ task_runner_.get(), GL_TEXTURE_2D);
}
protected:
@@ -32,6 +35,7 @@ class ResourcePoolTest : public testing::Test {
scoped_ptr<FakeOutputSurface> output_surface_;
scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
scoped_ptr<ResourceProvider> resource_provider_;
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
scoped_ptr<ResourcePool> resource_pool_;
};
@@ -50,7 +54,7 @@ TEST_F(ResourcePoolTest, AccountingSingleResource) {
// Limits high enough to not be hit by this test.
size_t bytes_limit = 10 * 1024 * 1024;
size_t count_limit = 100;
- resource_pool_->SetResourceUsageLimits(bytes_limit, bytes_limit, count_limit);
+ resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit);
gfx::Size size(100, 100);
ResourceFormat format = RGBA_8888;
@@ -58,38 +62,38 @@ TEST_F(ResourcePoolTest, AccountingSingleResource) {
ResourceUtil::UncheckedSizeInBytes<size_t>(size, format);
Resource* resource = resource_pool_->AcquireResource(size, format);
- EXPECT_EQ(resource_bytes, resource_pool_->total_memory_usage_bytes());
- EXPECT_EQ(resource_bytes, resource_pool_->acquired_memory_usage_bytes());
- EXPECT_EQ(1u, resource_pool_->total_resource_count());
- EXPECT_EQ(1u, resource_pool_->acquired_resource_count());
- EXPECT_EQ(0u, resource_pool_->busy_resource_count());
+ EXPECT_EQ(resource_bytes, resource_pool_->GetTotalMemoryUsageForTesting());
+ EXPECT_EQ(resource_bytes, resource_pool_->memory_usage_bytes());
+ EXPECT_EQ(1u, resource_pool_->GetTotalResourceCountForTesting());
+ EXPECT_EQ(1u, resource_pool_->resource_count());
+ EXPECT_EQ(0u, resource_pool_->GetBusyResourceCountForTesting());
resource_pool_->ReleaseResource(resource, 0u);
- EXPECT_EQ(resource_bytes, resource_pool_->total_memory_usage_bytes());
- EXPECT_EQ(1u, resource_pool_->total_resource_count());
- EXPECT_EQ(1u, resource_pool_->busy_resource_count());
+ EXPECT_EQ(resource_bytes, resource_pool_->GetTotalMemoryUsageForTesting());
+ EXPECT_EQ(1u, resource_pool_->GetTotalResourceCountForTesting());
+ EXPECT_EQ(1u, resource_pool_->GetBusyResourceCountForTesting());
resource_pool_->CheckBusyResources();
- EXPECT_EQ(resource_bytes, resource_pool_->total_memory_usage_bytes());
- EXPECT_EQ(0u, resource_pool_->acquired_memory_usage_bytes());
- EXPECT_EQ(1u, resource_pool_->total_resource_count());
- EXPECT_EQ(0u, resource_pool_->acquired_resource_count());
- EXPECT_EQ(0u, resource_pool_->busy_resource_count());
+ EXPECT_EQ(resource_bytes, resource_pool_->GetTotalMemoryUsageForTesting());
+ EXPECT_EQ(0u, resource_pool_->memory_usage_bytes());
+ EXPECT_EQ(1u, resource_pool_->GetTotalResourceCountForTesting());
+ EXPECT_EQ(0u, resource_pool_->resource_count());
+ EXPECT_EQ(0u, resource_pool_->GetBusyResourceCountForTesting());
- resource_pool_->SetResourceUsageLimits(0u, 0u, 0u);
+ resource_pool_->SetResourceUsageLimits(0u, 0u);
resource_pool_->ReduceResourceUsage();
- EXPECT_EQ(0u, resource_pool_->total_memory_usage_bytes());
- EXPECT_EQ(0u, resource_pool_->acquired_memory_usage_bytes());
- EXPECT_EQ(0u, resource_pool_->total_resource_count());
- EXPECT_EQ(0u, resource_pool_->acquired_resource_count());
- EXPECT_EQ(0u, resource_pool_->busy_resource_count());
+ EXPECT_EQ(0u, resource_pool_->GetTotalMemoryUsageForTesting());
+ EXPECT_EQ(0u, resource_pool_->memory_usage_bytes());
+ EXPECT_EQ(0u, resource_pool_->GetTotalResourceCountForTesting());
+ EXPECT_EQ(0u, resource_pool_->resource_count());
+ EXPECT_EQ(0u, resource_pool_->GetBusyResourceCountForTesting());
}
TEST_F(ResourcePoolTest, SimpleResourceReuse) {
// Limits high enough to not be hit by this test.
size_t bytes_limit = 10 * 1024 * 1024;
size_t count_limit = 100;
- resource_pool_->SetResourceUsageLimits(bytes_limit, bytes_limit, count_limit);
+ resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit);
gfx::Size size(100, 100);
ResourceFormat format = RGBA_8888;
@@ -118,7 +122,7 @@ TEST_F(ResourcePoolTest, LostResource) {
// Limits high enough to not be hit by this test.
size_t bytes_limit = 10 * 1024 * 1024;
size_t count_limit = 100;
- resource_pool_->SetResourceUsageLimits(bytes_limit, bytes_limit, count_limit);
+ resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit);
gfx::Size size(100, 100);
ResourceFormat format = RGBA_8888;
@@ -132,5 +136,87 @@ TEST_F(ResourcePoolTest, LostResource) {
EXPECT_EQ(0u, resource_provider_->num_resources());
}
+TEST_F(ResourcePoolTest, BusyResourcesEventuallyFreed) {
+ // Limits high enough to not be hit by this test.
+ size_t bytes_limit = 10 * 1024 * 1024;
+ size_t count_limit = 100;
+ resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit);
+
+ // Set a quick resource expiration delay so that this test doesn't take long
+ // to run.
+ resource_pool_->SetResourceExpirationDelayForTesting(
+ base::TimeDelta::FromMilliseconds(10));
+
+ gfx::Size size(100, 100);
+ ResourceFormat format = RGBA_8888;
+
+ Resource* resource = resource_pool_->AcquireResource(size, format);
+ EXPECT_EQ(1u, resource_provider_->num_resources());
+ EXPECT_EQ(40000u, resource_pool_->GetTotalMemoryUsageForTesting());
+ EXPECT_EQ(1u, resource_pool_->resource_count());
+
+ resource_pool_->ReleaseResource(resource, 0u);
+ EXPECT_EQ(1u, resource_provider_->num_resources());
+ EXPECT_EQ(40000u, resource_pool_->GetTotalMemoryUsageForTesting());
+ EXPECT_EQ(0u, resource_pool_->memory_usage_bytes());
+ EXPECT_EQ(1u, resource_pool_->GetBusyResourceCountForTesting());
+
+ // Wait for our resource pool to evict resources. We expect resources to be
+ // released within 10 ms, give the thread up to 200.
+ base::RunLoop run_loop;
+ task_runner_->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(),
+ base::TimeDelta::FromMillisecondsD(200));
+ run_loop.Run();
+
+ EXPECT_EQ(0u, resource_provider_->num_resources());
+ EXPECT_EQ(0u, resource_pool_->GetTotalMemoryUsageForTesting());
+ EXPECT_EQ(0u, resource_pool_->memory_usage_bytes());
+}
+
+TEST_F(ResourcePoolTest, UnusedResourcesEventuallyFreed) {
+ // Limits high enough to not be hit by this test.
+ size_t bytes_limit = 10 * 1024 * 1024;
+ size_t count_limit = 100;
+ resource_pool_->SetResourceUsageLimits(bytes_limit, count_limit);
+
+ // Set a quick resource expiration delay so that this test doesn't take long
+ // to run.
+ resource_pool_->SetResourceExpirationDelayForTesting(
+ base::TimeDelta::FromMilliseconds(100));
+
+ gfx::Size size(100, 100);
+ ResourceFormat format = RGBA_8888;
+
+ Resource* resource = resource_pool_->AcquireResource(size, format);
+ EXPECT_EQ(1u, resource_provider_->num_resources());
+ EXPECT_EQ(40000u, resource_pool_->GetTotalMemoryUsageForTesting());
+ EXPECT_EQ(1u, resource_pool_->GetTotalResourceCountForTesting());
+ EXPECT_EQ(1u, resource_pool_->resource_count());
+
+ resource_pool_->ReleaseResource(resource, 0u);
+ EXPECT_EQ(1u, resource_provider_->num_resources());
+ EXPECT_EQ(40000u, resource_pool_->GetTotalMemoryUsageForTesting());
+ EXPECT_EQ(1u, resource_pool_->GetTotalResourceCountForTesting());
+ EXPECT_EQ(1u, resource_pool_->GetBusyResourceCountForTesting());
+
+ // Transfer the resource from the busy pool to the unused pool.
+ resource_pool_->CheckBusyResources();
+ EXPECT_EQ(1u, resource_provider_->num_resources());
+ EXPECT_EQ(40000u, resource_pool_->GetTotalMemoryUsageForTesting());
+ EXPECT_EQ(1u, resource_pool_->GetTotalResourceCountForTesting());
+ EXPECT_EQ(0u, resource_pool_->resource_count());
+ EXPECT_EQ(0u, resource_pool_->GetBusyResourceCountForTesting());
+
+ // Wait for our resource pool to evict resources. We expect resources to be
+ // released within 100 ms, give the thread up to 200.
+ base::RunLoop run_loop;
+ task_runner_->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(),
+ base::TimeDelta::FromMillisecondsD(200));
+ run_loop.Run();
+
+ EXPECT_EQ(0u, resource_provider_->num_resources());
+ EXPECT_EQ(0u, resource_pool_->GetTotalMemoryUsageForTesting());
+}
+
} // namespace
} // namespace cc
« no previous file with comments | « cc/resources/resource_pool.cc ('k') | cc/test/fake_picture_layer_tiling_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698