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

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

Issue 1839833003: Add medium image quality to software predecode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing. Created 4 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_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
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(
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()) {
124 SkScalar y_scale = 1.f;
vmpstr 2016/04/29 19:09:41 nit: i'd just do the math below unconditionally, b
cblume 2016/05/01 01:03:37 I thought I had run into a situation where this ca
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);
vmpstr 2016/04/29 19:09:40 Should this be a NOTREACHED? Is this code called w
cblume 2016/05/01 01:03:37 I changed it to NOTREACHED but in our unit test of
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 {
vmpstr 2016/04/29 19:09:40 nit: } else if (...) { } else { }
cblume 2016/05/01 01:03:37 Done.
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 "SoftwareImageDecodeController::GetTaskForImageAndRef", "key", 230 "SoftwareImageDecodeController::GetTaskForImageAndRef", "key",
182 key.ToString()); 231 key.ToString());
183 232
184 // If the target size is empty, we can skip this image during draw (and thus 233 // 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). 234 // we don't need to decode it or ref it).
186 if (key.target_size().IsEmpty()) { 235 if (key.target_size().IsEmpty()) {
187 *task = nullptr; 236 *task = nullptr;
188 return false; 237 return false;
189 } 238 }
190 239
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_); 240 base::AutoLock lock(lock_);
211 241
212 // If we already have the image in cache, then we can return it. 242 // If we already have the image in cache, then we can return it.
213 auto decoded_it = decoded_images_.Get(key); 243 auto decoded_it = decoded_images_.Get(key);
214 bool new_image_fits_in_memory = 244 bool new_image_fits_in_memory =
215 locked_images_budget_.AvailableMemoryBytes() >= key.locked_bytes(); 245 locked_images_budget_.AvailableMemoryBytes() >= key.locked_bytes();
216 if (decoded_it != decoded_images_.end()) { 246 if (decoded_it != decoded_images_.end()) {
217 bool image_was_locked = decoded_it->second->is_locked(); 247 bool image_was_locked = decoded_it->second->is_locked();
218 if (image_was_locked || 248 if (image_was_locked ||
219 (new_image_fits_in_memory && decoded_it->second->Lock())) { 249 (new_image_fits_in_memory && decoded_it->second->Lock())) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 312 }
283 313
284 void SoftwareImageDecodeController::UnrefImage(const DrawImage& image) { 314 void SoftwareImageDecodeController::UnrefImage(const DrawImage& image) {
285 // When we unref the image, there are several situations we need to consider: 315 // 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. 316 // 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. 317 // 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 318 // 2a. The image isn't in the locked cache because we didn't get to decode
289 // it yet (or failed to decode it). 319 // it yet (or failed to decode it).
290 // 2b. Unlock the image but keep it in list. 320 // 2b. Unlock the image but keep it in list.
291 const ImageKey& key = ImageKey::FromDrawImage(image); 321 const ImageKey& key = ImageKey::FromDrawImage(image);
292 DCHECK(CanHandleImage(key)) << key.ToString();
293 TRACE_EVENT1("disabled-by-default-cc.debug", 322 TRACE_EVENT1("disabled-by-default-cc.debug",
294 "SoftwareImageDecodeController::UnrefImage", "key", 323 "SoftwareImageDecodeController::UnrefImage", "key",
295 key.ToString()); 324 key.ToString());
296 325
297 base::AutoLock lock(lock_); 326 base::AutoLock lock(lock_);
298 auto ref_count_it = decoded_images_ref_counts_.find(key); 327 auto ref_count_it = decoded_images_ref_counts_.find(key);
299 DCHECK(ref_count_it != decoded_images_ref_counts_.end()); 328 DCHECK(ref_count_it != decoded_images_ref_counts_.end());
300 329
301 --ref_count_it->second; 330 --ref_count_it->second;
302 if (ref_count_it->second == 0) { 331 if (ref_count_it->second == 0) {
(...skipping 10 matching lines...) Expand all
313 DCHECK(decoded_image_it->second->is_locked()); 342 DCHECK(decoded_image_it->second->is_locked());
314 decoded_image_it->second->Unlock(); 343 decoded_image_it->second->Unlock();
315 } 344 }
316 SanityCheckState(__LINE__, true); 345 SanityCheckState(__LINE__, true);
317 } 346 }
318 347
319 void SoftwareImageDecodeController::DecodeImage(const ImageKey& key, 348 void SoftwareImageDecodeController::DecodeImage(const ImageKey& key,
320 const DrawImage& image) { 349 const DrawImage& image) {
321 TRACE_EVENT1("cc", "SoftwareImageDecodeController::DecodeImage", "key", 350 TRACE_EVENT1("cc", "SoftwareImageDecodeController::DecodeImage", "key",
322 key.ToString()); 351 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_); 352 base::AutoLock lock(lock_);
338 AutoRemoveKeyFromTaskMap remove_key_from_task_map(&pending_image_tasks_, key); 353 AutoRemoveKeyFromTaskMap remove_key_from_task_map(&pending_image_tasks_, key);
339 354
340 // We could have finished all of the raster tasks (cancelled) while the task 355 // 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 356 // 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 357 // wasn't cancelled. So, if the ref count for the image is 0 then we can just
343 // abort. 358 // abort.
344 if (decoded_images_ref_counts_.find(key) == 359 if (decoded_images_ref_counts_.find(key) ==
345 decoded_images_ref_counts_.end()) { 360 decoded_images_ref_counts_.end()) {
346 return; 361 return;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 if (decoded_images_ref_counts_.find(key) == 398 if (decoded_images_ref_counts_.find(key) ==
384 decoded_images_ref_counts_.end()) { 399 decoded_images_ref_counts_.end()) {
385 decoded_image->Unlock(); 400 decoded_image->Unlock();
386 } 401 }
387 402
388 decoded_images_.Put(key, std::move(decoded_image)); 403 decoded_images_.Put(key, std::move(decoded_image));
389 SanityCheckState(__LINE__, true); 404 SanityCheckState(__LINE__, true);
390 } 405 }
391 406
392 std::unique_ptr<SoftwareImageDecodeController::DecodedImage> 407 std::unique_ptr<SoftwareImageDecodeController::DecodedImage>
408 SoftwareImageDecodeController::GetMediumQualityImageDecode(
409 const ImageKey& key,
410 sk_sp<const SkImage> image) {
411 SkSize mipmap_scale = GetMipMapScaleAdjustment(key);
412 // -1 represents an invalid scale.
413 // So add 1 and compare to epsilon.
vmpstr 2016/04/29 19:09:40 Comment is still wrong :)
cblume 2016/05/01 01:03:37 Oops. I could have sworn I fixed that.
414 if (mipmap_scale.width() <= 0.f || mipmap_scale.height() <= 0.f) {
vmpstr 2016/04/29 19:09:40 Can this be a DCHECK instead? That is, are there c
cblume 2016/05/01 01:03:37 This is similar to the NOTREACHED thing above. Whe
cblume 2016/05/01 22:51:27 I switched this over to a DCHECK since it is separ
415 return nullptr;
416 }
417
418 if (mipmap_scale.width() == 1.f && mipmap_scale.height() == 1.f) {
419 return GetOriginalImageDecode(key, std::move(image));
420 } else {
421 DrawImage mip_image(
422 image, gfx::RectToSkIRect(key.src_rect()), kMedium_SkFilterQuality,
423 SkMatrix::MakeScale(mipmap_scale.width(), mipmap_scale.height()));
424 auto mip_key = ImageKey::FromDrawImage(mip_image);
425 return GetScaledImageDecode(mip_key, std::move(image));
426 }
427 }
428
429 std::unique_ptr<SoftwareImageDecodeController::DecodedImage>
393 SoftwareImageDecodeController::DecodeImageInternal( 430 SoftwareImageDecodeController::DecodeImageInternal(
394 const ImageKey& key, 431 const ImageKey& key,
395 const DrawImage& draw_image) { 432 const DrawImage& draw_image) {
396 TRACE_EVENT1("disabled-by-default-cc.debug", 433 TRACE_EVENT1("disabled-by-default-cc.debug",
397 "SoftwareImageDecodeController::DecodeImageInternal", "key", 434 "SoftwareImageDecodeController::DecodeImageInternal", "key",
398 key.ToString()); 435 key.ToString());
399 sk_sp<const SkImage> image = draw_image.image(); 436 sk_sp<const SkImage> image = draw_image.image();
400 if (!image) 437 if (!image)
401 return nullptr; 438 return nullptr;
402 439
403 switch (key.filter_quality()) { 440 switch (key.filter_quality()) {
404 case kNone_SkFilterQuality: 441 case kNone_SkFilterQuality:
405 case kLow_SkFilterQuality: 442 case kLow_SkFilterQuality:
406 return GetOriginalImageDecode(key, std::move(image)); 443 return GetOriginalImageDecode(key, std::move(image));
407 case kMedium_SkFilterQuality: 444 case kMedium_SkFilterQuality:
408 NOTIMPLEMENTED(); 445 return GetMediumQualityImageDecode(key, std::move(image));
vmpstr 2016/04/29 19:09:40 I'm a bit concerned about the fact that key and ke
cblume 2016/05/01 01:03:37 You are completely correct. This should be fixed n
409 return nullptr;
410 case kHigh_SkFilterQuality: 446 case kHigh_SkFilterQuality:
411 return GetScaledImageDecode(key, std::move(image)); 447 return GetScaledImageDecode(key, std::move(image));
412 default: 448 default:
413 NOTREACHED(); 449 NOTREACHED();
414 return nullptr; 450 return nullptr;
415 } 451 }
416 } 452 }
417 453
418 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDraw( 454 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDraw(
419 const DrawImage& draw_image) { 455 const DrawImage& draw_image) {
420 ImageKey key = ImageKey::FromDrawImage(draw_image); 456 ImageKey key = ImageKey::FromDrawImage(draw_image);
421 TRACE_EVENT1("disabled-by-default-cc.debug", 457 TRACE_EVENT1("disabled-by-default-cc.debug",
422 "SoftwareImageDecodeController::GetDecodedImageForDraw", "key", 458 "SoftwareImageDecodeController::GetDecodedImageForDraw", "key",
423 key.ToString()); 459 key.ToString());
424 // If the target size is empty, we can skip this image draw. 460 // If the target size is empty, we can skip this image draw.
425 if (key.target_size().IsEmpty()) 461 if (key.target_size().IsEmpty())
426 return DecodedDrawImage(nullptr, kNone_SkFilterQuality); 462 return DecodedDrawImage(nullptr, kNone_SkFilterQuality);
427 463
428 if (!CanHandleImage(key))
429 return DecodedDrawImage(draw_image.image(), draw_image.filter_quality());
430
431 return GetDecodedImageForDrawInternal(key, draw_image); 464 return GetDecodedImageForDrawInternal(key, draw_image);
432 } 465 }
433 466
434 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal( 467 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal(
435 const ImageKey& key, 468 const ImageKey& key,
436 const DrawImage& draw_image) { 469 const DrawImage& draw_image) {
437 TRACE_EVENT1("disabled-by-default-cc.debug", 470 TRACE_EVENT1("disabled-by-default-cc.debug",
438 "SoftwareImageDecodeController::GetDecodedImageForDrawInternal", 471 "SoftwareImageDecodeController::GetDecodedImageForDrawInternal",
439 "key", key.ToString()); 472 "key", key.ToString());
440 base::AutoLock lock(lock_); 473 base::AutoLock lock(lock_);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 { 631 {
599 TRACE_EVENT0( 632 TRACE_EVENT0(
600 "disabled-by-default-cc.debug", 633 "disabled-by-default-cc.debug",
601 "SoftwareImageDecodeController::ScaleImage - allocate scaled pixels"); 634 "SoftwareImageDecodeController::ScaleImage - allocate scaled pixels");
602 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() 635 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance()
603 ->AllocateLockedDiscardableMemory( 636 ->AllocateLockedDiscardableMemory(
604 scaled_info.minRowBytes() * scaled_info.height()); 637 scaled_info.minRowBytes() * scaled_info.height());
605 } 638 }
606 SkPixmap scaled_pixmap(scaled_info, scaled_pixels->data(), 639 SkPixmap scaled_pixmap(scaled_info, scaled_pixels->data(),
607 scaled_info.minRowBytes()); 640 scaled_info.minRowBytes());
608 // TODO(vmpstr): Start handling more than just high filter quality. 641 DCHECK(key.filter_quality() == kHigh_SkFilterQuality ||
609 DCHECK_EQ(kHigh_SkFilterQuality, key.filter_quality()); 642 key.filter_quality() == kMedium_SkFilterQuality);
610 { 643 {
611 TRACE_EVENT0("disabled-by-default-cc.debug", 644 TRACE_EVENT0("disabled-by-default-cc.debug",
612 "SoftwareImageDecodeController::ScaleImage - scale pixels"); 645 "SoftwareImageDecodeController::ScaleImage - scale pixels");
613 bool result = 646 bool result =
614 decoded_pixmap.scalePixels(scaled_pixmap, key.filter_quality()); 647 decoded_pixmap.scalePixels(scaled_pixmap, key.filter_quality());
615 DCHECK(result) << key.ToString(); 648 DCHECK(result) << key.ToString();
616 } 649 }
617 650
618 // Release the original sized decode. Any other intermediate result to release 651 // 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 652 // would be the subrect memory. However, that's in a scoped_ptr and will be
620 // deleted automatically when we return. 653 // deleted automatically when we return.
621 DrawWithImageFinished(original_size_draw_image, decoded_draw_image); 654 DrawWithImageFinished(original_size_draw_image, decoded_draw_image);
622 655
623 return base::WrapUnique( 656 return base::WrapUnique(
624 new DecodedImage(scaled_info, std::move(scaled_pixels), 657 new DecodedImage(scaled_info, std::move(scaled_pixels),
625 SkSize::Make(-key.src_rect().x(), -key.src_rect().y()), 658 SkSize::Make(-key.src_rect().x(), -key.src_rect().y()),
626 next_tracing_id_.GetNext())); 659 next_tracing_id_.GetNext()));
627 } 660 }
628 661
629 void SoftwareImageDecodeController::DrawWithImageFinished( 662 void SoftwareImageDecodeController::DrawWithImageFinished(
630 const DrawImage& image, 663 const DrawImage& image,
631 const DecodedDrawImage& decoded_image) { 664 const DecodedDrawImage& decoded_image) {
632 TRACE_EVENT1("disabled-by-default-cc.debug", 665 TRACE_EVENT1("disabled-by-default-cc.debug",
633 "SoftwareImageDecodeController::DrawWithImageFinished", "key", 666 "SoftwareImageDecodeController::DrawWithImageFinished", "key",
634 ImageKey::FromDrawImage(image).ToString()); 667 ImageKey::FromDrawImage(image).ToString());
635 ImageKey key = ImageKey::FromDrawImage(image); 668 ImageKey key = ImageKey::FromDrawImage(image);
636 if (!decoded_image.image() || !CanHandleImage(key)) 669 if (!decoded_image.image())
637 return; 670 return;
638 671
639 if (decoded_image.is_at_raster_decode()) 672 if (decoded_image.is_at_raster_decode())
640 UnrefAtRasterImage(key); 673 UnrefAtRasterImage(key);
641 else 674 else
642 UnrefImage(image); 675 UnrefImage(image);
643 SanityCheckState(__LINE__, false); 676 SanityCheckState(__LINE__, false);
644 } 677 }
645 678
646 void SoftwareImageDecodeController::RefAtRasterImage(const ImageKey& key) { 679 void SoftwareImageDecodeController::RefAtRasterImage(const ImageKey& key) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 DCHECK(decoded_images_ref_counts_.find(key) == 726 DCHECK(decoded_images_ref_counts_.find(key) ==
694 decoded_images_ref_counts_.end()); 727 decoded_images_ref_counts_.end());
695 at_raster_image_it->second->Unlock(); 728 at_raster_image_it->second->Unlock();
696 decoded_images_.Erase(image_it); 729 decoded_images_.Erase(image_it);
697 decoded_images_.Put(key, std::move(at_raster_image_it->second)); 730 decoded_images_.Put(key, std::move(at_raster_image_it->second));
698 } 731 }
699 at_raster_decoded_images_.Erase(at_raster_image_it); 732 at_raster_decoded_images_.Erase(at_raster_image_it);
700 } 733 }
701 } 734 }
702 735
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() { 736 void SoftwareImageDecodeController::ReduceCacheUsage() {
709 TRACE_EVENT0("cc", "SoftwareImageDecodeController::ReduceCacheUsage"); 737 TRACE_EVENT0("cc", "SoftwareImageDecodeController::ReduceCacheUsage");
710 base::AutoLock lock(lock_); 738 base::AutoLock lock(lock_);
711 size_t num_to_remove = (decoded_images_.size() > kMaxItemsInCache) 739 size_t num_to_remove = (decoded_images_.size() > kMaxItemsInCache)
712 ? (decoded_images_.size() - kMaxItemsInCache) 740 ? (decoded_images_.size() - kMaxItemsInCache)
713 : 0; 741 : 0;
714 for (auto it = decoded_images_.rbegin(); 742 for (auto it = decoded_images_.rbegin();
715 num_to_remove != 0 && it != decoded_images_.rend();) { 743 num_to_remove != 0 && it != decoded_images_.rend();) {
716 if (it->second->is_locked()) { 744 if (it->second->is_locked()) {
717 ++it; 745 ++it;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { 989 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() {
962 current_usage_bytes_ = 0; 990 current_usage_bytes_ = 0;
963 } 991 }
964 992
965 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() 993 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe()
966 const { 994 const {
967 return current_usage_bytes_.ValueOrDie(); 995 return current_usage_bytes_.ValueOrDie();
968 } 996 }
969 997
970 } // namespace cc 998 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698