| 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 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 | 815 |
| 816 NOTREACHED() << "Unable to decode theme image resource " << resource_id; | 816 NOTREACHED() << "Unable to decode theme image resource " << resource_id; |
| 817 return false; | 817 return false; |
| 818 } | 818 } |
| 819 | 819 |
| 820 bool ResourceBundle::LoadBitmap(int resource_id, | 820 bool ResourceBundle::LoadBitmap(int resource_id, |
| 821 ScaleFactor* scale_factor, | 821 ScaleFactor* scale_factor, |
| 822 SkBitmap* bitmap, | 822 SkBitmap* bitmap, |
| 823 bool* fell_back_to_1x) const { | 823 bool* fell_back_to_1x) const { |
| 824 DCHECK(fell_back_to_1x); | 824 DCHECK(fell_back_to_1x); |
| 825 ResourceHandle* data_handle_100_percent = nullptr; | 825 for (const auto& pack : data_packs_) { |
| 826 for (size_t i = 0; i < data_packs_.size(); ++i) { | 826 if (pack->GetScaleFactor() == ui::SCALE_FACTOR_NONE && |
| 827 if (data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE && | 827 LoadBitmap(*pack, resource_id, bitmap, fell_back_to_1x)) { |
| 828 LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) { | |
| 829 DCHECK(!*fell_back_to_1x); | 828 DCHECK(!*fell_back_to_1x); |
| 830 *scale_factor = ui::SCALE_FACTOR_NONE; | 829 *scale_factor = ui::SCALE_FACTOR_NONE; |
| 831 return true; | 830 return true; |
| 832 } | 831 } |
| 833 if (data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_100P) | |
| 834 data_handle_100_percent = data_packs_[i]; | |
| 835 | 832 |
| 836 if (data_packs_[i]->GetScaleFactor() == *scale_factor && | 833 if (pack->GetScaleFactor() == *scale_factor && |
| 837 LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) { | 834 LoadBitmap(*pack, resource_id, bitmap, fell_back_to_1x)) { |
| 838 return true; | 835 return true; |
| 839 } | 836 } |
| 840 } | 837 } |
| 841 | 838 |
| 842 // Unit tests may only have 1x data pack. Allow them to fallback to 1x | 839 // Unit tests may only have 1x data pack. Allow them to fallback to 1x |
| 843 // resources. | 840 // resources. |
| 844 if (*scale_factor != ui::SCALE_FACTOR_100P && is_test_resources_ && | 841 if (is_test_resources_ && *scale_factor != ui::SCALE_FACTOR_100P) { |
| 845 data_handle_100_percent && | 842 for (const auto& pack : data_packs_) { |
| 846 LoadBitmap(*data_handle_100_percent, resource_id, bitmap, | 843 if (pack->GetScaleFactor() == ui::SCALE_FACTOR_100P && |
| 847 fell_back_to_1x)) { | 844 LoadBitmap(*pack, resource_id, bitmap, fell_back_to_1x)) { |
| 848 *fell_back_to_1x = true; | 845 *fell_back_to_1x = true; |
| 849 return true; | 846 return true; |
| 847 } |
| 848 } |
| 850 } | 849 } |
| 851 | 850 |
| 852 return false; | 851 return false; |
| 853 } | 852 } |
| 854 | 853 |
| 855 gfx::Image& ResourceBundle::GetEmptyImage() { | 854 gfx::Image& ResourceBundle::GetEmptyImage() { |
| 856 base::AutoLock lock(*images_and_fonts_lock_); | 855 base::AutoLock lock(*images_and_fonts_lock_); |
| 857 | 856 |
| 858 if (empty_image_.IsEmpty()) { | 857 if (empty_image_.IsEmpty()) { |
| 859 // The placeholder bitmap is bright red so people notice the problem. | 858 // The placeholder bitmap is bright red so people notice the problem. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 // static | 900 // static |
| 902 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 901 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
| 903 size_t size, | 902 size_t size, |
| 904 SkBitmap* bitmap, | 903 SkBitmap* bitmap, |
| 905 bool* fell_back_to_1x) { | 904 bool* fell_back_to_1x) { |
| 906 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 905 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
| 907 return gfx::PNGCodec::Decode(buf, size, bitmap); | 906 return gfx::PNGCodec::Decode(buf, size, bitmap); |
| 908 } | 907 } |
| 909 | 908 |
| 910 } // namespace ui | 909 } // namespace ui |
| OLD | NEW |