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