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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/big_endian.h" | 9 #include "base/big_endian.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 : rb_(rb), resource_id_(resource_id) {} | 98 : rb_(rb), resource_id_(resource_id) {} |
99 virtual ~ResourceBundleImageSource() {} | 99 virtual ~ResourceBundleImageSource() {} |
100 | 100 |
101 // gfx::ImageSkiaSource overrides: | 101 // gfx::ImageSkiaSource overrides: |
102 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 102 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { |
103 SkBitmap image; | 103 SkBitmap image; |
104 bool fell_back_to_1x = false; | 104 bool fell_back_to_1x = false; |
105 ScaleFactor scale_factor = GetSupportedScaleFactor(scale); | 105 ScaleFactor scale_factor = GetSupportedScaleFactor(scale); |
106 bool found = rb_->LoadBitmap(resource_id_, &scale_factor, | 106 bool found = rb_->LoadBitmap(resource_id_, &scale_factor, |
107 &image, &fell_back_to_1x); | 107 &image, &fell_back_to_1x); |
| 108 // If the resource is in the package with SCALE_FACTOR_NONE, it |
| 109 // can be used in any scale factor. The image is maked as "unscaled" |
| 110 // so that the ImageSkia do not automatically scale. |
| 111 bool unscaled = scale_factor == ui::SCALE_FACTOR_NONE; |
| 112 if (unscaled) |
| 113 scale_factor = ui::SCALE_FACTOR_100P; |
| 114 |
108 if (!found) | 115 if (!found) |
109 return gfx::ImageSkiaRep(); | 116 return gfx::ImageSkiaRep(); |
110 | 117 |
111 if (fell_back_to_1x) { | 118 if (fell_back_to_1x) { |
112 // GRIT fell back to the 100% image, so rescale it to the correct size. | 119 // GRIT fell back to the 100% image, so rescale it to the correct size. |
113 image = skia::ImageOperations::Resize( | 120 image = skia::ImageOperations::Resize( |
114 image, | 121 image, |
115 skia::ImageOperations::RESIZE_LANCZOS3, | 122 skia::ImageOperations::RESIZE_LANCZOS3, |
116 gfx::ToCeiledInt(image.width() * scale), | 123 gfx::ToCeiledInt(image.width() * scale), |
117 gfx::ToCeiledInt(image.height() * scale)); | 124 gfx::ToCeiledInt(image.height() * scale)); |
118 } else { | 125 } else if (!unscaled) { |
119 image = PlatformScaleImage(image, | 126 image = PlatformScaleImage(image, |
120 ui::GetScaleForScaleFactor(scale_factor), | 127 ui::GetScaleForScaleFactor(scale_factor), |
121 scale); | 128 scale); |
122 } | 129 } |
123 return gfx::ImageSkiaRep(image, scale); | 130 return gfx::ImageSkiaRep(image, unscaled ? 0.0f : scale); |
124 } | 131 } |
125 | 132 |
126 private: | 133 private: |
127 ResourceBundle* rb_; | 134 ResourceBundle* rb_; |
128 const int resource_id_; | 135 const int resource_id_; |
129 | 136 |
130 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageSource); | 137 DISALLOW_COPY_AND_ASSIGN(ResourceBundleImageSource); |
131 }; | 138 }; |
132 | 139 |
133 // static | 140 // static |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 NOTREACHED() << "Unable to decode theme image resource " << resource_id; | 728 NOTREACHED() << "Unable to decode theme image resource " << resource_id; |
722 return false; | 729 return false; |
723 } | 730 } |
724 | 731 |
725 bool ResourceBundle::LoadBitmap(int resource_id, | 732 bool ResourceBundle::LoadBitmap(int resource_id, |
726 ScaleFactor* scale_factor, | 733 ScaleFactor* scale_factor, |
727 SkBitmap* bitmap, | 734 SkBitmap* bitmap, |
728 bool* fell_back_to_1x) const { | 735 bool* fell_back_to_1x) const { |
729 DCHECK(fell_back_to_1x); | 736 DCHECK(fell_back_to_1x); |
730 for (size_t i = 0; i < data_packs_.size(); ++i) { | 737 for (size_t i = 0; i < data_packs_.size(); ++i) { |
731 // If the resource is in the package with SCALE_FACTOR_NONE, it | |
732 // can be used in any scale factor, but set 100P in ImageSkia so | |
733 // that it will be scaled property. | |
734 if (data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE && | 738 if (data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE && |
735 LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) { | 739 LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) { |
736 *scale_factor = ui::SCALE_FACTOR_100P; | |
737 DCHECK(!*fell_back_to_1x); | 740 DCHECK(!*fell_back_to_1x); |
| 741 *scale_factor = ui::SCALE_FACTOR_NONE; |
738 return true; | 742 return true; |
739 } | 743 } |
740 if (data_packs_[i]->GetScaleFactor() == *scale_factor && | 744 if (data_packs_[i]->GetScaleFactor() == *scale_factor && |
741 LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) { | 745 LoadBitmap(*data_packs_[i], resource_id, bitmap, fell_back_to_1x)) { |
742 return true; | 746 return true; |
743 } | 747 } |
744 } | 748 } |
745 return false; | 749 return false; |
746 } | 750 } |
747 | 751 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 #if !defined(OS_WIN) | 809 #if !defined(OS_WIN) |
806 // static | 810 // static |
807 SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, | 811 SkBitmap ResourceBundle::PlatformScaleImage(const SkBitmap& image, |
808 float loaded_image_scale, | 812 float loaded_image_scale, |
809 float desired_scale) { | 813 float desired_scale) { |
810 return image; | 814 return image; |
811 } | 815 } |
812 #endif | 816 #endif |
813 | 817 |
814 } // namespace ui | 818 } // namespace ui |
OLD | NEW |