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_command_buffer_stub.h" | 5 #include "content/common/gpu/gpu_command_buffer_stub.h" |
6 #include "content/common/gpu/gpu_memory_allocation.h" | 6 #include "content/common/gpu/gpu_memory_allocation.h" |
7 #include "content/common/gpu/gpu_memory_manager.h" | 7 #include "content/common/gpu/gpu_memory_manager.h" |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 class FakeCommandBufferStub : public GpuCommandBufferStubBase { | 11 class FakeCommandBufferStub : public GpuCommandBufferStubBase { |
12 public: | 12 public: |
13 SurfaceState surface_state_; | 13 SurfaceState surface_state_; |
14 GpuMemoryAllocation allocation_; | 14 GpuMemoryAllocation allocation_; |
15 | 15 |
16 FakeCommandBufferStub() | 16 FakeCommandBufferStub() |
17 : surface_state_(0, false, base::TimeTicks()) { | 17 : surface_state_(0, false, base::TimeTicks()) { |
18 } | 18 } |
19 | 19 |
20 FakeCommandBufferStub(int32 surface_id, | 20 FakeCommandBufferStub(int32 surface_id, |
21 bool visible, | 21 bool visible, |
22 base::TimeTicks last_used_time) | 22 base::TimeTicks last_used_time) |
23 : surface_state_(surface_id, visible, last_used_time) { | 23 : surface_state_(surface_id, visible, last_used_time) { |
24 } | 24 } |
25 | 25 |
26 virtual bool client_has_memory_allocation_changed_callback() const { | |
27 return true; | |
28 } | |
29 virtual bool has_surface_state() const { | 26 virtual bool has_surface_state() const { |
30 return surface_state_.surface_id != 0; | 27 return surface_state_.surface_id != 0; |
31 } | 28 } |
32 virtual const SurfaceState& surface_state() const { | 29 virtual const SurfaceState& surface_state() const { |
33 return surface_state_; | 30 return surface_state_; |
34 } | 31 } |
35 | 32 |
36 virtual bool IsInSameContextShareGroup( | 33 virtual bool IsInSameContextShareGroup( |
37 const GpuCommandBufferStubBase& stub) const { | 34 const GpuCommandBufferStubBase& stub) const { |
38 return false; | 35 return false; |
39 } | 36 } |
40 virtual void SendMemoryAllocationToProxy(const GpuMemoryAllocation& alloc) { | 37 virtual void SendMemoryAllocationToProxy(const GpuMemoryAllocation& alloc) { |
41 } | 38 } |
42 virtual void SetMemoryAllocation(const GpuMemoryAllocation& alloc) { | 39 virtual void SetMemoryAllocation(const GpuMemoryAllocation& alloc) { |
43 allocation_ = alloc; | 40 allocation_ = alloc; |
44 } | 41 } |
45 }; | 42 }; |
46 | 43 |
47 class FakeCommandBufferStubWithoutSurface : public GpuCommandBufferStubBase { | 44 class FakeCommandBufferStubWithoutSurface : public GpuCommandBufferStubBase { |
48 public: | 45 public: |
49 GpuMemoryAllocation allocation_; | 46 GpuMemoryAllocation allocation_; |
50 std::vector<GpuCommandBufferStubBase*> share_group_; | 47 std::vector<GpuCommandBufferStubBase*> share_group_; |
51 | 48 |
52 FakeCommandBufferStubWithoutSurface() { | 49 FakeCommandBufferStubWithoutSurface() { |
53 } | 50 } |
54 | 51 |
55 virtual bool client_has_memory_allocation_changed_callback() const { | |
56 return true; | |
57 } | |
58 virtual bool has_surface_state() const { | 52 virtual bool has_surface_state() const { |
59 return false; | 53 return false; |
60 } | 54 } |
61 virtual const SurfaceState& surface_state() const { | 55 virtual const SurfaceState& surface_state() const { |
62 NOTREACHED(); | 56 NOTREACHED(); |
63 static SurfaceState* surface_state_; | 57 static SurfaceState* surface_state_; |
64 return *surface_state_; | 58 return *surface_state_; |
65 } | 59 } |
66 | 60 |
67 virtual bool IsInSameContextShareGroup( | 61 virtual bool IsInSameContextShareGroup( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 older_ = base::TimeTicks::FromInternalValue(1); | 93 older_ = base::TimeTicks::FromInternalValue(1); |
100 newer_ = base::TimeTicks::FromInternalValue(2); | 94 newer_ = base::TimeTicks::FromInternalValue(2); |
101 newest_ = base::TimeTicks::FromInternalValue(3); | 95 newest_ = base::TimeTicks::FromInternalValue(3); |
102 } | 96 } |
103 | 97 |
104 static int32 GenerateUniqueSurfaceId() { | 98 static int32 GenerateUniqueSurfaceId() { |
105 static int32 surface_id_ = 1; | 99 static int32 surface_id_ = 1; |
106 return surface_id_++; | 100 return surface_id_++; |
107 } | 101 } |
108 | 102 |
109 static bool IsMoreImportant(GpuCommandBufferStubBase* lhs, | 103 static bool is_more_important(GpuCommandBufferStubBase* lhs, |
110 GpuCommandBufferStubBase* rhs) { | 104 GpuCommandBufferStubBase* rhs) { |
111 return GpuMemoryManager::StubWithSurfaceComparator()(lhs, rhs); | 105 return GpuMemoryManager::StubWithSurfaceComparator()(lhs, rhs); |
112 } | 106 } |
113 | 107 |
114 static bool IsAllocationForegroundForSurfaceYes( | |
115 const GpuMemoryAllocation& alloc) { | |
116 return alloc.suggest_have_frontbuffer && | |
117 alloc.suggest_have_backbuffer && | |
118 alloc.gpu_resource_size_in_bytes >= | |
119 GpuMemoryManager::kMinimumAllocationForTab; | |
120 } | |
121 static bool IsAllocationBackgroundForSurfaceYes( | |
122 const GpuMemoryAllocation& alloc) { | |
123 return alloc.suggest_have_frontbuffer && | |
124 !alloc.suggest_have_backbuffer && | |
125 alloc.gpu_resource_size_in_bytes == 0; | |
126 } | |
127 static bool IsAllocationHibernatedForSurfaceYes( | |
128 const GpuMemoryAllocation& alloc) { | |
129 return !alloc.suggest_have_frontbuffer && | |
130 !alloc.suggest_have_backbuffer && | |
131 alloc.gpu_resource_size_in_bytes == 0; | |
132 } | |
133 static bool IsAllocationForegroundForSurfaceNo( | |
134 const GpuMemoryAllocation& alloc) { | |
135 return !alloc.suggest_have_frontbuffer && | |
136 !alloc.suggest_have_backbuffer && | |
137 alloc.gpu_resource_size_in_bytes == | |
138 GpuMemoryManager::kMinimumAllocationForTab; | |
139 } | |
140 static bool IsAllocationBackgroundForSurfaceNo( | |
141 const GpuMemoryAllocation& alloc) { | |
142 return !alloc.suggest_have_frontbuffer && | |
143 !alloc.suggest_have_backbuffer && | |
144 alloc.gpu_resource_size_in_bytes == | |
145 GpuMemoryManager::kMinimumAllocationForTab; | |
146 } | |
147 static bool IsAllocationHibernatedForSurfaceNo( | |
148 const GpuMemoryAllocation& alloc) { | |
149 return !alloc.suggest_have_frontbuffer && | |
150 !alloc.suggest_have_backbuffer && | |
151 alloc.gpu_resource_size_in_bytes == 0; | |
152 } | |
153 | |
154 void Manage() { | 108 void Manage() { |
155 memory_manager_.Manage(); | 109 memory_manager_.Manage(); |
156 } | 110 } |
157 | 111 |
158 base::TimeTicks older_, newer_, newest_; | 112 base::TimeTicks older_, newer_, newest_; |
159 FakeClient client_; | 113 FakeClient client_; |
160 GpuMemoryManager memory_manager_; | 114 GpuMemoryManager memory_manager_; |
161 }; | 115 }; |
162 | 116 |
163 // Create fake stubs with every combination of {visibilty,last_use_time} | 117 // Create fake stubs with every combination of {visibilty,last_use_time} |
164 // and make sure they compare correctly. Only compare stubs with surfaces. | 118 // and make sure they compare correctly. Only compare stubs with surfaces. |
165 // Expect {more visible, newer} surfaces to be more important, in that order. | 119 // Expect {more visible, newer} surfaces to be more important, in that order. |
166 TEST_F(GpuMemoryManagerTest, ComparatorTests) { | 120 TEST_F(GpuMemoryManagerTest, ComparatorTests) { |
167 FakeCommandBufferStub stub_true1(GenerateUniqueSurfaceId(), true, older_), | 121 FakeCommandBufferStub stub_true1(GenerateUniqueSurfaceId(), true, older_), |
168 stub_true2(GenerateUniqueSurfaceId(), true, newer_), | 122 stub_true2(GenerateUniqueSurfaceId(), true, newer_), |
169 stub_true3(GenerateUniqueSurfaceId(), true, newest_), | 123 stub_true3(GenerateUniqueSurfaceId(), true, newest_), |
170 stub_false1(GenerateUniqueSurfaceId(), false, older_), | 124 stub_false1(GenerateUniqueSurfaceId(), false, older_), |
171 stub_false2(GenerateUniqueSurfaceId(), false, newer_), | 125 stub_false2(GenerateUniqueSurfaceId(), false, newer_), |
172 stub_false3(GenerateUniqueSurfaceId(), false, newest_); | 126 stub_false3(GenerateUniqueSurfaceId(), false, newest_); |
173 | 127 |
174 // Should never be more important than self: | 128 // Should never be more important than self: |
175 EXPECT_FALSE(IsMoreImportant(&stub_true1, &stub_true1)); | 129 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true1)); |
176 EXPECT_FALSE(IsMoreImportant(&stub_true2, &stub_true2)); | 130 EXPECT_FALSE(is_more_important(&stub_true2, &stub_true2)); |
177 EXPECT_FALSE(IsMoreImportant(&stub_true3, &stub_true3)); | 131 EXPECT_FALSE(is_more_important(&stub_true3, &stub_true3)); |
178 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_false1)); | 132 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false1)); |
179 EXPECT_FALSE(IsMoreImportant(&stub_false2, &stub_false2)); | 133 EXPECT_FALSE(is_more_important(&stub_false2, &stub_false2)); |
180 EXPECT_FALSE(IsMoreImportant(&stub_false3, &stub_false3)); | 134 EXPECT_FALSE(is_more_important(&stub_false3, &stub_false3)); |
181 | 135 |
182 // Visible should always be more important than non visible: | 136 // Visible should always be more important than non visible: |
183 EXPECT_TRUE(IsMoreImportant(&stub_true1, &stub_false1)); | 137 EXPECT_TRUE(is_more_important(&stub_true1, &stub_false1)); |
184 EXPECT_TRUE(IsMoreImportant(&stub_true1, &stub_false2)); | 138 EXPECT_TRUE(is_more_important(&stub_true1, &stub_false2)); |
185 EXPECT_TRUE(IsMoreImportant(&stub_true1, &stub_false3)); | 139 EXPECT_TRUE(is_more_important(&stub_true1, &stub_false3)); |
186 EXPECT_TRUE(IsMoreImportant(&stub_true2, &stub_false1)); | 140 EXPECT_TRUE(is_more_important(&stub_true2, &stub_false1)); |
187 EXPECT_TRUE(IsMoreImportant(&stub_true2, &stub_false2)); | 141 EXPECT_TRUE(is_more_important(&stub_true2, &stub_false2)); |
188 EXPECT_TRUE(IsMoreImportant(&stub_true2, &stub_false3)); | 142 EXPECT_TRUE(is_more_important(&stub_true2, &stub_false3)); |
189 EXPECT_TRUE(IsMoreImportant(&stub_true3, &stub_false1)); | 143 EXPECT_TRUE(is_more_important(&stub_true3, &stub_false1)); |
190 EXPECT_TRUE(IsMoreImportant(&stub_true3, &stub_false2)); | 144 EXPECT_TRUE(is_more_important(&stub_true3, &stub_false2)); |
191 EXPECT_TRUE(IsMoreImportant(&stub_true3, &stub_false3)); | 145 EXPECT_TRUE(is_more_important(&stub_true3, &stub_false3)); |
192 | 146 |
193 // Not visible should never be more important than visible: | 147 // Not visible should never be more important than visible: |
194 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_true1)); | 148 EXPECT_FALSE(is_more_important(&stub_false1, &stub_true1)); |
195 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_true2)); | 149 EXPECT_FALSE(is_more_important(&stub_false1, &stub_true2)); |
196 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_true3)); | 150 EXPECT_FALSE(is_more_important(&stub_false1, &stub_true3)); |
197 EXPECT_FALSE(IsMoreImportant(&stub_false2, &stub_true1)); | 151 EXPECT_FALSE(is_more_important(&stub_false2, &stub_true1)); |
198 EXPECT_FALSE(IsMoreImportant(&stub_false2, &stub_true2)); | 152 EXPECT_FALSE(is_more_important(&stub_false2, &stub_true2)); |
199 EXPECT_FALSE(IsMoreImportant(&stub_false2, &stub_true3)); | 153 EXPECT_FALSE(is_more_important(&stub_false2, &stub_true3)); |
200 EXPECT_FALSE(IsMoreImportant(&stub_false3, &stub_true1)); | 154 EXPECT_FALSE(is_more_important(&stub_false3, &stub_true1)); |
201 EXPECT_FALSE(IsMoreImportant(&stub_false3, &stub_true2)); | 155 EXPECT_FALSE(is_more_important(&stub_false3, &stub_true2)); |
202 EXPECT_FALSE(IsMoreImportant(&stub_false3, &stub_true3)); | 156 EXPECT_FALSE(is_more_important(&stub_false3, &stub_true3)); |
203 | 157 |
204 // Newer should always be more important than older: | 158 // Newer should always be more important than older: |
205 EXPECT_TRUE(IsMoreImportant(&stub_true2, &stub_true1)); | 159 EXPECT_TRUE(is_more_important(&stub_true2, &stub_true1)); |
206 EXPECT_TRUE(IsMoreImportant(&stub_true3, &stub_true1)); | 160 EXPECT_TRUE(is_more_important(&stub_true3, &stub_true1)); |
207 EXPECT_TRUE(IsMoreImportant(&stub_true3, &stub_true2)); | 161 EXPECT_TRUE(is_more_important(&stub_true3, &stub_true2)); |
208 EXPECT_TRUE(IsMoreImportant(&stub_false2, &stub_false1)); | 162 EXPECT_TRUE(is_more_important(&stub_false2, &stub_false1)); |
209 EXPECT_TRUE(IsMoreImportant(&stub_false3, &stub_false1)); | 163 EXPECT_TRUE(is_more_important(&stub_false3, &stub_false1)); |
210 EXPECT_TRUE(IsMoreImportant(&stub_false3, &stub_false2)); | 164 EXPECT_TRUE(is_more_important(&stub_false3, &stub_false2)); |
211 | 165 |
212 // Older should never be more important than newer: | 166 // Older should never be more important than newer: |
213 EXPECT_FALSE(IsMoreImportant(&stub_true1, &stub_true2)); | 167 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true2)); |
214 EXPECT_FALSE(IsMoreImportant(&stub_true1, &stub_true3)); | 168 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true3)); |
215 EXPECT_FALSE(IsMoreImportant(&stub_true2, &stub_true3)); | 169 EXPECT_FALSE(is_more_important(&stub_true2, &stub_true3)); |
216 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_false2)); | 170 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false2)); |
217 EXPECT_FALSE(IsMoreImportant(&stub_false1, &stub_false3)); | 171 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false3)); |
218 EXPECT_FALSE(IsMoreImportant(&stub_false2, &stub_false3)); | 172 EXPECT_FALSE(is_more_important(&stub_false2, &stub_false3)); |
219 } | 173 } |
220 | 174 |
221 // Test GpuMemoryManager::Manage basic functionality. | 175 // Test GpuMemoryManager::Manage basic functionality. |
222 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according | 176 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according |
223 // to visibility and last used time for stubs with surface. | 177 // to visibility and last used time for stubs with surface. |
224 // Expect memory allocation to be shared according to share groups for stubs | 178 // Expect memory allocation to be shared according to share groups for stubs |
225 // without a surface. | 179 // without a surface. |
226 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) { | 180 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) { |
227 // Test stubs with surface. | 181 // Test stubs with surface. |
228 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), | 182 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), |
229 stub2(GenerateUniqueSurfaceId(), false, older_); | 183 stub2(GenerateUniqueSurfaceId(), false, older_); |
230 client_.stubs_.push_back(&stub1); | 184 client_.stubs_.push_back(&stub1); |
231 client_.stubs_.push_back(&stub2); | 185 client_.stubs_.push_back(&stub2); |
232 | 186 |
233 Manage(); | 187 Manage(); |
234 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | 188 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
235 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 189 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); |
| 190 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
| 191 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
236 | 192 |
237 // Test stubs without surface, with share group of 1 stub. | 193 // Test stubs without surface, with share group of 1 stub. |
238 FakeCommandBufferStubWithoutSurface stub3, stub4; | 194 FakeCommandBufferStubWithoutSurface stub3, stub4; |
239 stub3.share_group_.push_back(&stub1); | 195 stub3.share_group_.push_back(&stub1); |
240 stub4.share_group_.push_back(&stub2); | 196 stub4.share_group_.push_back(&stub2); |
241 client_.stubs_.push_back(&stub3); | 197 client_.stubs_.push_back(&stub3); |
242 client_.stubs_.push_back(&stub4); | 198 client_.stubs_.push_back(&stub4); |
243 | 199 |
244 Manage(); | 200 Manage(); |
245 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | 201 EXPECT_EQ(stub1.allocation_, stub3.allocation_); |
246 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 202 EXPECT_EQ(stub2.allocation_, stub4.allocation_); |
247 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); | |
248 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); | |
249 | 203 |
250 // Test stub without surface, with share group of multiple stubs. | 204 // Test stub without surface, with share group of multiple stubs. |
251 FakeCommandBufferStubWithoutSurface stub5; | 205 FakeCommandBufferStubWithoutSurface stub5; |
252 stub5.share_group_.push_back(&stub1); | 206 stub5.share_group_.push_back(&stub1); |
253 stub5.share_group_.push_back(&stub2); | 207 stub5.share_group_.push_back(&stub2); |
254 client_.stubs_.push_back(&stub5); | 208 client_.stubs_.push_back(&stub5); |
255 | 209 |
256 Manage(); | 210 Manage(); |
257 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); | 211 EXPECT_EQ(stub1.allocation_, stub5.allocation_); |
258 } | 212 } |
259 | 213 |
260 // Test GpuMemoryManager::Manage functionality: changing visibility. | 214 // Test GpuMemoryManager::Manage functionality: changing visibility. |
261 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according | 215 // Expect memory allocation to set suggest_have_frontbuffer/backbuffer according |
262 // to visibility and last used time for stubs with surface. | 216 // to visibility and last used time for stubs with surface. |
263 // Expect memory allocation to be shared according to share groups for stubs | 217 // Expect memory allocation to be shared according to share groups for stubs |
264 // without a surface. | 218 // without a surface. |
265 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) { | 219 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) { |
266 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), | 220 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), |
267 stub2(GenerateUniqueSurfaceId(), false, older_); | 221 stub2(GenerateUniqueSurfaceId(), false, older_); |
268 client_.stubs_.push_back(&stub1); | 222 client_.stubs_.push_back(&stub1); |
269 client_.stubs_.push_back(&stub2); | 223 client_.stubs_.push_back(&stub2); |
270 | 224 |
271 FakeCommandBufferStubWithoutSurface stub3, stub4; | 225 FakeCommandBufferStubWithoutSurface stub3, stub4; |
272 stub3.share_group_.push_back(&stub1); | 226 stub3.share_group_.push_back(&stub1); |
273 stub4.share_group_.push_back(&stub2); | 227 stub4.share_group_.push_back(&stub2); |
274 client_.stubs_.push_back(&stub3); | 228 client_.stubs_.push_back(&stub3); |
275 client_.stubs_.push_back(&stub4); | 229 client_.stubs_.push_back(&stub4); |
276 | 230 |
277 FakeCommandBufferStubWithoutSurface stub5; | 231 FakeCommandBufferStubWithoutSurface stub5; |
278 stub5.share_group_.push_back(&stub1); | 232 stub5.share_group_.push_back(&stub1); |
279 stub5.share_group_.push_back(&stub2); | 233 stub5.share_group_.push_back(&stub2); |
280 client_.stubs_.push_back(&stub5); | 234 client_.stubs_.push_back(&stub5); |
281 | 235 |
282 Manage(); | 236 Manage(); |
283 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | 237 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
284 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 238 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); |
285 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); | 239 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
286 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); | 240 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
287 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); | 241 EXPECT_EQ(stub1.allocation_, stub3.allocation_); |
| 242 EXPECT_EQ(stub2.allocation_, stub4.allocation_); |
| 243 EXPECT_EQ(stub1.allocation_, stub5.allocation_); |
288 | 244 |
289 stub1.surface_state_.visible = false; | 245 stub1.surface_state_.visible = false; |
290 stub2.surface_state_.visible = true; | 246 stub2.surface_state_.visible = true; |
291 | 247 |
292 Manage(); | 248 Manage(); |
293 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | 249 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
294 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | 250 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
295 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); | 251 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
296 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); | 252 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); |
297 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); | 253 EXPECT_EQ(stub1.allocation_, stub3.allocation_); |
| 254 EXPECT_EQ(stub2.allocation_, stub4.allocation_); |
| 255 EXPECT_EQ(stub2.allocation_, stub5.allocation_); |
298 } | 256 } |
299 | 257 |
300 // Test GpuMemoryManager::Manage functionality: Test more than threshold number | 258 // Test GpuMemoryManager::Manage functionality: Test more than threshold number |
301 // of visible stubs. | 259 // of visible stubs. |
302 // Expect all allocations to continue to have frontbuffer. | 260 // Expect all allocations to continue to have frontbuffer. |
303 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) { | 261 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) { |
304 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), | 262 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), |
305 stub2(GenerateUniqueSurfaceId(), true, older_), | 263 stub2(GenerateUniqueSurfaceId(), true, older_), |
306 stub3(GenerateUniqueSurfaceId(), true, older_), | 264 stub3(GenerateUniqueSurfaceId(), true, older_), |
307 stub4(GenerateUniqueSurfaceId(), true, older_); | 265 stub4(GenerateUniqueSurfaceId(), true, older_); |
308 client_.stubs_.push_back(&stub1); | 266 client_.stubs_.push_back(&stub1); |
309 client_.stubs_.push_back(&stub2); | 267 client_.stubs_.push_back(&stub2); |
310 client_.stubs_.push_back(&stub3); | 268 client_.stubs_.push_back(&stub3); |
311 client_.stubs_.push_back(&stub4); | 269 client_.stubs_.push_back(&stub4); |
312 | 270 |
313 FakeCommandBufferStubWithoutSurface stub5, stub6; | 271 FakeCommandBufferStubWithoutSurface stub5, stub6; |
314 stub5.share_group_.push_back(&stub1); | 272 stub5.share_group_.push_back(&stub1); |
315 stub6.share_group_.push_back(&stub2); | 273 stub6.share_group_.push_back(&stub2); |
316 client_.stubs_.push_back(&stub5); | 274 client_.stubs_.push_back(&stub5); |
317 client_.stubs_.push_back(&stub6); | 275 client_.stubs_.push_back(&stub6); |
318 | 276 |
319 FakeCommandBufferStubWithoutSurface stub7; | 277 FakeCommandBufferStubWithoutSurface stub7; |
320 stub7.share_group_.push_back(&stub1); | 278 stub7.share_group_.push_back(&stub1); |
321 stub7.share_group_.push_back(&stub2); | 279 stub7.share_group_.push_back(&stub2); |
322 client_.stubs_.push_back(&stub7); | 280 client_.stubs_.push_back(&stub7); |
323 | 281 |
324 Manage(); | 282 Manage(); |
325 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | 283 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
326 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | 284 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); |
327 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub3.allocation_)); | 285 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
328 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub4.allocation_)); | 286 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); |
329 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_)); | 287 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); |
330 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub6.allocation_)); | 288 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, true); |
331 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub7.allocation_)); | 289 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, true); |
| 290 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, true); |
| 291 EXPECT_EQ(stub5.allocation_, stub1.allocation_); |
| 292 EXPECT_EQ(stub6.allocation_, stub2.allocation_); |
| 293 EXPECT_EQ(stub7.allocation_, stub1.allocation_); |
332 } | 294 } |
333 | 295 |
334 // Test GpuMemoryManager::Manage functionality: Test more than threshold number | 296 // Test GpuMemoryManager::Manage functionality: Test more than threshold number |
335 // of not visible stubs. | 297 // of not visible stubs. |
336 // Expect the stubs surpassing the threshold to not have a backbuffer. | 298 // Expect the stubs surpassing the threshold to not have a backbuffer. |
337 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) { | 299 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) { |
338 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), | 300 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), |
339 stub2(GenerateUniqueSurfaceId(), false, newer_), | 301 stub2(GenerateUniqueSurfaceId(), false, newer_), |
340 stub3(GenerateUniqueSurfaceId(), false, newer_), | 302 stub3(GenerateUniqueSurfaceId(), false, newer_), |
341 stub4(GenerateUniqueSurfaceId(), false, older_); | 303 stub4(GenerateUniqueSurfaceId(), false, older_); |
342 client_.stubs_.push_back(&stub1); | 304 client_.stubs_.push_back(&stub1); |
343 client_.stubs_.push_back(&stub2); | 305 client_.stubs_.push_back(&stub2); |
344 client_.stubs_.push_back(&stub3); | 306 client_.stubs_.push_back(&stub3); |
345 client_.stubs_.push_back(&stub4); | 307 client_.stubs_.push_back(&stub4); |
346 | 308 |
347 FakeCommandBufferStubWithoutSurface stub5, stub6; | 309 FakeCommandBufferStubWithoutSurface stub5, stub6; |
348 stub5.share_group_.push_back(&stub1); | 310 stub5.share_group_.push_back(&stub1); |
349 stub6.share_group_.push_back(&stub4); | 311 stub6.share_group_.push_back(&stub4); |
350 client_.stubs_.push_back(&stub5); | 312 client_.stubs_.push_back(&stub5); |
351 client_.stubs_.push_back(&stub6); | 313 client_.stubs_.push_back(&stub6); |
352 | 314 |
353 FakeCommandBufferStubWithoutSurface stub7; | 315 FakeCommandBufferStubWithoutSurface stub7; |
354 stub7.share_group_.push_back(&stub1); | 316 stub7.share_group_.push_back(&stub1); |
355 stub7.share_group_.push_back(&stub4); | 317 stub7.share_group_.push_back(&stub4); |
356 client_.stubs_.push_back(&stub7); | 318 client_.stubs_.push_back(&stub7); |
357 | 319 |
358 Manage(); | 320 Manage(); |
359 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | 321 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
360 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 322 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
361 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_)); | 323 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
362 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_)); | 324 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
363 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_)); | 325 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); |
364 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_)); | 326 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); |
365 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_)); | 327 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, false); |
| 328 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false); |
| 329 EXPECT_EQ(stub5.allocation_, stub1.allocation_); |
| 330 EXPECT_EQ(stub6.allocation_, stub4.allocation_); |
| 331 EXPECT_EQ(stub7.allocation_, stub1.allocation_); |
366 } | 332 } |
367 | 333 |
368 // Test GpuMemoryManager::Manage functionality: Test changing the last used | 334 // Test GpuMemoryManager::Manage functionality: Test changing the last used |
369 // time of stubs when doing so causes change in which stubs surpass threshold. | 335 // time of stubs when doing so causes change in which stubs surpass threshold. |
370 // Expect frontbuffer to be dropped for the older stub. | 336 // Expect frontbuffer to be dropped for the older stub. |
371 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) { | 337 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) { |
372 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), | 338 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_), |
373 stub2(GenerateUniqueSurfaceId(), false, newer_), | 339 stub2(GenerateUniqueSurfaceId(), false, newer_), |
374 stub3(GenerateUniqueSurfaceId(), false, newer_), | 340 stub3(GenerateUniqueSurfaceId(), false, newer_), |
375 stub4(GenerateUniqueSurfaceId(), false, older_); | 341 stub4(GenerateUniqueSurfaceId(), false, older_); |
376 client_.stubs_.push_back(&stub1); | 342 client_.stubs_.push_back(&stub1); |
377 client_.stubs_.push_back(&stub2); | 343 client_.stubs_.push_back(&stub2); |
378 client_.stubs_.push_back(&stub3); | 344 client_.stubs_.push_back(&stub3); |
379 client_.stubs_.push_back(&stub4); | 345 client_.stubs_.push_back(&stub4); |
380 | 346 |
381 FakeCommandBufferStubWithoutSurface stub5, stub6; | 347 FakeCommandBufferStubWithoutSurface stub5, stub6; |
382 stub5.share_group_.push_back(&stub3); | 348 stub5.share_group_.push_back(&stub3); |
383 stub6.share_group_.push_back(&stub4); | 349 stub6.share_group_.push_back(&stub4); |
384 client_.stubs_.push_back(&stub5); | 350 client_.stubs_.push_back(&stub5); |
385 client_.stubs_.push_back(&stub6); | 351 client_.stubs_.push_back(&stub6); |
386 | 352 |
387 FakeCommandBufferStubWithoutSurface stub7; | 353 FakeCommandBufferStubWithoutSurface stub7; |
388 stub7.share_group_.push_back(&stub3); | 354 stub7.share_group_.push_back(&stub3); |
389 stub7.share_group_.push_back(&stub4); | 355 stub7.share_group_.push_back(&stub4); |
390 client_.stubs_.push_back(&stub7); | 356 client_.stubs_.push_back(&stub7); |
391 | 357 |
392 Manage(); | 358 Manage(); |
393 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | 359 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, true); |
394 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 360 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); |
395 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_)); | 361 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, false); |
396 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_)); | 362 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false); |
397 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_)); | 363 EXPECT_EQ(stub5.allocation_, stub3.allocation_); |
398 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_)); | 364 EXPECT_EQ(stub6.allocation_, stub4.allocation_); |
399 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_)); | 365 EXPECT_EQ(stub7.allocation_, stub3.allocation_); |
400 | 366 |
401 stub3.surface_state_.last_used_time = older_; | 367 stub3.surface_state_.last_used_time = older_; |
402 stub4.surface_state_.last_used_time = newer_; | 368 stub4.surface_state_.last_used_time = newer_; |
403 | 369 |
404 Manage(); | 370 Manage(); |
405 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | 371 EXPECT_EQ(stub3.allocation_.suggest_have_frontbuffer, false); |
406 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 372 EXPECT_EQ(stub3.allocation_.suggest_have_backbuffer, false); |
407 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub3.allocation_)); | 373 EXPECT_EQ(stub4.allocation_.suggest_have_frontbuffer, true); |
408 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub4.allocation_)); | 374 EXPECT_EQ(stub4.allocation_.suggest_have_backbuffer, false); |
409 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub5.allocation_)); | 375 EXPECT_EQ(stub5.allocation_, stub3.allocation_); |
410 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub6.allocation_)); | 376 EXPECT_EQ(stub6.allocation_, stub4.allocation_); |
411 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_)); | 377 EXPECT_EQ(stub7.allocation_, stub4.allocation_); |
412 } | 378 } |
413 | 379 |
414 // Test GpuMemoryManager::Manage functionality: Test changing importance of | 380 // Test GpuMemoryManager::Manage functionality: Test changing importance of |
415 // enough stubs so that every stub in share group crosses threshold. | 381 // enough stubs so that every stub in share group crosses threshold. |
416 // Expect memory allocation of the stubs without surface to share memory | 382 // Expect memory allocation of the stubs without surface to share memory |
417 // allocation with the most visible stub in share group. | 383 // allocation with the most visible stub in share group. |
418 TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) { | 384 TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) { |
419 FakeCommandBufferStub stubIgnoreA(GenerateUniqueSurfaceId(), true, newer_), | 385 FakeCommandBufferStub stubA(GenerateUniqueSurfaceId(), true, newer_), |
420 stubIgnoreB(GenerateUniqueSurfaceId(), false, newer_), | 386 stubB(GenerateUniqueSurfaceId(), false, newer_), |
421 stubIgnoreC(GenerateUniqueSurfaceId(), false, newer_); | 387 stubC(GenerateUniqueSurfaceId(), false, newer_); |
422 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, newest_), | 388 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, newest_), |
423 stub2(GenerateUniqueSurfaceId(), true, newest_); | 389 stub2(GenerateUniqueSurfaceId(), true, newest_); |
424 client_.stubs_.push_back(&stubIgnoreA); | 390 client_.stubs_.push_back(&stubA); |
425 client_.stubs_.push_back(&stubIgnoreB); | 391 client_.stubs_.push_back(&stubB); |
426 client_.stubs_.push_back(&stubIgnoreC); | 392 client_.stubs_.push_back(&stubC); |
427 client_.stubs_.push_back(&stub1); | 393 client_.stubs_.push_back(&stub1); |
428 client_.stubs_.push_back(&stub2); | 394 client_.stubs_.push_back(&stub2); |
429 | 395 |
430 FakeCommandBufferStubWithoutSurface stub3, stub4; | 396 FakeCommandBufferStubWithoutSurface stub3, stub4; |
431 stub3.share_group_.push_back(&stub1); | 397 stub3.share_group_.push_back(&stub1); |
432 stub3.share_group_.push_back(&stub2); | 398 stub3.share_group_.push_back(&stub2); |
433 stub4.share_group_.push_back(&stub1); | 399 stub4.share_group_.push_back(&stub1); |
434 stub4.share_group_.push_back(&stub2); | 400 stub4.share_group_.push_back(&stub2); |
435 client_.stubs_.push_back(&stub3); | 401 client_.stubs_.push_back(&stub3); |
436 client_.stubs_.push_back(&stub4); | 402 client_.stubs_.push_back(&stub4); |
437 | 403 |
438 Manage(); | 404 Manage(); |
439 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | 405 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
440 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | 406 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, true); |
441 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_)); | 407 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
442 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); | 408 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); |
| 409 EXPECT_EQ(stub3.allocation_, stub1.allocation_); |
| 410 EXPECT_EQ(stub3.allocation_, stub2.allocation_); |
| 411 EXPECT_EQ(stub4.allocation_, stub1.allocation_); |
| 412 EXPECT_EQ(stub4.allocation_, stub2.allocation_); |
443 | 413 |
444 stub1.surface_state_.visible = false; | 414 stub1.surface_state_.visible = false; |
445 | 415 |
446 Manage(); | 416 Manage(); |
447 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | 417 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
448 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | 418 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
449 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); | 419 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
450 EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_)); | 420 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, true); |
| 421 EXPECT_NE(stub3.allocation_, stub1.allocation_); |
| 422 EXPECT_EQ(stub3.allocation_, stub2.allocation_); |
| 423 EXPECT_NE(stub4.allocation_, stub1.allocation_); |
| 424 EXPECT_EQ(stub4.allocation_, stub2.allocation_); |
451 | 425 |
452 stub2.surface_state_.visible = false; | 426 stub2.surface_state_.visible = false; |
453 | 427 |
454 Manage(); | 428 Manage(); |
455 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_)); | 429 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, true); |
456 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 430 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
457 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); | 431 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
458 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); | 432 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
| 433 EXPECT_EQ(stub3.allocation_, stub1.allocation_); |
| 434 EXPECT_EQ(stub3.allocation_, stub2.allocation_); |
| 435 EXPECT_EQ(stub4.allocation_, stub1.allocation_); |
| 436 EXPECT_EQ(stub4.allocation_, stub2.allocation_); |
459 | 437 |
460 stub1.surface_state_.last_used_time = older_; | 438 stub1.surface_state_.last_used_time = older_; |
461 | 439 |
462 Manage(); | 440 Manage(); |
463 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); | 441 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, false); |
464 EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_)); | 442 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
465 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_)); | 443 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, true); |
466 EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_)); | 444 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
| 445 EXPECT_NE(stub3.allocation_, stub1.allocation_); |
| 446 EXPECT_EQ(stub3.allocation_, stub2.allocation_); |
| 447 EXPECT_NE(stub4.allocation_, stub1.allocation_); |
| 448 EXPECT_EQ(stub4.allocation_, stub2.allocation_); |
467 | 449 |
468 stub2.surface_state_.last_used_time = older_; | 450 stub2.surface_state_.last_used_time = older_; |
469 | 451 |
470 Manage(); | 452 Manage(); |
471 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_)); | 453 EXPECT_EQ(stub1.allocation_.suggest_have_frontbuffer, false); |
472 EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_)); | 454 EXPECT_EQ(stub1.allocation_.suggest_have_backbuffer, false); |
473 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_)); | 455 EXPECT_EQ(stub2.allocation_.suggest_have_frontbuffer, false); |
474 EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_)); | 456 EXPECT_EQ(stub2.allocation_.suggest_have_backbuffer, false); |
475 } | 457 EXPECT_EQ(stub3.allocation_, stub1.allocation_); |
476 | 458 EXPECT_EQ(stub3.allocation_, stub2.allocation_); |
477 // Test GpuMemoryAllocation memory allocation bonuses: | 459 EXPECT_EQ(stub4.allocation_, stub1.allocation_); |
478 // When the number of visible tabs is small, each tab should get a | 460 EXPECT_EQ(stub4.allocation_, stub2.allocation_); |
479 // gpu_resource_size_in_bytes allocation value that is greater than | |
480 // kMinimumAllocationForTab, and when the number of tabs is large, each should | |
481 // get exactly kMinimumAllocationForTab and not less. | |
482 TEST_F(GpuMemoryManagerTest, TestForegroundStubsGetBonusAllocation) { | |
483 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_), | |
484 stub2(GenerateUniqueSurfaceId(), true, older_), | |
485 stub3(GenerateUniqueSurfaceId(), true, older_); | |
486 client_.stubs_.push_back(&stub1); | |
487 client_.stubs_.push_back(&stub2); | |
488 client_.stubs_.push_back(&stub3); | |
489 | |
490 Manage(); | |
491 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | |
492 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | |
493 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub3.allocation_)); | |
494 EXPECT_GT(stub1.allocation_.gpu_resource_size_in_bytes, | |
495 static_cast<size_t>(GpuMemoryManager::kMinimumAllocationForTab)); | |
496 EXPECT_GT(stub2.allocation_.gpu_resource_size_in_bytes, | |
497 static_cast<size_t>(GpuMemoryManager::kMinimumAllocationForTab)); | |
498 EXPECT_GT(stub3.allocation_.gpu_resource_size_in_bytes, | |
499 static_cast<size_t>(GpuMemoryManager::kMinimumAllocationForTab)); | |
500 | |
501 FakeCommandBufferStub stub4(GenerateUniqueSurfaceId(), true, older_), | |
502 stub5(GenerateUniqueSurfaceId(), true, older_), | |
503 stub6(GenerateUniqueSurfaceId(), true, older_), | |
504 stub7(GenerateUniqueSurfaceId(), true, older_), | |
505 stub8(GenerateUniqueSurfaceId(), true, older_), | |
506 stub9(GenerateUniqueSurfaceId(), true, older_); | |
507 client_.stubs_.push_back(&stub4); | |
508 client_.stubs_.push_back(&stub5); | |
509 client_.stubs_.push_back(&stub6); | |
510 client_.stubs_.push_back(&stub7); | |
511 client_.stubs_.push_back(&stub8); | |
512 client_.stubs_.push_back(&stub9); | |
513 | |
514 Manage(); | |
515 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_)); | |
516 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_)); | |
517 EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub3.allocation_)); | |
518 EXPECT_EQ(stub1.allocation_.gpu_resource_size_in_bytes, | |
519 GpuMemoryManager::kMinimumAllocationForTab); | |
520 EXPECT_EQ(stub2.allocation_.gpu_resource_size_in_bytes, | |
521 GpuMemoryManager::kMinimumAllocationForTab); | |
522 EXPECT_EQ(stub3.allocation_.gpu_resource_size_in_bytes, | |
523 GpuMemoryManager::kMinimumAllocationForTab); | |
524 } | 461 } |
525 | 462 |
526 // Test GpuMemoryAllocation comparison operators: Iterate over all possible | 463 // Test GpuMemoryAllocation comparison operators: Iterate over all possible |
527 // combinations of gpu_resource_size_in_bytes, suggest_have_backbuffer, and | 464 // combinations of gpu_resource_size_in_bytes, suggest_have_backbuffer, and |
528 // suggest_have_frontbuffer, and make sure allocations with equal values test | 465 // suggest_have_frontbuffer, and make sure allocations with equal values test |
529 // equal and non equal values test not equal. | 466 // equal and non equal values test not equal. |
530 TEST_F(GpuMemoryManagerTest, GpuMemoryAllocationCompareTests) { | 467 TEST_F(GpuMemoryManagerTest, GpuMemoryAllocationCompareTests) { |
531 std::vector<int> gpu_resource_size_in_bytes_values; | 468 int gpu_resource_size_in_bytes_values[] = { 0, 1, 12345678 }; |
532 gpu_resource_size_in_bytes_values.push_back(0); | 469 bool suggest_have_backbuffer_values[] = { false, true }; |
533 gpu_resource_size_in_bytes_values.push_back(1); | 470 bool suggest_have_frontbuffer_values[] = { false, true }; |
534 gpu_resource_size_in_bytes_values.push_back(12345678); | |
535 | 471 |
536 std::vector<int> suggested_buffer_allocation_values; | 472 for(int* sz = &gpu_resource_size_in_bytes_values[0]; |
537 suggested_buffer_allocation_values.push_back( | 473 sz != &gpu_resource_size_in_bytes_values[3]; ++sz) { |
538 GpuMemoryAllocation::kHasFrontbuffer | | 474 for(bool* shbb = &suggest_have_backbuffer_values[0]; |
539 GpuMemoryAllocation::kHasBackbuffer); | 475 shbb != &suggest_have_backbuffer_values[2]; ++shbb) { |
540 suggested_buffer_allocation_values.push_back( | 476 for(bool* shfb = &suggest_have_frontbuffer_values[0]; |
541 GpuMemoryAllocation::kHasFrontbuffer); | 477 shfb != &suggest_have_frontbuffer_values[2]; ++shfb) { |
542 suggested_buffer_allocation_values.push_back( | 478 GpuMemoryAllocation allocation(*sz, *shbb, *shfb); |
543 GpuMemoryAllocation::kHasBackbuffer); | 479 EXPECT_EQ(allocation, GpuMemoryAllocation(*sz, *shbb, *shfb)); |
544 suggested_buffer_allocation_values.push_back( | 480 EXPECT_NE(allocation, GpuMemoryAllocation(*sz+1, *shbb, *shfb)); |
545 GpuMemoryAllocation::kHasNoBuffers); | 481 EXPECT_NE(allocation, GpuMemoryAllocation(*sz, !*shbb, *shfb)); |
546 | 482 EXPECT_NE(allocation, GpuMemoryAllocation(*sz, *shbb, !*shfb)); |
547 for(size_t i = 0; i != gpu_resource_size_in_bytes_values.size(); ++i) { | |
548 for(size_t j = 0; j != suggested_buffer_allocation_values.size(); ++j) { | |
549 int sz = gpu_resource_size_in_bytes_values[i]; | |
550 int buffer_allocation = suggested_buffer_allocation_values[j]; | |
551 GpuMemoryAllocation allocation(sz, buffer_allocation); | |
552 | |
553 EXPECT_EQ(allocation, GpuMemoryAllocation(sz, buffer_allocation)); | |
554 EXPECT_NE(allocation, GpuMemoryAllocation(sz+1, buffer_allocation)); | |
555 | |
556 for(size_t k = 0; k != suggested_buffer_allocation_values.size(); ++k) { | |
557 int buffer_allocation_other = suggested_buffer_allocation_values[k]; | |
558 if (buffer_allocation == buffer_allocation_other) continue; | |
559 EXPECT_NE(allocation, GpuMemoryAllocation(sz, buffer_allocation_other)); | |
560 } | 483 } |
561 } | 484 } |
562 } | 485 } |
563 } | 486 } |
OLD | NEW |