Home | History | Annotate | Download | only in service
      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
      3 // found in the LICENSE file.
      4 
      5 #include "gpu/command_buffer/service/query_manager.h"
      6 #include "gpu/command_buffer/common/gles2_cmd_format.h"
      7 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
      8 #include "gpu/command_buffer/service/error_state_mock.h"
      9 #include "gpu/command_buffer/service/feature_info.h"
     10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
     11 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
     12 #include "gpu/command_buffer/service/gpu_service_test.h"
     13 #include "gpu/command_buffer/service/test_helper.h"
     14 #include "testing/gtest/include/gtest/gtest.h"
     15 #include "ui/gl/gl_mock.h"
     16 
     17 using ::testing::_;
     18 using ::testing::InSequence;
     19 using ::testing::Return;
     20 using ::testing::SetArgumentPointee;
     21 
     22 namespace gpu {
     23 namespace gles2 {
     24 
     25 class QueryManagerTest : public GpuServiceTest {
     26  public:
     27   static const int32 kSharedMemoryId = 401;
     28   static const size_t kSharedBufferSize = 2048;
     29   static const uint32 kSharedMemoryOffset = 132;
     30   static const int32 kInvalidSharedMemoryId = 402;
     31   static const uint32 kInvalidSharedMemoryOffset = kSharedBufferSize + 1;
     32   static const uint32 kInitialResult = 0xBDBDBDBDu;
     33   static const uint8 kInitialMemoryValue = 0xBDu;
     34 
     35   QueryManagerTest() {
     36   }
     37   virtual ~QueryManagerTest() {
     38   }
     39 
     40  protected:
     41   virtual void SetUp() {
     42     GpuServiceTest::SetUp();
     43     engine_.reset(new MockCommandBufferEngine());
     44     decoder_.reset(new MockGLES2Decoder());
     45     decoder_->set_engine(engine_.get());
     46     TestHelper::SetupFeatureInfoInitExpectations(
     47         gl_.get(),
     48         "GL_EXT_occlusion_query_boolean");
     49     scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
     50     feature_info->Initialize();
     51     manager_.reset(new QueryManager(decoder_.get(), feature_info.get()));
     52   }
     53 
     54   virtual void TearDown() {
     55     decoder_.reset();
     56     manager_->Destroy(false);
     57     manager_.reset();
     58     engine_.reset();
     59     GpuServiceTest::TearDown();
     60   }
     61 
     62   QueryManager::Query* CreateQuery(
     63       GLenum target, GLuint client_id, int32 shm_id, uint32 shm_offset,
     64       GLuint service_id) {
     65     EXPECT_CALL(*gl_, GenQueriesARB(1, _))
     66        .WillOnce(SetArgumentPointee<1>(service_id))
     67        .RetiresOnSaturation();
     68     return manager_->CreateQuery(target, client_id, shm_id, shm_offset);
     69   }
     70 
     71   void QueueQuery(QueryManager::Query* query,
     72                   GLuint service_id,
     73                   base::subtle::Atomic32 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 
     84   scoped_ptr<MockGLES2Decoder> decoder_;
     85   scoped_ptr<QueryManager> manager_;
     86 
     87  private:
     88   class MockCommandBufferEngine : public CommandBufferEngine {
     89    public:
     90     MockCommandBufferEngine() {
     91       scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
     92       shared_memory->CreateAndMapAnonymous(kSharedBufferSize);
     93       valid_buffer_ =
     94           MakeBufferFromSharedMemory(shared_memory.Pass(), kSharedBufferSize);
     95       data_ = static_cast<uint8*>(valid_buffer_->memory());
     96       ClearSharedMemory();
     97     }
     98 
     99     virtual ~MockCommandBufferEngine() {
    100     }
    101 
    102     virtual scoped_refptr<gpu::Buffer> GetSharedMemoryBuffer(int32 shm_id)
    103         OVERRIDE {
    104       return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_;
    105     }
    106 
    107     void ClearSharedMemory() {
    108       memset(data_, kInitialMemoryValue, kSharedBufferSize);
    109     }
    110 
    111     virtual void set_token(int32 token) OVERRIDE {
    112       DCHECK(false);
    113     }
    114 
    115     virtual bool SetGetBuffer(int32 /* transfer_buffer_id */) OVERRIDE {
    116       DCHECK(false);
    117       return false;
    118     }
    119 
    120     // Overridden from CommandBufferEngine.
    121     virtual bool SetGetOffset(int32 offset) OVERRIDE {
    122       DCHECK(false);
    123       return false;
    124     }
    125 
    126     // Overridden from CommandBufferEngine.
    127     virtual int32 GetGetOffset() OVERRIDE {
    128       DCHECK(false);
    129       return 0;
    130     }
    131 
    132    private:
    133     uint8* data_;
    134     scoped_refptr<gpu::Buffer> valid_buffer_;
    135     scoped_refptr<gpu::Buffer> invalid_buffer_;
    136   };
    137 
    138   scoped_ptr<MockCommandBufferEngine> engine_;
    139 };
    140 
    141 // GCC requires these declarations, but MSVC requires they not be present
    142 #ifndef COMPILER_MSVC
    143 const int32 QueryManagerTest::kSharedMemoryId;
    144 const size_t QueryManagerTest::kSharedBufferSize;
    145 const uint32 QueryManagerTest::kSharedMemoryOffset;
    146 const int32 QueryManagerTest::kInvalidSharedMemoryId;
    147 const uint32 QueryManagerTest::kInvalidSharedMemoryOffset;
    148 const uint32 QueryManagerTest::kInitialResult;
    149 const uint8 QueryManagerTest::kInitialMemoryValue;
    150 #endif
    151 
    152 TEST_F(QueryManagerTest, Basic) {
    153   const GLuint kClient1Id = 1;
    154   const GLuint kService1Id = 11;
    155   const GLuint kClient2Id = 2;
    156 
    157   EXPECT_FALSE(manager_->HavePendingQueries());
    158   // Check we can create a Query.
    159   scoped_refptr<QueryManager::Query> query(
    160       CreateQuery(GL_ANY_SAMPLES_PASSED_EXT, kClient1Id,
    161                   kSharedMemoryId, kSharedMemoryOffset, kService1Id));
    162   ASSERT_TRUE(query.get() != NULL);
    163   // Check we can get the same Query.
    164   EXPECT_EQ(query.get(), manager_->GetQuery(kClient1Id));
    165   // Check we get nothing for a non-existent query.
    166   EXPECT_TRUE(manager_->GetQuery(kClient2Id) == NULL);
    167   // Check we can delete the query.
    168   manager_->RemoveQuery(kClient1Id);
    169   // Check we get nothing for a non-existent query.
    170   EXPECT_TRUE(manager_->GetQuery(kClient1Id) == NULL);
    171   // Check query is deleted
    172   EXPECT_TRUE(query->IsDeleted());
    173   EXPECT_FALSE(manager_->HavePendingQueries());
    174 }
    175 
    176 TEST_F(QueryManagerTest, Destroy) {
    177   const GLuint kClient1Id = 1;
    178   const GLuint kService1Id = 11;
    179 
    180   // Create Query.
    181   scoped_refptr<QueryManager::Query> query(
    182       CreateQuery(GL_ANY_SAMPLES_PASSED_EXT, kClient1Id,
    183                   kSharedMemoryId, kSharedMemoryOffset, kService1Id));
    184   ASSERT_TRUE(query.get() != NULL);
    185   EXPECT_CALL(*gl_, DeleteQueriesARB(1, ::testing::Pointee(kService1Id)))
    186       .Times(1)
    187       .RetiresOnSaturation();
    188   manager_->Destroy(true);
    189   // Check we get nothing for a non-existent query.
    190   EXPECT_TRUE(manager_->GetQuery(kClient1Id) == NULL);
    191   // Check query is deleted
    192   EXPECT_TRUE(query->IsDeleted());
    193 }
    194 
    195 TEST_F(QueryManagerTest, QueryBasic) {
    196   const GLuint kClient1Id = 1;
    197   const GLuint kService1Id = 11;
    198   const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT;
    199 
    200   // Create Query.
    201   scoped_refptr<QueryManager::Query> query(
    202       CreateQuery(kTarget, kClient1Id,
    203                   kSharedMemoryId, kSharedMemoryOffset, kService1Id));
    204   ASSERT_TRUE(query.get() != NULL);
    205 
    206   EXPECT_TRUE(query->IsValid());
    207   EXPECT_FALSE(query->IsDeleted());
    208   EXPECT_FALSE(query->pending());
    209   EXPECT_EQ(kTarget, query->target());
    210   EXPECT_EQ(kSharedMemoryId, query->shm_id());
    211   EXPECT_EQ(kSharedMemoryOffset, query->shm_offset());
    212 }
    213 
    214 TEST_F(QueryManagerTest, ProcessPendingQuery) {
    215   const GLuint kClient1Id = 1;
    216   const GLuint kService1Id = 11;
    217   const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT;
    218   const base::subtle::Atomic32 kSubmitCount = 123;
    219   const GLuint kResult = 1;
    220 
    221   // Check nothing happens if there are no pending queries.
    222   EXPECT_TRUE(manager_->ProcessPendingQueries());
    223 
    224   // Create Query.
    225   scoped_refptr<QueryManager::Query> query(
    226       CreateQuery(kTarget, kClient1Id,
    227                   kSharedMemoryId, kSharedMemoryOffset, kService1Id));
    228   ASSERT_TRUE(query.get() != NULL);
    229 
    230   // Setup shared memory like client would.
    231   QuerySync* sync = decoder_->GetSharedMemoryAs<QuerySync*>(
    232       kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync));
    233   ASSERT_TRUE(sync != NULL);
    234   sync->Reset();
    235 
    236   // Queue it
    237   QueueQuery(query.get(), kService1Id, kSubmitCount);
    238   EXPECT_TRUE(query->pending());
    239   EXPECT_TRUE(manager_->HavePendingQueries());
    240 
    241   // Process with return not available.
    242   // Expect 1 GL command.
    243   EXPECT_CALL(*gl_,
    244       GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _))
    245       .WillOnce(SetArgumentPointee<2>(0))
    246       .RetiresOnSaturation();
    247   EXPECT_TRUE(manager_->ProcessPendingQueries());
    248   EXPECT_TRUE(query->pending());
    249   EXPECT_EQ(0, sync->process_count);
    250   EXPECT_EQ(0u, sync->result);
    251 
    252   // Process with return available.
    253   // Expect 2 GL commands.
    254   EXPECT_CALL(*gl_,
    255       GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _))
    256       .WillOnce(SetArgumentPointee<2>(1))
    257       .RetiresOnSaturation();
    258   EXPECT_CALL(*gl_,
    259       GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _))
    260       .WillOnce(SetArgumentPointee<2>(kResult))
    261       .RetiresOnSaturation();
    262   EXPECT_TRUE(manager_->ProcessPendingQueries());
    263   EXPECT_FALSE(query->pending());
    264   EXPECT_EQ(kSubmitCount, sync->process_count);
    265   EXPECT_EQ(kResult, sync->result);
    266   EXPECT_FALSE(manager_->HavePendingQueries());
    267 
    268   // Process with no queries.
    269   // Expect no GL commands/
    270   EXPECT_TRUE(manager_->ProcessPendingQueries());
    271 }
    272 
    273 TEST_F(QueryManagerTest, ProcessPendingQueries) {
    274   const GLuint kClient1Id = 1;
    275   const GLuint kService1Id = 11;
    276   const GLuint kClient2Id = 2;
    277   const GLuint kService2Id = 12;
    278   const GLuint kClient3Id = 3;
    279   const GLuint kService3Id = 13;
    280   const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT;
    281   const base::subtle::Atomic32 kSubmitCount1 = 123;
    282   const base::subtle::Atomic32 kSubmitCount2 = 123;
    283   const base::subtle::Atomic32 kSubmitCount3 = 123;
    284   const GLuint kResult1 = 1;
    285   const GLuint kResult2 = 1;
    286   const GLuint kResult3 = 1;
    287 
    288   // Setup shared memory like client would.
    289   QuerySync* sync1 = decoder_->GetSharedMemoryAs<QuerySync*>(
    290       kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync1) * 3);
    291   ASSERT_TRUE(sync1 != NULL);
    292   QuerySync* sync2 = sync1 + 1;
    293   QuerySync* sync3 = sync2 + 1;
    294 
    295   // Create Queries.
    296   scoped_refptr<QueryManager::Query> query1(
    297       CreateQuery(kTarget, kClient1Id,
    298                   kSharedMemoryId, kSharedMemoryOffset + sizeof(*sync1) * 0,
    299                   kService1Id));
    300   scoped_refptr<QueryManager::Query> query2(
    301       CreateQuery(kTarget, kClient2Id,
    302                   kSharedMemoryId, kSharedMemoryOffset + sizeof(*sync1) * 1,
    303                   kService2Id));
    304   scoped_refptr<QueryManager::Query> query3(
    305       CreateQuery(kTarget, kClient3Id,
    306                   kSharedMemoryId, kSharedMemoryOffset + sizeof(*sync1) * 2,
    307                   kService3Id));
    308   ASSERT_TRUE(query1.get() != NULL);
    309   ASSERT_TRUE(query2.get() != NULL);
    310   ASSERT_TRUE(query3.get() != NULL);
    311   EXPECT_FALSE(manager_->HavePendingQueries());
    312 
    313   sync1->Reset();
    314   sync2->Reset();
    315   sync3->Reset();
    316 
    317   // Queue them
    318   QueueQuery(query1.get(), kService1Id, kSubmitCount1);
    319   QueueQuery(query2.get(), kService2Id, kSubmitCount2);
    320   QueueQuery(query3.get(), kService3Id, kSubmitCount3);
    321   EXPECT_TRUE(query1->pending());
    322   EXPECT_TRUE(query2->pending());
    323   EXPECT_TRUE(query3->pending());
    324   EXPECT_TRUE(manager_->HavePendingQueries());
    325 
    326   // Process with return available for first 2 queries.
    327   // Expect 4 GL commands.
    328   {
    329     InSequence s;
    330     EXPECT_CALL(*gl_,
    331         GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _))
    332         .WillOnce(SetArgumentPointee<2>(1))
    333         .RetiresOnSaturation();
    334     EXPECT_CALL(*gl_,
    335         GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _))
    336         .WillOnce(SetArgumentPointee<2>(kResult1))
    337         .RetiresOnSaturation();
    338     EXPECT_CALL(*gl_,
    339         GetQueryObjectuivARB(kService2Id, GL_QUERY_RESULT_AVAILABLE_EXT, _))
    340         .WillOnce(SetArgumentPointee<2>(1))
    341         .RetiresOnSaturation();
    342     EXPECT_CALL(*gl_,
    343         GetQueryObjectuivARB(kService2Id, GL_QUERY_RESULT_EXT, _))
    344         .WillOnce(SetArgumentPointee<2>(kResult2))
    345         .RetiresOnSaturation();
    346     EXPECT_CALL(*gl_,
    347         GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _))
    348         .WillOnce(SetArgumentPointee<2>(0))
    349         .RetiresOnSaturation();
    350     EXPECT_TRUE(manager_->ProcessPendingQueries());
    351   }
    352   EXPECT_FALSE(query1->pending());
    353   EXPECT_FALSE(query2->pending());
    354   EXPECT_TRUE(query3->pending());
    355   EXPECT_EQ(kSubmitCount1, sync1->process_count);
    356   EXPECT_EQ(kSubmitCount2, sync2->process_count);
    357   EXPECT_EQ(kResult1, sync1->result);
    358   EXPECT_EQ(kResult2, sync2->result);
    359   EXPECT_EQ(0, sync3->process_count);
    360   EXPECT_EQ(0u, sync3->result);
    361   EXPECT_TRUE(manager_->HavePendingQueries());
    362 
    363   // Process with renaming query. No result.
    364   // Expect 1 GL commands.
    365   EXPECT_CALL(*gl_,
    366       GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _))
    367       .WillOnce(SetArgumentPointee<2>(0))
    368       .RetiresOnSaturation();
    369   EXPECT_TRUE(manager_->ProcessPendingQueries());
    370   EXPECT_TRUE(query3->pending());
    371   EXPECT_EQ(0, sync3->process_count);
    372   EXPECT_EQ(0u, sync3->result);
    373   EXPECT_TRUE(manager_->HavePendingQueries());
    374 
    375   // Process with renaming query. With result.
    376   // Expect 2 GL commands.
    377   EXPECT_CALL(*gl_,
    378       GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _))
    379       .WillOnce(SetArgumentPointee<2>(1))
    380       .RetiresOnSaturation();
    381   EXPECT_CALL(*gl_,
    382       GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_EXT, _))
    383       .WillOnce(SetArgumentPointee<2>(kResult3))
    384       .RetiresOnSaturation();
    385   EXPECT_TRUE(manager_->ProcessPendingQueries());
    386   EXPECT_FALSE(query3->pending());
    387   EXPECT_EQ(kSubmitCount3, sync3->process_count);
    388   EXPECT_EQ(kResult3, sync3->result);
    389   EXPECT_FALSE(manager_->HavePendingQueries());
    390 }
    391 
    392 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryId) {
    393   const GLuint kClient1Id = 1;
    394   const GLuint kService1Id = 11;
    395   const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT;
    396   const base::subtle::Atomic32 kSubmitCount = 123;
    397   const GLuint kResult = 1;
    398 
    399   // Create Query.
    400   scoped_refptr<QueryManager::Query> query(
    401       CreateQuery(kTarget, kClient1Id,
    402                   kInvalidSharedMemoryId, kSharedMemoryOffset, kService1Id));
    403   ASSERT_TRUE(query.get() != NULL);
    404 
    405   // Queue it
    406   QueueQuery(query.get(), kService1Id, kSubmitCount);
    407 
    408   // Process with return available.
    409   // Expect 2 GL commands.
    410   EXPECT_CALL(*gl_,
    411       GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _))
    412       .WillOnce(SetArgumentPointee<2>(1))
    413       .RetiresOnSaturation();
    414   EXPECT_CALL(*gl_,
    415       GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _))
    416       .WillOnce(SetArgumentPointee<2>(kResult))
    417       .RetiresOnSaturation();
    418   EXPECT_FALSE(manager_->ProcessPendingQueries());
    419 }
    420 
    421 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryOffset) {
    422   const GLuint kClient1Id = 1;
    423   const GLuint kService1Id = 11;
    424   const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT;
    425   const base::subtle::Atomic32 kSubmitCount = 123;
    426   const GLuint kResult = 1;
    427 
    428   // Create Query.
    429   scoped_refptr<QueryManager::Query> query(
    430       CreateQuery(kTarget, kClient1Id,
    431                   kSharedMemoryId, kInvalidSharedMemoryOffset, kService1Id));
    432   ASSERT_TRUE(query.get() != NULL);
    433 
    434   // Queue it
    435   QueueQuery(query.get(), kService1Id, kSubmitCount);
    436 
    437   // Process with return available.
    438   // Expect 2 GL commands.
    439   EXPECT_CALL(*gl_,
    440       GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _))
    441       .WillOnce(SetArgumentPointee<2>(1))
    442       .RetiresOnSaturation();
    443   EXPECT_CALL(*gl_,
    444       GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _))
    445       .WillOnce(SetArgumentPointee<2>(kResult))
    446       .RetiresOnSaturation();
    447   EXPECT_FALSE(manager_->ProcessPendingQueries());
    448 }
    449 
    450 TEST_F(QueryManagerTest, ExitWithPendingQuery) {
    451   const GLuint kClient1Id = 1;
    452   const GLuint kService1Id = 11;
    453   const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT;
    454   const base::subtle::Atomic32 kSubmitCount = 123;
    455 
    456   // Create Query.
    457   scoped_refptr<QueryManager::Query> query(
    458       CreateQuery(kTarget, kClient1Id,
    459                   kSharedMemoryId, kSharedMemoryOffset, kService1Id));
    460   ASSERT_TRUE(query.get() != NULL);
    461 
    462   // Queue it
    463   QueueQuery(query.get(), kService1Id, kSubmitCount);
    464 }
    465 
    466 // Test that when based on ARB_occlusion_query2 we use GL_ANY_SAMPLES_PASSED_ARB
    467 // for GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT
    468 TEST_F(QueryManagerTest, ARBOcclusionQuery2) {
    469   const GLuint kClient1Id = 1;
    470   const GLuint kService1Id = 11;
    471   const GLenum kTarget = GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT;
    472   const base::subtle::Atomic32 kSubmitCount = 123;
    473 
    474   TestHelper::SetupFeatureInfoInitExpectations(
    475       gl_.get(),
    476       "GL_ARB_occlusion_query2");
    477   scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
    478   feature_info->Initialize();
    479   scoped_ptr<QueryManager> manager(
    480       new QueryManager(decoder_.get(), feature_info.get()));
    481 
    482   EXPECT_CALL(*gl_, GenQueriesARB(1, _))
    483      .WillOnce(SetArgumentPointee<1>(kService1Id))
    484      .RetiresOnSaturation();
    485   QueryManager::Query* query = manager->CreateQuery(
    486       kTarget, kClient1Id, kSharedMemoryId, kSharedMemoryOffset);
    487   ASSERT_TRUE(query != NULL);
    488 
    489   EXPECT_CALL(*gl_, BeginQueryARB(GL_ANY_SAMPLES_PASSED_EXT, kService1Id))
    490       .Times(1)
    491       .RetiresOnSaturation();
    492   EXPECT_CALL(*gl_, EndQueryARB(GL_ANY_SAMPLES_PASSED_EXT))
    493       .Times(1)
    494       .RetiresOnSaturation();
    495   EXPECT_TRUE(manager->BeginQuery(query));
    496   EXPECT_TRUE(manager->EndQuery(query, kSubmitCount));
    497   manager->Destroy(false);
    498 }
    499 
    500 // Test that when based on ARB_occlusion_query we use GL_SAMPLES_PASSED_ARB
    501 // for GL_ANY_SAMPLES_PASSED_EXT
    502 TEST_F(QueryManagerTest, ARBOcclusionQuery) {
    503   const GLuint kClient1Id = 1;
    504   const GLuint kService1Id = 11;
    505   const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT;
    506   const base::subtle::Atomic32 kSubmitCount = 123;
    507 
    508   TestHelper::SetupFeatureInfoInitExpectations(
    509       gl_.get(),
    510       "GL_ARB_occlusion_query");
    511   scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
    512   feature_info->Initialize();
    513   scoped_ptr<QueryManager> manager(
    514       new QueryManager(decoder_.get(), feature_info.get()));
    515 
    516   EXPECT_CALL(*gl_, GenQueriesARB(1, _))
    517      .WillOnce(SetArgumentPointee<1>(kService1Id))
    518      .RetiresOnSaturation();
    519   QueryManager::Query* query = manager->CreateQuery(
    520       kTarget, kClient1Id, kSharedMemoryId, kSharedMemoryOffset);
    521   ASSERT_TRUE(query != NULL);
    522 
    523   EXPECT_CALL(*gl_, BeginQueryARB(GL_SAMPLES_PASSED_ARB, kService1Id))
    524       .Times(1)
    525       .RetiresOnSaturation();
    526   EXPECT_CALL(*gl_, EndQueryARB(GL_SAMPLES_PASSED_ARB))
    527       .Times(1)
    528       .RetiresOnSaturation();
    529   EXPECT_TRUE(manager->BeginQuery(query));
    530   EXPECT_TRUE(manager->EndQuery(query, kSubmitCount));
    531   manager->Destroy(false);
    532 }
    533 
    534 TEST_F(QueryManagerTest, GetErrorQuery) {
    535   const GLuint kClient1Id = 1;
    536   const GLenum kTarget = GL_GET_ERROR_QUERY_CHROMIUM;
    537   const base::subtle::Atomic32 kSubmitCount = 123;
    538 
    539   TestHelper::SetupFeatureInfoInitExpectations(gl_.get(), "");
    540   scoped_refptr<FeatureInfo> feature_info(new FeatureInfo());
    541   feature_info->Initialize();
    542   scoped_ptr<QueryManager> manager(
    543       new QueryManager(decoder_.get(), feature_info.get()));
    544 
    545   QueryManager::Query* query = manager->CreateQuery(
    546       kTarget, kClient1Id, kSharedMemoryId, kSharedMemoryOffset);
    547   ASSERT_TRUE(query != NULL);
    548 
    549   // Setup shared memory like client would.
    550   QuerySync* sync = decoder_->GetSharedMemoryAs<QuerySync*>(
    551       kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync));
    552   ASSERT_TRUE(sync != NULL);
    553   sync->Reset();
    554 
    555   EXPECT_TRUE(manager->BeginQuery(query));
    556 
    557   MockErrorState mock_error_state;
    558   EXPECT_CALL(*decoder_.get(), GetErrorState())
    559       .WillRepeatedly(Return(&mock_error_state));
    560   EXPECT_CALL(mock_error_state, GetGLError())
    561       .WillOnce(Return(GL_INVALID_ENUM))
    562       .RetiresOnSaturation();
    563 
    564   EXPECT_TRUE(manager->EndQuery(query, kSubmitCount));
    565   EXPECT_FALSE(query->pending());
    566 
    567   EXPECT_EQ(static_cast<GLuint>(GL_INVALID_ENUM), sync->result);
    568 
    569   manager->Destroy(false);
    570 }
    571 
    572 }  // namespace gles2
    573 }  // namespace gpu
    574 
    575 
    576