| 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 <algorithm> |
| 9 #include <functional> | 10 #include <functional> |
| 10 | 11 |
| 11 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/discardable_memory.h" | 14 #include "base/memory/discardable_memory.h" |
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 17 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 18 #include "base/trace_event/memory_dump_manager.h" | 19 #include "base/trace_event/memory_dump_manager.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 SoftwareImageDecodeController* controller_; | 92 SoftwareImageDecodeController* controller_; |
| 92 SoftwareImageDecodeController::ImageKey image_key_; | 93 SoftwareImageDecodeController::ImageKey image_key_; |
| 93 DrawImage image_; | 94 DrawImage image_; |
| 94 const ImageDecodeController::TracingInfo tracing_info_; | 95 const ImageDecodeController::TracingInfo tracing_info_; |
| 95 | 96 |
| 96 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); | 97 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); |
| 97 }; | 98 }; |
| 98 | 99 |
| 100 // Most images are scaled from the source image's size to the target size. |
| 101 // But in the case of mipmaps, we are scaling from the mip level which is |
| 102 // larger than we need. |
| 103 // This function gets the scale of the mip level which will be used. |
| 104 SkSize GetMipMapScaleAdjustment(const gfx::Size& src_size, |
| 105 const gfx::Size& target_size) { |
| 106 int src_height = src_size.height(); |
| 107 int src_width = src_size.width(); |
| 108 int target_height = target_size.height(); |
| 109 int target_width = target_size.width(); |
| 110 if (target_height == 0 || target_width == 0) |
| 111 return SkSize::Make(-1.f, -1.f); |
| 112 |
| 113 int next_mip_height = src_height; |
| 114 int next_mip_width = src_width; |
| 115 for (int current_mip_level = 0;; current_mip_level++) { |
| 116 int mip_height = next_mip_height; |
| 117 int mip_width = next_mip_width; |
| 118 |
| 119 next_mip_height = std::max(1, src_height / (1 << (current_mip_level + 1))); |
| 120 next_mip_width = std::max(1, src_width / (1 << (current_mip_level + 1))); |
| 121 |
| 122 // Check if an axis on the next mip level would be smaller than the target. |
| 123 // If so, use the current mip level. |
| 124 // This effectively always uses the larger image and always scales down. |
| 125 if (next_mip_height < target_height || next_mip_width < target_width) { |
| 126 SkScalar y_scale = static_cast<float>(mip_height) / src_height; |
| 127 SkScalar x_scale = static_cast<float>(mip_width) / src_width; |
| 128 |
| 129 return SkSize::Make(x_scale, y_scale); |
| 130 } |
| 131 |
| 132 if (mip_height == 1 && mip_width == 1) { |
| 133 // We have reached the final mip level |
| 134 SkScalar y_scale = static_cast<float>(mip_height) / src_height; |
| 135 SkScalar x_scale = static_cast<float>(mip_width) / src_width; |
| 136 |
| 137 return SkSize::Make(x_scale, y_scale); |
| 138 } |
| 139 } |
| 140 } |
| 141 |
| 99 SkSize GetScaleAdjustment(const ImageDecodeControllerKey& key) { | 142 SkSize GetScaleAdjustment(const ImageDecodeControllerKey& key) { |
| 100 // If the requested filter quality did not require scale, then the adjustment | 143 // If the requested filter quality did not require scale, then the adjustment |
| 101 // is identity. | 144 // is identity. |
| 102 if (key.can_use_original_decode()) | 145 if (key.can_use_original_decode()) { |
| 103 return SkSize::Make(1.f, 1.f); | 146 return SkSize::Make(1.f, 1.f); |
| 104 | 147 } else if (key.filter_quality() == kMedium_SkFilterQuality) { |
| 105 float x_scale = | 148 return GetMipMapScaleAdjustment(key.src_rect().size(), key.target_size()); |
| 106 key.target_size().width() / static_cast<float>(key.src_rect().width()); | 149 } else { |
| 107 float y_scale = | 150 float x_scale = |
| 108 key.target_size().height() / static_cast<float>(key.src_rect().height()); | 151 key.target_size().width() / static_cast<float>(key.src_rect().width()); |
| 109 return SkSize::Make(x_scale, y_scale); | 152 float y_scale = key.target_size().height() / |
| 153 static_cast<float>(key.src_rect().height()); |
| 154 return SkSize::Make(x_scale, y_scale); |
| 155 } |
| 110 } | 156 } |
| 111 | 157 |
| 112 SkFilterQuality GetDecodedFilterQuality(const ImageDecodeControllerKey& key) { | 158 SkFilterQuality GetDecodedFilterQuality(const ImageDecodeControllerKey& key) { |
| 113 return std::min(key.filter_quality(), kLow_SkFilterQuality); | 159 return std::min(key.filter_quality(), kLow_SkFilterQuality); |
| 114 } | 160 } |
| 115 | 161 |
| 116 SkImageInfo CreateImageInfo(size_t width, | 162 SkImageInfo CreateImageInfo(size_t width, |
| 117 size_t height, | 163 size_t height, |
| 118 ResourceFormat format) { | 164 ResourceFormat format) { |
| 119 return SkImageInfo::Make(width, height, | 165 return SkImageInfo::Make(width, height, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 "SoftwareImageDecodeController::GetTaskForImageAndRef", "key", | 227 "SoftwareImageDecodeController::GetTaskForImageAndRef", "key", |
| 182 key.ToString()); | 228 key.ToString()); |
| 183 | 229 |
| 184 // If the target size is empty, we can skip this image during draw (and thus | 230 // If the target size is empty, we can skip this image during draw (and thus |
| 185 // we don't need to decode it or ref it). | 231 // we don't need to decode it or ref it). |
| 186 if (key.target_size().IsEmpty()) { | 232 if (key.target_size().IsEmpty()) { |
| 187 *task = nullptr; | 233 *task = nullptr; |
| 188 return false; | 234 return false; |
| 189 } | 235 } |
| 190 | 236 |
| 191 // If we're not going to do a scale, we will just create a task to preroll the | |
| 192 // image the first time we see it. This doesn't need to account for memory. | |
| 193 // TODO(vmpstr): We can also lock the original sized image, in which case it | |
| 194 // does require memory bookkeeping. | |
| 195 if (!CanHandleImage(key)) { | |
| 196 base::AutoLock lock(lock_); | |
| 197 if (prerolled_images_.count(key.image_id()) == 0) { | |
| 198 scoped_refptr<TileTask>& existing_task = pending_image_tasks_[key]; | |
| 199 if (!existing_task) { | |
| 200 existing_task = make_scoped_refptr( | |
| 201 new ImageDecodeTaskImpl(this, key, image, tracing_info)); | |
| 202 } | |
| 203 *task = existing_task; | |
| 204 } else { | |
| 205 *task = nullptr; | |
| 206 } | |
| 207 return false; | |
| 208 } | |
| 209 | |
| 210 base::AutoLock lock(lock_); | 237 base::AutoLock lock(lock_); |
| 211 | 238 |
| 212 // If we already have the image in cache, then we can return it. | 239 // If we already have the image in cache, then we can return it. |
| 213 auto decoded_it = decoded_images_.Get(key); | 240 auto decoded_it = decoded_images_.Get(key); |
| 214 bool new_image_fits_in_memory = | 241 bool new_image_fits_in_memory = |
| 215 locked_images_budget_.AvailableMemoryBytes() >= key.locked_bytes(); | 242 locked_images_budget_.AvailableMemoryBytes() >= key.locked_bytes(); |
| 216 if (decoded_it != decoded_images_.end()) { | 243 if (decoded_it != decoded_images_.end()) { |
| 217 bool image_was_locked = decoded_it->second->is_locked(); | 244 bool image_was_locked = decoded_it->second->is_locked(); |
| 218 if (image_was_locked || | 245 if (image_was_locked || |
| 219 (new_image_fits_in_memory && decoded_it->second->Lock())) { | 246 (new_image_fits_in_memory && decoded_it->second->Lock())) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 } | 309 } |
| 283 | 310 |
| 284 void SoftwareImageDecodeController::UnrefImage(const DrawImage& image) { | 311 void SoftwareImageDecodeController::UnrefImage(const DrawImage& image) { |
| 285 // When we unref the image, there are several situations we need to consider: | 312 // When we unref the image, there are several situations we need to consider: |
| 286 // 1. The ref did not reach 0, which means we have to keep the image locked. | 313 // 1. The ref did not reach 0, which means we have to keep the image locked. |
| 287 // 2. The ref reached 0, we should unlock it. | 314 // 2. The ref reached 0, we should unlock it. |
| 288 // 2a. The image isn't in the locked cache because we didn't get to decode | 315 // 2a. The image isn't in the locked cache because we didn't get to decode |
| 289 // it yet (or failed to decode it). | 316 // it yet (or failed to decode it). |
| 290 // 2b. Unlock the image but keep it in list. | 317 // 2b. Unlock the image but keep it in list. |
| 291 const ImageKey& key = ImageKey::FromDrawImage(image); | 318 const ImageKey& key = ImageKey::FromDrawImage(image); |
| 292 DCHECK(CanHandleImage(key)) << key.ToString(); | |
| 293 TRACE_EVENT1("disabled-by-default-cc.debug", | 319 TRACE_EVENT1("disabled-by-default-cc.debug", |
| 294 "SoftwareImageDecodeController::UnrefImage", "key", | 320 "SoftwareImageDecodeController::UnrefImage", "key", |
| 295 key.ToString()); | 321 key.ToString()); |
| 296 | 322 |
| 297 base::AutoLock lock(lock_); | 323 base::AutoLock lock(lock_); |
| 298 auto ref_count_it = decoded_images_ref_counts_.find(key); | 324 auto ref_count_it = decoded_images_ref_counts_.find(key); |
| 299 DCHECK(ref_count_it != decoded_images_ref_counts_.end()); | 325 DCHECK(ref_count_it != decoded_images_ref_counts_.end()); |
| 300 | 326 |
| 301 --ref_count_it->second; | 327 --ref_count_it->second; |
| 302 if (ref_count_it->second == 0) { | 328 if (ref_count_it->second == 0) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 313 DCHECK(decoded_image_it->second->is_locked()); | 339 DCHECK(decoded_image_it->second->is_locked()); |
| 314 decoded_image_it->second->Unlock(); | 340 decoded_image_it->second->Unlock(); |
| 315 } | 341 } |
| 316 SanityCheckState(__LINE__, true); | 342 SanityCheckState(__LINE__, true); |
| 317 } | 343 } |
| 318 | 344 |
| 319 void SoftwareImageDecodeController::DecodeImage(const ImageKey& key, | 345 void SoftwareImageDecodeController::DecodeImage(const ImageKey& key, |
| 320 const DrawImage& image) { | 346 const DrawImage& image) { |
| 321 TRACE_EVENT1("cc", "SoftwareImageDecodeController::DecodeImage", "key", | 347 TRACE_EVENT1("cc", "SoftwareImageDecodeController::DecodeImage", "key", |
| 322 key.ToString()); | 348 key.ToString()); |
| 323 if (!CanHandleImage(key)) { | |
| 324 image.image()->preroll(); | |
| 325 | |
| 326 base::AutoLock lock(lock_); | |
| 327 prerolled_images_.insert(key.image_id()); | |
| 328 // Erase the pending task from the queue, since the task won't be doing | |
| 329 // anything useful after this function terminates. Since we don't preroll | |
| 330 // images twice, this is actually not necessary but it behaves similar to | |
| 331 // the other code path: when this function finishes, the task isn't in the | |
| 332 // pending_image_tasks_ list. | |
| 333 pending_image_tasks_.erase(key); | |
| 334 return; | |
| 335 } | |
| 336 | |
| 337 base::AutoLock lock(lock_); | 349 base::AutoLock lock(lock_); |
| 338 AutoRemoveKeyFromTaskMap remove_key_from_task_map(&pending_image_tasks_, key); | 350 AutoRemoveKeyFromTaskMap remove_key_from_task_map(&pending_image_tasks_, key); |
| 339 | 351 |
| 340 // We could have finished all of the raster tasks (cancelled) while the task | 352 // We could have finished all of the raster tasks (cancelled) while the task |
| 341 // was just starting to run. Since this task already started running, it | 353 // was just starting to run. Since this task already started running, it |
| 342 // wasn't cancelled. So, if the ref count for the image is 0 then we can just | 354 // wasn't cancelled. So, if the ref count for the image is 0 then we can just |
| 343 // abort. | 355 // abort. |
| 344 if (decoded_images_ref_counts_.find(key) == | 356 if (decoded_images_ref_counts_.find(key) == |
| 345 decoded_images_ref_counts_.end()) { | 357 decoded_images_ref_counts_.end()) { |
| 346 return; | 358 return; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 key.ToString()); | 410 key.ToString()); |
| 399 sk_sp<const SkImage> image = draw_image.image(); | 411 sk_sp<const SkImage> image = draw_image.image(); |
| 400 if (!image) | 412 if (!image) |
| 401 return nullptr; | 413 return nullptr; |
| 402 | 414 |
| 403 switch (key.filter_quality()) { | 415 switch (key.filter_quality()) { |
| 404 case kNone_SkFilterQuality: | 416 case kNone_SkFilterQuality: |
| 405 case kLow_SkFilterQuality: | 417 case kLow_SkFilterQuality: |
| 406 return GetOriginalImageDecode(key, std::move(image)); | 418 return GetOriginalImageDecode(key, std::move(image)); |
| 407 case kMedium_SkFilterQuality: | 419 case kMedium_SkFilterQuality: |
| 408 NOTIMPLEMENTED(); | |
| 409 return nullptr; | |
| 410 case kHigh_SkFilterQuality: | 420 case kHigh_SkFilterQuality: |
| 411 return GetScaledImageDecode(key, std::move(image)); | 421 return GetScaledImageDecode(key, std::move(image)); |
| 412 default: | 422 default: |
| 413 NOTREACHED(); | 423 NOTREACHED(); |
| 414 return nullptr; | 424 return nullptr; |
| 415 } | 425 } |
| 416 } | 426 } |
| 417 | 427 |
| 418 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDraw( | 428 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDraw( |
| 419 const DrawImage& draw_image) { | 429 const DrawImage& draw_image) { |
| 420 ImageKey key = ImageKey::FromDrawImage(draw_image); | 430 ImageKey key = ImageKey::FromDrawImage(draw_image); |
| 421 TRACE_EVENT1("disabled-by-default-cc.debug", | 431 TRACE_EVENT1("disabled-by-default-cc.debug", |
| 422 "SoftwareImageDecodeController::GetDecodedImageForDraw", "key", | 432 "SoftwareImageDecodeController::GetDecodedImageForDraw", "key", |
| 423 key.ToString()); | 433 key.ToString()); |
| 424 // If the target size is empty, we can skip this image draw. | 434 // If the target size is empty, we can skip this image draw. |
| 425 if (key.target_size().IsEmpty()) | 435 if (key.target_size().IsEmpty()) |
| 426 return DecodedDrawImage(nullptr, kNone_SkFilterQuality); | 436 return DecodedDrawImage(nullptr, kNone_SkFilterQuality); |
| 427 | 437 |
| 428 if (!CanHandleImage(key)) | |
| 429 return DecodedDrawImage(draw_image.image(), draw_image.filter_quality()); | |
| 430 | |
| 431 return GetDecodedImageForDrawInternal(key, draw_image); | 438 return GetDecodedImageForDrawInternal(key, draw_image); |
| 432 } | 439 } |
| 433 | 440 |
| 434 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal( | 441 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal( |
| 435 const ImageKey& key, | 442 const ImageKey& key, |
| 436 const DrawImage& draw_image) { | 443 const DrawImage& draw_image) { |
| 437 TRACE_EVENT1("disabled-by-default-cc.debug", | 444 TRACE_EVENT1("disabled-by-default-cc.debug", |
| 438 "SoftwareImageDecodeController::GetDecodedImageForDrawInternal", | 445 "SoftwareImageDecodeController::GetDecodedImageForDrawInternal", |
| 439 "key", key.ToString()); | 446 "key", key.ToString()); |
| 440 base::AutoLock lock(lock_); | 447 base::AutoLock lock(lock_); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 { | 605 { |
| 599 TRACE_EVENT0( | 606 TRACE_EVENT0( |
| 600 "disabled-by-default-cc.debug", | 607 "disabled-by-default-cc.debug", |
| 601 "SoftwareImageDecodeController::ScaleImage - allocate scaled pixels"); | 608 "SoftwareImageDecodeController::ScaleImage - allocate scaled pixels"); |
| 602 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() | 609 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() |
| 603 ->AllocateLockedDiscardableMemory( | 610 ->AllocateLockedDiscardableMemory( |
| 604 scaled_info.minRowBytes() * scaled_info.height()); | 611 scaled_info.minRowBytes() * scaled_info.height()); |
| 605 } | 612 } |
| 606 SkPixmap scaled_pixmap(scaled_info, scaled_pixels->data(), | 613 SkPixmap scaled_pixmap(scaled_info, scaled_pixels->data(), |
| 607 scaled_info.minRowBytes()); | 614 scaled_info.minRowBytes()); |
| 608 // TODO(vmpstr): Start handling more than just high filter quality. | 615 DCHECK(key.filter_quality() == kHigh_SkFilterQuality || |
| 609 DCHECK_EQ(kHigh_SkFilterQuality, key.filter_quality()); | 616 key.filter_quality() == kMedium_SkFilterQuality); |
| 610 { | 617 { |
| 611 TRACE_EVENT0("disabled-by-default-cc.debug", | 618 TRACE_EVENT0("disabled-by-default-cc.debug", |
| 612 "SoftwareImageDecodeController::ScaleImage - scale pixels"); | 619 "SoftwareImageDecodeController::ScaleImage - scale pixels"); |
| 613 bool result = | 620 bool result = |
| 614 decoded_pixmap.scalePixels(scaled_pixmap, key.filter_quality()); | 621 decoded_pixmap.scalePixels(scaled_pixmap, key.filter_quality()); |
| 615 DCHECK(result) << key.ToString(); | 622 DCHECK(result) << key.ToString(); |
| 616 } | 623 } |
| 617 | 624 |
| 618 // Release the original sized decode. Any other intermediate result to release | 625 // Release the original sized decode. Any other intermediate result to release |
| 619 // would be the subrect memory. However, that's in a scoped_ptr and will be | 626 // would be the subrect memory. However, that's in a scoped_ptr and will be |
| 620 // deleted automatically when we return. | 627 // deleted automatically when we return. |
| 621 DrawWithImageFinished(original_size_draw_image, decoded_draw_image); | 628 DrawWithImageFinished(original_size_draw_image, decoded_draw_image); |
| 622 | 629 |
| 623 return base::WrapUnique( | 630 return base::WrapUnique( |
| 624 new DecodedImage(scaled_info, std::move(scaled_pixels), | 631 new DecodedImage(scaled_info, std::move(scaled_pixels), |
| 625 SkSize::Make(-key.src_rect().x(), -key.src_rect().y()), | 632 SkSize::Make(-key.src_rect().x(), -key.src_rect().y()), |
| 626 next_tracing_id_.GetNext())); | 633 next_tracing_id_.GetNext())); |
| 627 } | 634 } |
| 628 | 635 |
| 629 void SoftwareImageDecodeController::DrawWithImageFinished( | 636 void SoftwareImageDecodeController::DrawWithImageFinished( |
| 630 const DrawImage& image, | 637 const DrawImage& image, |
| 631 const DecodedDrawImage& decoded_image) { | 638 const DecodedDrawImage& decoded_image) { |
| 632 TRACE_EVENT1("disabled-by-default-cc.debug", | 639 TRACE_EVENT1("disabled-by-default-cc.debug", |
| 633 "SoftwareImageDecodeController::DrawWithImageFinished", "key", | 640 "SoftwareImageDecodeController::DrawWithImageFinished", "key", |
| 634 ImageKey::FromDrawImage(image).ToString()); | 641 ImageKey::FromDrawImage(image).ToString()); |
| 635 ImageKey key = ImageKey::FromDrawImage(image); | 642 ImageKey key = ImageKey::FromDrawImage(image); |
| 636 if (!decoded_image.image() || !CanHandleImage(key)) | 643 if (!decoded_image.image()) |
| 637 return; | 644 return; |
| 638 | 645 |
| 639 if (decoded_image.is_at_raster_decode()) | 646 if (decoded_image.is_at_raster_decode()) |
| 640 UnrefAtRasterImage(key); | 647 UnrefAtRasterImage(key); |
| 641 else | 648 else |
| 642 UnrefImage(image); | 649 UnrefImage(image); |
| 643 SanityCheckState(__LINE__, false); | 650 SanityCheckState(__LINE__, false); |
| 644 } | 651 } |
| 645 | 652 |
| 646 void SoftwareImageDecodeController::RefAtRasterImage(const ImageKey& key) { | 653 void SoftwareImageDecodeController::RefAtRasterImage(const ImageKey& key) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 DCHECK(decoded_images_ref_counts_.find(key) == | 700 DCHECK(decoded_images_ref_counts_.find(key) == |
| 694 decoded_images_ref_counts_.end()); | 701 decoded_images_ref_counts_.end()); |
| 695 at_raster_image_it->second->Unlock(); | 702 at_raster_image_it->second->Unlock(); |
| 696 decoded_images_.Erase(image_it); | 703 decoded_images_.Erase(image_it); |
| 697 decoded_images_.Put(key, std::move(at_raster_image_it->second)); | 704 decoded_images_.Put(key, std::move(at_raster_image_it->second)); |
| 698 } | 705 } |
| 699 at_raster_decoded_images_.Erase(at_raster_image_it); | 706 at_raster_decoded_images_.Erase(at_raster_image_it); |
| 700 } | 707 } |
| 701 } | 708 } |
| 702 | 709 |
| 703 bool SoftwareImageDecodeController::CanHandleImage(const ImageKey& key) { | |
| 704 // TODO(vmpstr): Start handling medium filter quality as well. | |
| 705 return key.filter_quality() != kMedium_SkFilterQuality; | |
| 706 } | |
| 707 | |
| 708 void SoftwareImageDecodeController::ReduceCacheUsage() { | 710 void SoftwareImageDecodeController::ReduceCacheUsage() { |
| 709 TRACE_EVENT0("cc", "SoftwareImageDecodeController::ReduceCacheUsage"); | 711 TRACE_EVENT0("cc", "SoftwareImageDecodeController::ReduceCacheUsage"); |
| 710 base::AutoLock lock(lock_); | 712 base::AutoLock lock(lock_); |
| 711 size_t num_to_remove = (decoded_images_.size() > kMaxItemsInCache) | 713 size_t num_to_remove = (decoded_images_.size() > kMaxItemsInCache) |
| 712 ? (decoded_images_.size() - kMaxItemsInCache) | 714 ? (decoded_images_.size() - kMaxItemsInCache) |
| 713 : 0; | 715 : 0; |
| 714 for (auto it = decoded_images_.rbegin(); | 716 for (auto it = decoded_images_.rbegin(); |
| 715 num_to_remove != 0 && it != decoded_images_.rend();) { | 717 num_to_remove != 0 && it != decoded_images_.rend();) { |
| 716 if (it->second->is_locked()) { | 718 if (it->second->is_locked()) { |
| 717 ++it; | 719 ++it; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 bool can_use_original_decode = | 851 bool can_use_original_decode = |
| 850 quality == kLow_SkFilterQuality || quality == kNone_SkFilterQuality; | 852 quality == kLow_SkFilterQuality || quality == kNone_SkFilterQuality; |
| 851 | 853 |
| 852 // If we're going to use the original decode, then the target size should be | 854 // If we're going to use the original decode, then the target size should be |
| 853 // the full image size, since that will allow for proper memory accounting. | 855 // the full image size, since that will allow for proper memory accounting. |
| 854 // Note we skip the decode if the target size is empty altogether, so don't | 856 // Note we skip the decode if the target size is empty altogether, so don't |
| 855 // update the target size in that case. | 857 // update the target size in that case. |
| 856 if (can_use_original_decode && !target_size.IsEmpty()) | 858 if (can_use_original_decode && !target_size.IsEmpty()) |
| 857 target_size = gfx::Size(image.image()->width(), image.image()->height()); | 859 target_size = gfx::Size(image.image()->width(), image.image()->height()); |
| 858 | 860 |
| 861 if (quality == kMedium_SkFilterQuality && !target_size.IsEmpty()) { |
| 862 SkSize mip_target_size = |
| 863 GetMipMapScaleAdjustment(src_rect.size(), target_size); |
| 864 DCHECK(mip_target_size.width() != -1.f && mip_target_size.height() != -1.f); |
| 865 target_size.set_width(src_rect.width() * mip_target_size.width()); |
| 866 target_size.set_height(src_rect.height() * mip_target_size.height()); |
| 867 } |
| 868 |
| 859 return ImageDecodeControllerKey(image.image()->uniqueID(), src_rect, | 869 return ImageDecodeControllerKey(image.image()->uniqueID(), src_rect, |
| 860 target_size, quality, | 870 target_size, quality, |
| 861 can_use_original_decode); | 871 can_use_original_decode); |
| 862 } | 872 } |
| 863 | 873 |
| 864 ImageDecodeControllerKey::ImageDecodeControllerKey( | 874 ImageDecodeControllerKey::ImageDecodeControllerKey( |
| 865 uint32_t image_id, | 875 uint32_t image_id, |
| 866 const gfx::Rect& src_rect, | 876 const gfx::Rect& src_rect, |
| 867 const gfx::Size& target_size, | 877 const gfx::Size& target_size, |
| 868 SkFilterQuality filter_quality, | 878 SkFilterQuality filter_quality, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { | 971 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { |
| 962 current_usage_bytes_ = 0; | 972 current_usage_bytes_ = 0; |
| 963 } | 973 } |
| 964 | 974 |
| 965 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() | 975 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() |
| 966 const { | 976 const { |
| 967 return current_usage_bytes_.ValueOrDie(); | 977 return current_usage_bytes_.ValueOrDie(); |
| 968 } | 978 } |
| 969 | 979 |
| 970 } // namespace cc | 980 } // namespace cc |
| OLD | NEW |