| 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 // Tests for GLES2Implementation. | 5 // Tests for GLES2Implementation. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 8 | 8 |
| 9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
| 10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 class TestContext { | 405 class TestContext { |
| 406 public: | 406 public: |
| 407 TestContext() : commands_(NULL), token_(0) {} | 407 TestContext() : commands_(NULL), token_(0) {} |
| 408 | 408 |
| 409 bool Initialize(ShareGroup* share_group, | 409 bool Initialize(ShareGroup* share_group, |
| 410 bool bind_generates_resource_client, | 410 bool bind_generates_resource_client, |
| 411 bool bind_generates_resource_service, | 411 bool bind_generates_resource_service, |
| 412 bool lose_context_when_out_of_memory, | 412 bool lose_context_when_out_of_memory, |
| 413 bool transfer_buffer_initialize_fail, | 413 bool transfer_buffer_initialize_fail, |
| 414 bool sync_query, | 414 bool sync_query, |
| 415 bool occlusion_query_boolean) { | 415 bool occlusion_query_boolean, |
| 416 bool timer_queries) { |
| 416 command_buffer_.reset(new StrictMock<MockClientCommandBuffer>()); | 417 command_buffer_.reset(new StrictMock<MockClientCommandBuffer>()); |
| 417 if (!command_buffer_->Initialize()) | 418 if (!command_buffer_->Initialize()) |
| 418 return false; | 419 return false; |
| 419 | 420 |
| 420 transfer_buffer_.reset( | 421 transfer_buffer_.reset( |
| 421 new MockTransferBuffer(command_buffer_.get(), | 422 new MockTransferBuffer(command_buffer_.get(), |
| 422 kTransferBufferSize, | 423 kTransferBufferSize, |
| 423 GLES2Implementation::kStartingOffset, | 424 GLES2Implementation::kStartingOffset, |
| 424 GLES2Implementation::kAlignment, | 425 GLES2Implementation::kAlignment, |
| 425 transfer_buffer_initialize_fail)); | 426 transfer_buffer_initialize_fail)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 450 capabilities.num_compressed_texture_formats = | 451 capabilities.num_compressed_texture_formats = |
| 451 kNumCompressedTextureFormats; | 452 kNumCompressedTextureFormats; |
| 452 capabilities.num_shader_binary_formats = kNumShaderBinaryFormats; | 453 capabilities.num_shader_binary_formats = kNumShaderBinaryFormats; |
| 453 capabilities.max_transform_feedback_separate_attribs = | 454 capabilities.max_transform_feedback_separate_attribs = |
| 454 kMaxTransformFeedbackSeparateAttribs; | 455 kMaxTransformFeedbackSeparateAttribs; |
| 455 capabilities.max_uniform_buffer_bindings = kMaxUniformBufferBindings; | 456 capabilities.max_uniform_buffer_bindings = kMaxUniformBufferBindings; |
| 456 capabilities.bind_generates_resource_chromium = | 457 capabilities.bind_generates_resource_chromium = |
| 457 bind_generates_resource_service ? 1 : 0; | 458 bind_generates_resource_service ? 1 : 0; |
| 458 capabilities.sync_query = sync_query; | 459 capabilities.sync_query = sync_query; |
| 459 capabilities.occlusion_query_boolean = occlusion_query_boolean; | 460 capabilities.occlusion_query_boolean = occlusion_query_boolean; |
| 461 capabilities.timer_queries = timer_queries; |
| 460 EXPECT_CALL(*gpu_control_, GetCapabilities()) | 462 EXPECT_CALL(*gpu_control_, GetCapabilities()) |
| 461 .WillOnce(testing::Return(capabilities)); | 463 .WillOnce(testing::Return(capabilities)); |
| 462 | 464 |
| 463 { | 465 { |
| 464 InSequence sequence; | 466 InSequence sequence; |
| 465 | 467 |
| 466 const bool support_client_side_arrays = true; | 468 const bool support_client_side_arrays = true; |
| 467 gl_.reset(new GLES2Implementation(helper_.get(), | 469 gl_.reset(new GLES2Implementation(helper_.get(), |
| 468 share_group, | 470 share_group, |
| 469 transfer_buffer_.get(), | 471 transfer_buffer_.get(), |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 return gl_->query_tracker_->GetQuery(id); | 544 return gl_->query_tracker_->GetQuery(id); |
| 543 } | 545 } |
| 544 | 546 |
| 545 struct ContextInitOptions { | 547 struct ContextInitOptions { |
| 546 ContextInitOptions() | 548 ContextInitOptions() |
| 547 : bind_generates_resource_client(true), | 549 : bind_generates_resource_client(true), |
| 548 bind_generates_resource_service(true), | 550 bind_generates_resource_service(true), |
| 549 lose_context_when_out_of_memory(false), | 551 lose_context_when_out_of_memory(false), |
| 550 transfer_buffer_initialize_fail(false), | 552 transfer_buffer_initialize_fail(false), |
| 551 sync_query(true), | 553 sync_query(true), |
| 552 occlusion_query_boolean(true) {} | 554 occlusion_query_boolean(true), |
| 555 timer_queries(true) {} |
| 553 | 556 |
| 554 bool bind_generates_resource_client; | 557 bool bind_generates_resource_client; |
| 555 bool bind_generates_resource_service; | 558 bool bind_generates_resource_service; |
| 556 bool lose_context_when_out_of_memory; | 559 bool lose_context_when_out_of_memory; |
| 557 bool transfer_buffer_initialize_fail; | 560 bool transfer_buffer_initialize_fail; |
| 558 bool sync_query; | 561 bool sync_query; |
| 559 bool occlusion_query_boolean; | 562 bool occlusion_query_boolean; |
| 563 bool timer_queries; |
| 560 }; | 564 }; |
| 561 | 565 |
| 562 bool Initialize(const ContextInitOptions& init_options) { | 566 bool Initialize(const ContextInitOptions& init_options) { |
| 563 bool success = true; | 567 bool success = true; |
| 564 share_group_ = new ShareGroup(init_options.bind_generates_resource_client); | 568 share_group_ = new ShareGroup(init_options.bind_generates_resource_client); |
| 565 | 569 |
| 566 for (int i = 0; i < kNumTestContexts; i++) { | 570 for (int i = 0; i < kNumTestContexts; i++) { |
| 567 if (!test_contexts_[i].Initialize( | 571 if (!test_contexts_[i].Initialize( |
| 568 share_group_.get(), | 572 share_group_.get(), |
| 569 init_options.bind_generates_resource_client, | 573 init_options.bind_generates_resource_client, |
| 570 init_options.bind_generates_resource_service, | 574 init_options.bind_generates_resource_service, |
| 571 init_options.lose_context_when_out_of_memory, | 575 init_options.lose_context_when_out_of_memory, |
| 572 init_options.transfer_buffer_initialize_fail, | 576 init_options.transfer_buffer_initialize_fail, |
| 573 init_options.sync_query, | 577 init_options.sync_query, |
| 574 init_options.occlusion_query_boolean)) | 578 init_options.occlusion_query_boolean, |
| 579 init_options.timer_queries)) |
| 575 success = false; | 580 success = false; |
| 576 } | 581 } |
| 577 | 582 |
| 578 // Default to test context 0. | 583 // Default to test context 0. |
| 579 gpu_control_ = test_contexts_[0].gpu_control_.get(); | 584 gpu_control_ = test_contexts_[0].gpu_control_.get(); |
| 580 helper_ = test_contexts_[0].helper_.get(); | 585 helper_ = test_contexts_[0].helper_.get(); |
| 581 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get(); | 586 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get(); |
| 582 gl_ = test_contexts_[0].gl_.get(); | 587 gl_ = test_contexts_[0].gl_.get(); |
| 583 commands_ = test_contexts_[0].commands_; | 588 commands_ = test_contexts_[0].commands_; |
| 584 return success; | 589 return success; |
| (...skipping 2625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3210 // Test GetQueryObjectui64vEXT CheckResultsAvailable | 3215 // Test GetQueryObjectui64vEXT CheckResultsAvailable |
| 3211 ClearCommands(); | 3216 ClearCommands(); |
| 3212 gl_->GetQueryObjectui64vEXT(id1, GL_QUERY_RESULT_AVAILABLE_EXT, &available2); | 3217 gl_->GetQueryObjectui64vEXT(id1, GL_QUERY_RESULT_AVAILABLE_EXT, &available2); |
| 3213 EXPECT_EQ(0u, available2); | 3218 EXPECT_EQ(0u, available2); |
| 3214 } | 3219 } |
| 3215 | 3220 |
| 3216 TEST_F(GLES2ImplementationManualInitTest, BadQueryTargets) { | 3221 TEST_F(GLES2ImplementationManualInitTest, BadQueryTargets) { |
| 3217 ContextInitOptions init_options; | 3222 ContextInitOptions init_options; |
| 3218 init_options.sync_query = false; | 3223 init_options.sync_query = false; |
| 3219 init_options.occlusion_query_boolean = false; | 3224 init_options.occlusion_query_boolean = false; |
| 3225 init_options.timer_queries = false; |
| 3220 ASSERT_TRUE(Initialize(init_options)); | 3226 ASSERT_TRUE(Initialize(init_options)); |
| 3221 | 3227 |
| 3222 GLuint id = 0; | 3228 GLuint id = 0; |
| 3223 gl_->GenQueriesEXT(1, &id); | 3229 gl_->GenQueriesEXT(1, &id); |
| 3224 ClearCommands(); | 3230 ClearCommands(); |
| 3225 | 3231 |
| 3226 gl_->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, id); | 3232 gl_->BeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, id); |
| 3227 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); | 3233 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); |
| 3228 EXPECT_EQ(nullptr, GetQuery(id)); | 3234 EXPECT_EQ(nullptr, GetQuery(id)); |
| 3229 | 3235 |
| 3230 gl_->BeginQueryEXT(GL_ANY_SAMPLES_PASSED, id); | 3236 gl_->BeginQueryEXT(GL_ANY_SAMPLES_PASSED, id); |
| 3231 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); | 3237 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); |
| 3232 EXPECT_EQ(nullptr, GetQuery(id)); | 3238 EXPECT_EQ(nullptr, GetQuery(id)); |
| 3233 | 3239 |
| 3234 gl_->BeginQueryEXT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE, id); | 3240 gl_->BeginQueryEXT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE, id); |
| 3235 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); | 3241 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); |
| 3236 EXPECT_EQ(nullptr, GetQuery(id)); | 3242 EXPECT_EQ(nullptr, GetQuery(id)); |
| 3237 | 3243 |
| 3244 gl_->BeginQueryEXT(GL_TIME_ELAPSED_EXT, id); |
| 3245 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); |
| 3246 EXPECT_EQ(nullptr, GetQuery(id)); |
| 3247 |
| 3238 gl_->BeginQueryEXT(0x123, id); | 3248 gl_->BeginQueryEXT(0x123, id); |
| 3249 EXPECT_EQ(GL_INVALID_ENUM, CheckError()); |
| 3250 EXPECT_EQ(nullptr, GetQuery(id)); |
| 3251 |
| 3252 gl_->QueryCounterEXT(id, GL_TIMESTAMP_EXT); |
| 3239 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); | 3253 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); |
| 3240 EXPECT_EQ(nullptr, GetQuery(id)); | 3254 EXPECT_EQ(nullptr, GetQuery(id)); |
| 3255 |
| 3256 gl_->QueryCounterEXT(id, 0x123); |
| 3257 EXPECT_EQ(GL_INVALID_ENUM, CheckError()); |
| 3258 EXPECT_EQ(nullptr, GetQuery(id)); |
| 3241 } | 3259 } |
| 3242 | 3260 |
| 3261 TEST_F(GLES2ImplementationTest, QueryCounterEXT) { |
| 3262 GLuint expected_ids[2] = { 1, 2 }; // These must match what's actually genned. |
| 3263 struct GenCmds { |
| 3264 cmds::GenQueriesEXTImmediate gen; |
| 3265 GLuint data[2]; |
| 3266 }; |
| 3267 GenCmds expected_gen_cmds; |
| 3268 expected_gen_cmds.gen.Init(arraysize(expected_ids), &expected_ids[0]); |
| 3269 GLuint ids[arraysize(expected_ids)] = { 0, }; |
| 3270 gl_->GenQueriesEXT(arraysize(expected_ids), &ids[0]); |
| 3271 EXPECT_EQ(0, memcmp( |
| 3272 &expected_gen_cmds, commands_, sizeof(expected_gen_cmds))); |
| 3273 GLuint id1 = ids[0]; |
| 3274 GLuint id2 = ids[1]; |
| 3275 ClearCommands(); |
| 3276 |
| 3277 // Test QueryCounterEXT fails if id = 0. |
| 3278 gl_->QueryCounterEXT(0, GL_TIMESTAMP_EXT); |
| 3279 EXPECT_TRUE(NoCommandsWritten()); |
| 3280 EXPECT_EQ(GL_INVALID_OPERATION, CheckError()); |
| 3281 |
| 3282 // Test QueryCounterEXT fails if target is unknown. |
| 3283 ClearCommands(); |
| 3284 gl_->QueryCounterEXT(id1, GL_TIME_ELAPSED_EXT); |
| 3285 EXPECT_TRUE(NoCommandsWritten()); |
| 3286 EXPECT_EQ(GL_INVALID_ENUM, CheckError()); |
| 3287 |
| 3288 // Test QueryCounterEXT inserts command. |
| 3289 struct QueryCounterCmds { |
| 3290 cmds::QueryCounterEXT query_counter; |
| 3291 }; |
| 3292 QueryCounterCmds expected_query_counter_cmds; |
| 3293 const void* commands = GetPut(); |
| 3294 gl_->QueryCounterEXT(id1, GL_TIMESTAMP_EXT); |
| 3295 EXPECT_EQ(GL_NO_ERROR, CheckError()); |
| 3296 QueryTracker::Query* query = GetQuery(id1); |
| 3297 ASSERT_TRUE(query != NULL); |
| 3298 expected_query_counter_cmds.query_counter.Init( |
| 3299 GL_TIMESTAMP_EXT, id1, query->shm_id(), query->shm_offset(), |
| 3300 query->submit_count()); |
| 3301 EXPECT_EQ(0, memcmp(&expected_query_counter_cmds, commands, |
| 3302 sizeof(expected_query_counter_cmds))); |
| 3303 ClearCommands(); |
| 3304 |
| 3305 // Test 2nd QueryCounterEXT succeeds. |
| 3306 commands = GetPut(); |
| 3307 gl_->QueryCounterEXT(id2, GL_TIMESTAMP_EXT); |
| 3308 EXPECT_EQ(GL_NO_ERROR, CheckError()); |
| 3309 QueryTracker::Query* query2 = GetQuery(id2); |
| 3310 ASSERT_TRUE(query2 != NULL); |
| 3311 expected_query_counter_cmds.query_counter.Init( |
| 3312 GL_TIMESTAMP_EXT, id2, query2->shm_id(), query2->shm_offset(), |
| 3313 query2->submit_count()); |
| 3314 EXPECT_EQ(0, memcmp(&expected_query_counter_cmds, commands, |
| 3315 sizeof(expected_query_counter_cmds))); |
| 3316 ClearCommands(); |
| 3317 |
| 3318 // Test QueryCounterEXT increments count. |
| 3319 base::subtle::Atomic32 old_submit_count = query->submit_count(); |
| 3320 commands = GetPut(); |
| 3321 gl_->QueryCounterEXT(id1, GL_TIMESTAMP_EXT); |
| 3322 EXPECT_EQ(GL_NO_ERROR, CheckError()); |
| 3323 EXPECT_NE(old_submit_count, query->submit_count()); |
| 3324 expected_query_counter_cmds.query_counter.Init( |
| 3325 GL_TIMESTAMP_EXT, id1, query->shm_id(), query->shm_offset(), |
| 3326 query->submit_count()); |
| 3327 EXPECT_EQ(0, memcmp(&expected_query_counter_cmds, commands, |
| 3328 sizeof(expected_query_counter_cmds))); |
| 3329 ClearCommands(); |
| 3330 |
| 3331 // Test GetQueryObjectuivEXT CheckResultsAvailable |
| 3332 GLuint available = 0xBDu; |
| 3333 ClearCommands(); |
| 3334 gl_->GetQueryObjectuivEXT(id1, GL_QUERY_RESULT_AVAILABLE_EXT, &available); |
| 3335 EXPECT_EQ(0u, available); |
| 3336 |
| 3337 // Test GetQueryObjectui64vEXT CheckResultsAvailable |
| 3338 GLuint64 available2 = 0xBDu; |
| 3339 ClearCommands(); |
| 3340 gl_->GetQueryObjectui64vEXT(id1, GL_QUERY_RESULT_AVAILABLE_EXT, &available2); |
| 3341 EXPECT_EQ(0u, available2); |
| 3342 } |
| 3343 |
| 3243 TEST_F(GLES2ImplementationTest, ErrorQuery) { | 3344 TEST_F(GLES2ImplementationTest, ErrorQuery) { |
| 3244 GLuint id = 0; | 3345 GLuint id = 0; |
| 3245 gl_->GenQueriesEXT(1, &id); | 3346 gl_->GenQueriesEXT(1, &id); |
| 3246 ClearCommands(); | 3347 ClearCommands(); |
| 3247 | 3348 |
| 3248 // Test BeginQueryEXT does NOT insert commands. | 3349 // Test BeginQueryEXT does NOT insert commands. |
| 3249 gl_->BeginQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM, id); | 3350 gl_->BeginQueryEXT(GL_GET_ERROR_QUERY_CHROMIUM, id); |
| 3250 EXPECT_TRUE(NoCommandsWritten()); | 3351 EXPECT_TRUE(NoCommandsWritten()); |
| 3251 QueryTracker::Query* query = GetQuery(id); | 3352 QueryTracker::Query* query = GetQuery(id); |
| 3252 ASSERT_TRUE(query != NULL); | 3353 ASSERT_TRUE(query != NULL); |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3860 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) { | 3961 TEST_F(GLES2ImplementationManualInitTest, FailInitOnTransferBufferFail) { |
| 3861 ContextInitOptions init_options; | 3962 ContextInitOptions init_options; |
| 3862 init_options.transfer_buffer_initialize_fail = true; | 3963 init_options.transfer_buffer_initialize_fail = true; |
| 3863 EXPECT_FALSE(Initialize(init_options)); | 3964 EXPECT_FALSE(Initialize(init_options)); |
| 3864 } | 3965 } |
| 3865 | 3966 |
| 3866 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" | 3967 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" |
| 3867 | 3968 |
| 3868 } // namespace gles2 | 3969 } // namespace gles2 |
| 3869 } // namespace gpu | 3970 } // namespace gpu |
| OLD | NEW |