Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Side by Side Diff: cc/tiles/software_image_decode_cache.cc

Issue 2857923004: cc: Keep PaintImage in DrawImage. (Closed)
Patch Set: .. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 const 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 DrawImage original_size_draw_image( 618 image.sk_image()->height());
619 std::move(image), gfx::RectToSkIRect(full_image_rect), 619 DrawImage original_size_draw_image(image, gfx::RectToSkIRect(full_image_rect),
620 kNone_SkFilterQuality, SkMatrix::I(), key.target_color_space()); 620 kNone_SkFilterQuality, SkMatrix::I(),
621 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())
628 << original_size_key.ToString(); 629 << original_size_key.ToString();
629 DCHECK(full_image_rect.size() == original_size_key.target_size()); 630 DCHECK(full_image_rect.size() == original_size_key.target_size());
630 631
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const 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(),
681 DrawImage original_size_draw_image( 682 image.sk_image()->height());
682 std::move(image), gfx::RectToSkIRect(full_image_rect), 683 DrawImage original_size_draw_image(image, gfx::RectToSkIRect(full_image_rect),
683 kNone_SkFilterQuality, SkMatrix::I(), key.target_color_space()); 684 kNone_SkFilterQuality, SkMatrix::I(),
685 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())
691 << original_size_key.ToString(); 693 << original_size_key.ToString();
692 DCHECK(full_image_rect.size() == original_size_key.target_size()); 694 DCHECK(full_image_rect.size() == original_size_key.target_size());
693 695
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « cc/tiles/software_image_decode_cache.h ('k') | cc/tiles/software_image_decode_cache_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698