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

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: The warning only disables at function scope. 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 #if defined(_MSC_VER)
vmpstr 2016/05/03 18:23:21 nit: let's just remove all of this and remove NOTR
cblume 2016/05/03 18:45:04 Done.
105 #pragma warning(push)
106 #pragma warning(disable : 4702) // unreachable code
107 #endif
108 // We wrap the function in the disabled unreachable code warning on VC.
109 // According to https://msdn.microsoft.com/en-us/library/2c8f766e(v=vs.140).aspx
110 // warnings in the range 4700-4999 apply to the following function scope.
111 // They cannot be applied to a single line, for example.
112 SkSize GetMipMapScaleAdjustment(const gfx::Size& src_size,
113 const gfx::Size& target_size) {
114 int src_height = src_size.height();
115 int src_width = src_size.width();
116 int target_height = target_size.height();
117 int target_width = target_size.width();
118 if (target_height == 0 || target_width == 0) {
vmpstr 2016/05/03 18:23:21 nit: remove braces.
cblume 2016/05/03 18:45:04 Done.
119 return SkSize::Make(-1.f, -1.f);
120 }
121
122 int next_mip_height = src_height;
123 int next_mip_width = src_width;
124 for (int current_mip_level = 0;; current_mip_level++) {
125 int mip_height = next_mip_height;
126 int mip_width = next_mip_width;
127
128 next_mip_height = std::max(1, src_height / (1 << (current_mip_level + 1)));
129 next_mip_width = std::max(1, src_width / (1 << (current_mip_level + 1)));
130
131 // Check if an axis on the next mip level would be smaller than the target.
132 // If so, use the current mip level.
133 // This effectively always uses the larger image and always scales down.
134 if (next_mip_height < target_height || next_mip_width < target_width) {
135 SkScalar y_scale = static_cast<float>(mip_height) / src_height;
136 SkScalar x_scale = static_cast<float>(mip_width) / src_width;
137
138 return SkSize::Make(x_scale, y_scale);
139 }
140
141 if (mip_height == 1 && mip_width == 1) {
142 // We have reached the final mip level
143 SkScalar y_scale = static_cast<float>(mip_height) / src_height;
144 SkScalar x_scale = static_cast<float>(mip_width) / src_width;
145
146 return SkSize::Make(x_scale, y_scale);
147 }
148 }
149
150 NOTREACHED();
151 }
152 #if defined(_MSC_VER)
153 #pragma warning(pop)
154 #endif
155
99 SkSize GetScaleAdjustment(const ImageDecodeControllerKey& key) { 156 SkSize GetScaleAdjustment(const ImageDecodeControllerKey& key) {
100 // If the requested filter quality did not require scale, then the adjustment 157 // If the requested filter quality did not require scale, then the adjustment
101 // is identity. 158 // is identity.
102 if (key.can_use_original_decode()) 159 if (key.can_use_original_decode()) {
103 return SkSize::Make(1.f, 1.f); 160 return SkSize::Make(1.f, 1.f);
104 161 } else if (key.filter_quality() == kMedium_SkFilterQuality) {
105 float x_scale = 162 return GetMipMapScaleAdjustment(key.src_rect().size(), key.target_size());
106 key.target_size().width() / static_cast<float>(key.src_rect().width()); 163 } else {
107 float y_scale = 164 float x_scale =
108 key.target_size().height() / static_cast<float>(key.src_rect().height()); 165 key.target_size().width() / static_cast<float>(key.src_rect().width());
109 return SkSize::Make(x_scale, y_scale); 166 float y_scale = key.target_size().height() /
167 static_cast<float>(key.src_rect().height());
168 return SkSize::Make(x_scale, y_scale);
169 }
110 } 170 }
111 171
112 SkFilterQuality GetDecodedFilterQuality(const ImageDecodeControllerKey& key) { 172 SkFilterQuality GetDecodedFilterQuality(const ImageDecodeControllerKey& key) {
113 return std::min(key.filter_quality(), kLow_SkFilterQuality); 173 return std::min(key.filter_quality(), kLow_SkFilterQuality);
114 } 174 }
115 175
116 SkImageInfo CreateImageInfo(size_t width, 176 SkImageInfo CreateImageInfo(size_t width,
117 size_t height, 177 size_t height,
118 ResourceFormat format) { 178 ResourceFormat format) {
119 return SkImageInfo::Make(width, height, 179 return SkImageInfo::Make(width, height,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 "SoftwareImageDecodeController::GetTaskForImageAndRef", "key", 241 "SoftwareImageDecodeController::GetTaskForImageAndRef", "key",
182 key.ToString()); 242 key.ToString());
183 243
184 // If the target size is empty, we can skip this image during draw (and thus 244 // 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). 245 // we don't need to decode it or ref it).
186 if (key.target_size().IsEmpty()) { 246 if (key.target_size().IsEmpty()) {
187 *task = nullptr; 247 *task = nullptr;
188 return false; 248 return false;
189 } 249 }
190 250
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_); 251 base::AutoLock lock(lock_);
211 252
212 // If we already have the image in cache, then we can return it. 253 // If we already have the image in cache, then we can return it.
213 auto decoded_it = decoded_images_.Get(key); 254 auto decoded_it = decoded_images_.Get(key);
214 bool new_image_fits_in_memory = 255 bool new_image_fits_in_memory =
215 locked_images_budget_.AvailableMemoryBytes() >= key.locked_bytes(); 256 locked_images_budget_.AvailableMemoryBytes() >= key.locked_bytes();
216 if (decoded_it != decoded_images_.end()) { 257 if (decoded_it != decoded_images_.end()) {
217 bool image_was_locked = decoded_it->second->is_locked(); 258 bool image_was_locked = decoded_it->second->is_locked();
218 if (image_was_locked || 259 if (image_was_locked ||
219 (new_image_fits_in_memory && decoded_it->second->Lock())) { 260 (new_image_fits_in_memory && decoded_it->second->Lock())) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 323 }
283 324
284 void SoftwareImageDecodeController::UnrefImage(const DrawImage& image) { 325 void SoftwareImageDecodeController::UnrefImage(const DrawImage& image) {
285 // When we unref the image, there are several situations we need to consider: 326 // 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. 327 // 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. 328 // 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 329 // 2a. The image isn't in the locked cache because we didn't get to decode
289 // it yet (or failed to decode it). 330 // it yet (or failed to decode it).
290 // 2b. Unlock the image but keep it in list. 331 // 2b. Unlock the image but keep it in list.
291 const ImageKey& key = ImageKey::FromDrawImage(image); 332 const ImageKey& key = ImageKey::FromDrawImage(image);
292 DCHECK(CanHandleImage(key)) << key.ToString();
293 TRACE_EVENT1("disabled-by-default-cc.debug", 333 TRACE_EVENT1("disabled-by-default-cc.debug",
294 "SoftwareImageDecodeController::UnrefImage", "key", 334 "SoftwareImageDecodeController::UnrefImage", "key",
295 key.ToString()); 335 key.ToString());
296 336
297 base::AutoLock lock(lock_); 337 base::AutoLock lock(lock_);
298 auto ref_count_it = decoded_images_ref_counts_.find(key); 338 auto ref_count_it = decoded_images_ref_counts_.find(key);
299 DCHECK(ref_count_it != decoded_images_ref_counts_.end()); 339 DCHECK(ref_count_it != decoded_images_ref_counts_.end());
300 340
301 --ref_count_it->second; 341 --ref_count_it->second;
302 if (ref_count_it->second == 0) { 342 if (ref_count_it->second == 0) {
(...skipping 10 matching lines...) Expand all
313 DCHECK(decoded_image_it->second->is_locked()); 353 DCHECK(decoded_image_it->second->is_locked());
314 decoded_image_it->second->Unlock(); 354 decoded_image_it->second->Unlock();
315 } 355 }
316 SanityCheckState(__LINE__, true); 356 SanityCheckState(__LINE__, true);
317 } 357 }
318 358
319 void SoftwareImageDecodeController::DecodeImage(const ImageKey& key, 359 void SoftwareImageDecodeController::DecodeImage(const ImageKey& key,
320 const DrawImage& image) { 360 const DrawImage& image) {
321 TRACE_EVENT1("cc", "SoftwareImageDecodeController::DecodeImage", "key", 361 TRACE_EVENT1("cc", "SoftwareImageDecodeController::DecodeImage", "key",
322 key.ToString()); 362 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_); 363 base::AutoLock lock(lock_);
338 AutoRemoveKeyFromTaskMap remove_key_from_task_map(&pending_image_tasks_, key); 364 AutoRemoveKeyFromTaskMap remove_key_from_task_map(&pending_image_tasks_, key);
339 365
340 // We could have finished all of the raster tasks (cancelled) while the task 366 // 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 367 // 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 368 // wasn't cancelled. So, if the ref count for the image is 0 then we can just
343 // abort. 369 // abort.
344 if (decoded_images_ref_counts_.find(key) == 370 if (decoded_images_ref_counts_.find(key) ==
345 decoded_images_ref_counts_.end()) { 371 decoded_images_ref_counts_.end()) {
346 return; 372 return;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 key.ToString()); 424 key.ToString());
399 sk_sp<const SkImage> image = draw_image.image(); 425 sk_sp<const SkImage> image = draw_image.image();
400 if (!image) 426 if (!image)
401 return nullptr; 427 return nullptr;
402 428
403 switch (key.filter_quality()) { 429 switch (key.filter_quality()) {
404 case kNone_SkFilterQuality: 430 case kNone_SkFilterQuality:
405 case kLow_SkFilterQuality: 431 case kLow_SkFilterQuality:
406 return GetOriginalImageDecode(key, std::move(image)); 432 return GetOriginalImageDecode(key, std::move(image));
407 case kMedium_SkFilterQuality: 433 case kMedium_SkFilterQuality:
408 NOTIMPLEMENTED();
409 return nullptr;
410 case kHigh_SkFilterQuality: 434 case kHigh_SkFilterQuality:
411 return GetScaledImageDecode(key, std::move(image)); 435 return GetScaledImageDecode(key, std::move(image));
412 default: 436 default:
413 NOTREACHED(); 437 NOTREACHED();
414 return nullptr; 438 return nullptr;
415 } 439 }
416 } 440 }
417 441
418 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDraw( 442 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDraw(
419 const DrawImage& draw_image) { 443 const DrawImage& draw_image) {
420 ImageKey key = ImageKey::FromDrawImage(draw_image); 444 ImageKey key = ImageKey::FromDrawImage(draw_image);
421 TRACE_EVENT1("disabled-by-default-cc.debug", 445 TRACE_EVENT1("disabled-by-default-cc.debug",
422 "SoftwareImageDecodeController::GetDecodedImageForDraw", "key", 446 "SoftwareImageDecodeController::GetDecodedImageForDraw", "key",
423 key.ToString()); 447 key.ToString());
424 // If the target size is empty, we can skip this image draw. 448 // If the target size is empty, we can skip this image draw.
425 if (key.target_size().IsEmpty()) 449 if (key.target_size().IsEmpty())
426 return DecodedDrawImage(nullptr, kNone_SkFilterQuality); 450 return DecodedDrawImage(nullptr, kNone_SkFilterQuality);
427 451
428 if (!CanHandleImage(key))
429 return DecodedDrawImage(draw_image.image(), draw_image.filter_quality());
430
431 return GetDecodedImageForDrawInternal(key, draw_image); 452 return GetDecodedImageForDrawInternal(key, draw_image);
432 } 453 }
433 454
434 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal( 455 DecodedDrawImage SoftwareImageDecodeController::GetDecodedImageForDrawInternal(
435 const ImageKey& key, 456 const ImageKey& key,
436 const DrawImage& draw_image) { 457 const DrawImage& draw_image) {
437 TRACE_EVENT1("disabled-by-default-cc.debug", 458 TRACE_EVENT1("disabled-by-default-cc.debug",
438 "SoftwareImageDecodeController::GetDecodedImageForDrawInternal", 459 "SoftwareImageDecodeController::GetDecodedImageForDrawInternal",
439 "key", key.ToString()); 460 "key", key.ToString());
440 base::AutoLock lock(lock_); 461 base::AutoLock lock(lock_);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 { 619 {
599 TRACE_EVENT0( 620 TRACE_EVENT0(
600 "disabled-by-default-cc.debug", 621 "disabled-by-default-cc.debug",
601 "SoftwareImageDecodeController::ScaleImage - allocate scaled pixels"); 622 "SoftwareImageDecodeController::ScaleImage - allocate scaled pixels");
602 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() 623 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance()
603 ->AllocateLockedDiscardableMemory( 624 ->AllocateLockedDiscardableMemory(
604 scaled_info.minRowBytes() * scaled_info.height()); 625 scaled_info.minRowBytes() * scaled_info.height());
605 } 626 }
606 SkPixmap scaled_pixmap(scaled_info, scaled_pixels->data(), 627 SkPixmap scaled_pixmap(scaled_info, scaled_pixels->data(),
607 scaled_info.minRowBytes()); 628 scaled_info.minRowBytes());
608 // TODO(vmpstr): Start handling more than just high filter quality. 629 DCHECK(key.filter_quality() == kHigh_SkFilterQuality ||
609 DCHECK_EQ(kHigh_SkFilterQuality, key.filter_quality()); 630 key.filter_quality() == kMedium_SkFilterQuality);
610 { 631 {
611 TRACE_EVENT0("disabled-by-default-cc.debug", 632 TRACE_EVENT0("disabled-by-default-cc.debug",
612 "SoftwareImageDecodeController::ScaleImage - scale pixels"); 633 "SoftwareImageDecodeController::ScaleImage - scale pixels");
613 bool result = 634 bool result =
614 decoded_pixmap.scalePixels(scaled_pixmap, key.filter_quality()); 635 decoded_pixmap.scalePixels(scaled_pixmap, key.filter_quality());
615 DCHECK(result) << key.ToString(); 636 DCHECK(result) << key.ToString();
616 } 637 }
617 638
618 // Release the original sized decode. Any other intermediate result to release 639 // 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 640 // would be the subrect memory. However, that's in a scoped_ptr and will be
620 // deleted automatically when we return. 641 // deleted automatically when we return.
621 DrawWithImageFinished(original_size_draw_image, decoded_draw_image); 642 DrawWithImageFinished(original_size_draw_image, decoded_draw_image);
622 643
623 return base::WrapUnique( 644 return base::WrapUnique(
624 new DecodedImage(scaled_info, std::move(scaled_pixels), 645 new DecodedImage(scaled_info, std::move(scaled_pixels),
625 SkSize::Make(-key.src_rect().x(), -key.src_rect().y()), 646 SkSize::Make(-key.src_rect().x(), -key.src_rect().y()),
626 next_tracing_id_.GetNext())); 647 next_tracing_id_.GetNext()));
627 } 648 }
628 649
629 void SoftwareImageDecodeController::DrawWithImageFinished( 650 void SoftwareImageDecodeController::DrawWithImageFinished(
630 const DrawImage& image, 651 const DrawImage& image,
631 const DecodedDrawImage& decoded_image) { 652 const DecodedDrawImage& decoded_image) {
632 TRACE_EVENT1("disabled-by-default-cc.debug", 653 TRACE_EVENT1("disabled-by-default-cc.debug",
633 "SoftwareImageDecodeController::DrawWithImageFinished", "key", 654 "SoftwareImageDecodeController::DrawWithImageFinished", "key",
634 ImageKey::FromDrawImage(image).ToString()); 655 ImageKey::FromDrawImage(image).ToString());
635 ImageKey key = ImageKey::FromDrawImage(image); 656 ImageKey key = ImageKey::FromDrawImage(image);
636 if (!decoded_image.image() || !CanHandleImage(key)) 657 if (!decoded_image.image())
637 return; 658 return;
638 659
639 if (decoded_image.is_at_raster_decode()) 660 if (decoded_image.is_at_raster_decode())
640 UnrefAtRasterImage(key); 661 UnrefAtRasterImage(key);
641 else 662 else
642 UnrefImage(image); 663 UnrefImage(image);
643 SanityCheckState(__LINE__, false); 664 SanityCheckState(__LINE__, false);
644 } 665 }
645 666
646 void SoftwareImageDecodeController::RefAtRasterImage(const ImageKey& key) { 667 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) == 714 DCHECK(decoded_images_ref_counts_.find(key) ==
694 decoded_images_ref_counts_.end()); 715 decoded_images_ref_counts_.end());
695 at_raster_image_it->second->Unlock(); 716 at_raster_image_it->second->Unlock();
696 decoded_images_.Erase(image_it); 717 decoded_images_.Erase(image_it);
697 decoded_images_.Put(key, std::move(at_raster_image_it->second)); 718 decoded_images_.Put(key, std::move(at_raster_image_it->second));
698 } 719 }
699 at_raster_decoded_images_.Erase(at_raster_image_it); 720 at_raster_decoded_images_.Erase(at_raster_image_it);
700 } 721 }
701 } 722 }
702 723
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() { 724 void SoftwareImageDecodeController::ReduceCacheUsage() {
709 TRACE_EVENT0("cc", "SoftwareImageDecodeController::ReduceCacheUsage"); 725 TRACE_EVENT0("cc", "SoftwareImageDecodeController::ReduceCacheUsage");
710 base::AutoLock lock(lock_); 726 base::AutoLock lock(lock_);
711 size_t num_to_remove = (decoded_images_.size() > kMaxItemsInCache) 727 size_t num_to_remove = (decoded_images_.size() > kMaxItemsInCache)
712 ? (decoded_images_.size() - kMaxItemsInCache) 728 ? (decoded_images_.size() - kMaxItemsInCache)
713 : 0; 729 : 0;
714 for (auto it = decoded_images_.rbegin(); 730 for (auto it = decoded_images_.rbegin();
715 num_to_remove != 0 && it != decoded_images_.rend();) { 731 num_to_remove != 0 && it != decoded_images_.rend();) {
716 if (it->second->is_locked()) { 732 if (it->second->is_locked()) {
717 ++it; 733 ++it;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 bool can_use_original_decode = 865 bool can_use_original_decode =
850 quality == kLow_SkFilterQuality || quality == kNone_SkFilterQuality; 866 quality == kLow_SkFilterQuality || quality == kNone_SkFilterQuality;
851 867
852 // If we're going to use the original decode, then the target size should be 868 // 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. 869 // 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 870 // Note we skip the decode if the target size is empty altogether, so don't
855 // update the target size in that case. 871 // update the target size in that case.
856 if (can_use_original_decode && !target_size.IsEmpty()) 872 if (can_use_original_decode && !target_size.IsEmpty())
857 target_size = gfx::Size(image.image()->width(), image.image()->height()); 873 target_size = gfx::Size(image.image()->width(), image.image()->height());
858 874
875 if (quality == kMedium_SkFilterQuality && !target_size.IsEmpty()) {
876 SkSize mip_target_size =
877 GetMipMapScaleAdjustment(src_rect.size(), target_size);
878 DCHECK(mip_target_size.width() != -1.f && mip_target_size.height() != -1.f);
879 target_size.set_width(src_rect.width() * mip_target_size.width());
880 target_size.set_height(src_rect.height() * mip_target_size.height());
881 }
882
859 return ImageDecodeControllerKey(image.image()->uniqueID(), src_rect, 883 return ImageDecodeControllerKey(image.image()->uniqueID(), src_rect,
860 target_size, quality, 884 target_size, quality,
861 can_use_original_decode); 885 can_use_original_decode);
862 } 886 }
863 887
864 ImageDecodeControllerKey::ImageDecodeControllerKey( 888 ImageDecodeControllerKey::ImageDecodeControllerKey(
865 uint32_t image_id, 889 uint32_t image_id,
866 const gfx::Rect& src_rect, 890 const gfx::Rect& src_rect,
867 const gfx::Size& target_size, 891 const gfx::Size& target_size,
868 SkFilterQuality filter_quality, 892 SkFilterQuality filter_quality,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { 985 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() {
962 current_usage_bytes_ = 0; 986 current_usage_bytes_ = 0;
963 } 987 }
964 988
965 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() 989 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe()
966 const { 990 const {
967 return current_usage_bytes_.ValueOrDie(); 991 return current_usage_bytes_.ValueOrDie();
968 } 992 }
969 993
970 } // namespace cc 994 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/software_image_decode_controller.h ('k') | cc/tiles/software_image_decode_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698