OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 = | |
528 mts.tile_versions[mts.raster_mode]; | |
529 | 506 |
530 if (tile->required_for_activation() && !tile_version.IsReadyToDraw()) { | 507 if (tile->required_for_activation() && !mts.draw_info.IsReadyToDraw()) { |
531 // If we can't raster on demand, give up early (and don't activate). | 508 // If we can't raster on demand, give up early (and don't activate). |
532 if (!allow_rasterize_on_demand) | 509 if (!allow_rasterize_on_demand) |
533 return; | 510 return; |
534 | 511 |
535 tile_version.set_rasterize_on_demand(); | 512 mts.draw_info.set_rasterize_on_demand(); |
536 client_->NotifyTileStateChanged(tile); | 513 client_->NotifyTileStateChanged(tile); |
537 } | 514 } |
538 } | 515 } |
539 | 516 |
540 DCHECK(IsReadyToActivate()); | 517 DCHECK(IsReadyToActivate()); |
541 ready_to_activate_check_notifier_.Schedule(); | 518 ready_to_activate_check_notifier_.Schedule(); |
542 return; | 519 return; |
543 } | 520 } |
544 | 521 |
545 if (task_set == REQUIRED_FOR_ACTIVATION) { | 522 if (task_set == REQUIRED_FOR_ACTIVATION) { |
(...skipping 19 matching lines...) Expand all Loading... |
565 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); | 542 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); |
566 | 543 |
567 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; | 544 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; |
568 const TreePriority tree_priority = global_state_.tree_priority; | 545 const TreePriority tree_priority = global_state_.tree_priority; |
569 | 546 |
570 // For each tree, bin into different categories of tiles. | 547 // For each tree, bin into different categories of tiles. |
571 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 548 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
572 Tile* tile = it->second; | 549 Tile* tile = it->second; |
573 ManagedTileState& mts = tile->managed_state(); | 550 ManagedTileState& mts = tile->managed_state(); |
574 | 551 |
575 const ManagedTileState::TileVersion& tile_version = | 552 bool tile_is_ready_to_draw = mts.draw_info.IsReadyToDraw(); |
576 tile->GetTileVersionForDrawing(); | 553 bool tile_is_active = tile_is_ready_to_draw || mts.raster_task.get(); |
577 bool tile_is_ready_to_draw = tile_version.IsReadyToDraw(); | |
578 bool tile_is_active = tile_is_ready_to_draw || | |
579 mts.tile_versions[mts.raster_mode].raster_task_.get(); | |
580 | 554 |
581 // Get the active priority and bin. | 555 // Get the active priority and bin. |
582 TilePriority active_priority = tile->priority(ACTIVE_TREE); | 556 TilePriority active_priority = tile->priority(ACTIVE_TREE); |
583 ManagedTileBin active_bin = BinFromTilePriority(active_priority); | 557 ManagedTileBin active_bin = BinFromTilePriority(active_priority); |
584 | 558 |
585 // Get the pending priority and bin. | 559 // Get the pending priority and bin. |
586 TilePriority pending_priority = tile->priority(PENDING_TREE); | 560 TilePriority pending_priority = tile->priority(PENDING_TREE); |
587 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority); | 561 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority); |
588 | 562 |
589 bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION; | 563 bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 // smoothness takes priority or memory policy allows nothing to be | 628 // smoothness takes priority or memory policy allows nothing to be |
655 // initialized. | 629 // initialized. |
656 DCHECK(!mts.required_for_activation || mts.bin != NEVER_BIN || | 630 DCHECK(!mts.required_for_activation || mts.bin != NEVER_BIN || |
657 tree_priority == SMOOTHNESS_TAKES_PRIORITY || | 631 tree_priority == SMOOTHNESS_TAKES_PRIORITY || |
658 memory_policy == ALLOW_NOTHING); | 632 memory_policy == ALLOW_NOTHING); |
659 | 633 |
660 // If the tile is in NEVER_BIN and it does not have an active task, then we | 634 // 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 | 635 // 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 | 636 // should keep it in the prioritized tile set to ensure that AssignGpuMemory |
663 // can visit it. | 637 // can visit it. |
664 if (mts.bin == NEVER_BIN && | 638 if (mts.bin == NEVER_BIN && !mts.raster_task.get()) { |
665 !mts.tile_versions[mts.raster_mode].raster_task_.get()) { | |
666 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | 639 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
667 continue; | 640 continue; |
668 } | 641 } |
669 | 642 |
670 // Insert the tile into a priority set. | 643 // Insert the tile into a priority set. |
671 tiles->InsertTile(tile, mts.bin); | 644 tiles->InsertTile(tile, mts.bin); |
672 } | 645 } |
673 } | 646 } |
674 | 647 |
675 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { | 648 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 | 759 |
787 size_t resources_left = resources_allocatable; | 760 size_t resources_left = resources_allocatable; |
788 bool oomed_soft = false; | 761 bool oomed_soft = false; |
789 bool oomed_hard = false; | 762 bool oomed_hard = false; |
790 bool have_hit_soft_memory = false; // Soft memory comes after hard. | 763 bool have_hit_soft_memory = false; // Soft memory comes after hard. |
791 | 764 |
792 unsigned schedule_priority = 1u; | 765 unsigned schedule_priority = 1u; |
793 for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) { | 766 for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) { |
794 Tile* tile = *it; | 767 Tile* tile = *it; |
795 ManagedTileState& mts = tile->managed_state(); | 768 ManagedTileState& mts = tile->managed_state(); |
796 | |
797 mts.scheduled_priority = schedule_priority++; | 769 mts.scheduled_priority = schedule_priority++; |
798 | 770 |
799 mts.raster_mode = tile->DetermineOverallRasterMode(); | |
800 | |
801 ManagedTileState::TileVersion& tile_version = | |
802 mts.tile_versions[mts.raster_mode]; | |
803 | |
804 // If this tile doesn't need a resource, then nothing to do. | 771 // If this tile doesn't need a resource, then nothing to do. |
805 if (!tile_version.requires_resource()) | 772 if (!mts.draw_info.requires_resource()) |
806 continue; | 773 continue; |
807 | 774 |
808 // If the tile is not needed, free it up. | 775 // If the tile is not needed, free it up. |
809 if (mts.bin == NEVER_BIN) { | 776 if (mts.bin == NEVER_BIN) { |
810 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | 777 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
811 continue; | 778 continue; |
812 } | 779 } |
813 | 780 |
814 const bool tile_uses_hard_limit = mts.bin <= NOW_BIN; | 781 const bool tile_uses_hard_limit = mts.bin <= NOW_BIN; |
815 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); | 782 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); |
816 const size_t tile_bytes_left = | 783 const size_t tile_bytes_left = |
817 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left; | 784 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left; |
818 | 785 |
819 // Hard-limit is reserved for tiles that would cause a calamity | 786 // 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 | 787 // 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. | 788 // priority memory, and must be at the front of the list. |
822 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); | 789 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); |
823 have_hit_soft_memory |= !tile_uses_hard_limit; | 790 have_hit_soft_memory |= !tile_uses_hard_limit; |
824 | 791 |
825 size_t tile_bytes = 0; | 792 size_t tile_bytes = 0; |
826 size_t tile_resources = 0; | 793 size_t tile_resources = 0; |
827 | 794 |
828 // It costs to maintain a resource. | 795 // It costs to maintain a resource. |
829 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 796 if (mts.draw_info.resource_) { |
830 if (mts.tile_versions[mode].resource_) { | 797 tile_bytes += bytes_if_allocated; |
831 tile_bytes += bytes_if_allocated; | 798 tile_resources++; |
832 tile_resources++; | |
833 } | |
834 } | 799 } |
835 | 800 |
836 // Allow lower priority tiles with initialized resources to keep | 801 // Allow lower priority tiles with initialized resources to keep |
837 // their memory by only assigning memory to new raster tasks if | 802 // their memory by only assigning memory to new raster tasks if |
838 // they can be scheduled. | 803 // they can be scheduled. |
839 bool reached_scheduled_raster_tasks_limit = | 804 bool reached_scheduled_raster_tasks_limit = |
840 tiles_that_need_to_be_rasterized->size() >= kScheduledRasterTasksLimit; | 805 tiles_that_need_to_be_rasterized->size() >= kScheduledRasterTasksLimit; |
841 if (!reached_scheduled_raster_tasks_limit) { | 806 if (!reached_scheduled_raster_tasks_limit) { |
842 // If we don't have the required version, and it's not in flight | 807 // 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. | 808 // then we'll have to pay to create a new task. |
844 if (!tile_version.resource_ && !tile_version.raster_task_.get()) { | 809 if (!mts.draw_info.resource_ && !mts.raster_task.get()) { |
845 tile_bytes += bytes_if_allocated; | 810 tile_bytes += bytes_if_allocated; |
846 tile_resources++; | 811 tile_resources++; |
847 } | 812 } |
848 } | 813 } |
849 | 814 |
850 // Tile is OOM. | 815 // Tile is OOM. |
851 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { | 816 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { |
852 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | 817 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
853 | 818 |
854 // This tile was already on screen and now its resources have been | 819 // This tile was already on screen and now its resources have been |
855 // released. In order to prevent checkerboarding, set this tile as | 820 // released. In order to prevent checkerboarding, set this tile as |
856 // rasterize on demand immediately. | 821 // rasterize on demand immediately. |
857 if (mts.visible_and_ready_to_draw) | 822 if (mts.visible_and_ready_to_draw) |
858 tile_version.set_rasterize_on_demand(); | 823 mts.draw_info.set_rasterize_on_demand(); |
859 | 824 |
860 oomed_soft = true; | 825 oomed_soft = true; |
861 if (tile_uses_hard_limit) { | 826 if (tile_uses_hard_limit) { |
862 oomed_hard = true; | 827 oomed_hard = true; |
863 bytes_that_exceeded_memory_budget += tile_bytes; | 828 bytes_that_exceeded_memory_budget += tile_bytes; |
864 } | 829 } |
865 } else { | 830 } else { |
866 resources_left -= tile_resources; | 831 resources_left -= tile_resources; |
867 hard_bytes_left -= tile_bytes; | 832 hard_bytes_left -= tile_bytes; |
868 soft_bytes_left = | 833 soft_bytes_left = |
869 (soft_bytes_left > tile_bytes) ? soft_bytes_left - tile_bytes : 0; | 834 (soft_bytes_left > tile_bytes) ? soft_bytes_left - tile_bytes : 0; |
870 if (tile_version.resource_) | 835 if (mts.draw_info.resource_) |
871 continue; | 836 continue; |
872 } | 837 } |
873 | 838 |
874 DCHECK(!tile_version.resource_); | 839 DCHECK(!mts.draw_info.resource_); |
875 | 840 |
876 // Tile shouldn't be rasterized if |tiles_that_need_to_be_rasterized| | 841 // 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 | 842 // 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 | 843 // or any higher priority tile. Preventing tiles that fit into memory |
879 // budget to be rasterized when higher priority tile is oom is | 844 // budget to be rasterized when higher priority tile is oom is |
880 // important for two reasons: | 845 // important for two reasons: |
881 // 1. Tile size should not impact raster priority. | 846 // 1. Tile size should not impact raster priority. |
882 // 2. Tiles with existing raster task could otherwise incorrectly | 847 // 2. Tiles with existing raster task could otherwise incorrectly |
883 // be added as they are not affected by |bytes_allocatable|. | 848 // be added as they are not affected by |bytes_allocatable|. |
884 bool can_schedule_tile = | 849 bool can_schedule_tile = |
(...skipping 25 matching lines...) Expand all Loading... |
910 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget", oomed_hard); | 875 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget", oomed_hard); |
911 memory_stats_from_last_assign_.total_budget_in_bytes = | 876 memory_stats_from_last_assign_.total_budget_in_bytes = |
912 global_state_.hard_memory_limit_in_bytes; | 877 global_state_.hard_memory_limit_in_bytes; |
913 memory_stats_from_last_assign_.bytes_allocated = | 878 memory_stats_from_last_assign_.bytes_allocated = |
914 hard_bytes_allocatable - hard_bytes_left; | 879 hard_bytes_allocatable - hard_bytes_left; |
915 memory_stats_from_last_assign_.bytes_unreleasable = | 880 memory_stats_from_last_assign_.bytes_unreleasable = |
916 resource_pool_->acquired_memory_usage_bytes() - bytes_releasable_; | 881 resource_pool_->acquired_memory_usage_bytes() - bytes_releasable_; |
917 memory_stats_from_last_assign_.bytes_over = bytes_that_exceeded_memory_budget; | 882 memory_stats_from_last_assign_.bytes_over = bytes_that_exceeded_memory_budget; |
918 } | 883 } |
919 | 884 |
920 void TileManager::FreeResourceForTile(Tile* tile, RasterMode mode) { | 885 void TileManager::FreeResourcesForTile(Tile* tile) { |
921 ManagedTileState& mts = tile->managed_state(); | 886 ManagedTileState& mts = tile->managed_state(); |
922 if (mts.tile_versions[mode].resource_) { | 887 if (mts.draw_info.resource_) { |
923 resource_pool_->ReleaseResource(mts.tile_versions[mode].resource_.Pass()); | 888 resource_pool_->ReleaseResource(mts.draw_info.resource_.Pass()); |
924 | 889 |
925 DCHECK_GE(bytes_releasable_, BytesConsumedIfAllocated(tile)); | 890 DCHECK_GE(bytes_releasable_, BytesConsumedIfAllocated(tile)); |
926 DCHECK_GE(resources_releasable_, 1u); | 891 DCHECK_GE(resources_releasable_, 1u); |
927 | 892 |
928 bytes_releasable_ -= BytesConsumedIfAllocated(tile); | 893 bytes_releasable_ -= BytesConsumedIfAllocated(tile); |
929 --resources_releasable_; | 894 --resources_releasable_; |
930 } | 895 } |
931 } | 896 } |
932 | 897 |
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( | 898 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( |
957 Tile* tile) { | 899 Tile* tile) { |
958 bool was_ready_to_draw = tile->IsReadyToDraw(); | 900 bool was_ready_to_draw = tile->IsReadyToDraw(); |
959 FreeResourcesForTile(tile); | 901 FreeResourcesForTile(tile); |
960 if (was_ready_to_draw) | 902 if (was_ready_to_draw) |
961 client_->NotifyTileStateChanged(tile); | 903 client_->NotifyTileStateChanged(tile); |
962 } | 904 } |
963 | 905 |
964 void TileManager::ScheduleTasks( | 906 void TileManager::ScheduleTasks( |
965 const TileVector& tiles_that_need_to_be_rasterized) { | 907 const TileVector& tiles_that_need_to_be_rasterized) { |
966 TRACE_EVENT1("cc", | 908 TRACE_EVENT1("cc", |
967 "TileManager::ScheduleTasks", | 909 "TileManager::ScheduleTasks", |
968 "count", | 910 "count", |
969 tiles_that_need_to_be_rasterized.size()); | 911 tiles_that_need_to_be_rasterized.size()); |
970 | 912 |
971 DCHECK(did_check_for_completed_tasks_since_last_schedule_tasks_); | 913 DCHECK(did_check_for_completed_tasks_since_last_schedule_tasks_); |
972 | 914 |
973 raster_queue_.Reset(); | 915 raster_queue_.Reset(); |
974 | 916 |
975 // Build a new task queue containing all task currently needed. Tasks | 917 // Build a new task queue containing all task currently needed. Tasks |
976 // are added in order of priority, highest priority task first. | 918 // are added in order of priority, highest priority task first. |
977 for (TileVector::const_iterator it = tiles_that_need_to_be_rasterized.begin(); | 919 for (TileVector::const_iterator it = tiles_that_need_to_be_rasterized.begin(); |
978 it != tiles_that_need_to_be_rasterized.end(); | 920 it != tiles_that_need_to_be_rasterized.end(); |
979 ++it) { | 921 ++it) { |
980 Tile* tile = *it; | 922 Tile* tile = *it; |
981 ManagedTileState& mts = tile->managed_state(); | 923 ManagedTileState& mts = tile->managed_state(); |
982 ManagedTileState::TileVersion& tile_version = | |
983 mts.tile_versions[mts.raster_mode]; | |
984 | 924 |
985 DCHECK(tile_version.requires_resource()); | 925 DCHECK(mts.draw_info.requires_resource()); |
986 DCHECK(!tile_version.resource_); | 926 DCHECK(!mts.draw_info.resource_); |
987 | 927 |
988 if (!tile_version.raster_task_.get()) | 928 if (!mts.raster_task.get()) |
989 tile_version.raster_task_ = CreateRasterTask(tile); | 929 mts.raster_task = CreateRasterTask(tile); |
990 | 930 |
991 TaskSetCollection task_sets; | 931 TaskSetCollection task_sets; |
992 if (tile->required_for_activation()) | 932 if (tile->required_for_activation()) |
993 task_sets.set(REQUIRED_FOR_ACTIVATION); | 933 task_sets.set(REQUIRED_FOR_ACTIVATION); |
994 task_sets.set(ALL); | 934 task_sets.set(ALL); |
995 raster_queue_.items.push_back( | 935 raster_queue_.items.push_back( |
996 RasterTaskQueue::Item(tile_version.raster_task_.get(), task_sets)); | 936 RasterTaskQueue::Item(mts.raster_task.get(), task_sets)); |
997 } | 937 } |
998 | 938 |
999 // We must reduce the amount of unused resoruces before calling | 939 // We must reduce the amount of unused resoruces before calling |
1000 // ScheduleTasks to prevent usage from rising above limits. | 940 // ScheduleTasks to prevent usage from rising above limits. |
1001 resource_pool_->ReduceResourceUsage(); | 941 resource_pool_->ReduceResourceUsage(); |
1002 | 942 |
1003 // Schedule running of |raster_tasks_|. This replaces any previously | 943 // Schedule running of |raster_queue_|. This replaces any previously |
1004 // scheduled tasks and effectively cancels all tasks not present | 944 // scheduled tasks and effectively cancels all tasks not present |
1005 // in |raster_tasks_|. | 945 // in |raster_queue_|. |
1006 rasterizer_->ScheduleTasks(&raster_queue_); | 946 rasterizer_->ScheduleTasks(&raster_queue_); |
1007 | 947 |
1008 // It's now safe to clean up orphan tasks as raster worker pool is not | 948 // It's now safe to clean up orphan tasks as raster worker pool is not |
1009 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has | 949 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has |
1010 // been called. | 950 // been called. |
1011 orphan_raster_tasks_.clear(); | 951 orphan_raster_tasks_.clear(); |
1012 | 952 |
1013 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; | 953 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; |
1014 } | 954 } |
1015 | 955 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 CreateImageDecodeTask(tile, pixel_ref); | 995 CreateImageDecodeTask(tile, pixel_ref); |
1056 decode_tasks.push_back(decode_task); | 996 decode_tasks.push_back(decode_task); |
1057 existing_pixel_refs[id] = decode_task; | 997 existing_pixel_refs[id] = decode_task; |
1058 } | 998 } |
1059 | 999 |
1060 return make_scoped_refptr( | 1000 return make_scoped_refptr( |
1061 new RasterTaskImpl(const_resource, | 1001 new RasterTaskImpl(const_resource, |
1062 tile->picture_pile(), | 1002 tile->picture_pile(), |
1063 tile->content_rect(), | 1003 tile->content_rect(), |
1064 tile->contents_scale(), | 1004 tile->contents_scale(), |
1065 mts.raster_mode, | |
1066 mts.resolution, | 1005 mts.resolution, |
1067 tile->layer_id(), | 1006 tile->layer_id(), |
1068 static_cast<const void*>(tile), | 1007 static_cast<const void*>(tile), |
1069 tile->source_frame_number(), | 1008 tile->source_frame_number(), |
1070 tile->use_picture_analysis(), | 1009 tile->use_picture_analysis(), |
1071 rendering_stats_instrumentation_, | 1010 rendering_stats_instrumentation_, |
1072 base::Bind(&TileManager::OnRasterTaskCompleted, | 1011 base::Bind(&TileManager::OnRasterTaskCompleted, |
1073 base::Unretained(this), | 1012 base::Unretained(this), |
1074 tile->id(), | 1013 tile->id(), |
1075 base::Passed(&resource), | 1014 base::Passed(&resource)), |
1076 mts.raster_mode), | |
1077 &decode_tasks)); | 1015 &decode_tasks)); |
1078 } | 1016 } |
1079 | 1017 |
1080 void TileManager::OnImageDecodeTaskCompleted(int layer_id, | 1018 void TileManager::OnImageDecodeTaskCompleted(int layer_id, |
1081 SkPixelRef* pixel_ref, | 1019 SkPixelRef* pixel_ref, |
1082 bool was_canceled) { | 1020 bool was_canceled) { |
1083 // If the task was canceled, we need to clean it up | 1021 // If the task was canceled, we need to clean it up |
1084 // from |image_decode_tasks_|. | 1022 // from |image_decode_tasks_|. |
1085 if (!was_canceled) | 1023 if (!was_canceled) |
1086 return; | 1024 return; |
1087 | 1025 |
1088 LayerPixelRefTaskMap::iterator layer_it = image_decode_tasks_.find(layer_id); | 1026 LayerPixelRefTaskMap::iterator layer_it = image_decode_tasks_.find(layer_id); |
1089 if (layer_it == image_decode_tasks_.end()) | 1027 if (layer_it == image_decode_tasks_.end()) |
1090 return; | 1028 return; |
1091 | 1029 |
1092 PixelRefTaskMap& pixel_ref_tasks = layer_it->second; | 1030 PixelRefTaskMap& pixel_ref_tasks = layer_it->second; |
1093 PixelRefTaskMap::iterator task_it = | 1031 PixelRefTaskMap::iterator task_it = |
1094 pixel_ref_tasks.find(pixel_ref->getGenerationID()); | 1032 pixel_ref_tasks.find(pixel_ref->getGenerationID()); |
1095 | 1033 |
1096 if (task_it != pixel_ref_tasks.end()) | 1034 if (task_it != pixel_ref_tasks.end()) |
1097 pixel_ref_tasks.erase(task_it); | 1035 pixel_ref_tasks.erase(task_it); |
1098 } | 1036 } |
1099 | 1037 |
1100 void TileManager::OnRasterTaskCompleted( | 1038 void TileManager::OnRasterTaskCompleted( |
1101 Tile::Id tile_id, | 1039 Tile::Id tile_id, |
1102 scoped_ptr<ScopedResource> resource, | 1040 scoped_ptr<ScopedResource> resource, |
1103 RasterMode raster_mode, | |
1104 const PicturePileImpl::Analysis& analysis, | 1041 const PicturePileImpl::Analysis& analysis, |
1105 bool was_canceled) { | 1042 bool was_canceled) { |
1106 DCHECK(tiles_.find(tile_id) != tiles_.end()); | 1043 DCHECK(tiles_.find(tile_id) != tiles_.end()); |
1107 | 1044 |
1108 Tile* tile = tiles_[tile_id]; | 1045 Tile* tile = tiles_[tile_id]; |
1109 ManagedTileState& mts = tile->managed_state(); | 1046 ManagedTileState& mts = tile->managed_state(); |
1110 ManagedTileState::TileVersion& tile_version = mts.tile_versions[raster_mode]; | 1047 DCHECK(mts.raster_task.get()); |
1111 DCHECK(tile_version.raster_task_.get()); | 1048 orphan_raster_tasks_.push_back(mts.raster_task); |
1112 orphan_raster_tasks_.push_back(tile_version.raster_task_); | 1049 mts.raster_task = NULL; |
1113 tile_version.raster_task_ = NULL; | |
1114 | 1050 |
1115 if (was_canceled) { | 1051 if (was_canceled) { |
1116 ++update_visible_tiles_stats_.canceled_count; | 1052 ++update_visible_tiles_stats_.canceled_count; |
1117 resource_pool_->ReleaseResource(resource.Pass()); | 1053 resource_pool_->ReleaseResource(resource.Pass()); |
1118 return; | 1054 return; |
1119 } | 1055 } |
1120 | 1056 |
1121 ++update_visible_tiles_stats_.completed_count; | 1057 ++update_visible_tiles_stats_.completed_count; |
1122 | 1058 |
1123 if (analysis.is_solid_color) { | 1059 if (analysis.is_solid_color) { |
1124 tile_version.set_solid_color(analysis.solid_color); | 1060 mts.draw_info.set_solid_color(analysis.solid_color); |
1125 resource_pool_->ReleaseResource(resource.Pass()); | 1061 resource_pool_->ReleaseResource(resource.Pass()); |
1126 } else { | 1062 } else { |
1127 tile_version.set_use_resource(); | 1063 mts.draw_info.set_use_resource(); |
1128 tile_version.resource_ = resource.Pass(); | 1064 mts.draw_info.resource_ = resource.Pass(); |
1129 | 1065 |
1130 bytes_releasable_ += BytesConsumedIfAllocated(tile); | 1066 bytes_releasable_ += BytesConsumedIfAllocated(tile); |
1131 ++resources_releasable_; | 1067 ++resources_releasable_; |
1132 } | 1068 } |
1133 | 1069 |
1134 FreeUnusedResourcesForTile(tile); | |
1135 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f) | 1070 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f) |
1136 did_initialize_visible_tile_ = true; | 1071 did_initialize_visible_tile_ = true; |
1137 | 1072 |
1138 client_->NotifyTileStateChanged(tile); | 1073 client_->NotifyTileStateChanged(tile); |
1139 } | 1074 } |
1140 | 1075 |
1141 scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile, | 1076 scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile, |
1142 const gfx::Size& tile_size, | 1077 const gfx::Size& tile_size, |
1143 const gfx::Rect& content_rect, | 1078 const gfx::Rect& content_rect, |
1144 float contents_scale, | 1079 float contents_scale, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); | 1118 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); |
1184 | 1119 |
1185 rasterizer_->CheckForCompletedTasks(); | 1120 rasterizer_->CheckForCompletedTasks(); |
1186 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1121 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
1187 | 1122 |
1188 if (IsReadyToActivate()) | 1123 if (IsReadyToActivate()) |
1189 client_->NotifyReadyToActivate(); | 1124 client_->NotifyReadyToActivate(); |
1190 } | 1125 } |
1191 | 1126 |
1192 } // namespace cc | 1127 } // namespace cc |
OLD | NEW |