| 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/image_decode_controller.h" | 5 #include "cc/tiles/image_decode_controller.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/discardable_memory.h" | 10 #include "base/memory/discardable_memory.h" |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 bool result = image->readPixels( | 311 bool result = image->readPixels( |
| 312 decoded_info, decoded_pixels.get(), decoded_info.minRowBytes(), | 312 decoded_info, decoded_pixels.get(), decoded_info.minRowBytes(), |
| 313 key.src_rect().x(), key.src_rect().y(), SkImage::kAllow_CachingHint); | 313 key.src_rect().x(), key.src_rect().y(), SkImage::kAllow_CachingHint); |
| 314 DCHECK(result); | 314 DCHECK(result); |
| 315 } | 315 } |
| 316 | 316 |
| 317 SkPixmap decoded_pixmap(decoded_info, decoded_pixels.get(), | 317 SkPixmap decoded_pixmap(decoded_info, decoded_pixels.get(), |
| 318 decoded_info.minRowBytes()); | 318 decoded_info.minRowBytes()); |
| 319 | 319 |
| 320 // Now scale the pixels into the destination size. | 320 // Now scale the pixels into the destination size. |
| 321 SkImageInfo scaled_info = SkImageInfo::MakeN32Premul( | 321 // TODO(vmpstr): Once we support skipping images altogether, we can remove |
| 322 key.target_size().width(), key.target_size().height()); | 322 // this and skip drawing images that are empty in size. crbug.com/581163 |
| 323 const gfx::Size& target_size = |
| 324 key.target_size().IsEmpty() ? gfx::Size(1, 1) : key.target_size(); |
| 325 SkImageInfo scaled_info = |
| 326 SkImageInfo::MakeN32Premul(target_size.width(), target_size.height()); |
| 323 scoped_ptr<base::DiscardableMemory> scaled_pixels; | 327 scoped_ptr<base::DiscardableMemory> scaled_pixels; |
| 324 { | 328 { |
| 325 TRACE_EVENT0( | 329 TRACE_EVENT0( |
| 326 "cc", | 330 "cc", |
| 327 "ImageDecodeController::DecodeImageInternal - allocate scaled pixels"); | 331 "ImageDecodeController::DecodeImageInternal - allocate scaled pixels"); |
| 328 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() | 332 scaled_pixels = base::DiscardableMemoryAllocator::GetInstance() |
| 329 ->AllocateLockedDiscardableMemory( | 333 ->AllocateLockedDiscardableMemory( |
| 330 scaled_info.minRowBytes() * scaled_info.height()); | 334 scaled_info.minRowBytes() * scaled_info.height()); |
| 331 } | 335 } |
| 332 SkPixmap scaled_pixmap(scaled_info, scaled_pixels->data(), | 336 SkPixmap scaled_pixmap(scaled_info, scaled_pixels->data(), |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 | 733 |
| 730 void ImageDecodeController::MemoryBudget::ResetUsage() { | 734 void ImageDecodeController::MemoryBudget::ResetUsage() { |
| 731 current_usage_bytes_ = 0; | 735 current_usage_bytes_ = 0; |
| 732 } | 736 } |
| 733 | 737 |
| 734 size_t ImageDecodeController::MemoryBudget::GetCurrentUsageSafe() const { | 738 size_t ImageDecodeController::MemoryBudget::GetCurrentUsageSafe() const { |
| 735 return current_usage_bytes_.ValueOrDie(); | 739 return current_usage_bytes_.ValueOrDie(); |
| 736 } | 740 } |
| 737 | 741 |
| 738 } // namespace cc | 742 } // namespace cc |
| OLD | NEW |