Chromium Code Reviews| Index: cc/tiles/software_image_decode_cache.cc |
| diff --git a/cc/tiles/software_image_decode_cache.cc b/cc/tiles/software_image_decode_cache.cc |
| index aa2066592517f744eaaaa1020d2ce9bf5d26c61d..53758c02552fe6e00642649291ca228f984df56b 100644 |
| --- a/cc/tiles/software_image_decode_cache.cc |
| +++ b/cc/tiles/software_image_decode_cache.cc |
| @@ -51,7 +51,10 @@ const size_t kSuspendedMaxItemsInCache = 0; |
| // The second part that much be true is that we cache only the needed subrect if |
| // the total size needed for the subrect is at most kMemoryRatioToSubrect * |
| // (size needed for the full original image). |
| +// Note that at least one of the dimensions has to be at least |
| +// kMinDimensionToSubrect before an image can breach the threshold. |
| const size_t kMemoryThresholdToSubrect = 64 * 1024 * 1024; |
| +const int kMinDimensionToSubrect = 4 * 1024; |
| const float kMemoryRatioToSubrect = 0.5f; |
| class AutoRemoveKeyFromTaskMap { |
| @@ -176,6 +179,17 @@ void RecordLockExistingCachedImageHistogram(TilePriority::PriorityBin bin, |
| } |
| } |
| +gfx::Rect GetSrcRect(const DrawImage& image) { |
|
enne (OOO)
2017/02/02 00:36:41
Does this end up being cheaper than the code that
ericrk
2017/02/02 00:37:56
Can we just store this on DrawImage rather than sr
vmpstr
2017/02/02 00:52:45
Hmm, I'm a little hesitant to do this, since there
vmpstr
2017/02/02 00:52:45
This alone speeds up the test by about 25%. There
ericrk
2017/02/02 22:21:28
I see, the full computations aren't needed everywh
|
| + const SkIRect& src_rect = image.src_rect(); |
|
ericrk
2017/02/02 00:37:56
DrawImage::src_rect() returns a "const SkIRect", n
vmpstr
2017/02/02 00:52:45
Done, the perf results are comparable.
ericrk
2017/02/02 22:21:28
Done.
|
| + int x = std::max(0, src_rect.x()); |
| + int y = std::max(0, src_rect.y()); |
| + int right = std::min(image.image()->width(), src_rect.right()); |
| + int bottom = std::min(image.image()->height(), src_rect.bottom()); |
| + if (x >= right || y >= bottom) |
| + return gfx::Rect(); |
| + return gfx::Rect(x, y, right - x, bottom - y); |
| +} |
| + |
| } // namespace |
| SoftwareImageDecodeCache::SoftwareImageDecodeCache( |
| @@ -898,10 +912,7 @@ ImageDecodeCacheKey ImageDecodeCacheKey::FromDrawImage(const DrawImage& image) { |
| // otherwise we might end up with uninitialized memory in the decode process. |
| // Note that the scale is still unchanged and the target size is now a |
| // function of the new src_rect. |
| - gfx::Rect src_rect = gfx::IntersectRects( |
| - gfx::SkIRectToRect(image.src_rect()), |
| - gfx::Rect(image.image()->width(), image.image()->height())); |
| - |
| + const gfx::Rect& src_rect = GetSrcRect(image); |
| gfx::Size target_size( |
| SkScalarRoundToInt(std::abs(src_rect.width() * scale.width())), |
| SkScalarRoundToInt(std::abs(src_rect.height() * scale.height()))); |
| @@ -950,7 +961,9 @@ ImageDecodeCacheKey ImageDecodeCacheKey::FromDrawImage(const DrawImage& image) { |
| bool can_use_original_decode = |
| quality == kLow_SkFilterQuality || quality == kNone_SkFilterQuality; |
| bool should_use_subrect = false; |
| - if (can_use_original_decode) { |
| + if (can_use_original_decode && |
| + (image.image()->width() >= kMinDimensionToSubrect || |
| + image.image()->height() >= kMinDimensionToSubrect)) { |
| base::CheckedNumeric<size_t> checked_original_size = 4u; |
| checked_original_size *= image.image()->width(); |
| checked_original_size *= image.image()->height(); |