OLD | NEW |
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 "cc/resources/resource_util.h" | 7 #include "cc/resources/resource_util.h" |
8 #include "cc/resources/scoped_resource.h" | 8 #include "cc/resources/scoped_resource.h" |
9 #include "cc/test/fake_output_surface.h" | 9 #include "cc/test/fake_output_surface.h" |
10 #include "cc/test/fake_output_surface_client.h" | 10 #include "cc/test/fake_output_surface_client.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 EXPECT_EQ(resource_bytes, resource_pool_->acquired_memory_usage_bytes()); | 62 EXPECT_EQ(resource_bytes, resource_pool_->acquired_memory_usage_bytes()); |
63 EXPECT_EQ(1u, resource_pool_->total_resource_count()); | 63 EXPECT_EQ(1u, resource_pool_->total_resource_count()); |
64 EXPECT_EQ(1u, resource_pool_->acquired_resource_count()); | 64 EXPECT_EQ(1u, resource_pool_->acquired_resource_count()); |
65 EXPECT_EQ(0u, resource_pool_->busy_resource_count()); | 65 EXPECT_EQ(0u, resource_pool_->busy_resource_count()); |
66 | 66 |
67 resource_pool_->ReleaseResource(resource, 0u); | 67 resource_pool_->ReleaseResource(resource, 0u); |
68 EXPECT_EQ(resource_bytes, resource_pool_->total_memory_usage_bytes()); | 68 EXPECT_EQ(resource_bytes, resource_pool_->total_memory_usage_bytes()); |
69 EXPECT_EQ(1u, resource_pool_->total_resource_count()); | 69 EXPECT_EQ(1u, resource_pool_->total_resource_count()); |
70 EXPECT_EQ(1u, resource_pool_->busy_resource_count()); | 70 EXPECT_EQ(1u, resource_pool_->busy_resource_count()); |
71 | 71 |
72 resource_pool_->CheckBusyResources(); | 72 bool wait_if_needed = false; |
| 73 resource_pool_->CheckBusyResources(wait_if_needed); |
73 EXPECT_EQ(resource_bytes, resource_pool_->total_memory_usage_bytes()); | 74 EXPECT_EQ(resource_bytes, resource_pool_->total_memory_usage_bytes()); |
74 EXPECT_EQ(0u, resource_pool_->acquired_memory_usage_bytes()); | 75 EXPECT_EQ(0u, resource_pool_->acquired_memory_usage_bytes()); |
75 EXPECT_EQ(1u, resource_pool_->total_resource_count()); | 76 EXPECT_EQ(1u, resource_pool_->total_resource_count()); |
76 EXPECT_EQ(0u, resource_pool_->acquired_resource_count()); | 77 EXPECT_EQ(0u, resource_pool_->acquired_resource_count()); |
77 EXPECT_EQ(0u, resource_pool_->busy_resource_count()); | 78 EXPECT_EQ(0u, resource_pool_->busy_resource_count()); |
78 | 79 |
79 resource_pool_->SetResourceUsageLimits(0u, 0u, 0u); | 80 resource_pool_->SetResourceUsageLimits(0u, 0u, 0u); |
80 resource_pool_->ReduceResourceUsage(); | 81 resource_pool_->ReduceResourceUsage(); |
81 EXPECT_EQ(0u, resource_pool_->total_memory_usage_bytes()); | 82 EXPECT_EQ(0u, resource_pool_->total_memory_usage_bytes()); |
82 EXPECT_EQ(0u, resource_pool_->acquired_memory_usage_bytes()); | 83 EXPECT_EQ(0u, resource_pool_->acquired_memory_usage_bytes()); |
83 EXPECT_EQ(0u, resource_pool_->total_resource_count()); | 84 EXPECT_EQ(0u, resource_pool_->total_resource_count()); |
84 EXPECT_EQ(0u, resource_pool_->acquired_resource_count()); | 85 EXPECT_EQ(0u, resource_pool_->acquired_resource_count()); |
85 EXPECT_EQ(0u, resource_pool_->busy_resource_count()); | 86 EXPECT_EQ(0u, resource_pool_->busy_resource_count()); |
86 } | 87 } |
87 | 88 |
88 TEST_F(ResourcePoolTest, SimpleResourceReuse) { | 89 TEST_F(ResourcePoolTest, SimpleResourceReuse) { |
89 // Limits high enough to not be hit by this test. | 90 // Limits high enough to not be hit by this test. |
90 size_t bytes_limit = 10 * 1024 * 1024; | 91 size_t bytes_limit = 10 * 1024 * 1024; |
91 size_t count_limit = 100; | 92 size_t count_limit = 100; |
92 resource_pool_->SetResourceUsageLimits(bytes_limit, bytes_limit, count_limit); | 93 resource_pool_->SetResourceUsageLimits(bytes_limit, bytes_limit, count_limit); |
93 | 94 |
94 gfx::Size size(100, 100); | 95 gfx::Size size(100, 100); |
95 ResourceFormat format = RGBA_8888; | 96 ResourceFormat format = RGBA_8888; |
| 97 bool wait_if_needed = false; |
96 | 98 |
97 Resource* resource = resource_pool_->AcquireResource(size, format); | 99 Resource* resource = resource_pool_->AcquireResource(size, format); |
98 resource_pool_->ReleaseResource(resource, 0u); | 100 resource_pool_->ReleaseResource(resource, 0u); |
99 resource_pool_->CheckBusyResources(); | 101 resource_pool_->CheckBusyResources(wait_if_needed); |
100 EXPECT_EQ(1u, resource_provider_->num_resources()); | 102 EXPECT_EQ(1u, resource_provider_->num_resources()); |
101 | 103 |
102 // Same size/format should re-use resource. | 104 // Same size/format should re-use resource. |
103 resource = resource_pool_->AcquireResource(size, format); | 105 resource = resource_pool_->AcquireResource(size, format); |
104 EXPECT_EQ(1u, resource_provider_->num_resources()); | 106 EXPECT_EQ(1u, resource_provider_->num_resources()); |
105 resource_pool_->ReleaseResource(resource, 0u); | 107 resource_pool_->ReleaseResource(resource, 0u); |
106 resource_pool_->CheckBusyResources(); | 108 resource_pool_->CheckBusyResources(wait_if_needed); |
107 EXPECT_EQ(1u, resource_provider_->num_resources()); | 109 EXPECT_EQ(1u, resource_provider_->num_resources()); |
108 | 110 |
109 // Different size/format should alloate new resource. | 111 // Different size/format should alloate new resource. |
110 resource = resource_pool_->AcquireResource(gfx::Size(50, 50), LUMINANCE_8); | 112 resource = resource_pool_->AcquireResource(gfx::Size(50, 50), LUMINANCE_8); |
111 EXPECT_EQ(2u, resource_provider_->num_resources()); | 113 EXPECT_EQ(2u, resource_provider_->num_resources()); |
112 resource_pool_->ReleaseResource(resource, 0u); | 114 resource_pool_->ReleaseResource(resource, 0u); |
113 resource_pool_->CheckBusyResources(); | 115 resource_pool_->CheckBusyResources(wait_if_needed); |
114 EXPECT_EQ(2u, resource_provider_->num_resources()); | 116 EXPECT_EQ(2u, resource_provider_->num_resources()); |
115 } | 117 } |
116 | 118 |
117 TEST_F(ResourcePoolTest, LostResource) { | 119 TEST_F(ResourcePoolTest, LostResource) { |
118 // Limits high enough to not be hit by this test. | 120 // Limits high enough to not be hit by this test. |
119 size_t bytes_limit = 10 * 1024 * 1024; | 121 size_t bytes_limit = 10 * 1024 * 1024; |
120 size_t count_limit = 100; | 122 size_t count_limit = 100; |
121 resource_pool_->SetResourceUsageLimits(bytes_limit, bytes_limit, count_limit); | 123 resource_pool_->SetResourceUsageLimits(bytes_limit, bytes_limit, count_limit); |
122 | 124 |
123 gfx::Size size(100, 100); | 125 gfx::Size size(100, 100); |
124 ResourceFormat format = RGBA_8888; | 126 ResourceFormat format = RGBA_8888; |
| 127 bool wait_if_needed = false; |
125 | 128 |
126 Resource* resource = resource_pool_->AcquireResource(size, format); | 129 Resource* resource = resource_pool_->AcquireResource(size, format); |
127 EXPECT_EQ(1u, resource_provider_->num_resources()); | 130 EXPECT_EQ(1u, resource_provider_->num_resources()); |
128 | 131 |
129 resource_provider_->LoseResourceForTesting(resource->id()); | 132 resource_provider_->LoseResourceForTesting(resource->id()); |
130 resource_pool_->ReleaseResource(resource, 0u); | 133 resource_pool_->ReleaseResource(resource, 0u); |
131 resource_pool_->CheckBusyResources(); | 134 resource_pool_->CheckBusyResources(wait_if_needed); |
132 EXPECT_EQ(0u, resource_provider_->num_resources()); | 135 EXPECT_EQ(0u, resource_provider_->num_resources()); |
133 } | 136 } |
134 | 137 |
135 } // namespace | 138 } // namespace |
136 } // namespace cc | 139 } // namespace cc |
OLD | NEW |