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 "gpu/command_buffer/service/feature_info.h" |
| 11 #include "gpu/command_buffer/service/test_helper.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
12 using ::testing::_; | 14 using ::testing::_; |
13 using ::testing::InSequence; | 15 using ::testing::InSequence; |
14 using ::testing::SetArgumentPointee; | 16 using ::testing::SetArgumentPointee; |
15 | 17 |
16 namespace gpu { | 18 namespace gpu { |
17 namespace gles2 { | 19 namespace gles2 { |
18 | 20 |
19 class MockDecoder : public CommonDecoder { | 21 class MockDecoder : public CommonDecoder { |
(...skipping 21 matching lines...) Expand all Loading... |
41 ~QueryManagerTest() { | 43 ~QueryManagerTest() { |
42 } | 44 } |
43 | 45 |
44 protected: | 46 protected: |
45 virtual void SetUp() { | 47 virtual void SetUp() { |
46 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 48 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
47 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 49 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
48 engine_.reset(new MockCommandBufferEngine()); | 50 engine_.reset(new MockCommandBufferEngine()); |
49 decoder_.reset(new MockDecoder()); | 51 decoder_.reset(new MockDecoder()); |
50 decoder_->set_engine(engine_.get()); | 52 decoder_->set_engine(engine_.get()); |
51 manager_.reset(new QueryManager(decoder_.get(), false)); | 53 TestHelper::SetupFeatureInfoInitExpectations( |
| 54 gl_.get(), |
| 55 "GL_EXT_occlusion_query_boolean"); |
| 56 FeatureInfo::Ref feature_info(new FeatureInfo()); |
| 57 feature_info->Initialize("*"); |
| 58 manager_.reset(new QueryManager(decoder_.get(), feature_info.get())); |
52 } | 59 } |
53 | 60 |
54 virtual void TearDown() { | 61 virtual void TearDown() { |
55 decoder_.reset(); | 62 decoder_.reset(); |
56 manager_->Destroy(false); | 63 manager_->Destroy(false); |
57 manager_.reset(); | 64 manager_.reset(); |
58 engine_.reset(); | 65 engine_.reset(); |
59 ::gfx::GLInterface::SetGLInterface(NULL); | 66 ::gfx::GLInterface::SetGLInterface(NULL); |
60 gl_.reset(); | 67 gl_.reset(); |
61 } | 68 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 EXPECT_EQ(kTarget, query->target()); | 215 EXPECT_EQ(kTarget, query->target()); |
209 EXPECT_EQ(kSharedMemoryId, query->shm_id()); | 216 EXPECT_EQ(kSharedMemoryId, query->shm_id()); |
210 EXPECT_EQ(kSharedMemoryOffset, query->shm_offset()); | 217 EXPECT_EQ(kSharedMemoryOffset, query->shm_offset()); |
211 } | 218 } |
212 | 219 |
213 TEST_F(QueryManagerTest, ProcessPendingQuery) { | 220 TEST_F(QueryManagerTest, ProcessPendingQuery) { |
214 const GLuint kClient1Id = 1; | 221 const GLuint kClient1Id = 1; |
215 const GLuint kService1Id = 11; | 222 const GLuint kService1Id = 11; |
216 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 223 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
217 const uint32 kSubmitCount = 123; | 224 const uint32 kSubmitCount = 123; |
218 const GLuint kResult = 456; | 225 const GLuint kResult = 1; |
219 | 226 |
220 // Check nothing happens if there are no pending queries. | 227 // Check nothing happens if there are no pending queries. |
221 EXPECT_TRUE(manager_->ProcessPendingQueries()); | 228 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
222 | 229 |
223 // Create Query. | 230 // Create Query. |
224 QueryManager::Query::Ref query( | 231 QueryManager::Query::Ref query( |
225 CreateQuery(kTarget, kClient1Id, | 232 CreateQuery(kTarget, kClient1Id, |
226 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); | 233 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
227 ASSERT_TRUE(query.get() != NULL); | 234 ASSERT_TRUE(query.get() != NULL); |
228 | 235 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 const GLuint kClient1Id = 1; | 280 const GLuint kClient1Id = 1; |
274 const GLuint kService1Id = 11; | 281 const GLuint kService1Id = 11; |
275 const GLuint kClient2Id = 2; | 282 const GLuint kClient2Id = 2; |
276 const GLuint kService2Id = 12; | 283 const GLuint kService2Id = 12; |
277 const GLuint kClient3Id = 3; | 284 const GLuint kClient3Id = 3; |
278 const GLuint kService3Id = 13; | 285 const GLuint kService3Id = 13; |
279 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 286 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
280 const uint32 kSubmitCount1 = 123; | 287 const uint32 kSubmitCount1 = 123; |
281 const uint32 kSubmitCount2 = 123; | 288 const uint32 kSubmitCount2 = 123; |
282 const uint32 kSubmitCount3 = 123; | 289 const uint32 kSubmitCount3 = 123; |
283 const GLuint kResult1 = 456; | 290 const GLuint kResult1 = 1; |
284 const GLuint kResult2 = 457; | 291 const GLuint kResult2 = 1; |
285 const GLuint kResult3 = 458; | 292 const GLuint kResult3 = 1; |
286 | 293 |
287 // Setup shared memory like client would. | 294 // Setup shared memory like client would. |
288 QuerySync* sync1 = decoder_->GetSharedMemoryAs<QuerySync*>( | 295 QuerySync* sync1 = decoder_->GetSharedMemoryAs<QuerySync*>( |
289 kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync1) * 3); | 296 kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync1) * 3); |
290 ASSERT_TRUE(sync1 != NULL); | 297 ASSERT_TRUE(sync1 != NULL); |
291 QuerySync* sync2 = sync1 + 1; | 298 QuerySync* sync2 = sync1 + 1; |
292 QuerySync* sync3 = sync2 + 1; | 299 QuerySync* sync3 = sync2 + 1; |
293 | 300 |
294 // Create Queries. | 301 // Create Queries. |
295 QueryManager::Query::Ref query1( | 302 QueryManager::Query::Ref query1( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 EXPECT_EQ(kSubmitCount3, sync3->process_count); | 393 EXPECT_EQ(kSubmitCount3, sync3->process_count); |
387 EXPECT_EQ(kResult3, sync3->result); | 394 EXPECT_EQ(kResult3, sync3->result); |
388 EXPECT_FALSE(manager_->HavePendingQueries()); | 395 EXPECT_FALSE(manager_->HavePendingQueries()); |
389 } | 396 } |
390 | 397 |
391 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryId) { | 398 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryId) { |
392 const GLuint kClient1Id = 1; | 399 const GLuint kClient1Id = 1; |
393 const GLuint kService1Id = 11; | 400 const GLuint kService1Id = 11; |
394 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 401 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
395 const uint32 kSubmitCount = 123; | 402 const uint32 kSubmitCount = 123; |
396 const GLuint kResult = 456; | 403 const GLuint kResult = 1; |
397 | 404 |
398 // Create Query. | 405 // Create Query. |
399 QueryManager::Query::Ref query( | 406 QueryManager::Query::Ref query( |
400 CreateQuery(kTarget, kClient1Id, | 407 CreateQuery(kTarget, kClient1Id, |
401 kInvalidSharedMemoryId, kSharedMemoryOffset, kService1Id)); | 408 kInvalidSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
402 ASSERT_TRUE(query.get() != NULL); | 409 ASSERT_TRUE(query.get() != NULL); |
403 | 410 |
404 // Queue it | 411 // Queue it |
405 QueueQuery(query.get(), kService1Id, kSubmitCount); | 412 QueueQuery(query.get(), kService1Id, kSubmitCount); |
406 | 413 |
407 // Process with return available. | 414 // Process with return available. |
408 // Expect 2 GL commands. | 415 // Expect 2 GL commands. |
409 EXPECT_CALL(*gl_, | 416 EXPECT_CALL(*gl_, |
410 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 417 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
411 .WillOnce(SetArgumentPointee<2>(1)) | 418 .WillOnce(SetArgumentPointee<2>(1)) |
412 .RetiresOnSaturation(); | 419 .RetiresOnSaturation(); |
413 EXPECT_CALL(*gl_, | 420 EXPECT_CALL(*gl_, |
414 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) | 421 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) |
415 .WillOnce(SetArgumentPointee<2>(kResult)) | 422 .WillOnce(SetArgumentPointee<2>(kResult)) |
416 .RetiresOnSaturation(); | 423 .RetiresOnSaturation(); |
417 EXPECT_FALSE(manager_->ProcessPendingQueries()); | 424 EXPECT_FALSE(manager_->ProcessPendingQueries()); |
418 } | 425 } |
419 | 426 |
420 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryOffset) { | 427 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryOffset) { |
421 const GLuint kClient1Id = 1; | 428 const GLuint kClient1Id = 1; |
422 const GLuint kService1Id = 11; | 429 const GLuint kService1Id = 11; |
423 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 430 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
424 const uint32 kSubmitCount = 123; | 431 const uint32 kSubmitCount = 123; |
425 const GLuint kResult = 456; | 432 const GLuint kResult = 1; |
426 | 433 |
427 // Create Query. | 434 // Create Query. |
428 QueryManager::Query::Ref query( | 435 QueryManager::Query::Ref query( |
429 CreateQuery(kTarget, kClient1Id, | 436 CreateQuery(kTarget, kClient1Id, |
430 kSharedMemoryId, kInvalidSharedMemoryOffset, kService1Id)); | 437 kSharedMemoryId, kInvalidSharedMemoryOffset, kService1Id)); |
431 ASSERT_TRUE(query.get() != NULL); | 438 ASSERT_TRUE(query.get() != NULL); |
432 | 439 |
433 // Queue it | 440 // Queue it |
434 QueueQuery(query.get(), kService1Id, kSubmitCount); | 441 QueueQuery(query.get(), kService1Id, kSubmitCount); |
435 | 442 |
(...skipping 25 matching lines...) Expand all Loading... |
461 // Queue it | 468 // Queue it |
462 QueueQuery(query.get(), kService1Id, kSubmitCount); | 469 QueueQuery(query.get(), kService1Id, kSubmitCount); |
463 } | 470 } |
464 | 471 |
465 TEST_F(QueryManagerTest, ARBOcclusionQuery2) { | 472 TEST_F(QueryManagerTest, ARBOcclusionQuery2) { |
466 const GLuint kClient1Id = 1; | 473 const GLuint kClient1Id = 1; |
467 const GLuint kService1Id = 11; | 474 const GLuint kService1Id = 11; |
468 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT; | 475 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT; |
469 const uint32 kSubmitCount = 123; | 476 const uint32 kSubmitCount = 123; |
470 | 477 |
471 scoped_ptr<QueryManager> manager(new QueryManager(decoder_.get(), true)); | 478 TestHelper::SetupFeatureInfoInitExpectations( |
| 479 gl_.get(), |
| 480 "GL_ARB_occlusion_query2"); |
| 481 FeatureInfo::Ref feature_info(new FeatureInfo()); |
| 482 feature_info->Initialize("*"); |
| 483 scoped_ptr<QueryManager> manager( |
| 484 new QueryManager(decoder_.get(), feature_info.get())); |
472 | 485 |
473 EXPECT_CALL(*gl_, GenQueriesARB(1, _)) | 486 EXPECT_CALL(*gl_, GenQueriesARB(1, _)) |
474 .WillOnce(SetArgumentPointee<1>(kService1Id)) | 487 .WillOnce(SetArgumentPointee<1>(kService1Id)) |
475 .RetiresOnSaturation(); | 488 .RetiresOnSaturation(); |
476 QueryManager::Query* query = manager->CreateQuery( | 489 QueryManager::Query* query = manager->CreateQuery( |
477 kTarget, kClient1Id, kSharedMemoryId, kSharedMemoryOffset); | 490 kTarget, kClient1Id, kSharedMemoryId, kSharedMemoryOffset); |
478 ASSERT_TRUE(query != NULL); | 491 ASSERT_TRUE(query != NULL); |
479 | 492 |
480 EXPECT_CALL(*gl_, BeginQueryARB(GL_ANY_SAMPLES_PASSED_EXT, kService1Id)) | 493 EXPECT_CALL(*gl_, BeginQueryARB(GL_ANY_SAMPLES_PASSED_EXT, kService1Id)) |
481 .Times(1) | 494 .Times(1) |
482 .RetiresOnSaturation(); | 495 .RetiresOnSaturation(); |
483 EXPECT_CALL(*gl_, EndQueryARB(GL_ANY_SAMPLES_PASSED_EXT)) | 496 EXPECT_CALL(*gl_, EndQueryARB(GL_ANY_SAMPLES_PASSED_EXT)) |
484 .Times(1) | 497 .Times(1) |
485 .RetiresOnSaturation(); | 498 .RetiresOnSaturation(); |
486 EXPECT_TRUE(manager->BeginQuery(query)); | 499 EXPECT_TRUE(manager->BeginQuery(query)); |
487 EXPECT_TRUE(manager->EndQuery(query, kSubmitCount)); | 500 EXPECT_TRUE(manager->EndQuery(query, kSubmitCount)); |
488 manager->Destroy(false); | 501 manager->Destroy(false); |
489 } | 502 } |
490 | 503 |
| 504 TEST_F(QueryManagerTest, ARBOcclusionQuery) { |
| 505 const GLuint kClient1Id = 1; |
| 506 const GLuint kService1Id = 11; |
| 507 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
| 508 const uint32 kSubmitCount = 123; |
| 509 |
| 510 TestHelper::SetupFeatureInfoInitExpectations( |
| 511 gl_.get(), |
| 512 "GL_ARB_occlusion_query"); |
| 513 FeatureInfo::Ref feature_info(new FeatureInfo()); |
| 514 feature_info->Initialize("*"); |
| 515 scoped_ptr<QueryManager> manager( |
| 516 new QueryManager(decoder_.get(), feature_info.get())); |
| 517 |
| 518 EXPECT_CALL(*gl_, GenQueriesARB(1, _)) |
| 519 .WillOnce(SetArgumentPointee<1>(kService1Id)) |
| 520 .RetiresOnSaturation(); |
| 521 QueryManager::Query* query = manager->CreateQuery( |
| 522 kTarget, kClient1Id, kSharedMemoryId, kSharedMemoryOffset); |
| 523 ASSERT_TRUE(query != NULL); |
| 524 |
| 525 EXPECT_CALL(*gl_, BeginQueryARB(GL_SAMPLES_PASSED_ARB, kService1Id)) |
| 526 .Times(1) |
| 527 .RetiresOnSaturation(); |
| 528 EXPECT_CALL(*gl_, EndQueryARB(GL_SAMPLES_PASSED_ARB)) |
| 529 .Times(1) |
| 530 .RetiresOnSaturation(); |
| 531 EXPECT_TRUE(manager->BeginQuery(query)); |
| 532 EXPECT_TRUE(manager->EndQuery(query, kSubmitCount)); |
| 533 manager->Destroy(false); |
| 534 } |
| 535 |
491 } // namespace gles2 | 536 } // namespace gles2 |
492 } // namespace gpu | 537 } // namespace gpu |
493 | 538 |
494 | 539 |
OLD | NEW |