OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/common/gpu/gpu_memory_manager.h" | 5 #include "content/common/gpu/gpu_memory_manager.h" |
6 #include "content/common/gpu/gpu_memory_manager_client.h" | 6 #include "content/common/gpu/gpu_memory_manager_client.h" |
7 #include "content/common/gpu/gpu_memory_tracking.h" | 7 #include "content/common/gpu/gpu_memory_tracking.h" |
8 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 8 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
9 #include "ui/gfx/size_conversions.h" | 9 #include "ui/gfx/size_conversions.h" |
10 | 10 |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 using gpu::MemoryAllocation; | 13 using gpu::MemoryAllocation; |
14 using gpu::ManagedMemoryStats; | |
15 | 14 |
16 #if defined(COMPILER_GCC) | 15 #if defined(COMPILER_GCC) |
17 namespace BASE_HASH_NAMESPACE { | 16 namespace BASE_HASH_NAMESPACE { |
18 template<> | 17 template<> |
19 struct hash<content::GpuMemoryManagerClient*> { | 18 struct hash<content::GpuMemoryManagerClient*> { |
20 uint64 operator()(content::GpuMemoryManagerClient* ptr) const { | 19 uint64 operator()(content::GpuMemoryManagerClient* ptr) const { |
21 return hash<uint64>()(reinterpret_cast<uint64>(ptr)); | 20 return hash<uint64>()(reinterpret_cast<uint64>(ptr)); |
22 } | 21 } |
23 }; | 22 }; |
24 } // namespace BASE_HASH_NAMESPACE | 23 } // namespace BASE_HASH_NAMESPACE |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 142 |
144 virtual gfx::Size GetSurfaceSize() const OVERRIDE { | 143 virtual gfx::Size GetSurfaceSize() const OVERRIDE { |
145 return surface_size_; | 144 return surface_size_; |
146 } | 145 } |
147 void SetSurfaceSize(gfx::Size size) { surface_size_ = size; } | 146 void SetSurfaceSize(gfx::Size size) { surface_size_ = size; } |
148 | 147 |
149 void SetVisible(bool visible) { | 148 void SetVisible(bool visible) { |
150 client_state_->SetVisible(visible); | 149 client_state_->SetVisible(visible); |
151 } | 150 } |
152 | 151 |
153 void SetManagedMemoryStats(const ManagedMemoryStats& stats) { | |
154 client_state_->SetManagedMemoryStats(stats); | |
155 } | |
156 | |
157 uint64 BytesWhenVisible() const { | 152 uint64 BytesWhenVisible() const { |
158 return allocation_.bytes_limit_when_visible; | 153 return allocation_.bytes_limit_when_visible; |
159 } | 154 } |
160 }; | 155 }; |
161 | 156 |
162 class GpuMemoryManagerTest : public testing::Test { | 157 class GpuMemoryManagerTest : public testing::Test { |
163 protected: | 158 protected: |
164 static const uint64 kFrontbufferLimitForTest = 3; | 159 static const uint64 kFrontbufferLimitForTest = 3; |
165 | 160 |
166 GpuMemoryManagerTest() | 161 GpuMemoryManagerTest() |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 bool IsAllocationHibernatedForSurfaceNo( | 194 bool IsAllocationHibernatedForSurfaceNo( |
200 const MemoryAllocation& alloc) { | 195 const MemoryAllocation& alloc) { |
201 return alloc.bytes_limit_when_visible == 0; | 196 return alloc.bytes_limit_when_visible == 0; |
202 } | 197 } |
203 | 198 |
204 void Manage() { | 199 void Manage() { |
205 ClientAssignmentCollector::ClearAllStats(); | 200 ClientAssignmentCollector::ClearAllStats(); |
206 memmgr_.Manage(); | 201 memmgr_.Manage(); |
207 } | 202 } |
208 | 203 |
209 void SetClientStats( | |
210 FakeClient* client, | |
211 uint64 required, | |
212 uint64 nicetohave) { | |
213 client->SetManagedMemoryStats( | |
214 ManagedMemoryStats(required, nicetohave, 0, false)); | |
215 } | |
216 | |
217 GpuMemoryManager memmgr_; | 204 GpuMemoryManager memmgr_; |
218 }; | 205 }; |
219 | 206 |
220 // Test GpuMemoryManager::Manage basic functionality. | 207 // Test GpuMemoryManager::Manage basic functionality. |
221 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer | 208 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer |
222 // according to visibility and last used time for stubs with surface. | 209 // according to visibility and last used time for stubs with surface. |
223 // Expect memory allocation to be shared according to share groups for stubs | 210 // Expect memory allocation to be shared according to share groups for stubs |
224 // without a surface. | 211 // without a surface. |
225 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) { | 212 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) { |
226 // Test stubs with surface. | 213 // Test stubs with surface. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 stub_ignore_c.SetVisible(true); | 410 stub_ignore_c.SetVisible(true); |
424 stub_ignore_c.SetVisible(false); | 411 stub_ignore_c.SetVisible(false); |
425 Manage(); | 412 Manage(); |
426 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); | 413 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); |
427 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); | 414 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); |
428 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); | 415 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); |
429 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); | 416 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); |
430 } | 417 } |
431 | 418 |
432 } // namespace content | 419 } // namespace content |
OLD | NEW |