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

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

Powered by Google App Engine
This is Rietveld 408576698