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 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 state->SetInteger("canceled_count", stats.canceled_count); | 365 state->SetInteger("canceled_count", stats.canceled_count); |
366 return state.PassAs<base::Value>(); | 366 return state.PassAs<base::Value>(); |
367 } | 367 } |
368 | 368 |
369 // static | 369 // static |
370 scoped_ptr<TileManager> TileManager::Create( | 370 scoped_ptr<TileManager> TileManager::Create( |
371 TileManagerClient* client, | 371 TileManagerClient* client, |
372 ResourcePool* resource_pool, | 372 ResourcePool* resource_pool, |
373 Rasterizer* rasterizer, | 373 Rasterizer* rasterizer, |
374 Rasterizer* gpu_rasterizer, | 374 Rasterizer* gpu_rasterizer, |
375 size_t max_raster_usage_bytes, | |
376 bool use_rasterize_on_demand, | 375 bool use_rasterize_on_demand, |
377 RenderingStatsInstrumentation* rendering_stats_instrumentation) { | 376 RenderingStatsInstrumentation* rendering_stats_instrumentation) { |
378 return make_scoped_ptr(new TileManager(client, | 377 return make_scoped_ptr(new TileManager(client, |
379 resource_pool, | 378 resource_pool, |
380 rasterizer, | 379 rasterizer, |
381 gpu_rasterizer, | 380 gpu_rasterizer, |
382 max_raster_usage_bytes, | |
383 use_rasterize_on_demand, | 381 use_rasterize_on_demand, |
384 rendering_stats_instrumentation)); | 382 rendering_stats_instrumentation)); |
385 } | 383 } |
386 | 384 |
387 TileManager::TileManager( | 385 TileManager::TileManager( |
388 TileManagerClient* client, | 386 TileManagerClient* client, |
389 ResourcePool* resource_pool, | 387 ResourcePool* resource_pool, |
390 Rasterizer* rasterizer, | 388 Rasterizer* rasterizer, |
391 Rasterizer* gpu_rasterizer, | 389 Rasterizer* gpu_rasterizer, |
392 size_t max_raster_usage_bytes, | |
393 bool use_rasterize_on_demand, | 390 bool use_rasterize_on_demand, |
394 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 391 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
395 : client_(client), | 392 : client_(client), |
396 resource_pool_(resource_pool), | 393 resource_pool_(resource_pool), |
397 prioritized_tiles_dirty_(false), | 394 prioritized_tiles_dirty_(false), |
398 all_tiles_that_need_to_be_rasterized_have_memory_(true), | 395 all_tiles_that_need_to_be_rasterized_have_memory_(true), |
399 all_tiles_required_for_activation_have_memory_(true), | 396 all_tiles_required_for_activation_have_memory_(true), |
400 memory_required_bytes_(0), | 397 memory_required_bytes_(0), |
401 memory_nice_to_have_bytes_(0), | 398 memory_nice_to_have_bytes_(0), |
402 bytes_releasable_(0), | 399 bytes_releasable_(0), |
403 resources_releasable_(0), | 400 resources_releasable_(0), |
404 max_raster_usage_bytes_(max_raster_usage_bytes), | |
405 ever_exceeded_memory_budget_(false), | 401 ever_exceeded_memory_budget_(false), |
406 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 402 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
407 did_initialize_visible_tile_(false), | 403 did_initialize_visible_tile_(false), |
408 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 404 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
409 use_rasterize_on_demand_(use_rasterize_on_demand) { | 405 use_rasterize_on_demand_(use_rasterize_on_demand) { |
410 Rasterizer* rasterizers[NUM_RASTERIZER_TYPES] = { | 406 Rasterizer* rasterizers[NUM_RASTERIZER_TYPES] = { |
411 rasterizer, // RASTERIZER_TYPE_DEFAULT | 407 rasterizer, // RASTERIZER_TYPE_DEFAULT |
412 gpu_rasterizer, // RASTERIZER_TYPE_GPU | 408 gpu_rasterizer, // RASTERIZER_TYPE_GPU |
413 }; | 409 }; |
414 rasterizer_delegate_ = | 410 rasterizer_delegate_ = |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 | 821 |
826 size_t bytes_that_exceeded_memory_budget = 0; | 822 size_t bytes_that_exceeded_memory_budget = 0; |
827 size_t soft_bytes_left = soft_bytes_allocatable; | 823 size_t soft_bytes_left = soft_bytes_allocatable; |
828 size_t hard_bytes_left = hard_bytes_allocatable; | 824 size_t hard_bytes_left = hard_bytes_allocatable; |
829 | 825 |
830 size_t resources_left = resources_allocatable; | 826 size_t resources_left = resources_allocatable; |
831 bool oomed_soft = false; | 827 bool oomed_soft = false; |
832 bool oomed_hard = false; | 828 bool oomed_hard = false; |
833 bool have_hit_soft_memory = false; // Soft memory comes after hard. | 829 bool have_hit_soft_memory = false; // Soft memory comes after hard. |
834 | 830 |
835 // Memory we assign to raster tasks now will be deducted from our memory | |
836 // in future iterations if priorities change. By assigning at most half | |
837 // the raster limit, we will always have another 50% left even if priorities | |
838 // change completely (assuming we check for completed/cancelled rasters | |
839 // between each call to this function). | |
reveman
2014/05/08 13:55:37
FYI, I'm OK removing this as I don't think this "a
vmpstr
2014/05/08 16:49:04
I agree with this as well. I think tile manager th
| |
840 size_t max_raster_bytes = max_raster_usage_bytes_ / 2; | |
841 size_t raster_bytes = 0; | |
842 | |
843 unsigned schedule_priority = 1u; | 831 unsigned schedule_priority = 1u; |
844 for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) { | 832 for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) { |
845 Tile* tile = *it; | 833 Tile* tile = *it; |
846 ManagedTileState& mts = tile->managed_state(); | 834 ManagedTileState& mts = tile->managed_state(); |
847 | 835 |
848 mts.scheduled_priority = schedule_priority++; | 836 mts.scheduled_priority = schedule_priority++; |
849 | 837 |
850 mts.raster_mode = tile->DetermineOverallRasterMode(); | 838 mts.raster_mode = tile->DetermineOverallRasterMode(); |
851 | 839 |
852 ManagedTileState::TileVersion& tile_version = | 840 ManagedTileState::TileVersion& tile_version = |
853 mts.tile_versions[mts.raster_mode]; | 841 mts.tile_versions[mts.raster_mode]; |
854 | 842 |
855 // If this tile doesn't need a resource, then nothing to do. | 843 // If this tile doesn't need a resource, then nothing to do. |
856 if (!tile_version.requires_resource()) | 844 if (!tile_version.requires_resource()) |
857 continue; | 845 continue; |
858 | 846 |
859 // If the tile is not needed, free it up. | 847 // If the tile is not needed, free it up. |
860 if (mts.bin == NEVER_BIN) { | 848 if (mts.bin == NEVER_BIN) { |
861 FreeResourcesForTile(tile); | 849 FreeResourcesForTile(tile); |
862 continue; | 850 continue; |
863 } | 851 } |
864 | 852 |
865 const bool tile_uses_hard_limit = mts.bin <= NOW_BIN; | 853 const bool tile_uses_hard_limit = mts.bin <= NOW_BIN; |
866 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); | 854 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); |
867 const size_t raster_bytes_if_rastered = raster_bytes + bytes_if_allocated; | |
868 const size_t tile_bytes_left = | 855 const size_t tile_bytes_left = |
869 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left; | 856 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left; |
870 | 857 |
871 // Hard-limit is reserved for tiles that would cause a calamity | 858 // Hard-limit is reserved for tiles that would cause a calamity |
872 // if they were to go away, so by definition they are the highest | 859 // if they were to go away, so by definition they are the highest |
873 // priority memory, and must be at the front of the list. | 860 // priority memory, and must be at the front of the list. |
874 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); | 861 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); |
875 have_hit_soft_memory |= !tile_uses_hard_limit; | 862 have_hit_soft_memory |= !tile_uses_hard_limit; |
876 | 863 |
877 size_t tile_bytes = 0; | 864 size_t tile_bytes = 0; |
878 size_t tile_resources = 0; | 865 size_t tile_resources = 0; |
879 | 866 |
880 // It costs to maintain a resource. | 867 // It costs to maintain a resource. |
881 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 868 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
882 if (mts.tile_versions[mode].resource_) { | 869 if (mts.tile_versions[mode].resource_) { |
883 tile_bytes += bytes_if_allocated; | 870 tile_bytes += bytes_if_allocated; |
884 tile_resources++; | 871 tile_resources++; |
885 } | 872 } |
886 } | 873 } |
887 | 874 |
888 // Allow lower priority tiles with initialized resources to keep | 875 // Allow lower priority tiles with initialized resources to keep |
889 // their memory by only assigning memory to new raster tasks if | 876 // their memory by only assigning memory to new raster tasks if |
890 // they can be scheduled. | 877 // they can be scheduled. |
891 if (raster_bytes_if_rastered <= max_raster_bytes) { | 878 if (tiles_that_need_to_be_rasterized->size() < kScheduledRasterTasksLimit) { |
reveman
2014/05/08 13:55:37
why do we need a conditional here now? was this co
vmpstr
2014/05/08 16:49:04
I think it should've been <= raster_bytes || size
reveman
2014/05/08 17:07:51
Ok, please add a variable here instead of doing "t
alokp
2014/05/08 18:04:47
Done.
| |
892 // If we don't have the required version, and it's not in flight | 879 // If we don't have the required version, and it's not in flight |
893 // then we'll have to pay to create a new task. | 880 // then we'll have to pay to create a new task. |
894 if (!tile_version.resource_ && !tile_version.raster_task_) { | 881 if (!tile_version.resource_ && !tile_version.raster_task_) { |
895 tile_bytes += bytes_if_allocated; | 882 tile_bytes += bytes_if_allocated; |
896 tile_resources++; | 883 tile_resources++; |
897 } | 884 } |
898 } | 885 } |
899 | 886 |
900 // Tile is OOM. | 887 // Tile is OOM. |
901 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { | 888 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { |
(...skipping 23 matching lines...) Expand all Loading... | |
925 | 912 |
926 // Tile shouldn't be rasterized if |tiles_that_need_to_be_rasterized| | 913 // Tile shouldn't be rasterized if |tiles_that_need_to_be_rasterized| |
927 // has reached it's limit or we've failed to assign gpu memory to this | 914 // has reached it's limit or we've failed to assign gpu memory to this |
928 // or any higher priority tile. Preventing tiles that fit into memory | 915 // or any higher priority tile. Preventing tiles that fit into memory |
929 // budget to be rasterized when higher priority tile is oom is | 916 // budget to be rasterized when higher priority tile is oom is |
930 // important for two reasons: | 917 // important for two reasons: |
931 // 1. Tile size should not impact raster priority. | 918 // 1. Tile size should not impact raster priority. |
932 // 2. Tiles with existing raster task could otherwise incorrectly | 919 // 2. Tiles with existing raster task could otherwise incorrectly |
933 // be added as they are not affected by |bytes_allocatable|. | 920 // be added as they are not affected by |bytes_allocatable|. |
934 bool can_schedule_tile = | 921 bool can_schedule_tile = |
935 !oomed_soft && raster_bytes_if_rastered <= max_raster_bytes && | 922 !oomed_soft && |
936 tiles_that_need_to_be_rasterized->size() < kScheduledRasterTasksLimit; | 923 tiles_that_need_to_be_rasterized->size() < kScheduledRasterTasksLimit; |
937 | 924 |
938 if (!can_schedule_tile) { | 925 if (!can_schedule_tile) { |
939 all_tiles_that_need_to_be_rasterized_have_memory_ = false; | 926 all_tiles_that_need_to_be_rasterized_have_memory_ = false; |
940 if (tile->required_for_activation()) | 927 if (tile->required_for_activation()) |
941 all_tiles_required_for_activation_have_memory_ = false; | 928 all_tiles_required_for_activation_have_memory_ = false; |
942 it.DisablePriorityOrdering(); | 929 it.DisablePriorityOrdering(); |
943 continue; | 930 continue; |
944 } | 931 } |
945 | 932 |
946 raster_bytes = raster_bytes_if_rastered; | |
947 tiles_that_need_to_be_rasterized->push_back(tile); | 933 tiles_that_need_to_be_rasterized->push_back(tile); |
948 } | 934 } |
949 | 935 |
950 // OOM reporting uses hard-limit, soft-OOM is normal depending on limit. | 936 // OOM reporting uses hard-limit, soft-OOM is normal depending on limit. |
951 ever_exceeded_memory_budget_ |= oomed_hard; | 937 ever_exceeded_memory_budget_ |= oomed_hard; |
952 if (ever_exceeded_memory_budget_) { | 938 if (ever_exceeded_memory_budget_) { |
953 TRACE_COUNTER_ID2("cc", | 939 TRACE_COUNTER_ID2("cc", |
954 "over_memory_budget", | 940 "over_memory_budget", |
955 this, | 941 this, |
956 "budget", | 942 "budget", |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1626 | 1612 |
1627 if (b_priority.resolution != a_priority.resolution) { | 1613 if (b_priority.resolution != a_priority.resolution) { |
1628 return (prioritize_low_res && b_priority.resolution == LOW_RESOLUTION) || | 1614 return (prioritize_low_res && b_priority.resolution == LOW_RESOLUTION) || |
1629 (!prioritize_low_res && b_priority.resolution == HIGH_RESOLUTION) || | 1615 (!prioritize_low_res && b_priority.resolution == HIGH_RESOLUTION) || |
1630 (a_priority.resolution == NON_IDEAL_RESOLUTION); | 1616 (a_priority.resolution == NON_IDEAL_RESOLUTION); |
1631 } | 1617 } |
1632 return a_priority.IsHigherPriorityThan(b_priority); | 1618 return a_priority.IsHigherPriorityThan(b_priority); |
1633 } | 1619 } |
1634 | 1620 |
1635 } // namespace cc | 1621 } // namespace cc |
OLD | NEW |