| 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 | 6 |
| 7 #include "base/atomicops.h" | 7 #include "base/atomicops.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| 11 #include "base/numerics/safe_math.h" | 11 #include "base/numerics/safe_math.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 14 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 15 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" | 15 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" |
| 16 #include "gpu/command_buffer/service/error_state.h" | 16 #include "gpu/command_buffer/service/error_state.h" |
| 17 #include "gpu/command_buffer/service/feature_info.h" | 17 #include "gpu/command_buffer/service/feature_info.h" |
| 18 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 18 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 19 #include "ui/gl/gl_fence.h" | |
| 20 | 19 |
| 21 namespace gpu { | 20 namespace gpu { |
| 22 namespace gles2 { | 21 namespace gles2 { |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 class AsyncPixelTransferCompletionObserverImpl | 25 class AsyncPixelTransferCompletionObserverImpl |
| 27 : public AsyncPixelTransferCompletionObserver { | 26 : public AsyncPixelTransferCompletionObserver { |
| 28 public: | 27 public: |
| 29 AsyncPixelTransferCompletionObserverImpl(base::subtle::Atomic32 submit_count) | 28 AsyncPixelTransferCompletionObserverImpl(base::subtle::Atomic32 submit_count) |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 382 |
| 384 void GetErrorQuery::Destroy(bool /* have_context */) { | 383 void GetErrorQuery::Destroy(bool /* have_context */) { |
| 385 if (!IsDeleted()) { | 384 if (!IsDeleted()) { |
| 386 MarkAsDeleted(); | 385 MarkAsDeleted(); |
| 387 } | 386 } |
| 388 } | 387 } |
| 389 | 388 |
| 390 GetErrorQuery::~GetErrorQuery() { | 389 GetErrorQuery::~GetErrorQuery() { |
| 391 } | 390 } |
| 392 | 391 |
| 393 class CommandsCompletedQuery : public QueryManager::Query { | |
| 394 public: | |
| 395 CommandsCompletedQuery(QueryManager* manager, | |
| 396 GLenum target, | |
| 397 int32 shm_id, | |
| 398 uint32 shm_offset); | |
| 399 | |
| 400 // Overridden from QueryManager::Query: | |
| 401 virtual bool Begin() OVERRIDE; | |
| 402 virtual bool End(base::subtle::Atomic32 submit_count) OVERRIDE; | |
| 403 virtual bool Process() OVERRIDE; | |
| 404 virtual void Destroy(bool have_context) OVERRIDE; | |
| 405 | |
| 406 protected: | |
| 407 virtual ~CommandsCompletedQuery(); | |
| 408 | |
| 409 private: | |
| 410 scoped_ptr<gfx::GLFence> fence_; | |
| 411 }; | |
| 412 | |
| 413 CommandsCompletedQuery::CommandsCompletedQuery(QueryManager* manager, | |
| 414 GLenum target, | |
| 415 int32 shm_id, | |
| 416 uint32 shm_offset) | |
| 417 : Query(manager, target, shm_id, shm_offset) {} | |
| 418 | |
| 419 bool CommandsCompletedQuery::Begin() { return true; } | |
| 420 | |
| 421 bool CommandsCompletedQuery::End(base::subtle::Atomic32 submit_count) { | |
| 422 fence_.reset(gfx::GLFence::Create()); | |
| 423 DCHECK(fence_); | |
| 424 return AddToPendingQueue(submit_count); | |
| 425 } | |
| 426 | |
| 427 bool CommandsCompletedQuery::Process() { | |
| 428 if (fence_ && !fence_->HasCompleted()) | |
| 429 return true; | |
| 430 return MarkAsCompleted(0); | |
| 431 } | |
| 432 | |
| 433 void CommandsCompletedQuery::Destroy(bool have_context) { | |
| 434 if (have_context && !IsDeleted()) { | |
| 435 fence_.reset(); | |
| 436 MarkAsDeleted(); | |
| 437 } | |
| 438 } | |
| 439 | |
| 440 CommandsCompletedQuery::~CommandsCompletedQuery() {} | |
| 441 | |
| 442 QueryManager::QueryManager( | 392 QueryManager::QueryManager( |
| 443 GLES2Decoder* decoder, | 393 GLES2Decoder* decoder, |
| 444 FeatureInfo* feature_info) | 394 FeatureInfo* feature_info) |
| 445 : decoder_(decoder), | 395 : decoder_(decoder), |
| 446 use_arb_occlusion_query2_for_occlusion_query_boolean_( | 396 use_arb_occlusion_query2_for_occlusion_query_boolean_( |
| 447 feature_info->feature_flags( | 397 feature_info->feature_flags( |
| 448 ).use_arb_occlusion_query2_for_occlusion_query_boolean), | 398 ).use_arb_occlusion_query2_for_occlusion_query_boolean), |
| 449 use_arb_occlusion_query_for_occlusion_query_boolean_( | 399 use_arb_occlusion_query_for_occlusion_query_boolean_( |
| 450 feature_info->feature_flags( | 400 feature_info->feature_flags( |
| 451 ).use_arb_occlusion_query_for_occlusion_query_boolean), | 401 ).use_arb_occlusion_query_for_occlusion_query_boolean), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 query = new AsyncPixelTransfersCompletedQuery( | 437 query = new AsyncPixelTransfersCompletedQuery( |
| 488 this, target, shm_id, shm_offset); | 438 this, target, shm_id, shm_offset); |
| 489 break; | 439 break; |
| 490 case GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM: | 440 case GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM: |
| 491 query = new AsyncReadPixelsCompletedQuery( | 441 query = new AsyncReadPixelsCompletedQuery( |
| 492 this, target, shm_id, shm_offset); | 442 this, target, shm_id, shm_offset); |
| 493 break; | 443 break; |
| 494 case GL_GET_ERROR_QUERY_CHROMIUM: | 444 case GL_GET_ERROR_QUERY_CHROMIUM: |
| 495 query = new GetErrorQuery(this, target, shm_id, shm_offset); | 445 query = new GetErrorQuery(this, target, shm_id, shm_offset); |
| 496 break; | 446 break; |
| 497 case GL_COMMANDS_COMPLETED_CHROMIUM: | |
| 498 query = new CommandsCompletedQuery(this, target, shm_id, shm_offset); | |
| 499 break; | |
| 500 default: { | 447 default: { |
| 501 GLuint service_id = 0; | 448 GLuint service_id = 0; |
| 502 glGenQueriesARB(1, &service_id); | 449 glGenQueriesARB(1, &service_id); |
| 503 DCHECK_NE(0u, service_id); | 450 DCHECK_NE(0u, service_id); |
| 504 query = new AllSamplesPassedQuery( | 451 query = new AllSamplesPassedQuery( |
| 505 this, target, shm_id, shm_offset, service_id); | 452 this, target, shm_id, shm_offset, service_id); |
| 506 break; | 453 break; |
| 507 } | 454 } |
| 508 } | 455 } |
| 509 std::pair<QueryMap::iterator, bool> result = | 456 std::pair<QueryMap::iterator, bool> result = |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 bool QueryManager::EndQuery(Query* query, base::subtle::Atomic32 submit_count) { | 672 bool QueryManager::EndQuery(Query* query, base::subtle::Atomic32 submit_count) { |
| 726 DCHECK(query); | 673 DCHECK(query); |
| 727 if (!RemovePendingQuery(query)) { | 674 if (!RemovePendingQuery(query)) { |
| 728 return false; | 675 return false; |
| 729 } | 676 } |
| 730 return query->End(submit_count); | 677 return query->End(submit_count); |
| 731 } | 678 } |
| 732 | 679 |
| 733 } // namespace gles2 | 680 } // namespace gles2 |
| 734 } // namespace gpu | 681 } // namespace gpu |
| OLD | NEW |