OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "base/mac/scoped_nsautorelease_pool.h" | 5 #include "base/mac/scoped_nsautorelease_pool.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "gpu/command_buffer/common/command_buffer_mock.h" | 7 #include "gpu/command_buffer/common/command_buffer_mock.h" |
8 #include "gpu/command_buffer/service/gpu_scheduler.h" | 8 #include "gpu/command_buffer/service/gpu_scheduler.h" |
9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
10 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" | 10 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 command_buffer_.reset(new MockCommandBuffer); | 38 command_buffer_.reset(new MockCommandBuffer); |
39 ON_CALL(*command_buffer_.get(), GetRingBuffer()) | 39 ON_CALL(*command_buffer_.get(), GetRingBuffer()) |
40 .WillByDefault(Return(shared_memory_buffer_)); | 40 .WillByDefault(Return(shared_memory_buffer_)); |
41 | 41 |
42 CommandBuffer::State default_state; | 42 CommandBuffer::State default_state; |
43 default_state.num_entries = kRingBufferEntries; | 43 default_state.num_entries = kRingBufferEntries; |
44 ON_CALL(*command_buffer_.get(), GetState()) | 44 ON_CALL(*command_buffer_.get(), GetState()) |
45 .WillByDefault(Return(default_state)); | 45 .WillByDefault(Return(default_state)); |
46 | 46 |
47 async_api_.reset(new StrictMock<SpecializedDoCommandAsyncAPIMock>); | 47 async_api_.reset(new StrictMock<AsyncAPIMock>); |
48 | 48 |
49 decoder_ = new gles2::MockGLES2Decoder(); | 49 decoder_ = new gles2::MockGLES2Decoder(); |
50 | 50 |
51 parser_ = new CommandParser(buffer_, | 51 parser_ = new CommandParser(buffer_, |
52 kRingBufferEntries, | 52 kRingBufferEntries, |
53 0, | 53 0, |
54 kRingBufferEntries, | 54 kRingBufferEntries, |
55 0, | 55 0, |
56 async_api_.get()); | 56 async_api_.get()); |
57 | 57 |
58 scheduler_.reset(new GpuScheduler(command_buffer_.get(), | 58 scheduler_.reset(gpu::GpuScheduler::CreateForTests(command_buffer_.get(), |
59 decoder_, | 59 decoder_, |
60 parser_, | 60 parser_)); |
61 2)); | |
62 | 61 |
63 EXPECT_CALL(*decoder_, Destroy()) | 62 EXPECT_CALL(*decoder_, Destroy()) |
64 .Times(1) | 63 .Times(1) |
65 .RetiresOnSaturation(); | 64 .RetiresOnSaturation(); |
66 } | 65 } |
67 | 66 |
68 virtual void TearDown() { | 67 virtual void TearDown() { |
69 // Ensure that any unexpected tasks posted by the GPU scheduler are executed | 68 // Ensure that any unexpected tasks posted by the GPU scheduler are executed |
70 // in order to fail the test. | 69 // in order to fail the test. |
71 MessageLoop::current()->RunAllPending(); | 70 MessageLoop::current()->RunAllPending(); |
(...skipping 18 matching lines...) Expand all Loading... |
90 TEST_F(GpuSchedulerTest, SchedulerDoesNothingIfRingBufferIsEmpty) { | 89 TEST_F(GpuSchedulerTest, SchedulerDoesNothingIfRingBufferIsEmpty) { |
91 CommandBuffer::State state; | 90 CommandBuffer::State state; |
92 | 91 |
93 state.put_offset = 0; | 92 state.put_offset = 0; |
94 EXPECT_CALL(*command_buffer_, GetState()) | 93 EXPECT_CALL(*command_buffer_, GetState()) |
95 .WillRepeatedly(Return(state)); | 94 .WillRepeatedly(Return(state)); |
96 | 95 |
97 EXPECT_CALL(*command_buffer_, SetParseError(_)) | 96 EXPECT_CALL(*command_buffer_, SetParseError(_)) |
98 .Times(0); | 97 .Times(0); |
99 | 98 |
100 scheduler_->PutChanged(true); | 99 scheduler_->PutChanged(); |
101 } | 100 } |
102 | 101 |
103 TEST_F(GpuSchedulerTest, ProcessesOneCommand) { | 102 TEST_F(GpuSchedulerTest, ProcessesOneCommand) { |
104 CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]); | 103 CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]); |
105 header[0].command = 7; | 104 header[0].command = 7; |
106 header[0].size = 2; | 105 header[0].size = 2; |
107 buffer_[1] = 123; | 106 buffer_[1] = 123; |
108 | 107 |
109 CommandBuffer::State state; | 108 CommandBuffer::State state; |
110 | 109 |
111 state.put_offset = 2; | 110 state.put_offset = 2; |
112 EXPECT_CALL(*command_buffer_, GetState()) | 111 EXPECT_CALL(*command_buffer_, GetState()) |
113 .WillRepeatedly(Return(state)); | 112 .WillRepeatedly(Return(state)); |
114 EXPECT_CALL(*command_buffer_, SetGetOffset(2)); | 113 EXPECT_CALL(*command_buffer_, SetGetOffset(2)); |
115 | 114 |
116 EXPECT_CALL(*async_api_, DoCommand(7, 1, &buffer_[0])) | 115 EXPECT_CALL(*async_api_, DoCommand(7, 1, &buffer_[0])) |
117 .WillOnce(Return(error::kNoError)); | 116 .WillOnce(Return(error::kNoError)); |
118 | 117 |
119 EXPECT_CALL(*command_buffer_, SetParseError(_)) | 118 EXPECT_CALL(*command_buffer_, SetParseError(_)) |
120 .Times(0); | 119 .Times(0); |
121 | 120 |
122 scheduler_->PutChanged(true); | 121 scheduler_->PutChanged(); |
123 } | 122 } |
124 | 123 |
125 TEST_F(GpuSchedulerTest, ProcessesTwoCommands) { | 124 TEST_F(GpuSchedulerTest, ProcessesTwoCommands) { |
126 CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]); | 125 CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]); |
127 header[0].command = 7; | 126 header[0].command = 7; |
128 header[0].size = 2; | 127 header[0].size = 2; |
129 buffer_[1] = 123; | 128 buffer_[1] = 123; |
130 header[2].command = 8; | 129 header[2].command = 8; |
131 header[2].size = 1; | 130 header[2].size = 1; |
132 | 131 |
133 CommandBuffer::State state; | 132 CommandBuffer::State state; |
134 | 133 |
135 state.put_offset = 3; | 134 state.put_offset = 3; |
136 EXPECT_CALL(*command_buffer_, GetState()) | 135 EXPECT_CALL(*command_buffer_, GetState()) |
137 .WillRepeatedly(Return(state)); | 136 .WillRepeatedly(Return(state)); |
138 | 137 |
139 EXPECT_CALL(*async_api_, DoCommand(7, 1, &buffer_[0])) | 138 EXPECT_CALL(*async_api_, DoCommand(7, 1, &buffer_[0])) |
140 .WillOnce(Return(error::kNoError)); | 139 .WillOnce(Return(error::kNoError)); |
141 EXPECT_CALL(*command_buffer_, SetGetOffset(2)); | 140 EXPECT_CALL(*command_buffer_, SetGetOffset(2)); |
142 | 141 |
143 EXPECT_CALL(*async_api_, DoCommand(8, 0, &buffer_[2])) | 142 EXPECT_CALL(*async_api_, DoCommand(8, 0, &buffer_[2])) |
144 .WillOnce(Return(error::kNoError)); | 143 .WillOnce(Return(error::kNoError)); |
145 EXPECT_CALL(*command_buffer_, SetGetOffset(3)); | 144 EXPECT_CALL(*command_buffer_, SetGetOffset(3)); |
146 | 145 |
147 scheduler_->PutChanged(true); | 146 scheduler_->PutChanged(); |
148 } | 147 } |
149 | 148 |
150 TEST_F(GpuSchedulerTest, SchedulerSetsTheGLContext) { | 149 TEST_F(GpuSchedulerTest, SchedulerSetsTheGLContext) { |
151 EXPECT_CALL(*decoder_, MakeCurrent()) | 150 EXPECT_CALL(*decoder_, MakeCurrent()) |
152 .WillOnce(Return(true)) | 151 .WillOnce(Return(true)) |
153 .WillOnce(Return(true)); | 152 .WillOnce(Return(true)); |
154 | 153 |
155 CommandBuffer::State state; | 154 CommandBuffer::State state; |
156 state.put_offset = 0; | 155 state.put_offset = 0; |
157 EXPECT_CALL(*command_buffer_, GetState()) | 156 EXPECT_CALL(*command_buffer_, GetState()) |
158 .WillRepeatedly(Return(state)); | 157 .WillRepeatedly(Return(state)); |
159 | 158 |
160 scheduler_->PutChanged(true); | 159 scheduler_->PutChanged(); |
161 } | |
162 | |
163 TEST_F(GpuSchedulerTest, PostsTaskToFinishRemainingCommands) { | |
164 unsigned int pauseCmd = SpecializedDoCommandAsyncAPIMock::kTestQuantumCommand; | |
165 CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]); | |
166 header[0].command = 7; | |
167 header[0].size = 2; | |
168 buffer_[1] = 123; | |
169 header[2].command = pauseCmd; | |
170 header[2].size = 1; | |
171 header[3].command = 9; | |
172 header[3].size = 1; | |
173 | |
174 CommandBuffer::State state; | |
175 | |
176 state.put_offset = 4; | |
177 EXPECT_CALL(*command_buffer_, GetState()) | |
178 .WillRepeatedly(Return(state)); | |
179 | |
180 EXPECT_CALL(*async_api_, DoCommand(7, 1, &buffer_[0])) | |
181 .WillOnce(Return(error::kNoError)); | |
182 EXPECT_CALL(*command_buffer_, SetGetOffset(2)); | |
183 | |
184 EXPECT_CALL(*async_api_, DoCommand(pauseCmd, 0, &buffer_[2])) | |
185 .WillOnce(Return(error::kNoError)); | |
186 EXPECT_CALL(*command_buffer_, SetGetOffset(3)); | |
187 | |
188 scheduler_->PutChanged(true); | |
189 | |
190 // ProcessCommands is called a second time when the pending task is run. | |
191 | |
192 state.put_offset = 4; | |
193 EXPECT_CALL(*command_buffer_, GetState()) | |
194 .WillRepeatedly(Return(state)); | |
195 | |
196 EXPECT_CALL(*async_api_, DoCommand(9, 0, &buffer_[3])) | |
197 .WillOnce(Return(error::kNoError)); | |
198 | |
199 EXPECT_CALL(*command_buffer_, SetGetOffset(4)); | |
200 | |
201 MessageLoop::current()->RunAllPending(); | |
202 } | 160 } |
203 | 161 |
204 TEST_F(GpuSchedulerTest, SetsErrorCodeOnCommandBuffer) { | 162 TEST_F(GpuSchedulerTest, SetsErrorCodeOnCommandBuffer) { |
205 CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]); | 163 CommandHeader* header = reinterpret_cast<CommandHeader*>(&buffer_[0]); |
206 header[0].command = 7; | 164 header[0].command = 7; |
207 header[0].size = 1; | 165 header[0].size = 1; |
208 | 166 |
209 CommandBuffer::State state; | 167 CommandBuffer::State state; |
210 | 168 |
211 state.put_offset = 1; | 169 state.put_offset = 1; |
212 EXPECT_CALL(*command_buffer_, GetState()) | 170 EXPECT_CALL(*command_buffer_, GetState()) |
213 .WillRepeatedly(Return(state)); | 171 .WillRepeatedly(Return(state)); |
214 | 172 |
215 EXPECT_CALL(*async_api_, DoCommand(7, 0, &buffer_[0])) | 173 EXPECT_CALL(*async_api_, DoCommand(7, 0, &buffer_[0])) |
216 .WillOnce(Return( | 174 .WillOnce(Return( |
217 error::kUnknownCommand)); | 175 error::kUnknownCommand)); |
218 EXPECT_CALL(*command_buffer_, SetGetOffset(1)); | 176 EXPECT_CALL(*command_buffer_, SetGetOffset(1)); |
219 | 177 |
220 EXPECT_CALL(*decoder_, GetContextLostReason()) | 178 EXPECT_CALL(*decoder_, GetContextLostReason()) |
221 .WillOnce(Return(error::kUnknown)); | 179 .WillOnce(Return(error::kUnknown)); |
222 EXPECT_CALL(*command_buffer_, | 180 EXPECT_CALL(*command_buffer_, |
223 SetParseError(error::kUnknownCommand)); | 181 SetParseError(error::kUnknownCommand)); |
224 | 182 |
225 scheduler_->PutChanged(true); | 183 scheduler_->PutChanged(); |
226 } | 184 } |
227 | 185 |
228 TEST_F(GpuSchedulerTest, ProcessCommandsDoesNothingAfterError) { | 186 TEST_F(GpuSchedulerTest, ProcessCommandsDoesNothingAfterError) { |
229 CommandBuffer::State state; | 187 CommandBuffer::State state; |
230 state.error = error::kGenericError; | 188 state.error = error::kGenericError; |
231 | 189 |
232 EXPECT_CALL(*command_buffer_, GetState()) | 190 EXPECT_CALL(*command_buffer_, GetState()) |
233 .WillRepeatedly(Return(state)); | 191 .WillRepeatedly(Return(state)); |
234 | 192 |
235 scheduler_->PutChanged(true); | 193 scheduler_->PutChanged(); |
236 } | 194 } |
237 | 195 |
238 TEST_F(GpuSchedulerTest, CanGetAddressOfSharedMemory) { | 196 TEST_F(GpuSchedulerTest, CanGetAddressOfSharedMemory) { |
239 EXPECT_CALL(*command_buffer_.get(), GetTransferBuffer(7)) | 197 EXPECT_CALL(*command_buffer_.get(), GetTransferBuffer(7)) |
240 .WillOnce(Return(shared_memory_buffer_)); | 198 .WillOnce(Return(shared_memory_buffer_)); |
241 | 199 |
242 EXPECT_EQ(&buffer_[0], scheduler_->GetSharedMemoryBuffer(7).ptr); | 200 EXPECT_EQ(&buffer_[0], scheduler_->GetSharedMemoryBuffer(7).ptr); |
243 } | 201 } |
244 | 202 |
245 ACTION_P2(SetPointee, address, value) { | 203 ACTION_P2(SetPointee, address, value) { |
246 *address = value; | 204 *address = value; |
247 } | 205 } |
248 | 206 |
249 TEST_F(GpuSchedulerTest, CanGetSizeOfSharedMemory) { | 207 TEST_F(GpuSchedulerTest, CanGetSizeOfSharedMemory) { |
250 EXPECT_CALL(*command_buffer_.get(), GetTransferBuffer(7)) | 208 EXPECT_CALL(*command_buffer_.get(), GetTransferBuffer(7)) |
251 .WillOnce(Return(shared_memory_buffer_)); | 209 .WillOnce(Return(shared_memory_buffer_)); |
252 | 210 |
253 EXPECT_EQ(kRingBufferSize, scheduler_->GetSharedMemoryBuffer(7).size); | 211 EXPECT_EQ(kRingBufferSize, scheduler_->GetSharedMemoryBuffer(7).size); |
254 } | 212 } |
255 | 213 |
256 TEST_F(GpuSchedulerTest, SetTokenForwardsToCommandBuffer) { | 214 TEST_F(GpuSchedulerTest, SetTokenForwardsToCommandBuffer) { |
257 EXPECT_CALL(*command_buffer_, SetToken(7)); | 215 EXPECT_CALL(*command_buffer_, SetToken(7)); |
258 scheduler_->set_token(7); | 216 scheduler_->set_token(7); |
259 } | 217 } |
260 | 218 |
261 } // namespace gpu | 219 } // namespace gpu |
OLD | NEW |