| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/tiles/gpu_image_decode_controller.h" | 5 #include "cc/tiles/gpu_image_decode_controller.h" |
| 6 | 6 |
| 7 #include <inttypes.h> | 7 #include <inttypes.h> |
| 8 | 8 |
| 9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
| 10 #include "base/memory/discardable_memory_allocator.h" | 10 #include "base/memory/discardable_memory_allocator.h" |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 .first; | 738 .first; |
| 739 } | 739 } |
| 740 | 740 |
| 741 DCHECK(found != in_use_cache_.end()); | 741 DCHECK(found != in_use_cache_.end()); |
| 742 ++found->second.ref_count; | 742 ++found->second.ref_count; |
| 743 ++found->second.image_data->upload.ref_count; | 743 ++found->second.image_data->upload.ref_count; |
| 744 OwnershipChanged(found->second.image_data.get()); | 744 OwnershipChanged(found->second.image_data.get()); |
| 745 } | 745 } |
| 746 | 746 |
| 747 void GpuImageDecodeController::UnrefImageInternal(const DrawImage& draw_image) { | 747 void GpuImageDecodeController::UnrefImageInternal(const DrawImage& draw_image) { |
| 748 TRACE_EVENT0("disabled-by-default-cc.debug", | |
| 749 "GpuImageDecodeController::UnrefImageInternal"); | |
| 750 lock_.AssertAcquired(); | 748 lock_.AssertAcquired(); |
| 751 auto found = in_use_cache_.find(GenerateInUseCacheKey(draw_image)); | 749 auto found = in_use_cache_.find(GenerateInUseCacheKey(draw_image)); |
| 752 DCHECK(found != in_use_cache_.end()); | 750 DCHECK(found != in_use_cache_.end()); |
| 753 DCHECK_GT(found->second.image_data->upload.ref_count, 0u); | 751 DCHECK_GT(found->second.image_data->upload.ref_count, 0u); |
| 754 DCHECK_GT(found->second.ref_count, 0u); | 752 DCHECK_GT(found->second.ref_count, 0u); |
| 755 --found->second.ref_count; | 753 --found->second.ref_count; |
| 756 --found->second.image_data->upload.ref_count; | 754 --found->second.image_data->upload.ref_count; |
| 757 OwnershipChanged(found->second.image_data.get()); | 755 OwnershipChanged(found->second.image_data.get()); |
| 758 if (found->second.ref_count == 0u) { | 756 if (found->second.ref_count == 0u) { |
| 759 in_use_cache_.erase(found); | 757 in_use_cache_.erase(found); |
| 760 } | 758 } |
| 761 } | 759 } |
| 762 | 760 |
| 763 // Called any time an image or decode ref count changes. Takes care of any | 761 // Called any time an image or decode ref count changes. Takes care of any |
| 764 // necessary memory budget book-keeping and cleanup. | 762 // necessary memory budget book-keeping and cleanup. |
| 765 void GpuImageDecodeController::OwnershipChanged(ImageData* image_data) { | 763 void GpuImageDecodeController::OwnershipChanged(ImageData* image_data) { |
| 766 TRACE_EVENT0("disabled-by-default-cc.debug", | |
| 767 "GpuImageDecodeController::OwnershipChanged"); | |
| 768 lock_.AssertAcquired(); | 764 lock_.AssertAcquired(); |
| 769 | 765 |
| 770 bool has_any_refs = | 766 bool has_any_refs = |
| 771 image_data->upload.ref_count > 0 || image_data->decode.ref_count > 0; | 767 image_data->upload.ref_count > 0 || image_data->decode.ref_count > 0; |
| 772 | 768 |
| 773 // Don't keep around orphaned images. | 769 // Don't keep around orphaned images. |
| 774 if (image_data->is_orphaned && !has_any_refs) { | 770 if (image_data->is_orphaned && !has_any_refs) { |
| 775 images_pending_deletion_.push_back(std::move(image_data->upload.image())); | 771 images_pending_deletion_.push_back(std::move(image_data->upload.image())); |
| 776 image_data->upload.SetImage(nullptr); | 772 image_data->upload.SetImage(nullptr); |
| 777 } | 773 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 if (CanFitSize(required_size) && !ExceedsPreferredCount()) | 893 if (CanFitSize(required_size) && !ExceedsPreferredCount()) |
| 898 return true; | 894 return true; |
| 899 } | 895 } |
| 900 | 896 |
| 901 // Preferred count is only used as a guideline when triming the cache. Allow | 897 // Preferred count is only used as a guideline when triming the cache. Allow |
| 902 // new elements to be added as long as we are below our size limit. | 898 // new elements to be added as long as we are below our size limit. |
| 903 return CanFitSize(required_size); | 899 return CanFitSize(required_size); |
| 904 } | 900 } |
| 905 | 901 |
| 906 bool GpuImageDecodeController::CanFitSize(size_t size) const { | 902 bool GpuImageDecodeController::CanFitSize(size_t size) const { |
| 907 TRACE_EVENT0("disabled-by-default-cc.debug", | |
| 908 "GpuImageDecodeController::CanFitSize"); | |
| 909 lock_.AssertAcquired(); | 903 lock_.AssertAcquired(); |
| 910 | 904 |
| 911 base::CheckedNumeric<uint32_t> new_size(bytes_used_); | 905 base::CheckedNumeric<uint32_t> new_size(bytes_used_); |
| 912 new_size += size; | 906 new_size += size; |
| 913 return new_size.IsValid() && new_size.ValueOrDie() <= cached_bytes_limit_; | 907 return new_size.IsValid() && new_size.ValueOrDie() <= cached_bytes_limit_; |
| 914 } | 908 } |
| 915 | 909 |
| 916 bool GpuImageDecodeController::ExceedsPreferredCount() const { | 910 bool GpuImageDecodeController::ExceedsPreferredCount() const { |
| 917 TRACE_EVENT0("disabled-by-default-cc.debug", | |
| 918 "GpuImageDecodeController::ExceedsPreferredCount"); | |
| 919 lock_.AssertAcquired(); | 911 lock_.AssertAcquired(); |
| 920 | 912 |
| 921 return persistent_cache_.size() > cached_items_limit_; | 913 return persistent_cache_.size() > cached_items_limit_; |
| 922 } | 914 } |
| 923 | 915 |
| 924 void GpuImageDecodeController::DecodeImageIfNecessary( | 916 void GpuImageDecodeController::DecodeImageIfNecessary( |
| 925 const DrawImage& draw_image, | 917 const DrawImage& draw_image, |
| 926 ImageData* image_data) { | 918 ImageData* image_data) { |
| 927 lock_.AssertAcquired(); | 919 lock_.AssertAcquired(); |
| 928 | 920 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 } else { | 1075 } else { |
| 1084 mode = DecodedDataMode::GPU; | 1076 mode = DecodedDataMode::GPU; |
| 1085 } | 1077 } |
| 1086 | 1078 |
| 1087 return make_scoped_refptr( | 1079 return make_scoped_refptr( |
| 1088 new ImageData(mode, data_size, upload_scale_mip_level, | 1080 new ImageData(mode, data_size, upload_scale_mip_level, |
| 1089 CalculateUploadScaleFilterQuality(draw_image))); | 1081 CalculateUploadScaleFilterQuality(draw_image))); |
| 1090 } | 1082 } |
| 1091 | 1083 |
| 1092 void GpuImageDecodeController::DeletePendingImages() { | 1084 void GpuImageDecodeController::DeletePendingImages() { |
| 1093 TRACE_EVENT0("disabled-by-default-cc.debug", | |
| 1094 "GpuImageDecodeController::DeletePendingImages"); | |
| 1095 context_->GetLock()->AssertAcquired(); | 1085 context_->GetLock()->AssertAcquired(); |
| 1096 lock_.AssertAcquired(); | 1086 lock_.AssertAcquired(); |
| 1097 images_pending_deletion_.clear(); | 1087 images_pending_deletion_.clear(); |
| 1098 } | 1088 } |
| 1099 | 1089 |
| 1100 SkImageInfo GpuImageDecodeController::CreateImageInfoForDrawImage( | 1090 SkImageInfo GpuImageDecodeController::CreateImageInfoForDrawImage( |
| 1101 const DrawImage& draw_image, | 1091 const DrawImage& draw_image, |
| 1102 int upload_scale_mip_level) const { | 1092 int upload_scale_mip_level) const { |
| 1103 TRACE_EVENT0("disabled-by-default-cc.debug", | |
| 1104 "GpuImageDecodeController::CreateImageInfoForDrawImage"); | |
| 1105 gfx::Size mip_size = | 1093 gfx::Size mip_size = |
| 1106 CalculateSizeForMipLevel(draw_image, upload_scale_mip_level); | 1094 CalculateSizeForMipLevel(draw_image, upload_scale_mip_level); |
| 1107 return SkImageInfo::Make(mip_size.width(), mip_size.height(), | 1095 return SkImageInfo::Make(mip_size.width(), mip_size.height(), |
| 1108 ResourceFormatToClosestSkColorType(format_), | 1096 ResourceFormatToClosestSkColorType(format_), |
| 1109 kPremul_SkAlphaType); | 1097 kPremul_SkAlphaType); |
| 1110 } | 1098 } |
| 1111 | 1099 |
| 1112 // Tries to find an ImageData that can be used to draw the provided | 1100 // Tries to find an ImageData that can be used to draw the provided |
| 1113 // |draw_image|. First looks for an exact entry in our |in_use_cache_|. If one | 1101 // |draw_image|. First looks for an exact entry in our |in_use_cache_|. If one |
| 1114 // cannot be found, it looks for a compatible entry in our |persistent_cache_|. | 1102 // cannot be found, it looks for a compatible entry in our |persistent_cache_|. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1139 | 1127 |
| 1140 return nullptr; | 1128 return nullptr; |
| 1141 } | 1129 } |
| 1142 | 1130 |
| 1143 // Determines if we can draw the provided |draw_image| using the provided | 1131 // Determines if we can draw the provided |draw_image| using the provided |
| 1144 // |image_data|. This is true if the |image_data| is not scaled, or if it | 1132 // |image_data|. This is true if the |image_data| is not scaled, or if it |
| 1145 // is scaled at an equal or larger scale and equal or larger quality to | 1133 // is scaled at an equal or larger scale and equal or larger quality to |
| 1146 // the provided |draw_image|. | 1134 // the provided |draw_image|. |
| 1147 bool GpuImageDecodeController::IsCompatible(const ImageData* image_data, | 1135 bool GpuImageDecodeController::IsCompatible(const ImageData* image_data, |
| 1148 const DrawImage& draw_image) const { | 1136 const DrawImage& draw_image) const { |
| 1149 TRACE_EVENT0("disabled-by-default-cc.debug", | |
| 1150 "GpuImageDecodeController::IsCompatible"); | |
| 1151 bool is_scaled = image_data->upload_scale_mip_level != 0; | 1137 bool is_scaled = image_data->upload_scale_mip_level != 0; |
| 1152 bool scale_is_compatible = CalculateUploadScaleMipLevel(draw_image) >= | 1138 bool scale_is_compatible = CalculateUploadScaleMipLevel(draw_image) >= |
| 1153 image_data->upload_scale_mip_level; | 1139 image_data->upload_scale_mip_level; |
| 1154 bool quality_is_compatible = CalculateUploadScaleFilterQuality(draw_image) <= | 1140 bool quality_is_compatible = CalculateUploadScaleFilterQuality(draw_image) <= |
| 1155 image_data->upload_scale_filter_quality; | 1141 image_data->upload_scale_filter_quality; |
| 1156 return !is_scaled || (scale_is_compatible && quality_is_compatible); | 1142 return !is_scaled || (scale_is_compatible && quality_is_compatible); |
| 1157 } | 1143 } |
| 1158 | 1144 |
| 1159 size_t GpuImageDecodeController::GetDrawImageSizeForTesting( | 1145 size_t GpuImageDecodeController::GetDrawImageSizeForTesting( |
| 1160 const DrawImage& image) { | 1146 const DrawImage& image) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 // TODO(tasak): free this component's caches as much as possible before | 1180 // TODO(tasak): free this component's caches as much as possible before |
| 1195 // suspending renderer. | 1181 // suspending renderer. |
| 1196 break; | 1182 break; |
| 1197 case base::MemoryState::UNKNOWN: | 1183 case base::MemoryState::UNKNOWN: |
| 1198 // NOT_REACHED. | 1184 // NOT_REACHED. |
| 1199 break; | 1185 break; |
| 1200 } | 1186 } |
| 1201 } | 1187 } |
| 1202 | 1188 |
| 1203 } // namespace cc | 1189 } // namespace cc |
| OLD | NEW |