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