| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/base/resource/resource_bundle.h" | 5 #include "ui/base/resource/resource_bundle.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 base::AutoLock lock_scope(*images_and_fonts_lock_); | 433 base::AutoLock lock_scope(*images_and_fonts_lock_); |
| 434 | 434 |
| 435 // Another thread raced the load and has already cached the image. | 435 // Another thread raced the load and has already cached the image. |
| 436 if (images_.count(resource_id)) | 436 if (images_.count(resource_id)) |
| 437 return images_[resource_id]; | 437 return images_[resource_id]; |
| 438 | 438 |
| 439 images_[resource_id] = image; | 439 images_[resource_id] = image; |
| 440 return images_[resource_id]; | 440 return images_[resource_id]; |
| 441 } | 441 } |
| 442 | 442 |
| 443 base::RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( | 443 base::RefCountedMemory* ResourceBundle::LoadDataResourceBytes( |
| 444 int resource_id) const { | 444 int resource_id) const { |
| 445 return LoadDataResourceBytesForScale(resource_id, ui::SCALE_FACTOR_NONE); | 445 return LoadDataResourceBytesForScale(resource_id, ui::SCALE_FACTOR_NONE); |
| 446 } | 446 } |
| 447 | 447 |
| 448 base::RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytesForScale( | 448 base::RefCountedMemory* ResourceBundle::LoadDataResourceBytesForScale( |
| 449 int resource_id, | 449 int resource_id, |
| 450 ScaleFactor scale_factor) const { | 450 ScaleFactor scale_factor) const { |
| 451 base::RefCountedStaticMemory* bytes = NULL; | 451 base::RefCountedMemory* bytes = NULL; |
| 452 if (delegate_) | 452 if (delegate_) |
| 453 bytes = delegate_->LoadDataResourceBytes(resource_id, scale_factor); | 453 bytes = delegate_->LoadDataResourceBytes(resource_id, scale_factor); |
| 454 | 454 |
| 455 if (!bytes) { | 455 if (!bytes) { |
| 456 base::StringPiece data = | 456 base::StringPiece data = |
| 457 GetRawDataResourceForScale(resource_id, scale_factor); | 457 GetRawDataResourceForScale(resource_id, scale_factor); |
| 458 if (!data.empty()) { | 458 if (!data.empty()) { |
| 459 bytes = new base::RefCountedStaticMemory(data.data(), data.length()); | 459 bytes = new base::RefCountedStaticMemory(data.data(), data.length()); |
| 460 } | 460 } |
| 461 } | 461 } |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 // static | 896 // static |
| 897 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 897 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
| 898 size_t size, | 898 size_t size, |
| 899 SkBitmap* bitmap, | 899 SkBitmap* bitmap, |
| 900 bool* fell_back_to_1x) { | 900 bool* fell_back_to_1x) { |
| 901 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 901 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
| 902 return gfx::PNGCodec::Decode(buf, size, bitmap); | 902 return gfx::PNGCodec::Decode(buf, size, bitmap); |
| 903 } | 903 } |
| 904 | 904 |
| 905 } // namespace ui | 905 } // namespace ui |
| OLD | NEW |