Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: gpu/command_buffer/service/query_manager.cc

Issue 2447533002: ui: Add ref-counting to GLFence class.
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/atomicops.h" 10 #include "base/atomicops.h"
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 bool QueryCounter(base::subtle::Atomic32 submit_count) override; 472 bool QueryCounter(base::subtle::Atomic32 submit_count) override;
473 void Pause() override; 473 void Pause() override;
474 void Resume() override; 474 void Resume() override;
475 bool Process(bool did_finish) override; 475 bool Process(bool did_finish) override;
476 void Destroy(bool have_context) override; 476 void Destroy(bool have_context) override;
477 477
478 protected: 478 protected:
479 ~CommandsCompletedQuery() override; 479 ~CommandsCompletedQuery() override;
480 480
481 private: 481 private:
482 std::unique_ptr<gl::GLFence> fence_; 482 scoped_refptr<gl::GLFence> fence_;
483 base::TimeTicks begin_time_; 483 base::TimeTicks begin_time_;
484 }; 484 };
485 485
486 CommandsCompletedQuery::CommandsCompletedQuery(QueryManager* manager, 486 CommandsCompletedQuery::CommandsCompletedQuery(QueryManager* manager,
487 GLenum target, 487 GLenum target,
488 int32_t shm_id, 488 int32_t shm_id,
489 uint32_t shm_offset) 489 uint32_t shm_offset)
490 : Query(manager, target, shm_id, shm_offset) {} 490 : Query(manager, target, shm_id, shm_offset) {}
491 491
492 bool CommandsCompletedQuery::Begin() { 492 bool CommandsCompletedQuery::Begin() {
493 MarkAsActive(); 493 MarkAsActive();
494 begin_time_ = base::TimeTicks::Now(); 494 begin_time_ = base::TimeTicks::Now();
495 return true; 495 return true;
496 } 496 }
497 497
498 void CommandsCompletedQuery::Pause() { 498 void CommandsCompletedQuery::Pause() {
499 MarkAsPaused(); 499 MarkAsPaused();
500 } 500 }
501 501
502 void CommandsCompletedQuery::Resume() { 502 void CommandsCompletedQuery::Resume() {
503 MarkAsActive(); 503 MarkAsActive();
504 } 504 }
505 505
506 bool CommandsCompletedQuery::End(base::subtle::Atomic32 submit_count) { 506 bool CommandsCompletedQuery::End(base::subtle::Atomic32 submit_count) {
507 if (fence_ && fence_->ResetSupported()) { 507 if (fence_ && fence_->ResetSupported()) {
508 fence_->ResetState(); 508 fence_->ResetState();
509 } 509 }
510 else { 510 else {
511 fence_.reset(gl::GLFence::Create()); 511 fence_ = gl::GLFence::Create();
512 } 512 }
513 DCHECK(fence_); 513 DCHECK(fence_);
514 return AddToPendingQueue(submit_count); 514 return AddToPendingQueue(submit_count);
515 } 515 }
516 516
517 bool CommandsCompletedQuery::QueryCounter(base::subtle::Atomic32 submit_count) { 517 bool CommandsCompletedQuery::QueryCounter(base::subtle::Atomic32 submit_count) {
518 NOTREACHED(); 518 NOTREACHED();
519 return false; 519 return false;
520 } 520 }
521 521
522 bool CommandsCompletedQuery::Process(bool did_finish) { 522 bool CommandsCompletedQuery::Process(bool did_finish) {
523 // Note: |did_finish| guarantees that the GPU has passed the fence but 523 // Note: |did_finish| guarantees that the GPU has passed the fence but
524 // we cannot assume that GLFence::HasCompleted() will return true yet as 524 // we cannot assume that GLFence::HasCompleted() will return true yet as
525 // that's not guaranteed by all GLFence implementations. 525 // that's not guaranteed by all GLFence implementations.
526 if (!did_finish && fence_ && !fence_->HasCompleted()) 526 if (!did_finish && fence_ && !fence_->HasCompleted())
527 return true; 527 return true;
528 528
529 const base::TimeDelta elapsed = base::TimeTicks::Now() - begin_time_; 529 const base::TimeDelta elapsed = base::TimeTicks::Now() - begin_time_;
530 return MarkAsCompleted(elapsed.InMicroseconds()); 530 return MarkAsCompleted(elapsed.InMicroseconds());
531 } 531 }
532 532
533 void CommandsCompletedQuery::Destroy(bool have_context) { 533 void CommandsCompletedQuery::Destroy(bool have_context) {
534 if (have_context && !IsDeleted()) { 534 if (have_context && !IsDeleted()) {
535 fence_.reset(); 535 fence_ = nullptr;
536 MarkAsDeleted(); 536 MarkAsDeleted();
537 } 537 }
538 } 538 }
539 539
540 CommandsCompletedQuery::~CommandsCompletedQuery() {} 540 CommandsCompletedQuery::~CommandsCompletedQuery() {}
541 541
542 class TimeElapsedQuery : public QueryManager::Query { 542 class TimeElapsedQuery : public QueryManager::Query {
543 public: 543 public:
544 TimeElapsedQuery(QueryManager* manager, 544 TimeElapsedQuery(QueryManager* manager,
545 GLenum target, 545 GLenum target,
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 for (std::pair<const GLenum, scoped_refptr<Query> >& it : active_queries_) { 1132 for (std::pair<const GLenum, scoped_refptr<Query> >& it : active_queries_) {
1133 if (it.second->IsPaused()) { 1133 if (it.second->IsPaused()) {
1134 it.second->Resume(); 1134 it.second->Resume();
1135 DCHECK(it.second->IsActive()); 1135 DCHECK(it.second->IsActive());
1136 } 1136 }
1137 } 1137 }
1138 } 1138 }
1139 1139
1140 } // namespace gles2 1140 } // namespace gles2
1141 } // namespace gpu 1141 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/mailbox_manager_sync.cc ('k') | gpu/command_buffer/tests/gl_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698