| 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())); |
| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 const uint8 QueryManagerTest::kInitialMemoryValue; | 148 const uint8 QueryManagerTest::kInitialMemoryValue; |
| 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 // Check we can create a Query. | 156 // Check we can create a Query. |
| 136 QueryManager::Query::Ref query( | 157 QueryManager::Query::Ref query( |
| 137 manager_->CreateQuery(kClient1Id, kService1Id)); | 158 CreateQuery(GL_ANY_SAMPLES_PASSED_EXT, kClient1Id, |
| 159 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
| 138 ASSERT_TRUE(query.get() != NULL); | 160 ASSERT_TRUE(query.get() != NULL); |
| 139 // Check we can get the same Query. | 161 // Check we can get the same Query. |
| 140 EXPECT_EQ(query.get(), manager_->GetQuery(kClient1Id)); | 162 EXPECT_EQ(query.get(), manager_->GetQuery(kClient1Id)); |
| 141 // Check we can get the client id. | |
| 142 GLuint client_id = -1; | |
| 143 EXPECT_TRUE(manager_->GetClientId(kService1Id, &client_id)); | |
| 144 EXPECT_EQ(kClient1Id, client_id); | |
| 145 // Check we get nothing for a non-existent query. | 163 // Check we get nothing for a non-existent query. |
| 146 EXPECT_TRUE(manager_->GetQuery(kClient2Id) == NULL); | 164 EXPECT_TRUE(manager_->GetQuery(kClient2Id) == NULL); |
| 147 // Check we can delete the query. | 165 // Check we can delete the query. |
| 148 manager_->RemoveQuery(kClient1Id); | 166 manager_->RemoveQuery(kClient1Id); |
| 149 // Check we get nothing for a non-existent query. | 167 // Check we get nothing for a non-existent query. |
| 150 EXPECT_TRUE(manager_->GetQuery(kClient1Id) == NULL); | 168 EXPECT_TRUE(manager_->GetQuery(kClient1Id) == NULL); |
| 151 // Check query is deleted | 169 // Check query is deleted |
| 152 EXPECT_TRUE(query->IsDeleted()); | 170 EXPECT_TRUE(query->IsDeleted()); |
| 153 } | 171 } |
| 154 | 172 |
| 155 TEST_F(QueryManagerTest, Destroy) { | 173 TEST_F(QueryManagerTest, Destroy) { |
| 156 const GLuint kClient1Id = 1; | 174 const GLuint kClient1Id = 1; |
| 157 const GLuint kService1Id = 11; | 175 const GLuint kService1Id = 11; |
| 158 | 176 |
| 159 // Create Query. | 177 // Create Query. |
| 160 QueryManager::Query::Ref query( | 178 QueryManager::Query::Ref query( |
| 161 manager_->CreateQuery(kClient1Id, kService1Id)); | 179 CreateQuery(GL_ANY_SAMPLES_PASSED_EXT, kClient1Id, |
| 180 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
| 162 ASSERT_TRUE(query.get() != NULL); | 181 ASSERT_TRUE(query.get() != NULL); |
| 163 EXPECT_CALL(*gl_, DeleteQueriesARB(1, ::testing::Pointee(kService1Id))) | 182 EXPECT_CALL(*gl_, DeleteQueriesARB(1, ::testing::Pointee(kService1Id))) |
| 164 .Times(1) | 183 .Times(1) |
| 165 .RetiresOnSaturation(); | 184 .RetiresOnSaturation(); |
| 166 manager_->Destroy(true); | 185 manager_->Destroy(true); |
| 167 // Check we get nothing for a non-existent query. | 186 // Check we get nothing for a non-existent query. |
| 168 EXPECT_TRUE(manager_->GetQuery(kClient1Id) == NULL); | 187 EXPECT_TRUE(manager_->GetQuery(kClient1Id) == NULL); |
| 169 // Check query is deleted | 188 // Check query is deleted |
| 170 EXPECT_TRUE(query->IsDeleted()); | 189 EXPECT_TRUE(query->IsDeleted()); |
| 171 } | 190 } |
| 172 | 191 |
| 173 TEST_F(QueryManagerTest, QueryBasic) { | 192 TEST_F(QueryManagerTest, QueryBasic) { |
| 174 const GLuint kClient1Id = 1; | 193 const GLuint kClient1Id = 1; |
| 175 const GLuint kService1Id = 11; | 194 const GLuint kService1Id = 11; |
| 176 | |
| 177 // Create Query. | |
| 178 QueryManager::Query::Ref query( | |
| 179 manager_->CreateQuery(kClient1Id, kService1Id)); | |
| 180 ASSERT_TRUE(query.get() != NULL); | |
| 181 | |
| 182 EXPECT_FALSE(query->IsValid()); | |
| 183 EXPECT_FALSE(query->IsDeleted()); | |
| 184 EXPECT_FALSE(query->IsInitialized()); | |
| 185 EXPECT_FALSE(query->pending()); | |
| 186 } | |
| 187 | |
| 188 TEST_F(QueryManagerTest, QueryInitialize) { | |
| 189 const GLuint kClient1Id = 1; | |
| 190 const GLuint kService1Id = 11; | |
| 191 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 195 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
| 192 | 196 |
| 193 // Create Query. | 197 // Create Query. |
| 194 QueryManager::Query::Ref query( | 198 QueryManager::Query::Ref query( |
| 195 manager_->CreateQuery(kClient1Id, kService1Id)); | 199 CreateQuery(kTarget, kClient1Id, |
| 200 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
| 196 ASSERT_TRUE(query.get() != NULL); | 201 ASSERT_TRUE(query.get() != NULL); |
| 197 | 202 |
| 198 query->Initialize(kTarget, kSharedMemoryId, kSharedMemoryOffset); | 203 EXPECT_TRUE(query->IsValid()); |
| 204 EXPECT_FALSE(query->IsDeleted()); |
| 205 EXPECT_FALSE(query->pending()); |
| 199 EXPECT_EQ(kTarget, query->target()); | 206 EXPECT_EQ(kTarget, query->target()); |
| 200 EXPECT_EQ(kSharedMemoryId, query->shm_id()); | 207 EXPECT_EQ(kSharedMemoryId, query->shm_id()); |
| 201 EXPECT_EQ(kSharedMemoryOffset, query->shm_offset()); | 208 EXPECT_EQ(kSharedMemoryOffset, query->shm_offset()); |
| 202 | |
| 203 EXPECT_TRUE(query->IsValid()); | |
| 204 EXPECT_FALSE(query->IsDeleted()); | |
| 205 EXPECT_TRUE(query->IsInitialized()); | |
| 206 EXPECT_FALSE(query->pending()); | |
| 207 } | 209 } |
| 208 | 210 |
| 209 TEST_F(QueryManagerTest, ProcessPendingQuery) { | 211 TEST_F(QueryManagerTest, ProcessPendingQuery) { |
| 210 const GLuint kClient1Id = 1; | 212 const GLuint kClient1Id = 1; |
| 211 const GLuint kService1Id = 11; | 213 const GLuint kService1Id = 11; |
| 212 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 214 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
| 213 const uint32 kSubmitCount = 123; | 215 const uint32 kSubmitCount = 123; |
| 214 const GLuint kResult = 456; | 216 const GLuint kResult = 456; |
| 215 | 217 |
| 216 // Check nothing happens if there are no pending queries. | 218 // Check nothing happens if there are no pending queries. |
| 217 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 219 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
| 218 | 220 |
| 219 // Create Query. | 221 // Create Query. |
| 220 QueryManager::Query::Ref query( | 222 QueryManager::Query::Ref query( |
| 221 manager_->CreateQuery(kClient1Id, kService1Id)); | 223 CreateQuery(kTarget, kClient1Id, |
| 224 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
| 222 ASSERT_TRUE(query.get() != NULL); | 225 ASSERT_TRUE(query.get() != NULL); |
| 223 query->Initialize(kTarget, kSharedMemoryId, kSharedMemoryOffset); | |
| 224 | 226 |
| 225 // Setup shared memory like client would. | 227 // Setup shared memory like client would. |
| 226 QuerySync* sync = decoder_->GetSharedMemoryAs<QuerySync*>( | 228 QuerySync* sync = decoder_->GetSharedMemoryAs<QuerySync*>( |
| 227 kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync)); | 229 kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync)); |
| 228 ASSERT_TRUE(sync != NULL); | 230 ASSERT_TRUE(sync != NULL); |
| 229 sync->Reset(); | 231 sync->Reset(); |
| 230 | 232 |
| 231 // Queue it | 233 // Queue it |
| 232 manager_->AddPendingQuery(query.get(), kSubmitCount); | 234 QueueQuery(query.get(), kService1Id, kSubmitCount); |
| 233 EXPECT_TRUE(query->pending()); | 235 EXPECT_TRUE(query->pending()); |
| 234 | 236 |
| 235 // Process with return not available. | 237 // Process with return not available. |
| 236 // Expect 1 GL command. | 238 // Expect 1 GL command. |
| 237 EXPECT_CALL(*gl_, | 239 EXPECT_CALL(*gl_, |
| 238 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 240 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
| 239 .WillOnce(SetArgumentPointee<2>(0)) | 241 .WillOnce(SetArgumentPointee<2>(0)) |
| 240 .RetiresOnSaturation(); | 242 .RetiresOnSaturation(); |
| 241 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 243 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
| 242 EXPECT_TRUE(query->pending()); | 244 EXPECT_TRUE(query->pending()); |
| 243 EXPECT_EQ(0u, sync->process_count); | 245 EXPECT_EQ(0u, sync->process_count); |
| 244 EXPECT_EQ(0u, sync->result); | 246 EXPECT_EQ(0u, sync->result); |
| 245 | 247 |
| 246 // Process with return available. | 248 // Process with return available. |
| 247 // Expect 2 GL commands. | 249 // Expect 2 GL commands. |
| 248 EXPECT_CALL(*gl_, | 250 EXPECT_CALL(*gl_, |
| 249 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 251 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
| 250 .WillOnce(SetArgumentPointee<2>(1)) | 252 .WillOnce(SetArgumentPointee<2>(1)) |
| 251 .RetiresOnSaturation(); | 253 .RetiresOnSaturation(); |
| 252 EXPECT_CALL(*gl_, | 254 EXPECT_CALL(*gl_, |
| 253 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) | 255 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) |
| 254 .WillOnce(SetArgumentPointee<2>(kResult)) | 256 .WillOnce(SetArgumentPointee<2>(kResult)) |
| 255 .RetiresOnSaturation(); | 257 .RetiresOnSaturation(); |
| 256 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 258 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
| 257 EXPECT_FALSE(query->pending()); | 259 EXPECT_FALSE(query->pending()); |
| 258 EXPECT_EQ(kSubmitCount, sync->process_count); | 260 EXPECT_EQ(kSubmitCount, sync->process_count); |
| 259 EXPECT_EQ(kResult, sync->result); | 261 EXPECT_EQ(kResult, sync->result); |
| 260 | 262 |
| 261 // Process with no queries. | 263 // Process with no queries. |
| 262 // Expect no GL commands/ | 264 // Expect no GL commands/ |
| 263 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 265 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
| 264 } | 266 } |
| 265 | 267 |
| 266 TEST_F(QueryManagerTest, ProcessPendingQueries) { | 268 TEST_F(QueryManagerTest, ProcessPendingQueries) { |
| 267 const GLuint kClient1Id = 1; | 269 const GLuint kClient1Id = 1; |
| 268 const GLuint kService1Id = 11; | 270 const GLuint kService1Id = 11; |
| 269 const GLuint kClient2Id = 2; | 271 const GLuint kClient2Id = 2; |
| 270 const GLuint kService2Id = 12; | 272 const GLuint kService2Id = 12; |
| 271 const GLuint kClient3Id = 3; | 273 const GLuint kClient3Id = 3; |
| 272 const GLuint kService3Id = 13; | 274 const GLuint kService3Id = 13; |
| 273 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 275 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
| 274 const uint32 kSubmitCount1 = 123; | 276 const uint32 kSubmitCount1 = 123; |
| 275 const uint32 kSubmitCount2 = 123; | 277 const uint32 kSubmitCount2 = 123; |
| 276 const uint32 kSubmitCount3 = 123; | 278 const uint32 kSubmitCount3 = 123; |
| 277 const GLuint kResult1 = 456; | 279 const GLuint kResult1 = 456; |
| 278 const GLuint kResult2 = 457; | 280 const GLuint kResult2 = 457; |
| 279 const GLuint kResult3 = 458; | 281 const GLuint kResult3 = 458; |
| 280 | 282 |
| 281 // Create Queries. | |
| 282 QueryManager::Query::Ref query1( | |
| 283 manager_->CreateQuery(kClient1Id, kService1Id)); | |
| 284 QueryManager::Query::Ref query2( | |
| 285 manager_->CreateQuery(kClient2Id, kService2Id)); | |
| 286 QueryManager::Query::Ref query3( | |
| 287 manager_->CreateQuery(kClient3Id, kService3Id)); | |
| 288 ASSERT_TRUE(query1.get() != NULL); | |
| 289 ASSERT_TRUE(query2.get() != NULL); | |
| 290 ASSERT_TRUE(query3.get() != NULL); | |
| 291 | |
| 292 // Setup shared memory like client would. | 283 // Setup shared memory like client would. |
| 293 QuerySync* sync1 = decoder_->GetSharedMemoryAs<QuerySync*>( | 284 QuerySync* sync1 = decoder_->GetSharedMemoryAs<QuerySync*>( |
| 294 kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync1) * 3); | 285 kSharedMemoryId, kSharedMemoryOffset, sizeof(*sync1) * 3); |
| 295 ASSERT_TRUE(sync1 != NULL); | 286 ASSERT_TRUE(sync1 != NULL); |
| 296 QuerySync* sync2 = sync1 + 1; | 287 QuerySync* sync2 = sync1 + 1; |
| 297 QuerySync* sync3 = sync2 + 1; | 288 QuerySync* sync3 = sync2 + 1; |
| 298 | 289 |
| 290 // Create Queries. |
| 291 QueryManager::Query::Ref query1( |
| 292 CreateQuery(kTarget, kClient1Id, |
| 293 kSharedMemoryId, kSharedMemoryOffset + sizeof(*sync1) * 0, |
| 294 kService1Id)); |
| 295 QueryManager::Query::Ref query2( |
| 296 CreateQuery(kTarget, kClient2Id, |
| 297 kSharedMemoryId, kSharedMemoryOffset + sizeof(*sync1) * 1, |
| 298 kService2Id)); |
| 299 QueryManager::Query::Ref query3( |
| 300 CreateQuery(kTarget, kClient3Id, |
| 301 kSharedMemoryId, kSharedMemoryOffset + sizeof(*sync1) * 2, |
| 302 kService3Id)); |
| 303 ASSERT_TRUE(query1.get() != NULL); |
| 304 ASSERT_TRUE(query2.get() != NULL); |
| 305 ASSERT_TRUE(query3.get() != NULL); |
| 306 |
| 299 sync1->Reset(); | 307 sync1->Reset(); |
| 300 sync2->Reset(); | 308 sync2->Reset(); |
| 301 sync3->Reset(); | 309 sync3->Reset(); |
| 302 | 310 |
| 303 query1->Initialize(kTarget, kSharedMemoryId, kSharedMemoryOffset); | |
| 304 query2->Initialize(kTarget, kSharedMemoryId, | |
| 305 kSharedMemoryOffset + sizeof(*sync1)); | |
| 306 query3->Initialize(kTarget, kSharedMemoryId, | |
| 307 kSharedMemoryOffset + sizeof(*sync1) * 2); | |
| 308 | |
| 309 // Queue them | 311 // Queue them |
| 310 manager_->AddPendingQuery(query1.get(), kSubmitCount1); | 312 QueueQuery(query1.get(), kService1Id, kSubmitCount1); |
| 311 manager_->AddPendingQuery(query2.get(), kSubmitCount2); | 313 QueueQuery(query2.get(), kService2Id, kSubmitCount2); |
| 312 manager_->AddPendingQuery(query3.get(), kSubmitCount3); | 314 QueueQuery(query3.get(), kService3Id, kSubmitCount3); |
| 313 EXPECT_TRUE(query1->pending()); | 315 EXPECT_TRUE(query1->pending()); |
| 314 EXPECT_TRUE(query2->pending()); | 316 EXPECT_TRUE(query2->pending()); |
| 315 EXPECT_TRUE(query3->pending()); | 317 EXPECT_TRUE(query3->pending()); |
| 316 | 318 |
| 317 // Process with return available for first 2 queries. | 319 // Process with return available for first 2 queries. |
| 318 // Expect 4 GL commands. | 320 // Expect 4 GL commands. |
| 319 { | 321 { |
| 320 InSequence s; | 322 InSequence s; |
| 321 EXPECT_CALL(*gl_, | 323 EXPECT_CALL(*gl_, |
| 322 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 324 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
| 323 .WillOnce(SetArgumentPointee<2>(1)) | 325 .WillOnce(SetArgumentPointee<2>(1)) |
| 324 .RetiresOnSaturation(); | 326 .RetiresOnSaturation(); |
| 325 EXPECT_CALL(*gl_, | 327 EXPECT_CALL(*gl_, |
| 326 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) | 328 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) |
| 327 .WillOnce(SetArgumentPointee<2>(kResult1)) | 329 .WillOnce(SetArgumentPointee<2>(kResult1)) |
| 328 .RetiresOnSaturation(); | 330 .RetiresOnSaturation(); |
| 329 EXPECT_CALL(*gl_, | 331 EXPECT_CALL(*gl_, |
| 330 GetQueryObjectuivARB(kService2Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 332 GetQueryObjectuivARB(kService2Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
| 331 .WillOnce(SetArgumentPointee<2>(1)) | 333 .WillOnce(SetArgumentPointee<2>(1)) |
| 332 .RetiresOnSaturation(); | 334 .RetiresOnSaturation(); |
| 333 EXPECT_CALL(*gl_, | 335 EXPECT_CALL(*gl_, |
| 334 GetQueryObjectuivARB(kService2Id, GL_QUERY_RESULT_EXT, _)) | 336 GetQueryObjectuivARB(kService2Id, GL_QUERY_RESULT_EXT, _)) |
| 335 .WillOnce(SetArgumentPointee<2>(kResult2)) | 337 .WillOnce(SetArgumentPointee<2>(kResult2)) |
| 336 .RetiresOnSaturation(); | 338 .RetiresOnSaturation(); |
| 337 EXPECT_CALL(*gl_, | 339 EXPECT_CALL(*gl_, |
| 338 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 340 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
| 339 .WillOnce(SetArgumentPointee<2>(0)) | 341 .WillOnce(SetArgumentPointee<2>(0)) |
| 340 .RetiresOnSaturation(); | 342 .RetiresOnSaturation(); |
| 341 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 343 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
| 342 } | 344 } |
| 343 EXPECT_FALSE(query1->pending()); | 345 EXPECT_FALSE(query1->pending()); |
| 344 EXPECT_FALSE(query2->pending()); | 346 EXPECT_FALSE(query2->pending()); |
| 345 EXPECT_TRUE(query3->pending()); | 347 EXPECT_TRUE(query3->pending()); |
| 346 EXPECT_EQ(kSubmitCount1, sync1->process_count); | 348 EXPECT_EQ(kSubmitCount1, sync1->process_count); |
| 347 EXPECT_EQ(kSubmitCount2, sync2->process_count); | 349 EXPECT_EQ(kSubmitCount2, sync2->process_count); |
| 348 EXPECT_EQ(kResult1, sync1->result); | 350 EXPECT_EQ(kResult1, sync1->result); |
| 349 EXPECT_EQ(kResult2, sync2->result); | 351 EXPECT_EQ(kResult2, sync2->result); |
| 350 EXPECT_EQ(0u, sync3->process_count); | 352 EXPECT_EQ(0u, sync3->process_count); |
| 351 EXPECT_EQ(0u, sync3->result); | 353 EXPECT_EQ(0u, sync3->result); |
| 352 | 354 |
| 353 // Process with renaming query. No result. | 355 // Process with renaming query. No result. |
| 354 // Expect 1 GL commands. | 356 // Expect 1 GL commands. |
| 355 EXPECT_CALL(*gl_, | 357 EXPECT_CALL(*gl_, |
| 356 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 358 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
| 357 .WillOnce(SetArgumentPointee<2>(0)) | 359 .WillOnce(SetArgumentPointee<2>(0)) |
| 358 .RetiresOnSaturation(); | 360 .RetiresOnSaturation(); |
| 359 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 361 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
| 360 EXPECT_TRUE(query3->pending()); | 362 EXPECT_TRUE(query3->pending()); |
| 361 EXPECT_EQ(0u, sync3->process_count); | 363 EXPECT_EQ(0u, sync3->process_count); |
| 362 EXPECT_EQ(0u, sync3->result); | 364 EXPECT_EQ(0u, sync3->result); |
| 363 | 365 |
| 364 // Process with renaming query. With result. | 366 // Process with renaming query. With result. |
| 365 // Expect 2 GL commands. | 367 // Expect 2 GL commands. |
| 366 EXPECT_CALL(*gl_, | 368 EXPECT_CALL(*gl_, |
| 367 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 369 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
| 368 .WillOnce(SetArgumentPointee<2>(1)) | 370 .WillOnce(SetArgumentPointee<2>(1)) |
| 369 .RetiresOnSaturation(); | 371 .RetiresOnSaturation(); |
| 370 EXPECT_CALL(*gl_, | 372 EXPECT_CALL(*gl_, |
| 371 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_EXT, _)) | 373 GetQueryObjectuivARB(kService3Id, GL_QUERY_RESULT_EXT, _)) |
| 372 .WillOnce(SetArgumentPointee<2>(kResult3)) | 374 .WillOnce(SetArgumentPointee<2>(kResult3)) |
| 373 .RetiresOnSaturation(); | 375 .RetiresOnSaturation(); |
| 374 EXPECT_TRUE(manager_->ProcessPendingQueries(decoder_.get())); | 376 EXPECT_TRUE(manager_->ProcessPendingQueries()); |
| 375 EXPECT_FALSE(query3->pending()); | 377 EXPECT_FALSE(query3->pending()); |
| 376 EXPECT_EQ(kSubmitCount3, sync3->process_count); | 378 EXPECT_EQ(kSubmitCount3, sync3->process_count); |
| 377 EXPECT_EQ(kResult3, sync3->result); | 379 EXPECT_EQ(kResult3, sync3->result); |
| 378 } | 380 } |
| 379 | 381 |
| 380 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryId) { | 382 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryId) { |
| 381 const GLuint kClient1Id = 1; | 383 const GLuint kClient1Id = 1; |
| 382 const GLuint kService1Id = 11; | 384 const GLuint kService1Id = 11; |
| 383 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 385 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
| 384 const uint32 kSubmitCount = 123; | 386 const uint32 kSubmitCount = 123; |
| 385 const GLuint kResult = 456; | 387 const GLuint kResult = 456; |
| 386 | 388 |
| 387 // Create Query. | 389 // Create Query. |
| 388 QueryManager::Query::Ref query( | 390 QueryManager::Query::Ref query( |
| 389 manager_->CreateQuery(kClient1Id, kService1Id)); | 391 CreateQuery(kTarget, kClient1Id, |
| 392 kInvalidSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
| 390 ASSERT_TRUE(query.get() != NULL); | 393 ASSERT_TRUE(query.get() != NULL); |
| 391 query->Initialize(kTarget, kInvalidSharedMemoryId, kSharedMemoryOffset); | |
| 392 | 394 |
| 393 // Queue it | 395 // Queue it |
| 394 manager_->AddPendingQuery(query.get(), kSubmitCount); | 396 QueueQuery(query.get(), kService1Id, kSubmitCount); |
| 395 | 397 |
| 396 // Process with return available. | 398 // Process with return available. |
| 397 // Expect 2 GL commands. | 399 // Expect 2 GL commands. |
| 398 EXPECT_CALL(*gl_, | 400 EXPECT_CALL(*gl_, |
| 399 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 401 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
| 400 .WillOnce(SetArgumentPointee<2>(1)) | 402 .WillOnce(SetArgumentPointee<2>(1)) |
| 401 .RetiresOnSaturation(); | 403 .RetiresOnSaturation(); |
| 402 EXPECT_CALL(*gl_, | 404 EXPECT_CALL(*gl_, |
| 403 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) | 405 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) |
| 404 .WillOnce(SetArgumentPointee<2>(kResult)) | 406 .WillOnce(SetArgumentPointee<2>(kResult)) |
| 405 .RetiresOnSaturation(); | 407 .RetiresOnSaturation(); |
| 406 EXPECT_FALSE(manager_->ProcessPendingQueries(decoder_.get())); | 408 EXPECT_FALSE(manager_->ProcessPendingQueries()); |
| 407 } | 409 } |
| 408 | 410 |
| 409 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryOffset) { | 411 TEST_F(QueryManagerTest, ProcessPendingBadSharedMemoryOffset) { |
| 410 const GLuint kClient1Id = 1; | 412 const GLuint kClient1Id = 1; |
| 411 const GLuint kService1Id = 11; | 413 const GLuint kService1Id = 11; |
| 412 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 414 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
| 413 const uint32 kSubmitCount = 123; | 415 const uint32 kSubmitCount = 123; |
| 414 const GLuint kResult = 456; | 416 const GLuint kResult = 456; |
| 415 | 417 |
| 416 // Create Query. | 418 // Create Query. |
| 417 QueryManager::Query::Ref query( | 419 QueryManager::Query::Ref query( |
| 418 manager_->CreateQuery(kClient1Id, kService1Id)); | 420 CreateQuery(kTarget, kClient1Id, |
| 421 kSharedMemoryId, kInvalidSharedMemoryOffset, kService1Id)); |
| 419 ASSERT_TRUE(query.get() != NULL); | 422 ASSERT_TRUE(query.get() != NULL); |
| 420 query->Initialize(kTarget, kSharedMemoryId, kInvalidSharedMemoryOffset); | |
| 421 | 423 |
| 422 // Queue it | 424 // Queue it |
| 423 manager_->AddPendingQuery(query.get(), kSubmitCount); | 425 QueueQuery(query.get(), kService1Id, kSubmitCount); |
| 424 | 426 |
| 425 // Process with return available. | 427 // Process with return available. |
| 426 // Expect 2 GL commands. | 428 // Expect 2 GL commands. |
| 427 EXPECT_CALL(*gl_, | 429 EXPECT_CALL(*gl_, |
| 428 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) | 430 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_AVAILABLE_EXT, _)) |
| 429 .WillOnce(SetArgumentPointee<2>(1)) | 431 .WillOnce(SetArgumentPointee<2>(1)) |
| 430 .RetiresOnSaturation(); | 432 .RetiresOnSaturation(); |
| 431 EXPECT_CALL(*gl_, | 433 EXPECT_CALL(*gl_, |
| 432 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) | 434 GetQueryObjectuivARB(kService1Id, GL_QUERY_RESULT_EXT, _)) |
| 433 .WillOnce(SetArgumentPointee<2>(kResult)) | 435 .WillOnce(SetArgumentPointee<2>(kResult)) |
| 434 .RetiresOnSaturation(); | 436 .RetiresOnSaturation(); |
| 435 EXPECT_FALSE(manager_->ProcessPendingQueries(decoder_.get())); | 437 EXPECT_FALSE(manager_->ProcessPendingQueries()); |
| 436 } | 438 } |
| 437 | 439 |
| 438 TEST_F(QueryManagerTest, ExitWithPendingQuery) { | 440 TEST_F(QueryManagerTest, ExitWithPendingQuery) { |
| 439 const GLuint kClient1Id = 1; | 441 const GLuint kClient1Id = 1; |
| 440 const GLuint kService1Id = 11; | 442 const GLuint kService1Id = 11; |
| 441 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; | 443 const GLenum kTarget = GL_ANY_SAMPLES_PASSED_EXT; |
| 442 const uint32 kSubmitCount = 123; | 444 const uint32 kSubmitCount = 123; |
| 443 | 445 |
| 444 // Create Query. | 446 // Create Query. |
| 445 QueryManager::Query::Ref query( | 447 QueryManager::Query::Ref query( |
| 446 manager_->CreateQuery(kClient1Id, kService1Id)); | 448 CreateQuery(kTarget, kClient1Id, |
| 449 kSharedMemoryId, kSharedMemoryOffset, kService1Id)); |
| 447 ASSERT_TRUE(query.get() != NULL); | 450 ASSERT_TRUE(query.get() != NULL); |
| 448 query->Initialize(kTarget, kSharedMemoryId, kSharedMemoryOffset); | |
| 449 | 451 |
| 450 // Queue it | 452 // Queue it |
| 451 manager_->AddPendingQuery(query.get(), kSubmitCount); | 453 QueueQuery(query.get(), kService1Id, kSubmitCount); |
| 452 } | 454 } |
| 453 | 455 |
| 454 } // namespace gles2 | 456 } // namespace gles2 |
| 455 } // namespace gpu | 457 } // namespace gpu |
| 456 | 458 |
| 457 | 459 |
| OLD | NEW |