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

Side by Side Diff: content/common/gpu/gpu_memory_manager_unittest.cc

Issue 9289052: Adding GpuMemoryManager to track GpuCommandBufferStub visibility and last_used_time and dictate mem… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 8 years, 10 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 unified diff | Download patch
« no previous file with comments | « content/common/gpu/gpu_memory_manager.cc ('k') | content/content_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/common/gpu/gpu_command_buffer_stub.h"
6 #include "content/common/gpu/gpu_memory_allocation.h"
7 #include "content/common/gpu/gpu_memory_manager.h"
8
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 class FakeCommandBufferStub : public GpuCommandBufferStubBase {
12 public:
13 SurfaceState surface_state_;
14 GpuMemoryAllocation allocation_;
15
16 FakeCommandBufferStub()
17 : surface_state_(0, false, base::TimeTicks()) {
18 }
19
20 FakeCommandBufferStub(int32 surface_id,
21 bool visible,
22 base::TimeTicks last_used_time)
23 : surface_state_(surface_id, visible, last_used_time) {
24 }
25
26 virtual bool has_surface_state() { return surface_state_.surface_id != 0; }
27 virtual const SurfaceState& surface_state() { return surface_state_; }
28 virtual void SendMemoryAllocationToProxy(const GpuMemoryAllocation& alloc) {
29 allocation_ = alloc;
30 }
31 };
32
33 class FakeClient : public GpuMemoryManagerClient {
34 public:
35 std::vector<GpuCommandBufferStubBase*> stubs_;
36
37 virtual void AppendAllCommandBufferStubs(
38 std::vector<GpuCommandBufferStubBase*>& stubs) {
39 stubs.insert(stubs.end(), stubs_.begin(), stubs_.end());
40 }
41 };
42
43 class GpuMemoryManagerTest : public testing::Test {
44 protected:
45 static const size_t kFrontbufferLimitForTest = 3;
46
47 GpuMemoryManagerTest()
48 : memory_manager_(&client_, kFrontbufferLimitForTest) {
49 }
50
51 virtual void SetUp() {
52 older_ = base::TimeTicks::FromInternalValue(1);
53 newer_ = base::TimeTicks::FromInternalValue(2);
54 newest_ = base::TimeTicks::FromInternalValue(3);
55 }
56
57 static int32 GenerateUniqueSurfaceId() {
58 static int32 surface_id_ = 1;
59 return surface_id_++;
60 }
61
62 static bool is_more_important(GpuCommandBufferStubBase* lhs,
63 GpuCommandBufferStubBase* rhs) {
64 return GpuMemoryManager::StubWithSurfaceComparator()(lhs, rhs);
65 }
66
67 void Manage() {
68 memory_manager_.Manage();
69 }
70
71 base::TimeTicks older_, newer_, newest_;
72 FakeClient client_;
73 GpuMemoryManager memory_manager_;
74 };
75
76
77 // Create fake stubs with every combination of {visibilty,last_use_time}
78 // and make sure they compare correctly. Only compare stubs with surfaces.
79 // Expect {more visible, newer} surfaces to be more important, in that order.
80 TEST_F(GpuMemoryManagerTest, ComparatorTests) {
81 FakeCommandBufferStub stub_true1(GenerateUniqueSurfaceId(), true, older_),
82 stub_true2(GenerateUniqueSurfaceId(), true, newer_),
83 stub_true3(GenerateUniqueSurfaceId(), true, newest_),
84 stub_false1(GenerateUniqueSurfaceId(), false, older_),
85 stub_false2(GenerateUniqueSurfaceId(), false, newer_),
86 stub_false3(GenerateUniqueSurfaceId(), false, newest_);
87
88 // Should never be more important than self:
89 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true1));
90 EXPECT_FALSE(is_more_important(&stub_true2, &stub_true2));
91 EXPECT_FALSE(is_more_important(&stub_true3, &stub_true3));
92 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false1));
93 EXPECT_FALSE(is_more_important(&stub_false2, &stub_false2));
94 EXPECT_FALSE(is_more_important(&stub_false3, &stub_false3));
95
96 // Visible should always be more important than non visible:
97 EXPECT_TRUE(is_more_important(&stub_true1, &stub_false1));
98 EXPECT_TRUE(is_more_important(&stub_true1, &stub_false2));
99 EXPECT_TRUE(is_more_important(&stub_true1, &stub_false3));
100 EXPECT_TRUE(is_more_important(&stub_true2, &stub_false1));
101 EXPECT_TRUE(is_more_important(&stub_true2, &stub_false2));
102 EXPECT_TRUE(is_more_important(&stub_true2, &stub_false3));
103 EXPECT_TRUE(is_more_important(&stub_true3, &stub_false1));
104 EXPECT_TRUE(is_more_important(&stub_true3, &stub_false2));
105 EXPECT_TRUE(is_more_important(&stub_true3, &stub_false3));
106
107 // Not visible should never be more important than visible:
108 EXPECT_FALSE(is_more_important(&stub_false1, &stub_true1));
109 EXPECT_FALSE(is_more_important(&stub_false1, &stub_true2));
110 EXPECT_FALSE(is_more_important(&stub_false1, &stub_true3));
111 EXPECT_FALSE(is_more_important(&stub_false2, &stub_true1));
112 EXPECT_FALSE(is_more_important(&stub_false2, &stub_true2));
113 EXPECT_FALSE(is_more_important(&stub_false2, &stub_true3));
114 EXPECT_FALSE(is_more_important(&stub_false3, &stub_true1));
115 EXPECT_FALSE(is_more_important(&stub_false3, &stub_true2));
116 EXPECT_FALSE(is_more_important(&stub_false3, &stub_true3));
117
118 // Newer should always be more important than older:
119 EXPECT_TRUE(is_more_important(&stub_true2, &stub_true1));
120 EXPECT_TRUE(is_more_important(&stub_true3, &stub_true1));
121 EXPECT_TRUE(is_more_important(&stub_true3, &stub_true2));
122 EXPECT_TRUE(is_more_important(&stub_false2, &stub_false1));
123 EXPECT_TRUE(is_more_important(&stub_false3, &stub_false1));
124 EXPECT_TRUE(is_more_important(&stub_false3, &stub_false2));
125
126 // Older should never be more important than newer:
127 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true2));
128 EXPECT_FALSE(is_more_important(&stub_true1, &stub_true3));
129 EXPECT_FALSE(is_more_important(&stub_true2, &stub_true3));
130 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false2));
131 EXPECT_FALSE(is_more_important(&stub_false1, &stub_false3));
132 EXPECT_FALSE(is_more_important(&stub_false2, &stub_false3));
133 }
134
135 // Test GpuMemoryManager::Manage basic functionality.
136 // Expect memory allocation to set hasFrontbuffer, hasBackbuffer according
137 // to visibility and last used time.
138 TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) {
139 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_),
140 stub2(GenerateUniqueSurfaceId(), false, older_);
141 client_.stubs_.push_back(&stub1);
142 client_.stubs_.push_back(&stub2);
143
144 Manage();
145 EXPECT_EQ(stub1.allocation_.hasFrontbuffer, true);
146 EXPECT_EQ(stub1.allocation_.hasBackbuffer, true);
147 EXPECT_EQ(stub2.allocation_.hasFrontbuffer, true);
148 EXPECT_EQ(stub2.allocation_.hasBackbuffer, false);
149 }
150
151 // Test GpuMemoryManager::Manage functionality: Test changing visibility
152 // Expect memory allocation to set hasFrontbuffer, hasBackbuffer according
153 // to visibility and last used time.
154 TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) {
155 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_),
156 stub2(GenerateUniqueSurfaceId(), false, older_);
157 client_.stubs_.push_back(&stub1);
158 client_.stubs_.push_back(&stub2);
159
160 Manage();
161 EXPECT_EQ(stub1.allocation_.hasFrontbuffer, true);
162 EXPECT_EQ(stub1.allocation_.hasBackbuffer, true);
163 EXPECT_EQ(stub2.allocation_.hasFrontbuffer, true);
164 EXPECT_EQ(stub2.allocation_.hasBackbuffer, false);
165
166 stub1.surface_state_.visible = false;
167 stub2.surface_state_.visible = true;
168
169 Manage();
170 EXPECT_EQ(stub1.allocation_.hasFrontbuffer, true);
171 EXPECT_EQ(stub1.allocation_.hasBackbuffer, false);
172 EXPECT_EQ(stub2.allocation_.hasFrontbuffer, true);
173 EXPECT_EQ(stub2.allocation_.hasBackbuffer, true);
174 }
175
176 // Test GpuMemoryManager::Manage functionality: Test more than threshold number
177 // of visible stubs.
178 // Expect all allocations to continue to have frontbuffer.
179 TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) {
180 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), true, older_),
181 stub2(GenerateUniqueSurfaceId(), true, older_),
182 stub3(GenerateUniqueSurfaceId(), true, older_),
183 stub4(GenerateUniqueSurfaceId(), true, older_);
184 client_.stubs_.push_back(&stub1);
185 client_.stubs_.push_back(&stub2);
186 client_.stubs_.push_back(&stub3);
187 client_.stubs_.push_back(&stub4);
188
189 Manage();
190 EXPECT_EQ(stub1.allocation_.hasFrontbuffer, true);
191 EXPECT_EQ(stub1.allocation_.hasBackbuffer, true);
192 EXPECT_EQ(stub2.allocation_.hasFrontbuffer, true);
193 EXPECT_EQ(stub2.allocation_.hasBackbuffer, true);
194 EXPECT_EQ(stub3.allocation_.hasFrontbuffer, true);
195 EXPECT_EQ(stub3.allocation_.hasBackbuffer, true);
196 EXPECT_EQ(stub4.allocation_.hasFrontbuffer, true);
197 EXPECT_EQ(stub4.allocation_.hasBackbuffer, true);
198 }
199
200 // Test GpuMemoryManager::Manage functionality: Test more than threshold number
201 // of not visible stubs.
202 // Expect the stubs surpassing the threshold to not have a backbuffer.
203 TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) {
204 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_),
205 stub2(GenerateUniqueSurfaceId(), false, newer_),
206 stub3(GenerateUniqueSurfaceId(), false, newer_),
207 stub4(GenerateUniqueSurfaceId(), false, older_);
208 client_.stubs_.push_back(&stub1);
209 client_.stubs_.push_back(&stub2);
210 client_.stubs_.push_back(&stub3);
211 client_.stubs_.push_back(&stub4);
212
213 Manage();
214 EXPECT_EQ(stub1.allocation_.hasFrontbuffer, true);
215 EXPECT_EQ(stub1.allocation_.hasBackbuffer, false);
216 EXPECT_EQ(stub2.allocation_.hasFrontbuffer, true);
217 EXPECT_EQ(stub2.allocation_.hasBackbuffer, false);
218 EXPECT_EQ(stub3.allocation_.hasFrontbuffer, true);
219 EXPECT_EQ(stub3.allocation_.hasBackbuffer, false);
220 EXPECT_EQ(stub4.allocation_.hasFrontbuffer, false);
221 EXPECT_EQ(stub4.allocation_.hasBackbuffer, false);
222 }
223
224 // Test GpuMemoryManager::Manage functionality: Test changing the last used
225 // time of stubs when doing so causes change in which stubs surpass threshold.
226 // Expect frontbuffer to be dropped for the older stub.
227 TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) {
228 FakeCommandBufferStub stub1(GenerateUniqueSurfaceId(), false, newer_),
229 stub2(GenerateUniqueSurfaceId(), false, newer_),
230 stub3(GenerateUniqueSurfaceId(), false, newer_),
231 stub4(GenerateUniqueSurfaceId(), false, older_);
232 client_.stubs_.push_back(&stub1);
233 client_.stubs_.push_back(&stub2);
234 client_.stubs_.push_back(&stub3);
235 client_.stubs_.push_back(&stub4);
236
237 Manage();
238 EXPECT_EQ(stub3.allocation_.hasFrontbuffer, true);
239 EXPECT_EQ(stub3.allocation_.hasBackbuffer, false);
240 EXPECT_EQ(stub4.allocation_.hasFrontbuffer, false);
241 EXPECT_EQ(stub4.allocation_.hasBackbuffer, false);
242
243 stub3.surface_state_.last_used_time = older_;
244 stub4.surface_state_.last_used_time = newer_;
245
246 Manage();
247 EXPECT_EQ(stub3.allocation_.hasFrontbuffer, false);
248 EXPECT_EQ(stub3.allocation_.hasBackbuffer, false);
249 EXPECT_EQ(stub4.allocation_.hasFrontbuffer, true);
250 EXPECT_EQ(stub4.allocation_.hasBackbuffer, false);
251 }
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_memory_manager.cc ('k') | content/content_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698