OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 return GetEmptyImage(); | 126 return GetEmptyImage(); |
127 } | 127 } |
128 | 128 |
129 // Create a data object from the raw bytes. | 129 // Create a data object from the raw bytes. |
130 base::scoped_nsobject<NSData> ns_data( | 130 base::scoped_nsobject<NSData> ns_data( |
131 [[NSData alloc] initWithBytes:data->front() length:data->size()]); | 131 [[NSData alloc] initWithBytes:data->front() length:data->size()]); |
132 | 132 |
133 bool is_fallback = PNGContainsFallbackMarker(data->front(), data->size()); | 133 bool is_fallback = PNGContainsFallbackMarker(data->front(), data->size()); |
134 // Create the image from the data. | 134 // Create the image from the data. |
135 CGFloat target_scale = ui::GetScaleForScaleFactor(scale_factor); | 135 CGFloat target_scale = ui::GetScaleForScaleFactor(scale_factor); |
136 CGFloat source_scale = is_fallback ? 1.0 : target_scale; | |
137 // Hack: The 200P pak file is the only pak file loaded on iOS devices with | 136 // Hack: The 200P pak file is the only pak file loaded on iOS devices with |
138 // an @3x scale factor. Force |source_scale| to be 2.0 to handle this case, | 137 // an @3x scale factor. Force |source_scale| to be 2.0 to handle this case, |
139 // since it cannot be anything else. | 138 // since it cannot be anything else. http://crbug.com/413300. |
140 // TODO(rohitrao): Support proper fallback by using the actual scale factor | 139 // TODO(rohitrao): Support proper fallback by using the actual scale factor |
141 // of the source image, rather than assuming it is 1.0 or 2.0. | 140 // of the source image, rather than assuming it is 1.0 or 2.0. |
142 if (scale_factor == SCALE_FACTOR_300P) { | 141 CGFloat source_scale = target_scale; |
| 142 if (is_fallback) { |
| 143 source_scale = 1.0; |
| 144 } else if (scale_factor == SCALE_FACTOR_300P) { |
143 source_scale = 2.0; | 145 source_scale = 2.0; |
144 } | 146 } |
145 base::scoped_nsobject<UIImage> ui_image( | 147 base::scoped_nsobject<UIImage> ui_image( |
146 [[UIImage alloc] initWithData:ns_data scale:source_scale]); | 148 [[UIImage alloc] initWithData:ns_data scale:source_scale]); |
147 | 149 |
148 // If the image is a 1x fallback, scale it up to a full-size representation. | 150 // If the image is a 1x fallback, scale it up to a full-size representation. |
149 if (is_fallback) { | 151 if (is_fallback) { |
150 CGSize source_size = [ui_image size]; | 152 CGSize source_size = [ui_image size]; |
151 CGSize target_size = CGSizeMake(source_size.width * target_scale, | 153 CGSize target_size = CGSizeMake(source_size.width * target_scale, |
152 source_size.height * target_scale); | 154 source_size.height * target_scale); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 189 |
188 // Another thread raced the load and has already cached the image. | 190 // Another thread raced the load and has already cached the image. |
189 if (images_.count(resource_id)) | 191 if (images_.count(resource_id)) |
190 return images_[resource_id]; | 192 return images_[resource_id]; |
191 | 193 |
192 images_[resource_id] = image; | 194 images_[resource_id] = image; |
193 return images_[resource_id]; | 195 return images_[resource_id]; |
194 } | 196 } |
195 | 197 |
196 } // namespace ui | 198 } // namespace ui |
OLD | NEW |