| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <functional> | 9 #include <functional> |
| 10 | 10 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 key.target_size().width() / static_cast<float>(key.src_rect().width()); | 100 key.target_size().width() / static_cast<float>(key.src_rect().width()); |
| 101 float y_scale = | 101 float y_scale = |
| 102 key.target_size().height() / static_cast<float>(key.src_rect().height()); | 102 key.target_size().height() / static_cast<float>(key.src_rect().height()); |
| 103 return SkSize::Make(x_scale, y_scale); | 103 return SkSize::Make(x_scale, y_scale); |
| 104 } | 104 } |
| 105 | 105 |
| 106 SkFilterQuality GetDecodedFilterQuality(const ImageDecodeControllerKey& key) { | 106 SkFilterQuality GetDecodedFilterQuality(const ImageDecodeControllerKey& key) { |
| 107 return std::min(key.filter_quality(), kLow_SkFilterQuality); | 107 return std::min(key.filter_quality(), kLow_SkFilterQuality); |
| 108 } | 108 } |
| 109 | 109 |
| 110 SkImageInfo CreateImageInfo(size_t width, |
| 111 size_t height, |
| 112 ResourceFormat format) { |
| 113 return SkImageInfo::Make(width, height, ResourceFormatToSkColorType(format), |
| 114 kPremul_SkAlphaType); |
| 115 } |
| 116 |
| 110 } // namespace | 117 } // namespace |
| 111 | 118 |
| 112 SoftwareImageDecodeController::SoftwareImageDecodeController() | 119 SoftwareImageDecodeController::SoftwareImageDecodeController( |
| 120 ResourceFormat format) |
| 113 : decoded_images_(ImageMRUCache::NO_AUTO_EVICT), | 121 : decoded_images_(ImageMRUCache::NO_AUTO_EVICT), |
| 114 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), | 122 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), |
| 115 locked_images_budget_(kLockedMemoryLimitBytes) {} | 123 locked_images_budget_(kLockedMemoryLimitBytes), |
| 124 format_(format) {} |
| 116 | 125 |
| 117 SoftwareImageDecodeController::~SoftwareImageDecodeController() { | 126 SoftwareImageDecodeController::~SoftwareImageDecodeController() { |
| 118 DCHECK_EQ(0u, decoded_images_ref_counts_.size()); | 127 DCHECK_EQ(0u, decoded_images_ref_counts_.size()); |
| 119 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size()); | 128 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size()); |
| 120 } | 129 } |
| 121 | 130 |
| 122 bool SoftwareImageDecodeController::GetTaskForImageAndRef( | 131 bool SoftwareImageDecodeController::GetTaskForImageAndRef( |
| 123 const DrawImage& image, | 132 const DrawImage& image, |
| 124 uint64_t prepare_tiles_id, | 133 uint64_t prepare_tiles_id, |
| 125 scoped_refptr<ImageDecodeTask>* task) { | 134 scoped_refptr<ImageDecodeTask>* task) { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 const DrawImage& draw_image) { | 347 const DrawImage& draw_image) { |
| 339 TRACE_EVENT1("disabled-by-default-cc.debug", | 348 TRACE_EVENT1("disabled-by-default-cc.debug", |
| 340 "SoftwareImageDecodeController::DecodeImageInternal", "key", | 349 "SoftwareImageDecodeController::DecodeImageInternal", "key", |
| 341 key.ToString()); | 350 key.ToString()); |
| 342 const SkImage* image = draw_image.image(); | 351 const SkImage* image = draw_image.image(); |
| 343 | 352 |
| 344 // If we can use the original decode, then we don't need to do scaling. We can | 353 // If we can use the original decode, then we don't need to do scaling. We can |
| 345 // just read pixels into the final memory. | 354 // just read pixels into the final memory. |
| 346 if (key.can_use_original_decode()) { | 355 if (key.can_use_original_decode()) { |
| 347 SkImageInfo decoded_info = | 356 SkImageInfo decoded_info = |
| 348 SkImageInfo::MakeN32Premul(image->width(), image->height()); | 357 CreateImageInfo(image->width(), image->height(), format_); |
| 349 scoped_ptr<base::DiscardableMemory> decoded_pixels; | 358 scoped_ptr<base::DiscardableMemory> decoded_pixels; |
| 350 { | 359 { |
| 351 TRACE_EVENT0( | 360 TRACE_EVENT0( |
| 352 "disabled-by-default-cc.debug", | 361 "disabled-by-default-cc.debug", |
| 353 "SoftwareImageDecodeController::DecodeImageInternal - allocate " | 362 "SoftwareImageDecodeController::DecodeImageInternal - allocate " |
| 354 "decoded pixels"); | 363 "decoded pixels"); |
| 355 decoded_pixels = | 364 decoded_pixels = |
| 356 base::DiscardableMemoryAllocator::GetInstance() | 365 base::DiscardableMemoryAllocator::GetInstance() |
| 357 ->AllocateLockedDiscardableMemory(decoded_info.minRowBytes() * | 366 ->AllocateLockedDiscardableMemory(decoded_info.minRowBytes() * |
| 358 decoded_info.height()); | 367 decoded_info.height()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 DCHECK(result); | 416 DCHECK(result); |
| 408 if (key.src_rect() != full_image_rect) { | 417 if (key.src_rect() != full_image_rect) { |
| 409 result = decoded_pixmap.extractSubset(&decoded_pixmap, | 418 result = decoded_pixmap.extractSubset(&decoded_pixmap, |
| 410 gfx::RectToSkIRect(key.src_rect())); | 419 gfx::RectToSkIRect(key.src_rect())); |
| 411 DCHECK(result); | 420 DCHECK(result); |
| 412 } | 421 } |
| 413 | 422 |
| 414 // Now we have a decoded_pixmap which represents the src_rect at the | 423 // Now we have a decoded_pixmap which represents the src_rect at the |
| 415 // original scale. All we need to do is scale it. | 424 // original scale. All we need to do is scale it. |
| 416 DCHECK(!key.target_size().IsEmpty()); | 425 DCHECK(!key.target_size().IsEmpty()); |
| 417 SkImageInfo scaled_info = SkImageInfo::MakeN32Premul( | 426 SkImageInfo scaled_info = CreateImageInfo( |
| 418 key.target_size().width(), key.target_size().height()); | 427 key.target_size().width(), key.target_size().height(), format_); |
| 419 scoped_ptr<base::DiscardableMemory> scaled_pixels; | 428 scoped_ptr<base::DiscardableMemory> scaled_pixels; |
| 420 { | 429 { |
| 421 TRACE_EVENT0( | 430 TRACE_EVENT0( |
| 422 "disabled-by-default-cc.debug", | 431 "disabled-by-default-cc.debug", |
| 423 "SoftwareImageDecodeController::DecodeImageInternal - allocate " | 432 "SoftwareImageDecodeController::DecodeImageInternal - allocate " |
| 424 "scaled pixels"); | 433 "scaled pixels"); |
| 425 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() | 434 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() |
| 426 ->AllocateLockedDiscardableMemory( | 435 ->AllocateLockedDiscardableMemory( |
| 427 scaled_info.minRowBytes() * scaled_info.height()); | 436 scaled_info.minRowBytes() * scaled_info.height()); |
| 428 } | 437 } |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { | 861 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { |
| 853 current_usage_bytes_ = 0; | 862 current_usage_bytes_ = 0; |
| 854 } | 863 } |
| 855 | 864 |
| 856 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() | 865 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() |
| 857 const { | 866 const { |
| 858 return current_usage_bytes_.ValueOrDie(); | 867 return current_usage_bytes_.ValueOrDie(); |
| 859 } | 868 } |
| 860 | 869 |
| 861 } // namespace cc | 870 } // namespace cc |
| OLD | NEW |