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

Side by Side Diff: cc/raster/one_copy_tile_task_worker_pool.cc

Issue 1441613002: cc: Remove ScopedPtrDeque. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « cc/raster/one_copy_tile_task_worker_pool.h ('k') | cc/raster/task_graph_runner_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "cc/raster/one_copy_tile_task_worker_pool.h" 5 #include "cc/raster/one_copy_tile_task_worker_pool.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "base/trace_event/memory_dump_manager.h" 12 #include "base/trace_event/memory_dump_manager.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "base/trace_event/trace_event_argument.h" 14 #include "base/trace_event/trace_event_argument.h"
15 #include "cc/base/container_util.h"
15 #include "cc/base/math_util.h" 16 #include "cc/base/math_util.h"
16 #include "cc/debug/traced_value.h" 17 #include "cc/debug/traced_value.h"
17 #include "cc/raster/raster_buffer.h" 18 #include "cc/raster/raster_buffer.h"
18 #include "cc/resources/platform_color.h" 19 #include "cc/resources/platform_color.h"
19 #include "cc/resources/resource_format.h" 20 #include "cc/resources/resource_format.h"
20 #include "cc/resources/resource_util.h" 21 #include "cc/resources/resource_util.h"
21 #include "cc/resources/scoped_resource.h" 22 #include "cc/resources/scoped_resource.h"
22 #include "gpu/GLES2/gl2extchromium.h" 23 #include "gpu/GLES2/gl2extchromium.h"
23 #include "gpu/command_buffer/client/gles2_interface.h" 24 #include "gpu/command_buffer/client/gles2_interface.h"
24 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 25 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 607
607 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); 608 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL();
608 DCHECK(gl); 609 DCHECK(gl);
609 610
610 // Check if any busy buffers have become available. 611 // Check if any busy buffers have become available.
611 if (resource_provider_->use_sync_query()) { 612 if (resource_provider_->use_sync_query()) {
612 while (!busy_buffers_.empty()) { 613 while (!busy_buffers_.empty()) {
613 if (!CheckForQueryResult(gl, busy_buffers_.front()->query_id)) 614 if (!CheckForQueryResult(gl, busy_buffers_.front()->query_id))
614 break; 615 break;
615 616
616 MarkStagingBufferAsFree(busy_buffers_.front()); 617 MarkStagingBufferAsFree(busy_buffers_.front().get());
617 free_buffers_.push_back(busy_buffers_.take_front()); 618 free_buffers_.push_back(PopFront(&busy_buffers_));
618 } 619 }
619 } 620 }
620 621
621 // Wait for memory usage of non-free buffers to become less than the limit. 622 // Wait for memory usage of non-free buffers to become less than the limit.
622 while ( 623 while (
623 (staging_buffer_usage_in_bytes_ - free_staging_buffer_usage_in_bytes_) >= 624 (staging_buffer_usage_in_bytes_ - free_staging_buffer_usage_in_bytes_) >=
624 max_staging_buffer_usage_in_bytes_) { 625 max_staging_buffer_usage_in_bytes_) {
625 // Stop when there are no more busy buffers to wait for. 626 // Stop when there are no more busy buffers to wait for.
626 if (busy_buffers_.empty()) 627 if (busy_buffers_.empty())
627 break; 628 break;
628 629
629 if (resource_provider_->use_sync_query()) { 630 if (resource_provider_->use_sync_query()) {
630 WaitForQueryResult(gl, busy_buffers_.front()->query_id); 631 WaitForQueryResult(gl, busy_buffers_.front()->query_id);
631 MarkStagingBufferAsFree(busy_buffers_.front()); 632 MarkStagingBufferAsFree(busy_buffers_.front().get());
632 free_buffers_.push_back(busy_buffers_.take_front()); 633 free_buffers_.push_back(PopFront(&busy_buffers_));
633 } else { 634 } else {
634 // Fall-back to glFinish if CHROMIUM_sync_query is not available. 635 // Fall-back to glFinish if CHROMIUM_sync_query is not available.
635 gl->Finish(); 636 gl->Finish();
636 while (!busy_buffers_.empty()) { 637 while (!busy_buffers_.empty()) {
637 MarkStagingBufferAsFree(busy_buffers_.front()); 638 MarkStagingBufferAsFree(busy_buffers_.front().get());
638 free_buffers_.push_back(busy_buffers_.take_front()); 639 free_buffers_.push_back(PopFront(&busy_buffers_));
639 } 640 }
640 } 641 }
641 } 642 }
642 643
643 // Find a staging buffer that allows us to perform partial raster when 644 // Find a staging buffer that allows us to perform partial raster when
644 // using persistent GpuMemoryBuffers. 645 // using persistent GpuMemoryBuffers.
645 if (use_partial_raster_ && previous_content_id) { 646 if (use_partial_raster_ && previous_content_id) {
646 StagingBufferDeque::iterator it = 647 StagingBufferDeque::iterator it = std::find_if(
647 std::find_if(free_buffers_.begin(), free_buffers_.end(), 648 free_buffers_.begin(), free_buffers_.end(),
648 [previous_content_id](const StagingBuffer* buffer) { 649 [previous_content_id](const scoped_ptr<StagingBuffer>& buffer) {
649 return buffer->content_id == previous_content_id; 650 return buffer->content_id == previous_content_id;
650 }); 651 });
651 if (it != free_buffers_.end()) { 652 if (it != free_buffers_.end()) {
652 staging_buffer = free_buffers_.take(it); 653 staging_buffer = it->Pass();
654 free_buffers_.erase(it);
653 MarkStagingBufferAsBusy(staging_buffer.get()); 655 MarkStagingBufferAsBusy(staging_buffer.get());
654 } 656 }
655 } 657 }
656 658
657 // Find staging buffer of correct size and format. 659 // Find staging buffer of correct size and format.
658 if (!staging_buffer) { 660 if (!staging_buffer) {
659 StagingBufferDeque::iterator it = 661 StagingBufferDeque::iterator it =
660 std::find_if(free_buffers_.begin(), free_buffers_.end(), 662 std::find_if(free_buffers_.begin(), free_buffers_.end(),
661 [resource](const StagingBuffer* buffer) { 663 [resource](const scoped_ptr<StagingBuffer>& buffer) {
662 return buffer->size == resource->size() && 664 return buffer->size == resource->size() &&
663 buffer->format == resource->format(); 665 buffer->format == resource->format();
664 }); 666 });
665 if (it != free_buffers_.end()) { 667 if (it != free_buffers_.end()) {
666 staging_buffer = free_buffers_.take(it); 668 staging_buffer = it->Pass();
669 free_buffers_.erase(it);
667 MarkStagingBufferAsBusy(staging_buffer.get()); 670 MarkStagingBufferAsBusy(staging_buffer.get());
668 } 671 }
669 } 672 }
670 673
671 // Create new staging buffer if necessary. 674 // Create new staging buffer if necessary.
672 if (!staging_buffer) { 675 if (!staging_buffer) {
673 staging_buffer = make_scoped_ptr( 676 staging_buffer = make_scoped_ptr(
674 new StagingBuffer(resource->size(), resource->format())); 677 new StagingBuffer(resource->size(), resource->format()));
675 AddStagingBuffer(staging_buffer.get(), resource->format()); 678 AddStagingBuffer(staging_buffer.get(), resource->format());
676 } 679 }
677 680
678 // Release enough free buffers to stay within the limit. 681 // Release enough free buffers to stay within the limit.
679 while (staging_buffer_usage_in_bytes_ > max_staging_buffer_usage_in_bytes_) { 682 while (staging_buffer_usage_in_bytes_ > max_staging_buffer_usage_in_bytes_) {
680 if (free_buffers_.empty()) 683 if (free_buffers_.empty())
681 break; 684 break;
682 685
683 free_buffers_.front()->DestroyGLResources(gl); 686 free_buffers_.front()->DestroyGLResources(gl);
684 MarkStagingBufferAsBusy(free_buffers_.front()); 687 MarkStagingBufferAsBusy(free_buffers_.front().get());
685 RemoveStagingBuffer(free_buffers_.front()); 688 RemoveStagingBuffer(free_buffers_.front().get());
686 free_buffers_.take_front(); 689 free_buffers_.pop_front();
687 } 690 }
688 691
689 return staging_buffer.Pass(); 692 return staging_buffer.Pass();
690 } 693 }
691 694
692 base::TimeTicks OneCopyTileTaskWorkerPool::GetUsageTimeForLRUBuffer() { 695 base::TimeTicks OneCopyTileTaskWorkerPool::GetUsageTimeForLRUBuffer() {
693 lock_.AssertAcquired(); 696 lock_.AssertAcquired();
694 697
695 if (!free_buffers_.empty()) 698 if (!free_buffers_.empty())
696 return free_buffers_.front()->last_usage; 699 return free_buffers_.front()->last_usage;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); 759 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL();
757 DCHECK(gl); 760 DCHECK(gl);
758 761
759 // Note: Front buffer is guaranteed to be LRU so we can stop releasing 762 // Note: Front buffer is guaranteed to be LRU so we can stop releasing
760 // buffers as soon as we find a buffer that has been used since |time|. 763 // buffers as soon as we find a buffer that has been used since |time|.
761 while (!free_buffers_.empty()) { 764 while (!free_buffers_.empty()) {
762 if (free_buffers_.front()->last_usage > time) 765 if (free_buffers_.front()->last_usage > time)
763 return; 766 return;
764 767
765 free_buffers_.front()->DestroyGLResources(gl); 768 free_buffers_.front()->DestroyGLResources(gl);
766 MarkStagingBufferAsBusy(free_buffers_.front()); 769 MarkStagingBufferAsBusy(free_buffers_.front().get());
767 RemoveStagingBuffer(free_buffers_.front()); 770 RemoveStagingBuffer(free_buffers_.front().get());
768 free_buffers_.take_front(); 771 free_buffers_.pop_front();
769 } 772 }
770 773
771 while (!busy_buffers_.empty()) { 774 while (!busy_buffers_.empty()) {
772 if (busy_buffers_.front()->last_usage > time) 775 if (busy_buffers_.front()->last_usage > time)
773 return; 776 return;
774 777
775 busy_buffers_.front()->DestroyGLResources(gl); 778 busy_buffers_.front()->DestroyGLResources(gl);
776 RemoveStagingBuffer(busy_buffers_.front()); 779 RemoveStagingBuffer(busy_buffers_.front().get());
777 busy_buffers_.take_front(); 780 busy_buffers_.pop_front();
778 } 781 }
779 } 782 }
780 } 783 }
781 784
782 void OneCopyTileTaskWorkerPool::OnTaskSetFinished(TaskSet task_set) { 785 void OneCopyTileTaskWorkerPool::OnTaskSetFinished(TaskSet task_set) {
783 TRACE_EVENT1("cc", "OneCopyTileTaskWorkerPool::OnTaskSetFinished", "task_set", 786 TRACE_EVENT1("cc", "OneCopyTileTaskWorkerPool::OnTaskSetFinished", "task_set",
784 task_set); 787 task_set);
785 788
786 DCHECK(tasks_pending_[task_set]); 789 DCHECK(tasks_pending_[task_set]);
787 tasks_pending_[task_set] = false; 790 tasks_pending_[task_set] = false;
(...skipping 28 matching lines...) Expand all
816 819
817 staging_state->SetInteger("staging_buffer_count", 820 staging_state->SetInteger("staging_buffer_count",
818 static_cast<int>(buffers_.size())); 821 static_cast<int>(buffers_.size()));
819 staging_state->SetInteger("busy_count", 822 staging_state->SetInteger("busy_count",
820 static_cast<int>(busy_buffers_.size())); 823 static_cast<int>(busy_buffers_.size()));
821 staging_state->SetInteger("free_count", 824 staging_state->SetInteger("free_count",
822 static_cast<int>(free_buffers_.size())); 825 static_cast<int>(free_buffers_.size()));
823 } 826 }
824 827
825 } // namespace cc 828 } // namespace cc
OLDNEW
« no previous file with comments | « cc/raster/one_copy_tile_task_worker_pool.h ('k') | cc/raster/task_graph_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698