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 "gpu/command_buffer/service/query_manager.h" | 5 #include "gpu/command_buffer/service/query_manager.h" |
6 #include "gpu/command_buffer/common/gl_mock.h" | 6 #include "gpu/command_buffer/common/gl_mock.h" |
7 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 7 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
8 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 8 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
9 #include "gpu/command_buffer/service/common_decoder.h" | 9 #include "gpu/command_buffer/service/common_decoder.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 ~QueryManagerTest() { | 41 ~QueryManagerTest() { |
42 } | 42 } |
43 | 43 |
44 protected: | 44 protected: |
45 virtual void SetUp() { | 45 virtual void SetUp() { |
46 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 46 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
47 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 47 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
48 engine_.reset(new MockCommandBufferEngine()); | 48 engine_.reset(new MockCommandBufferEngine()); |
49 decoder_.reset(new MockDecoder()); | 49 decoder_.reset(new MockDecoder()); |
50 decoder_->set_engine(engine_.get()); | 50 decoder_->set_engine(engine_.get()); |
51 manager_.reset(new QueryManager()); | 51 manager_.reset(new QueryManager(decoder_.get(), false)); |
52 } | 52 } |
53 | 53 |
54 virtual void TearDown() { | 54 virtual void TearDown() { |
55 decoder_.reset(); | 55 decoder_.reset(); |
56 manager_->Destroy(false); | 56 manager_->Destroy(false); |
57 manager_.reset(); | 57 manager_.reset(); |
58 engine_.reset(); | 58 engine_.reset(); |
59 ::gfx::GLInterface::SetGLInterface(NULL); | 59 ::gfx::GLInterface::SetGLInterface(NULL); |
60 gl_.reset(); | 60 gl_.reset(); |
61 } | 61 } |
62 | 62 |
| 63 QueryManager::Query* CreateQuery( |
| 64 GLenum target, GLuint client_id, int32 shm_id, uint32 shm_offset, |
| 65 GLuint service_id) { |
| 66 EXPECT_CALL(*gl_, GenQueriesARB(1, _)) |
| 67 .WillOnce(SetArgumentPointee<1>(service_id)) |
| 68 .RetiresOnSaturation(); |
| 69 return manager_->CreateQuery(target, client_id, shm_id, shm_offset); |
| 70 } |
| 71 |
| 72 void QueueQuery( |
| 73 QueryManager::Query* query, GLuint service_id, uint32 submit_count) { |
| 74 EXPECT_CALL(*gl_, BeginQueryARB(query->target(), service_id)) |
| 75 .Times(1) |
| 76 .RetiresOnSaturation(); |
| 77 EXPECT_CALL(*gl_, EndQueryARB(query->target())) |
| 78 .Times(1) |
| 79 .RetiresOnSaturation(); |
| 80 EXPECT_TRUE(manager_->BeginQuery(query)); |
| 81 EXPECT_TRUE(manager_->EndQuery(query, submit_count)); |
| 82 } |
| 83 |
63 // Use StrictMock to make 100% sure we know how GL will be called. | 84 // Use StrictMock to make 100% sure we know how GL will be called. |
64 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | 85 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
65 scoped_ptr<MockDecoder> decoder_; | 86 scoped_ptr<MockDecoder> decoder_; |
66 scoped_ptr<QueryManager> manager_; | 87 scoped_ptr<QueryManager> manager_; |
67 | 88 |
68 private: | 89 private: |
69 class MockCommandBufferEngine : public CommandBufferEngine { | 90 class MockCommandBufferEngine : public CommandBufferEngine { |
70 public: | 91 public: |
71 MockCommandBufferEngine() { | 92 MockCommandBufferEngine() { |
72 data_.reset(new int8[kSharedBufferSize]); | 93 data_.reset(new int8[kSharedBufferSize]); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 #endif | 149 #endif |
129 | 150 |
130 TEST_F(QueryManagerTest, Basic) { | 151 TEST_F(QueryManagerTest, Basic) { |
131 const GLuint kClient1Id = 1; | 152 const GLuint kClient1Id = 1; |
132 const GLuint kService1Id = 11; | 153 const GLuint kService1Id = 11; |
133 const GLuint kClient2Id = 2; | 154 const GLuint kClient2Id = 2; |
134 | 155 |
135 EXPECT_FALSE(manager_->HavePendingQueries()); | 156 EXPECT_FALSE(manager_->HavePendingQueries()); |
136 // Check we can create a Query. | 157 // Check we can create a Query. |
137 QueryManager::Query::Ref query( | 158 QueryManager::Query::Ref query( |
138 manager_->CreateQuery(kClient1Id, kService1Id)); | 159 CreateQuery(GL_ANY_SAMPLES_PASSED_EXT, kClient1Id, |
| 160 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
139 ASSERT_TRUE(query.get() != NULL); | 161 ASSERT_TRUE(query.get() != NULL); |
140 // Check we can get the same Query. | 162 // Check we can get the same Query. |
141 EXPECT_EQ(query.get(), manager_->GetQuery(kClient1Id)); | 163 EXPECT_EQ(query.get(), manager_->GetQuery(kClient1Id)); |
142 // Check we can get the client id. | |
143 GLuint client_id = -1; | |
144 EXPECT_TRUE(manager_->GetClientId(kService1Id, &client_id)); | |
145 EXPECT_EQ(kClient1Id, client_id); | |
146 EXPECT_FALSE(manager_->HavePendingQueries()); | |
147 // Check we get nothing for a non-existent query. | 164 // Check we get nothing for a non-existent query. |
148 EXPECT_TRUE(manager_->GetQuery(kClient2Id) == NULL); | 165 EXPECT_TRUE(manager_->GetQuery(kClient2Id) == NULL); |
149 // Check we can delete the query. | 166 // Check we can delete the query. |
150 manager_->RemoveQuery(kClient1Id); | 167 manager_->RemoveQuery(kClient1Id); |
151 // Check we get nothing for a non-existent query. | 168 // Check we get nothing for a non-existent query. |
152 EXPECT_TRUE(manager_->GetQuery(kClient1Id) == NULL); | 169 EXPECT_TRUE(manager_->GetQuery(kClient1Id) == NULL); |
153 // Check query is deleted | 170 // Check query is deleted |
154 EXPECT_TRUE(query->IsDeleted()); | 171 EXPECT_TRUE(query->IsDeleted()); |
155 EXPECT_FALSE(manager_->HavePendingQueries()); | 172 EXPECT_FALSE(manager_->HavePendingQueries()); |
156 } | 173 } |
157 | 174 |
158 TEST_F(QueryManagerTest, Destroy) { | 175 TEST_F(QueryManagerTest, Destroy) { |
159 const GLuint kClient1Id = 1; | 176 const GLuint kClient1Id = 1; |
160 const GLuint kService1Id = 11; | 177 const GLuint kService1Id = 11; |
161 | 178 |
162 // Create Query. | 179 // Create Query. |
163 QueryManager::Query::Ref query( | 180 QueryManager::Query::Ref query( |
164 manager_->CreateQuery(kClient1Id, kService1Id)); | 181 CreateQuery(GL_ANY_SAMPLES_PASSED_EXT, kClient1Id, |
| 182 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
165 ASSERT_TRUE(query.get() != NULL); | 183 ASSERT_TRUE(query.get() != NULL); |
166 EXPECT_CALL(*gl_, DeleteQueriesARB(1, ::testing::Pointee(kService1Id))) | 184 EXPECT_CALL(*gl_, DeleteQueriesARB(1, ::testing::Pointee(kService1Id))) |
167 .Times(1) | 185 .Times(1) |
168 .RetiresOnSaturation(); | 186 .RetiresOnSaturation(); |
169 manager_->Destroy(true); | 187 manager_->Destroy(true); |
170 // Check we get nothing for a non-existent query. | 188 // Check we get nothing for a non-existent query. |
171 EXPECT_TRUE(manager_->GetQuery(kClient1Id) == NULL); | 189 EXPECT_TRUE(manager_->GetQuery(kClient1Id) == NULL); |
172 // Check query is deleted | 190 // Check query is deleted |
173 EXPECT_TRUE(query->IsDeleted()); | 191 EXPECT_TRUE(query->IsDeleted()); |
174 } | 192 } |
175 | 193 |
176 TEST_F(QueryManagerTest, QueryBasic) { | 194 TEST_F(QueryManagerTest, QueryBasic) { |
177 const GLuint kClient1Id = 1; | 195 const GLuint kClient1Id = 1; |
178 const GLuint kService1Id = 11; | 196 const GLuint kService1Id = 11; |
179 | |
180 // Create Query. | |
181 QueryManager::Query::Ref query( | |
182 manager_->CreateQuery(kClient1Id, kService1Id)); | |
183 ASSERT_TRUE(query.get() != NULL); | |
184 | |
185 EXPECT_FALSE(query->IsValid()); | |
186 EXPECT_FALSE(query->IsDeleted()); | |
187 EXPECT_FALSE(query->IsInitialized()); | |
188 EXPECT_FALSE(query->pending()); | |
189 } | |
190 | |
191 TEST_F(QueryManagerTest, QueryInitialize) { | |
192 const GLuint kClient1Id = 1; | |
193 const GLuint kService1Id = 11; | |
194 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 197 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
195 | 198 |
196 // Create Query. | 199 // Create Query. |
197 QueryManager::Query::Ref query( | 200 QueryManager::Query::Ref query( |
198 manager_->CreateQuery(kClient1Id, kService1Id)); | 201 CreateQuery(kTarget, kClient1Id, |
| 202 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
199 ASSERT_TRUE(query.get() != NULL); | 203 ASSERT_TRUE(query.get() != NULL); |
200 | 204 |
201 query->Initialize(kTarget, kSharedMemoryId, kSharedMemoryOffset); | 205 EXPECT_TRUE(query->IsValid()); |
| 206 EXPECT_FALSE(query->IsDeleted()); |
| 207 EXPECT_FALSE(query->pending()); |
202 EXPECT_EQ(kTarget, query->target()); | 208 EXPECT_EQ(kTarget, query->target()); |
203 EXPECT_EQ(kSharedMemoryId, query->shm_id()); | 209 EXPECT_EQ(kSharedMemoryId, query->shm_id()); |
204 EXPECT_EQ(kSharedMemoryOffset, query->shm_offset()); | 210 EXPECT_EQ(kSharedMemoryOffset, query->shm_offset()); |
205 | |
206 EXPECT_TRUE(query->IsValid()); | |
207 EXPECT_FALSE(query->IsDeleted()); | |
208 EXPECT_TRUE(query->IsInitialized()); | |
209 EXPECT_FALSE(query->pending()); | |
210 } | 211 } |
211 | 212 |
212 TEST_F(QueryManagerTest, ProcessPendingQuery) { | 213 TEST_F(QueryManagerTest, ProcessPendingQuery) { |
213 const GLuint kClient1Id = 1; | 214 const GLuint kClient1Id = 1; |
214 const GLuint kService1Id = 11; | 215 const GLuint kService1Id = 11; |
215 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 216 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
216 const uint32 kSubmitCount = 123; | 217 const uint32 kSubmitCount = 123; |
217 const GLuint kResult = 456; | 218 const GLuint kResult = 456; |
218 | 219 |
219 // Check nothing happens if there are no pending queries. | 220 // Check nothing happens if there are no pending queries. |
220 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 221 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
221 | 222 |
222 // Create Query. | 223 // Create Query. |
223 QueryManager::Query::Ref query( | 224 QueryManager::Query::Ref query( |
224 manager_->CreateQuery(kClient1Id, kService1Id)); | 225 CreateQuery(kTarget, kClient1Id, |
| 226 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
225 ASSERT_TRUE(query.get() != NULL); | 227 ASSERT_TRUE(query.get() != NULL); |
226 query->Initialize(kTarget, kSharedMemoryId, kSharedMemoryOffset); | |
227 | 228 |
228 // Setup shared memory like client would. | 229 // Setup shared memory like client would. |
229 QuerySync* sync = decoder_->GetSharedMemoryAs<QuerySync*>( | 230 QuerySync* sync = decoder_->GetSharedMemoryAs<QuerySync*>( |
230 kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync)); | 231 kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync)); |
231 ASSERT_TRUE(sync != NULL); | 232 ASSERT_TRUE(sync != NULL); |
232 sync->Reset(); | 233 sync->Reset(); |
233 | 234 |
234 // Queue it | 235 // Queue it |
235 manager_->AddPendingQuery(query.get(), kSubmitCount); | 236 QueueQuery(query.get(), kService1Id, kSubmitCount); |
236 EXPECT_TRUE(query->pending()); | 237 EXPECT_TRUE(query->pending()); |
237 EXPECT_TRUE(manager_->HavePendingQueries()); | 238 EXPECT_TRUE(manager_->HavePendingQueries()); |
238 | 239 |
239 // Process with return not available. | 240 // Process with return not available. |
240 // Expect 1 GL command. | 241 // Expect 1 GL command. |
241 EXPECT_CALL(*gl_, | 242 EXPECT_CALL(*gl_, |
242 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 243 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
243 .WillOnce(SetArgumentPointee<2>(0)) | 244 .WillOnce(SetArgumentPointee<2>(0)) |
244 .RetiresOnSaturation(); | 245 .RetiresOnSaturation(); |
245 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 246 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
246 EXPECT_TRUE(query->pending()); | 247 EXPECT_TRUE(query->pending()); |
247 EXPECT_EQ(0u, sync->process_count); | 248 EXPECT_EQ(0u, sync->process_count); |
248 EXPECT_EQ(0u, sync->result); | 249 EXPECT_EQ(0u, sync->result); |
249 | 250 |
250 // Process with return available. | 251 // Process with return available. |
251 // Expect 2 GL commands. | 252 // Expect 2 GL commands. |
252 EXPECT_CALL(*gl_, | 253 EXPECT_CALL(*gl_, |
253 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 254 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
254 .WillOnce(SetArgumentPointee<2>(1)) | 255 .WillOnce(SetArgumentPointee<2>(1)) |
255 .RetiresOnSaturation(); | 256 .RetiresOnSaturation(); |
256 EXPECT_CALL(*gl_, | 257 EXPECT_CALL(*gl_, |
257 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) | 258 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) |
258 .WillOnce(SetArgumentPointee<2>(kResult)) | 259 .WillOnce(SetArgumentPointee<2>(kResult)) |
259 .RetiresOnSaturation(); | 260 .RetiresOnSaturation(); |
260 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 261 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
261 EXPECT_FALSE(query->pending()); | 262 EXPECT_FALSE(query->pending()); |
262 EXPECT_EQ(kSubmitCount, sync->process_count); | 263 EXPECT_EQ(kSubmitCount, sync->process_count); |
263 EXPECT_EQ(kResult, sync->result); | 264 EXPECT_EQ(kResult, sync->result); |
264 EXPECT_FALSE(manager_->HavePendingQueries()); | 265 EXPECT_FALSE(manager_->HavePendingQueries()); |
265 | 266 |
266 // Process with no queries. | 267 // Process with no queries. |
267 // Expect no GL commands/ | 268 // Expect no GL commands/ |
268 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 269 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
269 } | 270 } |
270 | 271 |
271 TEST_F(QueryManagerTest, ProcessPendingQueries) { | 272 TEST_F(QueryManagerTest, ProcessPendingQueries) { |
272 const GLuint kClient1Id = 1; | 273 const GLuint kClient1Id = 1; |
273 const GLuint kService1Id = 11; | 274 const GLuint kService1Id = 11; |
274 const GLuint kClient2Id = 2; | 275 const GLuint kClient2Id = 2; |
275 const GLuint kService2Id = 12; | 276 const GLuint kService2Id = 12; |
276 const GLuint kClient3Id = 3; | 277 const GLuint kClient3Id = 3; |
277 const GLuint kService3Id = 13; | 278 const GLuint kService3Id = 13; |
278 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 279 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
279 const uint32 kSubmitCount1 = 123; | 280 const uint32 kSubmitCount1 = 123; |
280 const uint32 kSubmitCount2 = 123; | 281 const uint32 kSubmitCount2 = 123; |
281 const uint32 kSubmitCount3 = 123; | 282 const uint32 kSubmitCount3 = 123; |
282 const GLuint kResult1 = 456; | 283 const GLuint kResult1 = 456; |
283 const GLuint kResult2 = 457; | 284 const GLuint kResult2 = 457; |
284 const GLuint kResult3 = 458; | 285 const GLuint kResult3 = 458; |
285 | 286 |
286 // Create Queries. | |
287 QueryManager::Query::Ref query1( | |
288 manager_->CreateQuery(kClient1Id, kService1Id)); | |
289 QueryManager::Query::Ref query2( | |
290 manager_->CreateQuery(kClient2Id, kService2Id)); | |
291 QueryManager::Query::Ref query3( | |
292 manager_->CreateQuery(kClient3Id, kService3Id)); | |
293 ASSERT_TRUE(query1.get() != NULL); | |
294 ASSERT_TRUE(query2.get() != NULL); | |
295 ASSERT_TRUE(query3.get() != NULL); | |
296 EXPECT_FALSE(manager_->HavePendingQueries()); | |
297 | |
298 // Setup shared memory like client would. | 287 // Setup shared memory like client would. |
299 QuerySync* sync1 = decoder_->GetSharedMemoryAs<QuerySync*>( | 288 QuerySync* sync1 = decoder_->GetSharedMemoryAs<QuerySync*>( |
300 kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync1) * 3); | 289 kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync1) * 3); |
301 ASSERT_TRUE(sync1 != NULL); | 290 ASSERT_TRUE(sync1 != NULL); |
302 QuerySync* sync2 = sync1 + 1; | 291 QuerySync* sync2 = sync1 + 1; |
303 QuerySync* sync3 = sync2 + 1; | 292 QuerySync* sync3 = sync2 + 1; |
304 | 293 |
| 294 // Create Queries. |
| 295 QueryManager::Query::Ref query1( |
| 296 CreateQuery(kTarget, kClient1Id, |
| 297 kSharedMemoryId, kSharedMemoryOffset + sizeof(*sync1) * 0, |
| 298 kService1Id)); |
| 299 QueryManager::Query::Ref query2( |
| 300 CreateQuery(kTarget, kClient2Id, |
| 301 kSharedMemoryId, kSharedMemoryOffset + sizeof(*sync1) * 1, |
| 302 kService2Id)); |
| 303 QueryManager::Query::Ref query3( |
| 304 CreateQuery(kTarget, kClient3Id, |
| 305 kSharedMemoryId, kSharedMemoryOffset + sizeof(*sync1) * 2, |
| 306 kService3Id)); |
| 307 ASSERT_TRUE(query1.get() != NULL); |
| 308 ASSERT_TRUE(query2.get() != NULL); |
| 309 ASSERT_TRUE(query3.get() != NULL); |
| 310 EXPECT_FALSE(manager_->HavePendingQueries()); |
| 311 |
305 sync1->Reset(); | 312 sync1->Reset(); |
306 sync2->Reset(); | 313 sync2->Reset(); |
307 sync3->Reset(); | 314 sync3->Reset(); |
308 | 315 |
309 query1->Initialize(kTarget, kSharedMemoryId, kSharedMemoryOffset); | |
310 query2->Initialize(kTarget, kSharedMemoryId, | |
311 kSharedMemoryOffset + sizeof(*sync1)); | |
312 query3->Initialize(kTarget, kSharedMemoryId, | |
313 kSharedMemoryOffset + sizeof(*sync1) * 2); | |
314 | |
315 // Queue them | 316 // Queue them |
316 manager_->AddPendingQuery(query1.get(), kSubmitCount1); | 317 QueueQuery(query1.get(), kService1Id, kSubmitCount1); |
317 manager_->AddPendingQuery(query2.get(), kSubmitCount2); | 318 QueueQuery(query2.get(), kService2Id, kSubmitCount2); |
318 manager_->AddPendingQuery(query3.get(), kSubmitCount3); | 319 QueueQuery(query3.get(), kService3Id, kSubmitCount3); |
319 EXPECT_TRUE(query1->pending()); | 320 EXPECT_TRUE(query1->pending()); |
320 EXPECT_TRUE(query2->pending()); | 321 EXPECT_TRUE(query2->pending()); |
321 EXPECT_TRUE(query3->pending()); | 322 EXPECT_TRUE(query3->pending()); |
322 EXPECT_TRUE(manager_->HavePendingQueries()); | 323 EXPECT_TRUE(manager_->HavePendingQueries()); |
323 | 324 |
324 // Process with return available for first 2 queries. | 325 // Process with return available for first 2 queries. |
325 // Expect 4 GL commands. | 326 // Expect 4 GL commands. |
326 { | 327 { |
327 InSequence s; | 328 InSequence s; |
328 EXPECT_CALL(*gl_, | 329 EXPECT_CALL(*gl_, |
329 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 330 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
330 .WillOnce(SetArgumentPointee<2>(1)) | 331 .WillOnce(SetArgumentPointee<2>(1)) |
331 .RetiresOnSaturation(); | 332 .RetiresOnSaturation(); |
332 EXPECT_CALL(*gl_, | 333 EXPECT_CALL(*gl_, |
333 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) | 334 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) |
334 .WillOnce(SetArgumentPointee<2>(kResult1)) | 335 .WillOnce(SetArgumentPointee<2>(kResult1)) |
335 .RetiresOnSaturation(); | 336 .RetiresOnSaturation(); |
336 EXPECT_CALL(*gl_, | 337 EXPECT_CALL(*gl_, |
337 GetQueryObjectuivARB(kService2Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 338 GetQueryObjectuivARB(kService2Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
338 .WillOnce(SetArgumentPointee<2>(1)) | 339 .WillOnce(SetArgumentPointee<2>(1)) |
339 .RetiresOnSaturation(); | 340 .RetiresOnSaturation(); |
340 EXPECT_CALL(*gl_, | 341 EXPECT_CALL(*gl_, |
341 GetQueryObjectuivARB(kService2Id, GL_QUERY_RESULT_EXT, _)) | 342 GetQueryObjectuivARB(kService2Id, GL_QUERY_RESULT_EXT, _)) |
342 .WillOnce(SetArgumentPointee<2>(kResult2)) | 343 .WillOnce(SetArgumentPointee<2>(kResult2)) |
343 .RetiresOnSaturation(); | 344 .RetiresOnSaturation(); |
344 EXPECT_CALL(*gl_, | 345 EXPECT_CALL(*gl_, |
345 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 346 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
346 .WillOnce(SetArgumentPointee<2>(0)) | 347 .WillOnce(SetArgumentPointee<2>(0)) |
347 .RetiresOnSaturation(); | 348 .RetiresOnSaturation(); |
348 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 349 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
349 } | 350 } |
350 EXPECT_FALSE(query1->pending()); | 351 EXPECT_FALSE(query1->pending()); |
351 EXPECT_FALSE(query2->pending()); | 352 EXPECT_FALSE(query2->pending()); |
352 EXPECT_TRUE(query3->pending()); | 353 EXPECT_TRUE(query3->pending()); |
353 EXPECT_EQ(kSubmitCount1, sync1->process_count); | 354 EXPECT_EQ(kSubmitCount1, sync1->process_count); |
354 EXPECT_EQ(kSubmitCount2, sync2->process_count); | 355 EXPECT_EQ(kSubmitCount2, sync2->process_count); |
355 EXPECT_EQ(kResult1, sync1->result); | 356 EXPECT_EQ(kResult1, sync1->result); |
356 EXPECT_EQ(kResult2, sync2->result); | 357 EXPECT_EQ(kResult2, sync2->result); |
357 EXPECT_EQ(0u, sync3->process_count); | 358 EXPECT_EQ(0u, sync3->process_count); |
358 EXPECT_EQ(0u, sync3->result); | 359 EXPECT_EQ(0u, sync3->result); |
359 EXPECT_TRUE(manager_->HavePendingQueries()); | 360 EXPECT_TRUE(manager_->HavePendingQueries()); |
360 | 361 |
361 // Process with renaming query. No result. | 362 // Process with renaming query. No result. |
362 // Expect 1 GL commands. | 363 // Expect 1 GL commands. |
363 EXPECT_CALL(*gl_, | 364 EXPECT_CALL(*gl_, |
364 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 365 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
365 .WillOnce(SetArgumentPointee<2>(0)) | 366 .WillOnce(SetArgumentPointee<2>(0)) |
366 .RetiresOnSaturation(); | 367 .RetiresOnSaturation(); |
367 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 368 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
368 EXPECT_TRUE(query3->pending()); | 369 EXPECT_TRUE(query3->pending()); |
369 EXPECT_EQ(0u, sync3->process_count); | 370 EXPECT_EQ(0u, sync3->process_count); |
370 EXPECT_EQ(0u, sync3->result); | 371 EXPECT_EQ(0u, sync3->result); |
371 EXPECT_TRUE(manager_->HavePendingQueries()); | 372 EXPECT_TRUE(manager_->HavePendingQueries()); |
372 | 373 |
373 // Process with renaming query. With result. | 374 // Process with renaming query. With result. |
374 // Expect 2 GL commands. | 375 // Expect 2 GL commands. |
375 EXPECT_CALL(*gl_, | 376 EXPECT_CALL(*gl_, |
376 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 377 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
377 .WillOnce(SetArgumentPointee<2>(1)) | 378 .WillOnce(SetArgumentPointee<2>(1)) |
378 .RetiresOnSaturation(); | 379 .RetiresOnSaturation(); |
379 EXPECT_CALL(*gl_, | 380 EXPECT_CALL(*gl_, |
380 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_EXT, _)) | 381 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_EXT, _)) |
381 .WillOnce(SetArgumentPointee<2>(kResult3)) | 382 .WillOnce(SetArgumentPointee<2>(kResult3)) |
382 .RetiresOnSaturation(); | 383 .RetiresOnSaturation(); |
383 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 384 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
384 EXPECT_FALSE(query3->pending()); | 385 EXPECT_FALSE(query3->pending()); |
385 EXPECT_EQ(kSubmitCount3, sync3->process_count); | 386 EXPECT_EQ(kSubmitCount3, sync3->process_count); |
386 EXPECT_EQ(kResult3, sync3->result); | 387 EXPECT_EQ(kResult3, sync3->result); |
387 EXPECT_FALSE(manager_->HavePendingQueries()); | 388 EXPECT_FALSE(manager_->HavePendingQueries()); |
388 } | 389 } |
389 | 390 |
390 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryId) { | 391 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryId) { |
391 const GLuint kClient1Id = 1; | 392 const GLuint kClient1Id = 1; |
392 const GLuint kService1Id = 11; | 393 const GLuint kService1Id = 11; |
393 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 394 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
394 const uint32 kSubmitCount = 123; | 395 const uint32 kSubmitCount = 123; |
395 const GLuint kResult = 456; | 396 const GLuint kResult = 456; |
396 | 397 |
397 // Create Query. | 398 // Create Query. |
398 QueryManager::Query::Ref query( | 399 QueryManager::Query::Ref query( |
399 manager_->CreateQuery(kClient1Id, kService1Id)); | 400 CreateQuery(kTarget, kClient1Id, |
| 401 kInvalidSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
400 ASSERT_TRUE(query.get() != NULL); | 402 ASSERT_TRUE(query.get() != NULL); |
401 query->Initialize(kTarget, kInvalidSharedMemoryId, kSharedMemoryOffset); | |
402 | 403 |
403 // Queue it | 404 // Queue it |
404 manager_->AddPendingQuery(query.get(), kSubmitCount); | 405 QueueQuery(query.get(), kService1Id, kSubmitCount); |
405 | 406 |
406 // Process with return available. | 407 // Process with return available. |
407 // Expect 2 GL commands. | 408 // Expect 2 GL commands. |
408 EXPECT_CALL(*gl_, | 409 EXPECT_CALL(*gl_, |
409 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 410 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
410 .WillOnce(SetArgumentPointee<2>(1)) | 411 .WillOnce(SetArgumentPointee<2>(1)) |
411 .RetiresOnSaturation(); | 412 .RetiresOnSaturation(); |
412 EXPECT_CALL(*gl_, | 413 EXPECT_CALL(*gl_, |
413 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) | 414 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) |
414 .WillOnce(SetArgumentPointee<2>(kResult)) | 415 .WillOnce(SetArgumentPointee<2>(kResult)) |
415 .RetiresOnSaturation(); | 416 .RetiresOnSaturation(); |
416 EXPECT_FALSE(manager_->ProcessPendingQueries(decoder_.get())); | 417 EXPECT_FALSE(manager_->ProcessPendingQueries()); |
417 } | 418 } |
418 | 419 |
419 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryOffset) { | 420 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryOffset) { |
420 const GLuint kClient1Id = 1; | 421 const GLuint kClient1Id = 1; |
421 const GLuint kService1Id = 11; | 422 const GLuint kService1Id = 11; |
422 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 423 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
423 const uint32 kSubmitCount = 123; | 424 const uint32 kSubmitCount = 123; |
424 const GLuint kResult = 456; | 425 const GLuint kResult = 456; |
425 | 426 |
426 // Create Query. | 427 // Create Query. |
427 QueryManager::Query::Ref query( | 428 QueryManager::Query::Ref query( |
428 manager_->CreateQuery(kClient1Id, kService1Id)); | 429 CreateQuery(kTarget, kClient1Id, |
| 430 kSharedMemoryId, kInvalidSharedMemoryOffset, kService1Id)); |
429 ASSERT_TRUE(query.get() != NULL); | 431 ASSERT_TRUE(query.get() != NULL); |
430 query->Initialize(kTarget, kSharedMemoryId, kInvalidSharedMemoryOffset); | |
431 | 432 |
432 // Queue it | 433 // Queue it |
433 manager_->AddPendingQuery(query.get(), kSubmitCount); | 434 QueueQuery(query.get(), kService1Id, kSubmitCount); |
434 | 435 |
435 // Process with return available. | 436 // Process with return available. |
436 // Expect 2 GL commands. | 437 // Expect 2 GL commands. |
437 EXPECT_CALL(*gl_, | 438 EXPECT_CALL(*gl_, |
438 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 439 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
439 .WillOnce(SetArgumentPointee<2>(1)) | 440 .WillOnce(SetArgumentPointee<2>(1)) |
440 .RetiresOnSaturation(); | 441 .RetiresOnSaturation(); |
441 EXPECT_CALL(*gl_, | 442 EXPECT_CALL(*gl_, |
442 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) | 443 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) |
443 .WillOnce(SetArgumentPointee<2>(kResult)) | 444 .WillOnce(SetArgumentPointee<2>(kResult)) |
444 .RetiresOnSaturation(); | 445 .RetiresOnSaturation(); |
445 EXPECT_FALSE(manager_->ProcessPendingQueries(decoder_.get())); | 446 EXPECT_FALSE(manager_->ProcessPendingQueries()); |
446 } | 447 } |
447 | 448 |
448 TEST_F(QueryManagerTest, ExitWithPendingQuery) { | 449 TEST_F(QueryManagerTest, ExitWithPendingQuery) { |
449 const GLuint kClient1Id = 1; | 450 const GLuint kClient1Id = 1; |
450 const GLuint kService1Id = 11; | 451 const GLuint kService1Id = 11; |
451 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 452 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
452 const uint32 kSubmitCount = 123; | 453 const uint32 kSubmitCount = 123; |
453 | 454 |
454 // Create Query. | 455 // Create Query. |
455 QueryManager::Query::Ref query( | 456 QueryManager::Query::Ref query( |
456 manager_->CreateQuery(kClient1Id, kService1Id)); | 457 CreateQuery(kTarget, kClient1Id, |
| 458 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
457 ASSERT_TRUE(query.get() != NULL); | 459 ASSERT_TRUE(query.get() != NULL); |
458 query->Initialize(kTarget, kSharedMemoryId, kSharedMemoryOffset); | |
459 | 460 |
460 // Queue it | 461 // Queue it |
461 manager_->AddPendingQuery(query.get(), kSubmitCount); | 462 QueueQuery(query.get(), kService1Id, kSubmitCount); |
| 463 } |
| 464 |
| 465 TEST_F(QueryManagerTest, ARBOcclusionQuery2) { |
| 466 const GLuint kClient1Id = 1; |
| 467 const GLuint kService1Id = 11; |
| 468 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT; |
| 469 const uint32 kSubmitCount = 123; |
| 470 |
| 471 scoped_ptr<QueryManager> manager(new QueryManager(decoder_.get(), true)); |
| 472 |
| 473 EXPECT_CALL(*gl_, GenQueriesARB(1, _)) |
| 474 .WillOnce(SetArgumentPointee<1>(kService1Id)) |
| 475 .RetiresOnSaturation(); |
| 476 QueryManager::Query* query = manager->CreateQuery( |
| 477 kTarget, kClient1Id, kSharedMemoryId, kSharedMemoryOffset); |
| 478 ASSERT_TRUE(query != NULL); |
| 479 |
| 480 EXPECT_CALL(*gl_, BeginQueryARB(GL_ANY_SAMPLES_PASSED_EXT, kService1Id)) |
| 481 .Times(1) |
| 482 .RetiresOnSaturation(); |
| 483 EXPECT_CALL(*gl_, EndQueryARB(GL_ANY_SAMPLES_PASSED_EXT)) |
| 484 .Times(1) |
| 485 .RetiresOnSaturation(); |
| 486 EXPECT_TRUE(manager->BeginQuery(query)); |
| 487 EXPECT_TRUE(manager->EndQuery(query, kSubmitCount)); |
| 488 manager->Destroy(false); |
462 } | 489 } |
463 | 490 |
464 } // namespace gles2 | 491 } // namespace gles2 |
465 } // namespace gpu | 492 } // namespace gpu |
466 | 493 |
467 | 494 |
OLD | NEW |