Chromium Code Reviews| 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/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/trace_event/memory_dump_manager.h" | 18 #include "base/trace_event/memory_dump_manager.h" |
| 18 #include "cc/debug/devtools_instrumentation.h" | 19 #include "cc/debug/devtools_instrumentation.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 private: | 90 private: |
| 90 SoftwareImageDecodeController* controller_; | 91 SoftwareImageDecodeController* controller_; |
| 91 SoftwareImageDecodeController::ImageKey image_key_; | 92 SoftwareImageDecodeController::ImageKey image_key_; |
| 92 DrawImage image_; | 93 DrawImage image_; |
| 93 skia::RefPtr<const SkImage> image_ref_; | 94 skia::RefPtr<const SkImage> image_ref_; |
| 94 uint64_t source_prepare_tiles_id_; | 95 uint64_t source_prepare_tiles_id_; |
| 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( | |
| 105 const SoftwareImageDecodeController::ImageKey& key) { | |
| 106 gfx::Rect src_rect = key.src_rect(); | |
| 107 int src_height = src_rect.height(); | |
| 108 int src_width = src_rect.width(); | |
| 109 | |
| 110 int next_mip_height = src_height; | |
| 111 int next_mip_width = src_width; | |
| 112 for (int current_mip_level = 0;; current_mip_level++) { | |
| 113 int mip_height = next_mip_height; | |
| 114 int mip_width = next_mip_width; | |
| 115 | |
| 116 next_mip_height = std::max(1, src_height / (1 << (current_mip_level + 1))); | |
| 117 next_mip_width = std::max(1, src_width / (1 << (current_mip_level + 1))); | |
| 118 | |
| 119 // Check if an axis on the next mip level would be smaller than the target. | |
| 120 // If so, use the current mip level. | |
| 121 // This effectively always uses the larger image and always scales down. | |
| 122 if (next_mip_height < key.target_size().height() || | |
| 123 next_mip_width < key.target_size().width()) { | |
|
ericrk
2016/04/23 00:25:48
I think this hits an edge case if you actually wan
cblume
2016/04/27 08:10:36
Done.
| |
| 124 SkScalar y_scale = 1.f; | |
| 125 SkScalar x_scale = 1.f; | |
| 126 if (current_mip_level != 0) { | |
| 127 y_scale = static_cast<float>(mip_height) / src_height; | |
| 128 x_scale = static_cast<float>(mip_width) / src_width; | |
| 129 } | |
| 130 | |
| 131 return SkSize::Make(x_scale, y_scale); | |
| 132 } | |
| 133 | |
| 134 if (mip_height == 1 && mip_width == 1) { | |
| 135 // We have reached the final mip level | |
| 136 break; | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 return SkSize::Make(-1.f, -1.f); | |
| 141 } | |
| 142 | |
| 99 SkSize GetScaleAdjustment(const ImageDecodeControllerKey& key) { | 143 SkSize GetScaleAdjustment(const ImageDecodeControllerKey& key) { |
| 100 // If the requested filter quality did not require scale, then the adjustment | 144 // If the requested filter quality did not require scale, then the adjustment |
| 101 // is identity. | 145 // is identity. |
| 102 if (key.can_use_original_decode()) | 146 if (key.can_use_original_decode()) { |
| 103 return SkSize::Make(1.f, 1.f); | 147 return SkSize::Make(1.f, 1.f); |
| 104 | 148 } else { |
| 105 float x_scale = | 149 if (key.filter_quality() == kMedium_SkFilterQuality) { |
| 106 key.target_size().width() / static_cast<float>(key.src_rect().width()); | 150 return GetMipMapScaleAdjustment(key); |
| 107 float y_scale = | 151 } else { |
| 108 key.target_size().height() / static_cast<float>(key.src_rect().height()); | 152 float x_scale = key.target_size().width() / |
| 109 return SkSize::Make(x_scale, y_scale); | 153 static_cast<float>(key.src_rect().width()); |
| 154 float y_scale = key.target_size().height() / | |
| 155 static_cast<float>(key.src_rect().height()); | |
| 156 return SkSize::Make(x_scale, y_scale); | |
| 157 } | |
| 158 } | |
| 110 } | 159 } |
| 111 | 160 |
| 112 SkFilterQuality GetDecodedFilterQuality(const ImageDecodeControllerKey& key) { | 161 SkFilterQuality GetDecodedFilterQuality(const ImageDecodeControllerKey& key) { |
| 113 return std::min(key.filter_quality(), kLow_SkFilterQuality); | 162 return std::min(key.filter_quality(), kLow_SkFilterQuality); |
| 114 } | 163 } |
| 115 | 164 |
| 116 SkImageInfo CreateImageInfo(size_t width, | 165 SkImageInfo CreateImageInfo(size_t width, |
| 117 size_t height, | 166 size_t height, |
| 118 ResourceFormat format) { | 167 ResourceFormat format) { |
| 119 return SkImageInfo::Make(width, height, | 168 return SkImageInfo::Make(width, height, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 "SoftwareImageDecodeController::GetTaskForImageAndRef", "key", | 215 "SoftwareImageDecodeController::GetTaskForImageAndRef", "key", |
| 167 key.ToString()); | 216 key.ToString()); |
| 168 | 217 |
| 169 // If the target size is empty, we can skip this image during draw (and thus | 218 // If the target size is empty, we can skip this image during draw (and thus |
| 170 // we don't need to decode it or ref it). | 219 // we don't need to decode it or ref it). |
| 171 if (key.target_size().IsEmpty()) { | 220 if (key.target_size().IsEmpty()) { |
| 172 *task = nullptr; | 221 *task = nullptr; |
| 173 return false; | 222 return false; |
| 174 } | 223 } |
| 175 | 224 |
| 176 // If we're not going to do a scale, we will just create a task to preroll the | |
| 177 // image the first time we see it. This doesn't need to account for memory. | |
| 178 // TODO(vmpstr): We can also lock the original sized image, in which case it | |
| 179 // does require memory bookkeeping. | |
| 180 if (!CanHandleImage(key)) { | |
| 181 base::AutoLock lock(lock_); | |
| 182 if (prerolled_images_.count(key.image_id()) == 0) { | |
| 183 scoped_refptr<TileTask>& existing_task = pending_image_tasks_[key]; | |
| 184 if (!existing_task) { | |
| 185 existing_task = make_scoped_refptr( | |
| 186 new ImageDecodeTaskImpl(this, key, image, prepare_tiles_id)); | |
| 187 } | |
| 188 *task = existing_task; | |
| 189 } else { | |
| 190 *task = nullptr; | |
| 191 } | |
| 192 return false; | |
| 193 } | |
| 194 | |
| 195 base::AutoLock lock(lock_); | 225 base::AutoLock lock(lock_); |
| 196 | 226 |
| 197 // If we already have the image in cache, then we can return it. | 227 // If we already have the image in cache, then we can return it. |
| 198 auto decoded_it = decoded_images_.Get(key); | 228 auto decoded_it = decoded_images_.Get(key); |
| 199 bool new_image_fits_in_memory = | 229 bool new_image_fits_in_memory = |
| 200 locked_images_budget_.AvailableMemoryBytes() >= key.locked_bytes(); | 230 locked_images_budget_.AvailableMemoryBytes() >= key.locked_bytes(); |
| 201 if (decoded_it != decoded_images_.end()) { | 231 if (decoded_it != decoded_images_.end()) { |
| 202 if (decoded_it->second->is_locked() || | 232 if (decoded_it->second->is_locked() || |
| 203 (new_image_fits_in_memory && decoded_it->second->Lock())) { | 233 (new_image_fits_in_memory && decoded_it->second->Lock())) { |
| 204 RefImage(key); | 234 RefImage(key); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 } | 286 } |
| 257 | 287 |
| 258 void SoftwareImageDecodeController::UnrefImage(const DrawImage& image) { | 288 void SoftwareImageDecodeController::UnrefImage(const DrawImage& image) { |
| 259 // When we unref the image, there are several situations we need to consider: | 289 // When we unref the image, there are several situations we need to consider: |
| 260 // 1. The ref did not reach 0, which means we have to keep the image locked. | 290 // 1. The ref did not reach 0, which means we have to keep the image locked. |
| 261 // 2. The ref reached 0, we should unlock it. | 291 // 2. The ref reached 0, we should unlock it. |
| 262 // 2a. The image isn't in the locked cache because we didn't get to decode | 292 // 2a. The image isn't in the locked cache because we didn't get to decode |
| 263 // it yet (or failed to decode it). | 293 // it yet (or failed to decode it). |
| 264 // 2b. Unlock the image but keep it in list. | 294 // 2b. Unlock the image but keep it in list. |
| 265 const ImageKey& key = ImageKey::FromDrawImage(image); | 295 const ImageKey& key = ImageKey::FromDrawImage(image); |
| 266 DCHECK(CanHandleImage(key)) << key.ToString(); | |
| 267 TRACE_EVENT1("disabled-by-default-cc.debug", | 296 TRACE_EVENT1("disabled-by-default-cc.debug", |
| 268 "SoftwareImageDecodeController::UnrefImage", "key", | 297 "SoftwareImageDecodeController::UnrefImage", "key", |
| 269 key.ToString()); | 298 key.ToString()); |
| 270 | 299 |
| 271 base::AutoLock lock(lock_); | 300 base::AutoLock lock(lock_); |
| 272 auto ref_count_it = decoded_images_ref_counts_.find(key); | 301 auto ref_count_it = decoded_images_ref_counts_.find(key); |
| 273 DCHECK(ref_count_it != decoded_images_ref_counts_.end()); | 302 DCHECK(ref_count_it != decoded_images_ref_counts_.end()); |
| 274 | 303 |
| 275 --ref_count_it->second; | 304 --ref_count_it->second; |
| 276 if (ref_count_it->second == 0) { | 305 if (ref_count_it->second == 0) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 287 DCHECK(decoded_image_it->second->is_locked()); | 316 DCHECK(decoded_image_it->second->is_locked()); |
| 288 decoded_image_it->second->Unlock(); | 317 decoded_image_it->second->Unlock(); |
| 289 } | 318 } |
| 290 SanityCheckState(__LINE__, true); | 319 SanityCheckState(__LINE__, true); |
| 291 } | 320 } |
| 292 | 321 |
| 293 void SoftwareImageDecodeController::DecodeImage(const ImageKey& key, | 322 void SoftwareImageDecodeController::DecodeImage(const ImageKey& key, |
| 294 const DrawImage& image) { | 323 const DrawImage& image) { |
| 295 TRACE_EVENT1("cc", "SoftwareImageDecodeController::DecodeImage", "key", | 324 TRACE_EVENT1("cc", "SoftwareImageDecodeController::DecodeImage", "key", |
| 296 key.ToString()); | 325 key.ToString()); |
| 297 if (!CanHandleImage(key)) { | |
| 298 image.image()->preroll(); | |
| 299 | |
| 300 base::AutoLock lock(lock_); | |
| 301 prerolled_images_.insert(key.image_id()); | |
| 302 // Erase the pending task from the queue, since the task won't be doing | |
| 303 // anything useful after this function terminates. Since we don't preroll | |
| 304 // images twice, this is actually not necessary but it behaves similar to | |
| 305 // the other code path: when this function finishes, the task isn't in the | |
| 306 // pending_image_tasks_ list. | |
| 307 pending_image_tasks_.erase(key); | |
| 308 return; | |
| 309 } | |
| 310 | |
| 311 base::AutoLock lock(lock_); | 326 base::AutoLock lock(lock_); |
| 312 AutoRemoveKeyFromTaskMap remove_key_from_task_map(&pending_image_tasks_, key); | 327 AutoRemoveKeyFromTaskMap remove_key_from_task_map(&pending_image_tasks_, key); |
| 313 | 328 |
| 314 // We could have finished all of the raster tasks (cancelled) while the task | 329 // We could have finished all of the raster tasks (cancelled) while the task |
| 315 // was just starting to run. Since this task already started running, it | 330 // was just starting to run. Since this task already started running, it |
| 316 // wasn't cancelled. So, if the ref count for the image is 0 then we can just | 331 // wasn't cancelled. So, if the ref count for the image is 0 then we can just |
| 317 // abort. | 332 // abort. |
| 318 if (decoded_images_ref_counts_.find(key) == | 333 if (decoded_images_ref_counts_.find(key) == |
| 319 decoded_images_ref_counts_.end()) { | 334 decoded_images_ref_counts_.end()) { |
| 320 return; | 335 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 if (decoded_images_ref_counts_.find(key) == | 372 if (decoded_images_ref_counts_.find(key) == |
| 358 decoded_images_ref_counts_.end()) { | 373 decoded_images_ref_counts_.end()) { |
| 359 decoded_image->Unlock(); | 374 decoded_image->Unlock(); |
| 360 } | 375 } |
| 361 | 376 |
| 362 decoded_images_.Put(key, std::move(decoded_image)); | 377 decoded_images_.Put(key, std::move(decoded_image)); |
| 363 SanityCheckState(__LINE__, true); | 378 SanityCheckState(__LINE__, true); |
| 364 } | 379 } |
| 365 | 380 |
| 366 std::unique_ptr<SoftwareImageDecodeController::DecodedImage> | 381 std::unique_ptr<SoftwareImageDecodeController::DecodedImage> |
| 382 SoftwareImageDecodeController::GetMediumQualityImageDecode( | |
| 383 const ImageKey& key, | |
| 384 const SkImage& image) { | |
| 385 SkSize mipmap_scale = GetMipMapScaleAdjustment(key); | |
| 386 // -1 represents an invalid scale. | |
| 387 // So add 1 and compare to epsilon. | |
|
vmpstr
2016/04/22 18:17:10
Comment is incorrect
cblume
2016/04/27 08:10:36
Done.
| |
| 388 if (mipmap_scale.width() == -1.f || mipmap_scale.height() == -1.f) { | |
|
vmpstr
2016/04/22 18:17:10
I understand your reasoning, but I think changing
vmpstr
2016/04/25 18:27:21
Also... The situation in which this can happen is
cblume
2016/04/27 08:10:36
Done.
| |
| 389 return nullptr; | |
| 390 } | |
| 391 | |
| 392 DrawImage mip_image( | |
| 393 &image, gfx::RectToSkIRect(key.src_rect()), kMedium_SkFilterQuality, | |
| 394 SkMatrix::MakeScale(mipmap_scale.width(), mipmap_scale.height())); | |
| 395 auto mip_key = ImageKey::FromDrawImage(mip_image); | |
| 396 return GetScaledImageDecode(mip_key, image); | |
| 397 } | |
| 398 | |
| 399 std::unique_ptr<SoftwareImageDecodeController::DecodedImage> | |
| 367 SoftwareImageDecodeController::DecodeImageInternal( | 400 SoftwareImageDecodeController::DecodeImageInternal( |
| 368 const ImageKey& key, | 401 const ImageKey& key, |
| 369 const DrawImage& draw_image) { | 402 const DrawImage& draw_image) { |
| 370 TRACE_EVENT1("disabled-by-default-cc.debug", | 403 TRACE_EVENT1("disabled-by-default-cc.debug", |
| 371 "SoftwareImageDecodeController::DecodeImageInternal", "key", | 404 "SoftwareImageDecodeController::DecodeImageInternal", "key", |
| 372 key.ToString()); | 405 key.ToString()); |
| 373 const SkImage* image = draw_image.image(); | 406 const SkImage* image = draw_image.image(); |
| 374 if (!image) | 407 if (!image) |
| 375 return nullptr; | 408 return nullptr; |
| 376 | 409 |
| 377 switch (key.filter_quality()) { | 410 switch (key.filter_quality()) { |
| 378 case kNone_SkFilterQuality: | 411 case kNone_SkFilterQuality: |
| 379 case kLow_SkFilterQuality: | 412 case kLow_SkFilterQuality: |
| 380 return GetOriginalImageDecode(key, *image); | 413 return GetOriginalImageDecode(key, *image); |
| 381 case kMedium_SkFilterQuality: | 414 case kMedium_SkFilterQuality: |
| 382 NOTIMPLEMENTED(); | 415 return GetMediumQualityImageDecode(key, *image); |
| 383 return nullptr; | |
| 384 case kHigh_SkFilterQuality: | 416 case kHigh_SkFilterQuality: |
| 385 return GetScaledImageDecode(key, *image); | 417 return GetScaledImageDecode(key, *image); |
| 386 default: | 418 default: |
| 387 NOTREACHED(); | 419 NOTREACHED(); |
| 388 return nullptr; | 420 return nullptr; |
| 389 } | 421 } |
| 390 } | 422 } |
| 391 | 423 |
| 392 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDraw( | 424 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDraw( |
| 393 const DrawImage& draw_image) { | 425 const DrawImage& draw_image) { |
| 394 ImageKey key = ImageKey::FromDrawImage(draw_image); | 426 ImageKey key = ImageKey::FromDrawImage(draw_image); |
| 395 TRACE_EVENT1("disabled-by-default-cc.debug", | 427 TRACE_EVENT1("disabled-by-default-cc.debug", |
| 396 "SoftwareImageDecodeController::GetDecodedImageForDraw", "key", | 428 "SoftwareImageDecodeController::GetDecodedImageForDraw", "key", |
| 397 key.ToString()); | 429 key.ToString()); |
| 398 // If the target size is empty, we can skip this image draw. | 430 // If the target size is empty, we can skip this image draw. |
| 399 if (key.target_size().IsEmpty()) | 431 if (key.target_size().IsEmpty()) |
| 400 return DecodedDrawImage(nullptr, kNone_SkFilterQuality); | 432 return DecodedDrawImage(nullptr, kNone_SkFilterQuality); |
| 401 | 433 |
| 402 if (!CanHandleImage(key)) | |
| 403 return DecodedDrawImage(draw_image.image(), draw_image.filter_quality()); | |
| 404 | |
| 405 return GetDecodedImageForDrawInternal(key, draw_image); | 434 return GetDecodedImageForDrawInternal(key, draw_image); |
| 406 } | 435 } |
| 407 | 436 |
| 408 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal( | 437 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal( |
| 409 const ImageKey& key, | 438 const ImageKey& key, |
| 410 const DrawImage& draw_image) { | 439 const DrawImage& draw_image) { |
| 411 TRACE_EVENT1("disabled-by-default-cc.debug", | 440 TRACE_EVENT1("disabled-by-default-cc.debug", |
| 412 "SoftwareImageDecodeController::GetDecodedImageForDrawInternal", | 441 "SoftwareImageDecodeController::GetDecodedImageForDrawInternal", |
| 413 "key", key.ToString()); | 442 "key", key.ToString()); |
| 414 base::AutoLock lock(lock_); | 443 base::AutoLock lock(lock_); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 { | 599 { |
| 571 TRACE_EVENT0( | 600 TRACE_EVENT0( |
| 572 "disabled-by-default-cc.debug", | 601 "disabled-by-default-cc.debug", |
| 573 "SoftwareImageDecodeController::ScaleImage - allocate scaled pixels"); | 602 "SoftwareImageDecodeController::ScaleImage - allocate scaled pixels"); |
| 574 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() | 603 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() |
| 575 ->AllocateLockedDiscardableMemory( | 604 ->AllocateLockedDiscardableMemory( |
| 576 scaled_info.minRowBytes() * scaled_info.height()); | 605 scaled_info.minRowBytes() * scaled_info.height()); |
| 577 } | 606 } |
| 578 SkPixmap scaled_pixmap(scaled_info, scaled_pixels->data(), | 607 SkPixmap scaled_pixmap(scaled_info, scaled_pixels->data(), |
| 579 scaled_info.minRowBytes()); | 608 scaled_info.minRowBytes()); |
| 580 // TODO(vmpstr): Start handling more than just high filter quality. | 609 DCHECK(key.filter_quality() == kHigh_SkFilterQuality || |
| 581 DCHECK_EQ(kHigh_SkFilterQuality, key.filter_quality()); | 610 key.filter_quality() == kMedium_SkFilterQuality); |
| 582 { | 611 { |
| 583 TRACE_EVENT0("disabled-by-default-cc.debug", | 612 TRACE_EVENT0("disabled-by-default-cc.debug", |
| 584 "SoftwareImageDecodeController::ScaleImage - scale pixels"); | 613 "SoftwareImageDecodeController::ScaleImage - scale pixels"); |
| 585 bool result = | 614 bool result = |
| 586 decoded_pixmap.scalePixels(scaled_pixmap, key.filter_quality()); | 615 decoded_pixmap.scalePixels(scaled_pixmap, key.filter_quality()); |
| 587 DCHECK(result) << key.ToString(); | 616 DCHECK(result) << key.ToString(); |
| 588 } | 617 } |
| 589 | 618 |
| 590 // Release the original sized decode. Any other intermediate result to release | 619 // Release the original sized decode. Any other intermediate result to release |
| 591 // would be the subrect memory. However, that's in a scoped_ptr and will be | 620 // would be the subrect memory. However, that's in a scoped_ptr and will be |
| 592 // deleted automatically when we return. | 621 // deleted automatically when we return. |
| 593 DrawWithImageFinished(original_size_draw_image, decoded_draw_image); | 622 DrawWithImageFinished(original_size_draw_image, decoded_draw_image); |
| 594 | 623 |
| 595 return base::WrapUnique( | 624 return base::WrapUnique( |
| 596 new DecodedImage(scaled_info, std::move(scaled_pixels), | 625 new DecodedImage(scaled_info, std::move(scaled_pixels), |
| 597 SkSize::Make(-key.src_rect().x(), -key.src_rect().y()), | 626 SkSize::Make(-key.src_rect().x(), -key.src_rect().y()), |
| 598 next_tracing_id_.GetNext())); | 627 next_tracing_id_.GetNext())); |
| 599 } | 628 } |
| 600 | 629 |
| 601 void SoftwareImageDecodeController::DrawWithImageFinished( | 630 void SoftwareImageDecodeController::DrawWithImageFinished( |
| 602 const DrawImage& image, | 631 const DrawImage& image, |
| 603 const DecodedDrawImage& decoded_image) { | 632 const DecodedDrawImage& decoded_image) { |
| 604 TRACE_EVENT1("disabled-by-default-cc.debug", | 633 TRACE_EVENT1("disabled-by-default-cc.debug", |
| 605 "SoftwareImageDecodeController::DrawWithImageFinished", "key", | 634 "SoftwareImageDecodeController::DrawWithImageFinished", "key", |
| 606 ImageKey::FromDrawImage(image).ToString()); | 635 ImageKey::FromDrawImage(image).ToString()); |
| 607 ImageKey key = ImageKey::FromDrawImage(image); | 636 ImageKey key = ImageKey::FromDrawImage(image); |
| 608 if (!decoded_image.image() || !CanHandleImage(key)) | 637 if (!decoded_image.image()) |
| 609 return; | 638 return; |
| 610 | 639 |
| 611 if (decoded_image.is_at_raster_decode()) | 640 if (decoded_image.is_at_raster_decode()) |
| 612 UnrefAtRasterImage(key); | 641 UnrefAtRasterImage(key); |
| 613 else | 642 else |
| 614 UnrefImage(image); | 643 UnrefImage(image); |
| 615 SanityCheckState(__LINE__, false); | 644 SanityCheckState(__LINE__, false); |
| 616 } | 645 } |
| 617 | 646 |
| 618 void SoftwareImageDecodeController::RefAtRasterImage(const ImageKey& key) { | 647 void SoftwareImageDecodeController::RefAtRasterImage(const ImageKey& key) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 DCHECK(decoded_images_ref_counts_.find(key) == | 694 DCHECK(decoded_images_ref_counts_.find(key) == |
| 666 decoded_images_ref_counts_.end()); | 695 decoded_images_ref_counts_.end()); |
| 667 at_raster_image_it->second->Unlock(); | 696 at_raster_image_it->second->Unlock(); |
| 668 decoded_images_.Erase(image_it); | 697 decoded_images_.Erase(image_it); |
| 669 decoded_images_.Put(key, std::move(at_raster_image_it->second)); | 698 decoded_images_.Put(key, std::move(at_raster_image_it->second)); |
| 670 } | 699 } |
| 671 at_raster_decoded_images_.Erase(at_raster_image_it); | 700 at_raster_decoded_images_.Erase(at_raster_image_it); |
| 672 } | 701 } |
| 673 } | 702 } |
| 674 | 703 |
| 675 bool SoftwareImageDecodeController::CanHandleImage(const ImageKey& key) { | |
| 676 // TODO(vmpstr): Start handling medium filter quality as well. | |
| 677 return key.filter_quality() != kMedium_SkFilterQuality; | |
| 678 } | |
| 679 | |
| 680 void SoftwareImageDecodeController::ReduceCacheUsage() { | 704 void SoftwareImageDecodeController::ReduceCacheUsage() { |
| 681 TRACE_EVENT0("cc", "SoftwareImageDecodeController::ReduceCacheUsage"); | 705 TRACE_EVENT0("cc", "SoftwareImageDecodeController::ReduceCacheUsage"); |
| 682 base::AutoLock lock(lock_); | 706 base::AutoLock lock(lock_); |
| 683 size_t num_to_remove = (decoded_images_.size() > kMaxItemsInCache) | 707 size_t num_to_remove = (decoded_images_.size() > kMaxItemsInCache) |
| 684 ? (decoded_images_.size() - kMaxItemsInCache) | 708 ? (decoded_images_.size() - kMaxItemsInCache) |
| 685 : 0; | 709 : 0; |
| 686 for (auto it = decoded_images_.rbegin(); | 710 for (auto it = decoded_images_.rbegin(); |
| 687 num_to_remove != 0 && it != decoded_images_.rend();) { | 711 num_to_remove != 0 && it != decoded_images_.rend();) { |
| 688 if (it->second->is_locked()) { | 712 if (it->second->is_locked()) { |
| 689 ++it; | 713 ++it; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 933 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { | 957 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { |
| 934 current_usage_bytes_ = 0; | 958 current_usage_bytes_ = 0; |
| 935 } | 959 } |
| 936 | 960 |
| 937 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() | 961 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() |
| 938 const { | 962 const { |
| 939 return current_usage_bytes_.ValueOrDie(); | 963 return current_usage_bytes_.ValueOrDie(); |
| 940 } | 964 } |
| 941 | 965 |
| 942 } // namespace cc | 966 } // namespace cc |
| OLD | NEW |