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

Side by Side Diff: cc/resources/tile_manager.cc

Issue 603683006: cc: Remove low quality mode and cleanup tile versions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 6 years, 2 months 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/resources/tile_manager.h" 5 #include "cc/resources/tile_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
(...skipping 21 matching lines...) Expand all
32 // a tile is of solid color. 32 // a tile is of solid color.
33 const bool kUseColorEstimator = true; 33 const bool kUseColorEstimator = true;
34 34
35 class RasterTaskImpl : public RasterTask { 35 class RasterTaskImpl : public RasterTask {
36 public: 36 public:
37 RasterTaskImpl( 37 RasterTaskImpl(
38 const Resource* resource, 38 const Resource* resource,
39 PicturePileImpl* picture_pile, 39 PicturePileImpl* picture_pile,
40 const gfx::Rect& content_rect, 40 const gfx::Rect& content_rect,
41 float contents_scale, 41 float contents_scale,
42 RasterMode raster_mode,
43 TileResolution tile_resolution, 42 TileResolution tile_resolution,
44 int layer_id, 43 int layer_id,
45 const void* tile_id, 44 const void* tile_id,
46 int source_frame_number, 45 int source_frame_number,
47 bool analyze_picture, 46 bool analyze_picture,
48 RenderingStatsInstrumentation* rendering_stats, 47 RenderingStatsInstrumentation* rendering_stats,
49 const base::Callback<void(const PicturePileImpl::Analysis&, bool)>& reply, 48 const base::Callback<void(const PicturePileImpl::Analysis&, bool)>& reply,
50 ImageDecodeTask::Vector* dependencies) 49 ImageDecodeTask::Vector* dependencies)
51 : RasterTask(resource, dependencies), 50 : RasterTask(resource, dependencies),
52 picture_pile_(picture_pile), 51 picture_pile_(picture_pile),
53 content_rect_(content_rect), 52 content_rect_(content_rect),
54 contents_scale_(contents_scale), 53 contents_scale_(contents_scale),
55 raster_mode_(raster_mode),
56 tile_resolution_(tile_resolution), 54 tile_resolution_(tile_resolution),
57 layer_id_(layer_id), 55 layer_id_(layer_id),
58 tile_id_(tile_id), 56 tile_id_(tile_id),
59 source_frame_number_(source_frame_number), 57 source_frame_number_(source_frame_number),
60 analyze_picture_(analyze_picture), 58 analyze_picture_(analyze_picture),
61 rendering_stats_(rendering_stats), 59 rendering_stats_(rendering_stats),
62 reply_(reply) {} 60 reply_(reply) {}
63 61
64 // Overridden from Task: 62 // Overridden from Task:
65 virtual void RunOnWorkerThread() OVERRIDE { 63 virtual void RunOnWorkerThread() OVERRIDE {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // Record the solid color prediction. 104 // Record the solid color prediction.
107 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", 105 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed",
108 analysis_.is_solid_color); 106 analysis_.is_solid_color);
109 107
110 // Clear the flag if we're not using the estimator. 108 // Clear the flag if we're not using the estimator.
111 analysis_.is_solid_color &= kUseColorEstimator; 109 analysis_.is_solid_color &= kUseColorEstimator;
112 } 110 }
113 111
114 void Raster(const PicturePileImpl* picture_pile) { 112 void Raster(const PicturePileImpl* picture_pile) {
115 frame_viewer_instrumentation::ScopedRasterTask raster_task( 113 frame_viewer_instrumentation::ScopedRasterTask raster_task(
116 tile_id_, 114 tile_id_, tile_resolution_, source_frame_number_, layer_id_);
117 tile_resolution_,
118 source_frame_number_,
119 layer_id_,
120 raster_mode_);
121 devtools_instrumentation::ScopedLayerTask layer_task( 115 devtools_instrumentation::ScopedLayerTask layer_task(
122 devtools_instrumentation::kRasterTask, layer_id_); 116 devtools_instrumentation::kRasterTask, layer_id_);
123 117
124 skia::RefPtr<SkCanvas> canvas = raster_buffer_->AcquireSkCanvas(); 118 skia::RefPtr<SkCanvas> canvas = raster_buffer_->AcquireSkCanvas();
125 DCHECK(canvas); 119 DCHECK(canvas);
126 120
127 skia::RefPtr<SkDrawFilter> draw_filter;
128 switch (raster_mode_) {
129 case LOW_QUALITY_RASTER_MODE:
130 draw_filter = skia::AdoptRef(new skia::PaintSimplifier);
danakj 2014/09/26 22:38:21 shall we inform skia folks that this is not used n
vmpstr 2014/09/26 22:51:39 PaintSimplifier is a skia/ext thing... so I'm not
danakj 2014/09/26 23:01:44 should we remove it then after this?
131 break;
132 case HIGH_QUALITY_RASTER_MODE:
133 break;
134 case NUM_RASTER_MODES:
135 default:
136 NOTREACHED();
137 }
138 canvas->setDrawFilter(draw_filter.get());
139
140 base::TimeDelta prev_rasterize_time = 121 base::TimeDelta prev_rasterize_time =
141 rendering_stats_->impl_thread_rendering_stats().rasterize_time; 122 rendering_stats_->impl_thread_rendering_stats().rasterize_time;
142 123
143 // Only record rasterization time for highres tiles, because 124 // Only record rasterization time for highres tiles, because
144 // lowres tiles are not required for activation and therefore 125 // lowres tiles are not required for activation and therefore
145 // introduce noise in the measurement (sometimes they get rasterized 126 // introduce noise in the measurement (sometimes they get rasterized
146 // before we draw and sometimes they aren't) 127 // before we draw and sometimes they aren't)
147 RenderingStatsInstrumentation* stats = 128 RenderingStatsInstrumentation* stats =
148 tile_resolution_ == HIGH_RESOLUTION ? rendering_stats_ : NULL; 129 tile_resolution_ == HIGH_RESOLUTION ? rendering_stats_ : NULL;
149 DCHECK(picture_pile); 130 DCHECK(picture_pile);
(...skipping 11 matching lines...) Expand all
161 100); 142 100);
162 } 143 }
163 144
164 raster_buffer_->ReleaseSkCanvas(canvas); 145 raster_buffer_->ReleaseSkCanvas(canvas);
165 } 146 }
166 147
167 PicturePileImpl::Analysis analysis_; 148 PicturePileImpl::Analysis analysis_;
168 scoped_refptr<PicturePileImpl> picture_pile_; 149 scoped_refptr<PicturePileImpl> picture_pile_;
169 gfx::Rect content_rect_; 150 gfx::Rect content_rect_;
170 float contents_scale_; 151 float contents_scale_;
171 RasterMode raster_mode_;
172 TileResolution tile_resolution_; 152 TileResolution tile_resolution_;
173 int layer_id_; 153 int layer_id_;
174 const void* tile_id_; 154 const void* tile_id_;
175 int source_frame_number_; 155 int source_frame_number_;
176 bool analyze_picture_; 156 bool analyze_picture_;
177 RenderingStatsInstrumentation* rendering_stats_; 157 RenderingStatsInstrumentation* rendering_stats_;
178 const base::Callback<void(const PicturePileImpl::Analysis&, bool)> reply_; 158 const base::Callback<void(const PicturePileImpl::Analysis&, bool)> reply_;
179 scoped_ptr<RasterBuffer> raster_buffer_; 159 scoped_ptr<RasterBuffer> raster_buffer_;
180 160
181 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); 161 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl);
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 bool allow_rasterize_on_demand = 497 bool allow_rasterize_on_demand =
518 global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY && 498 global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY &&
519 global_state_.memory_limit_policy != ALLOW_NOTHING; 499 global_state_.memory_limit_policy != ALLOW_NOTHING;
520 500
521 // Use on-demand raster for any required-for-activation tiles that have not 501 // Use on-demand raster for any required-for-activation tiles that have not
522 // been been assigned memory after reaching a steady memory state. This 502 // been been assigned memory after reaching a steady memory state. This
523 // ensures that we activate even when OOM. 503 // ensures that we activate even when OOM.
524 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 504 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
525 Tile* tile = it->second; 505 Tile* tile = it->second;
526 ManagedTileState& mts = tile->managed_state(); 506 ManagedTileState& mts = tile->managed_state();
527 ManagedTileState::TileVersion& tile_version = 507 ManagedTileState::TileDrawInfo& draw_info = mts.draw_info_;
528 mts.tile_versions[mts.raster_mode];
529 508
530 if (tile->required_for_activation() && !tile_version.IsReadyToDraw()) { 509 if (tile->required_for_activation() && !draw_info.IsReadyToDraw()) {
531 // If we can't raster on demand, give up early (and don't activate). 510 // If we can't raster on demand, give up early (and don't activate).
532 if (!allow_rasterize_on_demand) 511 if (!allow_rasterize_on_demand)
533 return; 512 return;
534 513
535 tile_version.set_rasterize_on_demand(); 514 draw_info.set_rasterize_on_demand();
536 client_->NotifyTileStateChanged(tile); 515 client_->NotifyTileStateChanged(tile);
537 } 516 }
538 } 517 }
539 518
540 DCHECK(IsReadyToActivate()); 519 DCHECK(IsReadyToActivate());
541 ready_to_activate_check_notifier_.Schedule(); 520 ready_to_activate_check_notifier_.Schedule();
542 return; 521 return;
543 } 522 }
544 523
545 if (task_set == REQUIRED_FOR_ACTIVATION) { 524 if (task_set == REQUIRED_FOR_ACTIVATION) {
(...skipping 19 matching lines...) Expand all
565 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); 544 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins");
566 545
567 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; 546 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy;
568 const TreePriority tree_priority = global_state_.tree_priority; 547 const TreePriority tree_priority = global_state_.tree_priority;
569 548
570 // For each tree, bin into different categories of tiles. 549 // For each tree, bin into different categories of tiles.
571 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 550 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
572 Tile* tile = it->second; 551 Tile* tile = it->second;
573 ManagedTileState& mts = tile->managed_state(); 552 ManagedTileState& mts = tile->managed_state();
574 553
575 const ManagedTileState::TileVersion& tile_version = 554 const ManagedTileState::TileDrawInfo& draw_info = tile->GetTileDrawInfo();
576 tile->GetTileVersionForDrawing(); 555 bool tile_is_ready_to_draw = draw_info.IsReadyToDraw();
577 bool tile_is_ready_to_draw = tile_version.IsReadyToDraw(); 556 bool tile_is_active =
578 bool tile_is_active = tile_is_ready_to_draw || 557 tile_is_ready_to_draw || mts.draw_info_.raster_task_.get();
579 mts.tile_versions[mts.raster_mode].raster_task_.get();
580 558
581 // Get the active priority and bin. 559 // Get the active priority and bin.
582 TilePriority active_priority = tile->priority(ACTIVE_TREE); 560 TilePriority active_priority = tile->priority(ACTIVE_TREE);
583 ManagedTileBin active_bin = BinFromTilePriority(active_priority); 561 ManagedTileBin active_bin = BinFromTilePriority(active_priority);
584 562
585 // Get the pending priority and bin. 563 // Get the pending priority and bin.
586 TilePriority pending_priority = tile->priority(PENDING_TREE); 564 TilePriority pending_priority = tile->priority(PENDING_TREE);
587 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority); 565 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority);
588 566
589 bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION; 567 bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 // smoothness takes priority or memory policy allows nothing to be 632 // smoothness takes priority or memory policy allows nothing to be
655 // initialized. 633 // initialized.
656 DCHECK(!mts.required_for_activation || mts.bin != NEVER_BIN || 634 DCHECK(!mts.required_for_activation || mts.bin != NEVER_BIN ||
657 tree_priority == SMOOTHNESS_TAKES_PRIORITY || 635 tree_priority == SMOOTHNESS_TAKES_PRIORITY ||
658 memory_policy == ALLOW_NOTHING); 636 memory_policy == ALLOW_NOTHING);
659 637
660 // If the tile is in NEVER_BIN and it does not have an active task, then we 638 // If the tile is in NEVER_BIN and it does not have an active task, then we
661 // can release the resources early. If it does have the task however, we 639 // can release the resources early. If it does have the task however, we
662 // should keep it in the prioritized tile set to ensure that AssignGpuMemory 640 // should keep it in the prioritized tile set to ensure that AssignGpuMemory
663 // can visit it. 641 // can visit it.
664 if (mts.bin == NEVER_BIN && 642 if (mts.bin == NEVER_BIN && !mts.draw_info_.raster_task_.get()) {
665 !mts.tile_versions[mts.raster_mode].raster_task_.get()) {
666 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); 643 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile);
667 continue; 644 continue;
668 } 645 }
669 646
670 // Insert the tile into a priority set. 647 // Insert the tile into a priority set.
671 tiles->InsertTile(tile, mts.bin); 648 tiles->InsertTile(tile, mts.bin);
672 } 649 }
673 } 650 }
674 651
675 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { 652 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 bool oomed_hard = false; 766 bool oomed_hard = false;
790 bool have_hit_soft_memory = false; // Soft memory comes after hard. 767 bool have_hit_soft_memory = false; // Soft memory comes after hard.
791 768
792 unsigned schedule_priority = 1u; 769 unsigned schedule_priority = 1u;
793 for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) { 770 for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) {
794 Tile* tile = *it; 771 Tile* tile = *it;
795 ManagedTileState& mts = tile->managed_state(); 772 ManagedTileState& mts = tile->managed_state();
796 773
797 mts.scheduled_priority = schedule_priority++; 774 mts.scheduled_priority = schedule_priority++;
798 775
799 mts.raster_mode = tile->DetermineOverallRasterMode(); 776 ManagedTileState::TileDrawInfo& draw_info = mts.draw_info_;
800
801 ManagedTileState::TileVersion& tile_version =
802 mts.tile_versions[mts.raster_mode];
803 777
804 // If this tile doesn't need a resource, then nothing to do. 778 // If this tile doesn't need a resource, then nothing to do.
805 if (!tile_version.requires_resource()) 779 if (!draw_info.requires_resource())
806 continue; 780 continue;
807 781
808 // If the tile is not needed, free it up. 782 // If the tile is not needed, free it up.
809 if (mts.bin == NEVER_BIN) { 783 if (mts.bin == NEVER_BIN) {
810 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); 784 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile);
811 continue; 785 continue;
812 } 786 }
813 787
814 const bool tile_uses_hard_limit = mts.bin <= NOW_BIN; 788 const bool tile_uses_hard_limit = mts.bin <= NOW_BIN;
815 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); 789 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile);
816 const size_t tile_bytes_left = 790 const size_t tile_bytes_left =
817 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left; 791 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left;
818 792
819 // Hard-limit is reserved for tiles that would cause a calamity 793 // Hard-limit is reserved for tiles that would cause a calamity
820 // if they were to go away, so by definition they are the highest 794 // if they were to go away, so by definition they are the highest
821 // priority memory, and must be at the front of the list. 795 // priority memory, and must be at the front of the list.
822 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); 796 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit));
823 have_hit_soft_memory |= !tile_uses_hard_limit; 797 have_hit_soft_memory |= !tile_uses_hard_limit;
824 798
825 size_t tile_bytes = 0; 799 size_t tile_bytes = 0;
826 size_t tile_resources = 0; 800 size_t tile_resources = 0;
827 801
828 // It costs to maintain a resource. 802 // It costs to maintain a resource.
829 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { 803 if (mts.draw_info_.resource_) {
830 if (mts.tile_versions[mode].resource_) { 804 tile_bytes += bytes_if_allocated;
831 tile_bytes += bytes_if_allocated; 805 tile_resources++;
832 tile_resources++;
833 }
834 } 806 }
835 807
836 // Allow lower priority tiles with initialized resources to keep 808 // Allow lower priority tiles with initialized resources to keep
837 // their memory by only assigning memory to new raster tasks if 809 // their memory by only assigning memory to new raster tasks if
838 // they can be scheduled. 810 // they can be scheduled.
839 bool reached_scheduled_raster_tasks_limit = 811 bool reached_scheduled_raster_tasks_limit =
840 tiles_that_need_to_be_rasterized->size() >= kScheduledRasterTasksLimit; 812 tiles_that_need_to_be_rasterized->size() >= kScheduledRasterTasksLimit;
841 if (!reached_scheduled_raster_tasks_limit) { 813 if (!reached_scheduled_raster_tasks_limit) {
842 // If we don't have the required version, and it's not in flight 814 // If we don't have the required version, and it's not in flight
843 // then we'll have to pay to create a new task. 815 // then we'll have to pay to create a new task.
844 if (!tile_version.resource_ && !tile_version.raster_task_.get()) { 816 if (!draw_info.resource_ && !draw_info.raster_task_.get()) {
845 tile_bytes += bytes_if_allocated; 817 tile_bytes += bytes_if_allocated;
846 tile_resources++; 818 tile_resources++;
847 } 819 }
848 } 820 }
849 821
850 // Tile is OOM. 822 // Tile is OOM.
851 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { 823 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) {
852 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); 824 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile);
853 825
854 // This tile was already on screen and now its resources have been 826 // This tile was already on screen and now its resources have been
855 // released. In order to prevent checkerboarding, set this tile as 827 // released. In order to prevent checkerboarding, set this tile as
856 // rasterize on demand immediately. 828 // rasterize on demand immediately.
857 if (mts.visible_and_ready_to_draw) 829 if (mts.visible_and_ready_to_draw)
858 tile_version.set_rasterize_on_demand(); 830 draw_info.set_rasterize_on_demand();
859 831
860 oomed_soft = true; 832 oomed_soft = true;
861 if (tile_uses_hard_limit) { 833 if (tile_uses_hard_limit) {
862 oomed_hard = true; 834 oomed_hard = true;
863 bytes_that_exceeded_memory_budget += tile_bytes; 835 bytes_that_exceeded_memory_budget += tile_bytes;
864 } 836 }
865 } else { 837 } else {
866 resources_left -= tile_resources; 838 resources_left -= tile_resources;
867 hard_bytes_left -= tile_bytes; 839 hard_bytes_left -= tile_bytes;
868 soft_bytes_left = 840 soft_bytes_left =
869 (soft_bytes_left > tile_bytes) ? soft_bytes_left - tile_bytes : 0; 841 (soft_bytes_left > tile_bytes) ? soft_bytes_left - tile_bytes : 0;
870 if (tile_version.resource_) 842 if (draw_info.resource_)
871 continue; 843 continue;
872 } 844 }
873 845
874 DCHECK(!tile_version.resource_); 846 DCHECK(!draw_info.resource_);
875 847
876 // Tile shouldn't be rasterized if |tiles_that_need_to_be_rasterized| 848 // Tile shouldn't be rasterized if |tiles_that_need_to_be_rasterized|
877 // has reached it's limit or we've failed to assign gpu memory to this 849 // has reached it's limit or we've failed to assign gpu memory to this
878 // or any higher priority tile. Preventing tiles that fit into memory 850 // or any higher priority tile. Preventing tiles that fit into memory
879 // budget to be rasterized when higher priority tile is oom is 851 // budget to be rasterized when higher priority tile is oom is
880 // important for two reasons: 852 // important for two reasons:
881 // 1. Tile size should not impact raster priority. 853 // 1. Tile size should not impact raster priority.
882 // 2. Tiles with existing raster task could otherwise incorrectly 854 // 2. Tiles with existing raster task could otherwise incorrectly
883 // be added as they are not affected by |bytes_allocatable|. 855 // be added as they are not affected by |bytes_allocatable|.
884 bool can_schedule_tile = 856 bool can_schedule_tile =
(...skipping 25 matching lines...) Expand all
910 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget", oomed_hard); 882 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget", oomed_hard);
911 memory_stats_from_last_assign_.total_budget_in_bytes = 883 memory_stats_from_last_assign_.total_budget_in_bytes =
912 global_state_.hard_memory_limit_in_bytes; 884 global_state_.hard_memory_limit_in_bytes;
913 memory_stats_from_last_assign_.bytes_allocated = 885 memory_stats_from_last_assign_.bytes_allocated =
914 hard_bytes_allocatable - hard_bytes_left; 886 hard_bytes_allocatable - hard_bytes_left;
915 memory_stats_from_last_assign_.bytes_unreleasable = 887 memory_stats_from_last_assign_.bytes_unreleasable =
916 resource_pool_->acquired_memory_usage_bytes() - bytes_releasable_; 888 resource_pool_->acquired_memory_usage_bytes() - bytes_releasable_;
917 memory_stats_from_last_assign_.bytes_over = bytes_that_exceeded_memory_budget; 889 memory_stats_from_last_assign_.bytes_over = bytes_that_exceeded_memory_budget;
918 } 890 }
919 891
920 void TileManager::FreeResourceForTile(Tile* tile, RasterMode mode) { 892 void TileManager::FreeResourcesForTile(Tile* tile) {
921 ManagedTileState& mts = tile->managed_state(); 893 ManagedTileState& mts = tile->managed_state();
922 if (mts.tile_versions[mode].resource_) { 894 if (mts.draw_info_.resource_) {
923 resource_pool_->ReleaseResource(mts.tile_versions[mode].resource_.Pass()); 895 resource_pool_->ReleaseResource(mts.draw_info_.resource_.Pass());
924 896
925 DCHECK_GE(bytes_releasable_, BytesConsumedIfAllocated(tile)); 897 DCHECK_GE(bytes_releasable_, BytesConsumedIfAllocated(tile));
926 DCHECK_GE(resources_releasable_, 1u); 898 DCHECK_GE(resources_releasable_, 1u);
927 899
928 bytes_releasable_ -= BytesConsumedIfAllocated(tile); 900 bytes_releasable_ -= BytesConsumedIfAllocated(tile);
929 --resources_releasable_; 901 --resources_releasable_;
930 } 902 }
931 } 903 }
932 904
933 void TileManager::FreeResourcesForTile(Tile* tile) {
934 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
935 FreeResourceForTile(tile, static_cast<RasterMode>(mode));
936 }
937 }
938
939 void TileManager::FreeUnusedResourcesForTile(Tile* tile) {
940 DCHECK(tile->IsReadyToDraw());
941 ManagedTileState& mts = tile->managed_state();
942 RasterMode used_mode = LOW_QUALITY_RASTER_MODE;
943 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
944 if (mts.tile_versions[mode].IsReadyToDraw()) {
945 used_mode = static_cast<RasterMode>(mode);
946 break;
947 }
948 }
949
950 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) {
951 if (mode != used_mode)
952 FreeResourceForTile(tile, static_cast<RasterMode>(mode));
953 }
954 }
955
956 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( 905 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(
957 Tile* tile) { 906 Tile* tile) {
958 bool was_ready_to_draw = tile->IsReadyToDraw(); 907 bool was_ready_to_draw = tile->IsReadyToDraw();
959 FreeResourcesForTile(tile); 908 FreeResourcesForTile(tile);
960 if (was_ready_to_draw) 909 if (was_ready_to_draw)
961 client_->NotifyTileStateChanged(tile); 910 client_->NotifyTileStateChanged(tile);
962 } 911 }
963 912
964 void TileManager::ScheduleTasks( 913 void TileManager::ScheduleTasks(
965 const TileVector& tiles_that_need_to_be_rasterized) { 914 const TileVector& tiles_that_need_to_be_rasterized) {
966 TRACE_EVENT1("cc", 915 TRACE_EVENT1("cc",
967 "TileManager::ScheduleTasks", 916 "TileManager::ScheduleTasks",
968 "count", 917 "count",
969 tiles_that_need_to_be_rasterized.size()); 918 tiles_that_need_to_be_rasterized.size());
970 919
971 DCHECK(did_check_for_completed_tasks_since_last_schedule_tasks_); 920 DCHECK(did_check_for_completed_tasks_since_last_schedule_tasks_);
972 921
973 raster_queue_.Reset(); 922 raster_queue_.Reset();
974 923
975 // Build a new task queue containing all task currently needed. Tasks 924 // Build a new task queue containing all task currently needed. Tasks
976 // are added in order of priority, highest priority task first. 925 // are added in order of priority, highest priority task first.
977 for (TileVector::const_iterator it = tiles_that_need_to_be_rasterized.begin(); 926 for (TileVector::const_iterator it = tiles_that_need_to_be_rasterized.begin();
978 it != tiles_that_need_to_be_rasterized.end(); 927 it != tiles_that_need_to_be_rasterized.end();
979 ++it) { 928 ++it) {
980 Tile* tile = *it; 929 Tile* tile = *it;
981 ManagedTileState& mts = tile->managed_state(); 930 ManagedTileState& mts = tile->managed_state();
982 ManagedTileState::TileVersion& tile_version = 931 ManagedTileState::TileDrawInfo& draw_info = mts.draw_info_;
983 mts.tile_versions[mts.raster_mode];
984 932
985 DCHECK(tile_version.requires_resource()); 933 DCHECK(draw_info.requires_resource());
986 DCHECK(!tile_version.resource_); 934 DCHECK(!draw_info.resource_);
987 935
988 if (!tile_version.raster_task_.get()) 936 if (!draw_info.raster_task_.get())
989 tile_version.raster_task_ = CreateRasterTask(tile); 937 draw_info.raster_task_ = CreateRasterTask(tile);
990 938
991 TaskSetCollection task_sets; 939 TaskSetCollection task_sets;
992 if (tile->required_for_activation()) 940 if (tile->required_for_activation())
993 task_sets.set(REQUIRED_FOR_ACTIVATION); 941 task_sets.set(REQUIRED_FOR_ACTIVATION);
994 task_sets.set(ALL); 942 task_sets.set(ALL);
995 raster_queue_.items.push_back( 943 raster_queue_.items.push_back(
996 RasterTaskQueue::Item(tile_version.raster_task_.get(), task_sets)); 944 RasterTaskQueue::Item(draw_info.raster_task_.get(), task_sets));
997 } 945 }
998 946
999 // We must reduce the amount of unused resoruces before calling 947 // We must reduce the amount of unused resoruces before calling
1000 // ScheduleTasks to prevent usage from rising above limits. 948 // ScheduleTasks to prevent usage from rising above limits.
1001 resource_pool_->ReduceResourceUsage(); 949 resource_pool_->ReduceResourceUsage();
1002 950
1003 // Schedule running of |raster_tasks_|. This replaces any previously 951 // Schedule running of |raster_tasks_|. This replaces any previously
1004 // scheduled tasks and effectively cancels all tasks not present 952 // scheduled tasks and effectively cancels all tasks not present
1005 // in |raster_tasks_|. 953 // in |raster_tasks_|.
1006 rasterizer_->ScheduleTasks(&raster_queue_); 954 rasterizer_->ScheduleTasks(&raster_queue_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 CreateImageDecodeTask(tile, pixel_ref); 1003 CreateImageDecodeTask(tile, pixel_ref);
1056 decode_tasks.push_back(decode_task); 1004 decode_tasks.push_back(decode_task);
1057 existing_pixel_refs[id] = decode_task; 1005 existing_pixel_refs[id] = decode_task;
1058 } 1006 }
1059 1007
1060 return make_scoped_refptr( 1008 return make_scoped_refptr(
1061 new RasterTaskImpl(const_resource, 1009 new RasterTaskImpl(const_resource,
1062 tile->picture_pile(), 1010 tile->picture_pile(),
1063 tile->content_rect(), 1011 tile->content_rect(),
1064 tile->contents_scale(), 1012 tile->contents_scale(),
1065 mts.raster_mode,
1066 mts.resolution, 1013 mts.resolution,
1067 tile->layer_id(), 1014 tile->layer_id(),
1068 static_cast<const void*>(tile), 1015 static_cast<const void*>(tile),
1069 tile->source_frame_number(), 1016 tile->source_frame_number(),
1070 tile->use_picture_analysis(), 1017 tile->use_picture_analysis(),
1071 rendering_stats_instrumentation_, 1018 rendering_stats_instrumentation_,
1072 base::Bind(&TileManager::OnRasterTaskCompleted, 1019 base::Bind(&TileManager::OnRasterTaskCompleted,
1073 base::Unretained(this), 1020 base::Unretained(this),
1074 tile->id(), 1021 tile->id(),
1075 base::Passed(&resource), 1022 base::Passed(&resource)),
1076 mts.raster_mode),
1077 &decode_tasks)); 1023 &decode_tasks));
1078 } 1024 }
1079 1025
1080 void TileManager::OnImageDecodeTaskCompleted(int layer_id, 1026 void TileManager::OnImageDecodeTaskCompleted(int layer_id,
1081 SkPixelRef* pixel_ref, 1027 SkPixelRef* pixel_ref,
1082 bool was_canceled) { 1028 bool was_canceled) {
1083 // If the task was canceled, we need to clean it up 1029 // If the task was canceled, we need to clean it up
1084 // from |image_decode_tasks_|. 1030 // from |image_decode_tasks_|.
1085 if (!was_canceled) 1031 if (!was_canceled)
1086 return; 1032 return;
1087 1033
1088 LayerPixelRefTaskMap::iterator layer_it = image_decode_tasks_.find(layer_id); 1034 LayerPixelRefTaskMap::iterator layer_it = image_decode_tasks_.find(layer_id);
1089 if (layer_it == image_decode_tasks_.end()) 1035 if (layer_it == image_decode_tasks_.end())
1090 return; 1036 return;
1091 1037
1092 PixelRefTaskMap& pixel_ref_tasks = layer_it->second; 1038 PixelRefTaskMap& pixel_ref_tasks = layer_it->second;
1093 PixelRefTaskMap::iterator task_it = 1039 PixelRefTaskMap::iterator task_it =
1094 pixel_ref_tasks.find(pixel_ref->getGenerationID()); 1040 pixel_ref_tasks.find(pixel_ref->getGenerationID());
1095 1041
1096 if (task_it != pixel_ref_tasks.end()) 1042 if (task_it != pixel_ref_tasks.end())
1097 pixel_ref_tasks.erase(task_it); 1043 pixel_ref_tasks.erase(task_it);
1098 } 1044 }
1099 1045
1100 void TileManager::OnRasterTaskCompleted( 1046 void TileManager::OnRasterTaskCompleted(
1101 Tile::Id tile_id, 1047 Tile::Id tile_id,
1102 scoped_ptr<ScopedResource> resource, 1048 scoped_ptr<ScopedResource> resource,
1103 RasterMode raster_mode,
1104 const PicturePileImpl::Analysis& analysis, 1049 const PicturePileImpl::Analysis& analysis,
1105 bool was_canceled) { 1050 bool was_canceled) {
1106 DCHECK(tiles_.find(tile_id) != tiles_.end()); 1051 DCHECK(tiles_.find(tile_id) != tiles_.end());
1107 1052
1108 Tile* tile = tiles_[tile_id]; 1053 Tile* tile = tiles_[tile_id];
1109 ManagedTileState& mts = tile->managed_state(); 1054 ManagedTileState& mts = tile->managed_state();
1110 ManagedTileState::TileVersion& tile_version = mts.tile_versions[raster_mode]; 1055 ManagedTileState::TileDrawInfo& draw_info = mts.draw_info_;
1111 DCHECK(tile_version.raster_task_.get()); 1056 DCHECK(draw_info.raster_task_.get());
1112 orphan_raster_tasks_.push_back(tile_version.raster_task_); 1057 orphan_raster_tasks_.push_back(draw_info.raster_task_);
1113 tile_version.raster_task_ = NULL; 1058 draw_info.raster_task_ = NULL;
1114 1059
1115 if (was_canceled) { 1060 if (was_canceled) {
1116 ++update_visible_tiles_stats_.canceled_count; 1061 ++update_visible_tiles_stats_.canceled_count;
1117 resource_pool_->ReleaseResource(resource.Pass()); 1062 resource_pool_->ReleaseResource(resource.Pass());
1118 return; 1063 return;
1119 } 1064 }
1120 1065
1121 ++update_visible_tiles_stats_.completed_count; 1066 ++update_visible_tiles_stats_.completed_count;
1122 1067
1123 if (analysis.is_solid_color) { 1068 if (analysis.is_solid_color) {
1124 tile_version.set_solid_color(analysis.solid_color); 1069 draw_info.set_solid_color(analysis.solid_color);
1125 resource_pool_->ReleaseResource(resource.Pass()); 1070 resource_pool_->ReleaseResource(resource.Pass());
1126 } else { 1071 } else {
1127 tile_version.set_use_resource(); 1072 draw_info.set_use_resource();
1128 tile_version.resource_ = resource.Pass(); 1073 draw_info.resource_ = resource.Pass();
1129 1074
1130 bytes_releasable_ += BytesConsumedIfAllocated(tile); 1075 bytes_releasable_ += BytesConsumedIfAllocated(tile);
1131 ++resources_releasable_; 1076 ++resources_releasable_;
1132 } 1077 }
1133 1078
1134 FreeUnusedResourcesForTile(tile);
1135 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f) 1079 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f)
1136 did_initialize_visible_tile_ = true; 1080 did_initialize_visible_tile_ = true;
1137 1081
1138 client_->NotifyTileStateChanged(tile); 1082 client_->NotifyTileStateChanged(tile);
1139 } 1083 }
1140 1084
1141 scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile, 1085 scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile,
1142 const gfx::Size& tile_size, 1086 const gfx::Size& tile_size,
1143 const gfx::Rect& content_rect, 1087 const gfx::Rect& content_rect,
1144 float contents_scale, 1088 float contents_scale,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); 1127 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate");
1184 1128
1185 rasterizer_->CheckForCompletedTasks(); 1129 rasterizer_->CheckForCompletedTasks();
1186 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; 1130 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
1187 1131
1188 if (IsReadyToActivate()) 1132 if (IsReadyToActivate())
1189 client_->NotifyReadyToActivate(); 1133 client_->NotifyReadyToActivate();
1190 } 1134 }
1191 1135
1192 } // namespace cc 1136 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698