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