| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/software_image_decode_cache.h" | 5 #include "cc/tiles/software_image_decode_cache.h" |
| 6 | 6 |
| 7 #include <inttypes.h> | 7 #include <inttypes.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 gfx::Size target_size( | 914 gfx::Size target_size( |
| 915 SkScalarRoundToInt(std::abs(src_rect.width() * scale.width())), | 915 SkScalarRoundToInt(std::abs(src_rect.width() * scale.width())), |
| 916 SkScalarRoundToInt(std::abs(src_rect.height() * scale.height()))); | 916 SkScalarRoundToInt(std::abs(src_rect.height() * scale.height()))); |
| 917 | 917 |
| 918 // Start with the quality that was requested. | 918 // Start with the quality that was requested. |
| 919 SkFilterQuality quality = image.filter_quality(); | 919 SkFilterQuality quality = image.filter_quality(); |
| 920 | 920 |
| 921 // If we're not going to do a scale, we can use low filter quality. Note that | 921 // If we're not going to do a scale, we can use low filter quality. Note that |
| 922 // checking if the sizes are the same is better than checking if scale is 1.f, | 922 // checking if the sizes are the same is better than checking if scale is 1.f, |
| 923 // because even non-1 scale can result in the same (rounded) width/height. | 923 // because even non-1 scale can result in the same (rounded) width/height. |
| 924 // If either dimension is a downscale, then use mipmaps (medium filter | 924 // If either dimension is a downscale, and the quality is not None (in which |
| 925 // quality). | 925 // case we need to preserve the pixelated scale), then use mipmaps (medium |
| 926 // filter quality). |
| 926 if (target_size.width() == src_rect.width() && | 927 if (target_size.width() == src_rect.width() && |
| 927 target_size.height() == src_rect.height()) { | 928 target_size.height() == src_rect.height()) { |
| 928 quality = std::min(quality, kLow_SkFilterQuality); | 929 quality = std::min(quality, kLow_SkFilterQuality); |
| 929 } else if (target_size.width() < src_rect.width() || | 930 } else if (quality != kNone_SkFilterQuality && |
| 930 target_size.height() < src_rect.height()) { | 931 (target_size.width() < src_rect.width() || |
| 931 quality = std::min(quality, kMedium_SkFilterQuality); | 932 target_size.height() < src_rect.height())) { |
| 933 quality = kMedium_SkFilterQuality; |
| 932 } | 934 } |
| 933 | 935 |
| 934 // Drop from high to medium if the the matrix we applied wasn't decomposable, | 936 // Drop from high to medium if the the matrix we applied wasn't decomposable, |
| 935 // or if the scaled image will be too large. | 937 // or if the scaled image will be too large. |
| 936 if (quality == kHigh_SkFilterQuality) { | 938 if (quality == kHigh_SkFilterQuality) { |
| 937 if (!image.matrix_is_decomposable()) { | 939 if (!image.matrix_is_decomposable()) { |
| 938 quality = kMedium_SkFilterQuality; | 940 quality = kMedium_SkFilterQuality; |
| 939 } else { | 941 } else { |
| 940 base::CheckedNumeric<size_t> size = 4u; | 942 base::CheckedNumeric<size_t> size = 4u; |
| 941 size *= target_size.width(); | 943 size *= target_size.width(); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 } | 1181 } |
| 1180 } | 1182 } |
| 1181 } | 1183 } |
| 1182 | 1184 |
| 1183 void SoftwareImageDecodeCache::OnPurgeMemory() { | 1185 void SoftwareImageDecodeCache::OnPurgeMemory() { |
| 1184 base::AutoLock lock(lock_); | 1186 base::AutoLock lock(lock_); |
| 1185 ReduceCacheUsageUntilWithinLimit(0); | 1187 ReduceCacheUsageUntilWithinLimit(0); |
| 1186 } | 1188 } |
| 1187 | 1189 |
| 1188 } // namespace cc | 1190 } // namespace cc |
| OLD | NEW |