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

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: Addressed comment 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
« no previous file with comments | « cc/tiles/software_image_decode_controller.h ('k') | cc/trees/layer_tree_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
reed1 2016/03/17 14:38:23 kGray_8_SkColorType
bashi 2016/03/17 23:29:38 Done.
123 case ETC1:
124 case RED_8:
125 case LUMINANCE_F16:
reed1 2016/03/17 14:38:23 BTW -- not hard for Skia to add native support for
bashi 2016/03/17 23:29:38 I'm not sure but I guess that LUM_16 is not common
126 return kN32_SkColorType;
127 }
128 NOTREACHED();
129 return kN32_SkColorType;
130 }
131
132 SkImageInfo CreateImageInfo(size_t width,
133 size_t height,
134 ResourceFormat format) {
135 return SkImageInfo::Make(width, height, SkColorTypeForDecoding(format),
136 kPremul_SkAlphaType);
reed1 2016/03/17 14:38:23 FYI -- Skia is actively working on native support
137 }
138
110 } // namespace 139 } // namespace
111 140
112 SoftwareImageDecodeController::SoftwareImageDecodeController() 141 SoftwareImageDecodeController::SoftwareImageDecodeController(
142 ResourceFormat format)
113 : decoded_images_(ImageMRUCache::NO_AUTO_EVICT), 143 : decoded_images_(ImageMRUCache::NO_AUTO_EVICT),
114 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT), 144 at_raster_decoded_images_(ImageMRUCache::NO_AUTO_EVICT),
115 locked_images_budget_(kLockedMemoryLimitBytes) {} 145 locked_images_budget_(kLockedMemoryLimitBytes),
146 format_(format) {}
116 147
117 SoftwareImageDecodeController::~SoftwareImageDecodeController() { 148 SoftwareImageDecodeController::~SoftwareImageDecodeController() {
118 DCHECK_EQ(0u, decoded_images_ref_counts_.size()); 149 DCHECK_EQ(0u, decoded_images_ref_counts_.size());
119 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size()); 150 DCHECK_EQ(0u, at_raster_decoded_images_ref_counts_.size());
120 } 151 }
121 152
122 bool SoftwareImageDecodeController::GetTaskForImageAndRef( 153 bool SoftwareImageDecodeController::GetTaskForImageAndRef(
123 const DrawImage& image, 154 const DrawImage& image,
124 uint64_t prepare_tiles_id, 155 uint64_t prepare_tiles_id,
125 scoped_refptr<ImageDecodeTask>* task) { 156 scoped_refptr<ImageDecodeTask>* task) {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 const DrawImage& draw_image) { 369 const DrawImage& draw_image) {
339 TRACE_EVENT1("disabled-by-default-cc.debug", 370 TRACE_EVENT1("disabled-by-default-cc.debug",
340 "SoftwareImageDecodeController::DecodeImageInternal", "key", 371 "SoftwareImageDecodeController::DecodeImageInternal", "key",
341 key.ToString()); 372 key.ToString());
342 const SkImage* image = draw_image.image(); 373 const SkImage* image = draw_image.image();
343 374
344 // If we can use the original decode, then we don't need to do scaling. We can 375 // 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. 376 // just read pixels into the final memory.
346 if (key.can_use_original_decode()) { 377 if (key.can_use_original_decode()) {
347 SkImageInfo decoded_info = 378 SkImageInfo decoded_info =
348 SkImageInfo::MakeN32Premul(image->width(), image->height()); 379 CreateImageInfo(image->width(), image->height(), format_);
349 scoped_ptr<base::DiscardableMemory> decoded_pixels; 380 scoped_ptr<base::DiscardableMemory> decoded_pixels;
350 { 381 {
351 TRACE_EVENT0( 382 TRACE_EVENT0(
352 "disabled-by-default-cc.debug", 383 "disabled-by-default-cc.debug",
353 "SoftwareImageDecodeController::DecodeImageInternal - allocate " 384 "SoftwareImageDecodeController::DecodeImageInternal - allocate "
354 "decoded pixels"); 385 "decoded pixels");
355 decoded_pixels = 386 decoded_pixels =
356 base::DiscardableMemoryAllocator::GetInstance() 387 base::DiscardableMemoryAllocator::GetInstance()
357 ->AllocateLockedDiscardableMemory(decoded_info.minRowBytes() * 388 ->AllocateLockedDiscardableMemory(decoded_info.minRowBytes() *
358 decoded_info.height()); 389 decoded_info.height());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 DCHECK(result); 438 DCHECK(result);
408 if (key.src_rect() != full_image_rect) { 439 if (key.src_rect() != full_image_rect) {
409 result = decoded_pixmap.extractSubset(&decoded_pixmap, 440 result = decoded_pixmap.extractSubset(&decoded_pixmap,
410 gfx::RectToSkIRect(key.src_rect())); 441 gfx::RectToSkIRect(key.src_rect()));
411 DCHECK(result); 442 DCHECK(result);
412 } 443 }
413 444
414 // Now we have a decoded_pixmap which represents the src_rect at the 445 // Now we have a decoded_pixmap which represents the src_rect at the
415 // original scale. All we need to do is scale it. 446 // original scale. All we need to do is scale it.
416 DCHECK(!key.target_size().IsEmpty()); 447 DCHECK(!key.target_size().IsEmpty());
417 SkImageInfo scaled_info = SkImageInfo::MakeN32Premul( 448 SkImageInfo scaled_info = CreateImageInfo(
418 key.target_size().width(), key.target_size().height()); 449 key.target_size().width(), key.target_size().height(), format_);
419 scoped_ptr<base::DiscardableMemory> scaled_pixels; 450 scoped_ptr<base::DiscardableMemory> scaled_pixels;
420 { 451 {
421 TRACE_EVENT0( 452 TRACE_EVENT0(
422 "disabled-by-default-cc.debug", 453 "disabled-by-default-cc.debug",
423 "SoftwareImageDecodeController::DecodeImageInternal - allocate " 454 "SoftwareImageDecodeController::DecodeImageInternal - allocate "
424 "scaled pixels"); 455 "scaled pixels");
425 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() 456 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance()
426 ->AllocateLockedDiscardableMemory( 457 ->AllocateLockedDiscardableMemory(
427 scaled_info.minRowBytes() * scaled_info.height()); 458 scaled_info.minRowBytes() * scaled_info.height());
428 } 459 }
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() { 883 void SoftwareImageDecodeController::MemoryBudget::ResetUsage() {
853 current_usage_bytes_ = 0; 884 current_usage_bytes_ = 0;
854 } 885 }
855 886
856 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe() 887 size_t SoftwareImageDecodeController::MemoryBudget::GetCurrentUsageSafe()
857 const { 888 const {
858 return current_usage_bytes_.ValueOrDie(); 889 return current_usage_bytes_.ValueOrDie();
859 } 890 }
860 891
861 } // namespace cc 892 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/software_image_decode_controller.h ('k') | cc/trees/layer_tree_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698