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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 102 } |
103 | 103 |
104 gfx::Image image; | 104 gfx::Image image; |
105 if (delegate_) | 105 if (delegate_) |
106 image = delegate_->GetNativeImageNamed(resource_id, rtl); | 106 image = delegate_->GetNativeImageNamed(resource_id, rtl); |
107 | 107 |
108 if (image.IsEmpty()) { | 108 if (image.IsEmpty()) { |
109 // Load the raw data from the resource pack at the current supported scale | 109 // Load the raw data from the resource pack at the current supported scale |
110 // factor. This code assumes that only one of the possible scale factors is | 110 // factor. This code assumes that only one of the possible scale factors is |
111 // supported at runtime, based on the device resolution. | 111 // supported at runtime, based on the device resolution. |
112 ui::ScaleFactor scale_factor = ui::GetMaxScaleFactor(); | 112 ui::ScaleFactor scale_factor = ui::GetMaxSupportedScaleFactor(); |
113 | 113 |
114 scoped_refptr<base::RefCountedStaticMemory> data( | 114 scoped_refptr<base::RefCountedStaticMemory> data( |
115 LoadDataResourceBytesForScale(resource_id, scale_factor)); | 115 LoadDataResourceBytesForScale(resource_id, scale_factor)); |
116 | 116 |
117 if (!data.get()) { | 117 if (!data.get()) { |
118 LOG(WARNING) << "Unable to load image with id " << resource_id; | 118 LOG(WARNING) << "Unable to load image with id " << resource_id; |
119 return GetEmptyImage(); | 119 return GetEmptyImage(); |
120 } | 120 } |
121 | 121 |
122 // Create a data object from the raw bytes. | 122 // Create a data object from the raw bytes. |
123 base::scoped_nsobject<NSData> ns_data( | 123 base::scoped_nsobject<NSData> ns_data( |
124 [[NSData alloc] initWithBytes:data->front() length:data->size()]); | 124 [[NSData alloc] initWithBytes:data->front() length:data->size()]); |
125 | 125 |
126 bool is_fallback = PNGContainsFallbackMarker(data->front(), data->size()); | 126 bool is_fallback = PNGContainsFallbackMarker(data->front(), data->size()); |
127 // Create the image from the data. | 127 // Create the image from the data. |
128 CGFloat target_scale = ui::GetScaleFactorScale(scale_factor); | 128 CGFloat target_scale = ui::GetImageScale(scale_factor); |
129 CGFloat source_scale = is_fallback ? 1.0 : target_scale; | 129 CGFloat source_scale = is_fallback ? 1.0 : target_scale; |
130 base::scoped_nsobject<UIImage> ui_image( | 130 base::scoped_nsobject<UIImage> ui_image( |
131 [[UIImage alloc] initWithData:ns_data scale:source_scale]); | 131 [[UIImage alloc] initWithData:ns_data scale:source_scale]); |
132 | 132 |
133 // If the image is a 1x fallback, scale it up to a full-size representation. | 133 // If the image is a 1x fallback, scale it up to a full-size representation. |
134 if (is_fallback) { | 134 if (is_fallback) { |
135 CGSize source_size = [ui_image size]; | 135 CGSize source_size = [ui_image size]; |
136 CGSize target_size = CGSizeMake(source_size.width * target_scale, | 136 CGSize target_size = CGSizeMake(source_size.width * target_scale, |
137 source_size.height * target_scale); | 137 source_size.height * target_scale); |
138 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( | 138 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 180 |
181 // Another thread raced the load and has already cached the image. | 181 // Another thread raced the load and has already cached the image. |
182 if (images_.count(resource_id)) | 182 if (images_.count(resource_id)) |
183 return images_[resource_id]; | 183 return images_[resource_id]; |
184 | 184 |
185 images_[resource_id] = image; | 185 images_[resource_id] = image; |
186 return images_[resource_id]; | 186 return images_[resource_id]; |
187 } | 187 } |
188 | 188 |
189 } // namespace ui | 189 } // namespace ui |
OLD | NEW |