Chromium Code Reviews| 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_controller.h" | 5 #include "cc/tiles/software_image_decode_controller.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 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 826 pending_image_tasks_.find(key) != pending_image_tasks_.end()) | 826 pending_image_tasks_.find(key) != pending_image_tasks_.end()) |
| 827 << line; | 827 << line; |
| 828 } | 828 } |
| 829 } | 829 } |
| 830 DCHECK_GE(budget.AvailableMemoryBytes(), | 830 DCHECK_GE(budget.AvailableMemoryBytes(), |
| 831 locked_images_budget_.AvailableMemoryBytes()) | 831 locked_images_budget_.AvailableMemoryBytes()) |
| 832 << line; | 832 << line; |
| 833 #endif // DCHECK_IS_ON() | 833 #endif // DCHECK_IS_ON() |
| 834 } | 834 } |
| 835 | 835 |
| 836 namespace { | |
|
vmpstr
2016/09/23 18:45:39
Move this to the top of the file please.
| |
| 837 | |
| 838 bool shouldDrawHighQuality(const DrawImage& image, | |
|
vmpstr
2016/09/23 18:45:39
ShouldDrawHighQuality
| |
| 839 const gfx::Size& target_size) { | |
| 840 // Drop from high to medium if the the matrix we applied wasn't decomposable, | |
| 841 // or if the scaled image will be too large. | |
| 842 if (!image.matrix_is_decomposable()) { | |
|
vmpstr
2016/09/23 18:45:39
braces optional for one liners
| |
| 843 return false; | |
| 844 } | |
| 845 | |
| 846 base::CheckedNumeric<size_t> size = 4u; | |
| 847 size *= target_size.width(); | |
| 848 size *= target_size.height(); | |
| 849 if (size.ValueOrDefault(std::numeric_limits<size_t>::max()) > | |
| 850 kMaxHighQualityImageSizeBytes) { | |
| 851 return false; | |
| 852 } | |
| 853 | |
| 854 // Filtering twice due to non-trivial transforms or subpixel phase produces | |
| 855 // results worse than kMedium or kLow. Just steer clear. | |
| 856 if (!image.matrix().isScaleTranslate()) { | |
|
vmpstr
2016/09/23 18:45:39
Can you reorder these checks so that the easy chec
| |
| 857 return false; | |
| 858 } | |
| 859 | |
| 860 SkRect dest; | |
| 861 image.matrix().mapRectScaleTranslate(&dest, SkRect::Make(image.src_rect())); | |
| 862 const SkIRect idest = dest.round(); | |
| 863 if (!SkScalarNearlyEqual(dest.left(), idest.left()) || | |
| 864 !SkScalarNearlyEqual(dest.top(), idest.top()) || | |
| 865 !SkScalarNearlyEqual(dest.right(), idest.right()) || | |
| 866 !SkScalarNearlyEqual(dest.bottom(), idest.bottom())) { | |
| 867 return false; | |
| 868 } | |
| 869 | |
| 870 return true; | |
| 871 } | |
|
vmpstr
2016/09/23 18:45:39
I wonder if we should just drop to medium for down
| |
| 872 | |
| 873 } // anonymous namespace | |
| 874 | |
| 836 // SoftwareImageDecodeControllerKey | 875 // SoftwareImageDecodeControllerKey |
| 837 ImageDecodeControllerKey ImageDecodeControllerKey::FromDrawImage( | 876 ImageDecodeControllerKey ImageDecodeControllerKey::FromDrawImage( |
| 838 const DrawImage& image) { | 877 const DrawImage& image) { |
| 839 const SkSize& scale = image.scale(); | 878 const SkSize& scale = image.scale(); |
| 840 // If the src_rect falls outside of the image, we need to clip it since | 879 // If the src_rect falls outside of the image, we need to clip it since |
| 841 // otherwise we might end up with uninitialized memory in the decode process. | 880 // otherwise we might end up with uninitialized memory in the decode process. |
| 842 // Note that the scale is still unchanged and the target size is now a | 881 // Note that the scale is still unchanged and the target size is now a |
| 843 // function of the new src_rect. | 882 // function of the new src_rect. |
| 844 gfx::Rect src_rect = gfx::IntersectRects( | 883 gfx::Rect src_rect = gfx::IntersectRects( |
| 845 gfx::SkIRectToRect(image.src_rect()), | 884 gfx::SkIRectToRect(image.src_rect()), |
| 846 gfx::Rect(image.image()->width(), image.image()->height())); | 885 gfx::Rect(image.image()->width(), image.image()->height())); |
| 847 | 886 |
| 848 gfx::Size target_size( | 887 gfx::Size target_size( |
| 849 SkScalarRoundToInt(std::abs(src_rect.width() * scale.width())), | 888 SkScalarRoundToInt(std::abs(src_rect.width() * scale.width())), |
| 850 SkScalarRoundToInt(std::abs(src_rect.height() * scale.height()))); | 889 SkScalarRoundToInt(std::abs(src_rect.height() * scale.height()))); |
| 851 | 890 |
| 852 // Start with the quality that was requested. | 891 // Start with the quality that was requested. |
| 853 SkFilterQuality quality = image.filter_quality(); | 892 SkFilterQuality quality = image.filter_quality(); |
| 854 | 893 |
| 855 // If we're not going to do a scale, we can use low filter quality. Note that | 894 // If we're not going to do a scale, we can use low filter quality. Note that |
| 856 // checking if the sizes are the same is better than checking if scale is 1.f, | 895 // checking if the sizes are the same is better than checking if scale is 1.f, |
| 857 // because even non-1 scale can result in the same (rounded) width/height. | 896 // because even non-1 scale can result in the same (rounded) width/height. |
| 858 if (target_size.width() == src_rect.width() && | 897 if (target_size.width() == src_rect.width() && |
| 859 target_size.height() == src_rect.height()) { | 898 target_size.height() == src_rect.height()) { |
| 860 quality = std::min(quality, kLow_SkFilterQuality); | 899 quality = std::min(quality, kLow_SkFilterQuality); |
| 861 } | 900 } |
| 862 | 901 |
| 863 // Drop from high to medium if the the matrix we applied wasn't decomposable, | 902 if (quality == kHigh_SkFilterQuality && |
| 864 // or if the scaled image will be too large. | 903 !shouldDrawHighQuality(image, target_size)) { |
| 865 if (quality == kHigh_SkFilterQuality) { | 904 quality = kMedium_SkFilterQuality; |
| 866 if (!image.matrix_is_decomposable()) { | |
| 867 quality = kMedium_SkFilterQuality; | |
| 868 } else { | |
| 869 base::CheckedNumeric<size_t> size = 4u; | |
| 870 size *= target_size.width(); | |
| 871 size *= target_size.height(); | |
| 872 if (size.ValueOrDefault(std::numeric_limits<size_t>::max()) > | |
| 873 kMaxHighQualityImageSizeBytes) { | |
| 874 quality = kMedium_SkFilterQuality; | |
| 875 } | |
| 876 } | |
| 877 } | 905 } |
| 878 | 906 |
| 879 // Drop from medium to low if the matrix we applied wasn't decomposable or if | 907 // Drop from medium to low if the matrix we applied wasn't decomposable or if |
| 880 // we're enlarging the image in both dimensions. | 908 // we're enlarging the image in both dimensions. |
| 881 if (quality == kMedium_SkFilterQuality) { | 909 if (quality == kMedium_SkFilterQuality) { |
| 882 if (!image.matrix_is_decomposable() || | 910 if (!image.matrix_is_decomposable() || |
| 883 (scale.width() >= 1.f && scale.height() >= 1.f)) { | 911 (scale.width() >= 1.f && scale.height() >= 1.f)) { |
| 884 quality = kLow_SkFilterQuality; | 912 quality = kLow_SkFilterQuality; |
| 885 } | 913 } |
| 886 } | 914 } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1097 // TODO(tasak): free this component's caches as much as possible before | 1125 // TODO(tasak): free this component's caches as much as possible before |
| 1098 // suspending renderer. | 1126 // suspending renderer. |
| 1099 break; | 1127 break; |
| 1100 case base::MemoryState::UNKNOWN: | 1128 case base::MemoryState::UNKNOWN: |
| 1101 // NOT_REACHED. | 1129 // NOT_REACHED. |
| 1102 break; | 1130 break; |
| 1103 } | 1131 } |
| 1104 } | 1132 } |
| 1105 | 1133 |
| 1106 } // namespace cc | 1134 } // namespace cc |
| OLD | NEW |