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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 "SoftwareImageDecodeCache::DecodeImageInternal", "key", | 438 "SoftwareImageDecodeCache::DecodeImageInternal", "key", |
439 key.ToString()); | 439 key.ToString()); |
440 sk_sp<const SkImage> image = draw_image.image(); | 440 sk_sp<const SkImage> image = draw_image.image(); |
441 if (!image) | 441 if (!image) |
442 return nullptr; | 442 return nullptr; |
443 | 443 |
444 switch (key.filter_quality()) { | 444 switch (key.filter_quality()) { |
445 case kNone_SkFilterQuality: | 445 case kNone_SkFilterQuality: |
446 case kLow_SkFilterQuality: | 446 case kLow_SkFilterQuality: |
447 if (key.should_use_subrect()) | 447 if (key.should_use_subrect()) |
448 return GetSubrectImageDecode(key, std::move(image)); | 448 return GetSubrectImageDecode(key, draw_image.paint_image()); |
449 return GetOriginalSizeImageDecode(key, std::move(image)); | 449 return GetOriginalSizeImageDecode(key, std::move(image)); |
450 case kMedium_SkFilterQuality: | 450 case kMedium_SkFilterQuality: |
451 case kHigh_SkFilterQuality: | 451 case kHigh_SkFilterQuality: |
452 return GetScaledImageDecode(key, std::move(image)); | 452 return GetScaledImageDecode(key, draw_image.paint_image()); |
453 default: | 453 default: |
454 NOTREACHED(); | 454 NOTREACHED(); |
455 return nullptr; | 455 return nullptr; |
456 } | 456 } |
457 } | 457 } |
458 | 458 |
459 DecodedDrawImage SoftwareImageDecodeCache::GetDecodedImageForDraw( | 459 DecodedDrawImage SoftwareImageDecodeCache::GetDecodedImageForDraw( |
460 const DrawImage& draw_image) { | 460 const DrawImage& draw_image) { |
461 ImageKey key = ImageKey::FromDrawImage(draw_image); | 461 ImageKey key = ImageKey::FromDrawImage(draw_image); |
462 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 462 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 604 } |
605 | 605 |
606 return base::MakeUnique<DecodedImage>( | 606 return base::MakeUnique<DecodedImage>( |
607 decoded_info.makeColorSpace(target_color_space), | 607 decoded_info.makeColorSpace(target_color_space), |
608 std::move(decoded_pixels), SkSize::Make(0, 0), | 608 std::move(decoded_pixels), SkSize::Make(0, 0), |
609 next_tracing_id_.GetNext()); | 609 next_tracing_id_.GetNext()); |
610 } | 610 } |
611 | 611 |
612 std::unique_ptr<SoftwareImageDecodeCache::DecodedImage> | 612 std::unique_ptr<SoftwareImageDecodeCache::DecodedImage> |
613 SoftwareImageDecodeCache::GetSubrectImageDecode(const ImageKey& key, | 613 SoftwareImageDecodeCache::GetSubrectImageDecode(const ImageKey& key, |
614 sk_sp<const SkImage> image) { | 614 PaintImage image) { |
615 // Construct a key to use in GetDecodedImageForDrawInternal(). | 615 // Construct a key to use in GetDecodedImageForDrawInternal(). |
616 // This allows us to reuse an image in any cache if available. | 616 // This allows us to reuse an image in any cache if available. |
617 gfx::Rect full_image_rect(image->width(), image->height()); | 617 gfx::Rect full_image_rect(image.sk_image()->width(), |
| 618 image.sk_image()->height()); |
618 DrawImage original_size_draw_image( | 619 DrawImage original_size_draw_image( |
619 std::move(image), gfx::RectToSkIRect(full_image_rect), | 620 std::move(image), gfx::RectToSkIRect(full_image_rect), |
620 kNone_SkFilterQuality, SkMatrix::I(), key.target_color_space()); | 621 kNone_SkFilterQuality, SkMatrix::I(), key.target_color_space()); |
621 ImageKey original_size_key = | 622 ImageKey original_size_key = |
622 ImageKey::FromDrawImage(original_size_draw_image); | 623 ImageKey::FromDrawImage(original_size_draw_image); |
623 sk_sp<SkColorSpace> target_color_space = | 624 sk_sp<SkColorSpace> target_color_space = |
624 key.target_color_space().ToSkColorSpace(); | 625 key.target_color_space().ToSkColorSpace(); |
625 | 626 |
626 // Sanity checks. | 627 // Sanity checks. |
627 DCHECK(original_size_key.can_use_original_size_decode()) | 628 DCHECK(original_size_key.can_use_original_size_decode()) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 | 668 |
668 return base::WrapUnique( | 669 return base::WrapUnique( |
669 new DecodedImage(subrect_info.makeColorSpace(target_color_space), | 670 new DecodedImage(subrect_info.makeColorSpace(target_color_space), |
670 std::move(subrect_pixels), | 671 std::move(subrect_pixels), |
671 SkSize::Make(-key.src_rect().x(), -key.src_rect().y()), | 672 SkSize::Make(-key.src_rect().x(), -key.src_rect().y()), |
672 next_tracing_id_.GetNext())); | 673 next_tracing_id_.GetNext())); |
673 } | 674 } |
674 | 675 |
675 std::unique_ptr<SoftwareImageDecodeCache::DecodedImage> | 676 std::unique_ptr<SoftwareImageDecodeCache::DecodedImage> |
676 SoftwareImageDecodeCache::GetScaledImageDecode(const ImageKey& key, | 677 SoftwareImageDecodeCache::GetScaledImageDecode(const ImageKey& key, |
677 sk_sp<const SkImage> image) { | 678 PaintImage image) { |
678 // Construct a key to use in GetDecodedImageForDrawInternal(). | 679 // Construct a key to use in GetDecodedImageForDrawInternal(). |
679 // This allows us to reuse an image in any cache if available. | 680 // This allows us to reuse an image in any cache if available. |
680 gfx::Rect full_image_rect(image->width(), image->height()); | 681 gfx::Rect full_image_rect(image.sk_image()->width(), |
| 682 image.sk_image()->height()); |
681 DrawImage original_size_draw_image( | 683 DrawImage original_size_draw_image( |
682 std::move(image), gfx::RectToSkIRect(full_image_rect), | 684 std::move(image), gfx::RectToSkIRect(full_image_rect), |
683 kNone_SkFilterQuality, SkMatrix::I(), key.target_color_space()); | 685 kNone_SkFilterQuality, SkMatrix::I(), key.target_color_space()); |
684 ImageKey original_size_key = | 686 ImageKey original_size_key = |
685 ImageKey::FromDrawImage(original_size_draw_image); | 687 ImageKey::FromDrawImage(original_size_draw_image); |
686 sk_sp<SkColorSpace> target_color_space = | 688 sk_sp<SkColorSpace> target_color_space = |
687 key.target_color_space().ToSkColorSpace(); | 689 key.target_color_space().ToSkColorSpace(); |
688 | 690 |
689 // Sanity checks. | 691 // Sanity checks. |
690 DCHECK(original_size_key.can_use_original_size_decode()) | 692 DCHECK(original_size_key.can_use_original_size_decode()) |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 } | 1179 } |
1178 } | 1180 } |
1179 } | 1181 } |
1180 | 1182 |
1181 void SoftwareImageDecodeCache::OnPurgeMemory() { | 1183 void SoftwareImageDecodeCache::OnPurgeMemory() { |
1182 base::AutoLock lock(lock_); | 1184 base::AutoLock lock(lock_); |
1183 ReduceCacheUsageUntilWithinLimit(0); | 1185 ReduceCacheUsageUntilWithinLimit(0); |
1184 } | 1186 } |
1185 | 1187 |
1186 } // namespace cc | 1188 } // namespace cc |
OLD | NEW |