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

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

Issue 1808633002: Use preferred format to allocate memory for decoded images (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 <functional> 9 #include <functional>
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 key.target_size().width() / static_cast<float>(key.src_rect().width()); 100 key.target_size().width() / static_cast<float>(key.src_rect().width());
101 float y_scale = 101 float y_scale =
102 key.target_size().height() / static_cast<float>(key.src_rect().height()); 102 key.target_size().height() / static_cast<float>(key.src_rect().height());
103 return SkSize::Make(x_scale, y_scale); 103 return SkSize::Make(x_scale, y_scale);
104 } 104 }
105 105
106 SkFilterQuality GetDecodedFilterQuality(const ImageDecodeControllerKey& key) { 106 SkFilterQuality GetDecodedFilterQuality(const ImageDecodeControllerKey& key) {
107 return std::min(key.filter_quality(), kLow_SkFilterQuality); 107 return std::min(key.filter_quality(), kLow_SkFilterQuality);
108 } 108 }
109 109
110 SkColorType SkColorTypeForDecoding(ResourceFormat format) {
111 // Use kN32_SkColorType if there is no corresponding SkColorType.
112 switch (format) {
113 case RGBA_4444:
114 return kARGB_4444_SkColorType;
115 case RGBA_8888:
116 case BGRA_8888:
117 return kN32_SkColorType;
118 case ALPHA_8:
119 return kAlpha_8_SkColorType;
120 case RGB_565:
121 return kRGB_565_SkColorType;
122 case LUMINANCE_8:
123 return kGray_8_SkColorType;
124 case ETC1:
125 case RED_8:
126 case LUMINANCE_F16:
127 return kN32_SkColorType;
128 }
129 NOTREACHED();
130 return kN32_SkColorType;
131 }
132
133 SkImageInfo CreateImageInfo(size_t width,
134 size_t height,
135 ResourceFormat format) {
136 return SkImageInfo::Make(width, height, SkColorTypeForDecoding(format),
137 kPremul_SkAlphaType);
138 }
139
110 } // namespace 140 } // namespace
111 141
112 SoftwareImageDecodeController::SoftwareImageDecodeController() 142 SoftwareImageDecodeController::SoftwareImageDecodeController(
143 ResourceFormat format)
113 : decoded_images_(ImageMRUCache::NO_AUTO_EVICT), 144 : decoded_images_(ImageMRUCache::NO_AUTO_EVICT),
114 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), 145 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT),
115 locked_images_budget_(kLockedMemoryLimitBytes) {} 146 locked_images_budget_(kLockedMemoryLimitBytes),
147 format_(format) {}
116 148
117 SoftwareImageDecodeController::~SoftwareImageDecodeController() { 149 SoftwareImageDecodeController::~SoftwareImageDecodeController() {
118 DCHECK_EQ(0u, decoded_images_ref_counts_.size()); 150 DCHECK_EQ(0u, decoded_images_ref_counts_.size());
119 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size()); 151 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size());
120 } 152 }
121 153
122 bool SoftwareImageDecodeController::GetTaskForImageAndRef( 154 bool SoftwareImageDecodeController::GetTaskForImageAndRef(
123 const DrawImage& image, 155 const DrawImage& image,
124 uint64_t prepare_tiles_id, 156 uint64_t prepare_tiles_id,
125 scoped_refptr<ImageDecodeTask>* task) { 157 scoped_refptr<ImageDecodeTask>* task) {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 const DrawImage& draw_image) { 370 const DrawImage& draw_image) {
339 TRACE_EVENT1("disabled-by-default-cc.debug", 371 TRACE_EVENT1("disabled-by-default-cc.debug",
340 "SoftwareImageDecodeController::DecodeImageInternal", "key", 372 "SoftwareImageDecodeController::DecodeImageInternal", "key",
341 key.ToString()); 373 key.ToString());
342 const SkImage* image = draw_image.image(); 374 const SkImage* image = draw_image.image();
343 375
344 // If we can use the original decode, then we don't need to do scaling. We can 376 // If we can use the original decode, then we don't need to do scaling. We can
345 // just read pixels into the final memory. 377 // just read pixels into the final memory.
346 if (key.can_use_original_decode()) { 378 if (key.can_use_original_decode()) {
347 SkImageInfo decoded_info = 379 SkImageInfo decoded_info =
348 SkImageInfo::MakeN32Premul(image->width(), image->height()); 380 CreateImageInfo(image->width(), image->height(), format_);
349 scoped_ptr<base::DiscardableMemory> decoded_pixels; 381 scoped_ptr<base::DiscardableMemory> decoded_pixels;
350 { 382 {
351 TRACE_EVENT0( 383 TRACE_EVENT0(
352 "disabled-by-default-cc.debug", 384 "disabled-by-default-cc.debug",
353 "SoftwareImageDecodeController::DecodeImageInternal - allocate " 385 "SoftwareImageDecodeController::DecodeImageInternal - allocate "
354 "decoded pixels"); 386 "decoded pixels");
355 decoded_pixels = 387 decoded_pixels =
356 base::DiscardableMemoryAllocator::GetInstance() 388 base::DiscardableMemoryAllocator::GetInstance()
357 ->AllocateLockedDiscardableMemory(decoded_info.minRowBytes() * 389 ->AllocateLockedDiscardableMemory(decoded_info.minRowBytes() *
358 decoded_info.height()); 390 decoded_info.height());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 DCHECK(result); 439 DCHECK(result);
408 if (key.src_rect() != full_image_rect) { 440 if (key.src_rect() != full_image_rect) {
409 result = decoded_pixmap.extractSubset(&decoded_pixmap, 441 result = decoded_pixmap.extractSubset(&decoded_pixmap,
410 gfx::RectToSkIRect(key.src_rect())); 442 gfx::RectToSkIRect(key.src_rect()));
411 DCHECK(result); 443 DCHECK(result);
412 } 444 }
413 445
414 // Now we have a decoded_pixmap which represents the src_rect at the 446 // Now we have a decoded_pixmap which represents the src_rect at the
415 // original scale. All we need to do is scale it. 447 // original scale. All we need to do is scale it.
416 DCHECK(!key.target_size().IsEmpty()); 448 DCHECK(!key.target_size().IsEmpty());
417 SkImageInfo scaled_info = SkImageInfo::MakeN32Premul( 449 SkImageInfo scaled_info = CreateImageInfo(
418 key.target_size().width(), key.target_size().height()); 450 key.target_size().width(), key.target_size().height(), format_);
419 scoped_ptr<base::DiscardableMemory> scaled_pixels; 451 scoped_ptr<base::DiscardableMemory> scaled_pixels;
420 { 452 {
421 TRACE_EVENT0( 453 TRACE_EVENT0(
422 "disabled-by-default-cc.debug", 454 "disabled-by-default-cc.debug",
423 "SoftwareImageDecodeController::DecodeImageInternal - allocate " 455 "SoftwareImageDecodeController::DecodeImageInternal - allocate "
424 "scaled pixels"); 456 "scaled pixels");
425 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() 457 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance()
426 ->AllocateLockedDiscardableMemory( 458 ->AllocateLockedDiscardableMemory(
427 scaled_info.minRowBytes() * scaled_info.height()); 459 scaled_info.minRowBytes() * scaled_info.height());
428 } 460 }
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { 884 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() {
853 current_usage_bytes_ = 0; 885 current_usage_bytes_ = 0;
854 } 886 }
855 887
856 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() 888 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe()
857 const { 889 const {
858 return current_usage_bytes_.ValueOrDie(); 890 return current_usage_bytes_.ValueOrDie();
859 } 891 }
860 892
861 } // namespace cc 893 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698