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 <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 100 } |
101 | 101 |
102 gfx::Image image; | 102 gfx::Image image; |
103 if (delegate_) | 103 if (delegate_) |
104 image = delegate_->GetNativeImageNamed(resource_id, rtl); | 104 image = delegate_->GetNativeImageNamed(resource_id, rtl); |
105 | 105 |
106 if (image.IsEmpty()) { | 106 if (image.IsEmpty()) { |
107 // Load the raw data from the resource pack at the current supported scale | 107 // Load the raw data from the resource pack at the current supported scale |
108 // factor. This code assumes that only one of the possible scale factors is | 108 // factor. This code assumes that only one of the possible scale factors is |
109 // supported at runtime, based on the device resolution. | 109 // supported at runtime, based on the device resolution. |
110 std::vector<ui::ScaleFactor> supported_scale_factors = | 110 ui::ScaleFactor scale_factor = ui::GetMaxScaleFactor(); |
111 ui::GetSupportedScaleFactors(); | |
112 DCHECK_EQ(1U, supported_scale_factors.size()); | |
113 ui::ScaleFactor scale_factor = supported_scale_factors[0]; | |
114 | 111 |
115 scoped_refptr<base::RefCountedStaticMemory> data( | 112 scoped_refptr<base::RefCountedStaticMemory> data( |
116 LoadDataResourceBytesForScale(resource_id, scale_factor)); | 113 LoadDataResourceBytesForScale(resource_id, scale_factor)); |
117 | 114 |
118 // Create a data object from the raw bytes. | 115 // Create a data object from the raw bytes. |
119 scoped_nsobject<NSData> ns_data( | 116 scoped_nsobject<NSData> ns_data( |
120 [[NSData alloc] initWithBytes:data->front() length:data->size()]); | 117 [[NSData alloc] initWithBytes:data->front() length:data->size()]); |
121 | 118 |
122 // Create the image from the data. The gfx::Image will take ownership. | 119 // Create the image from the data. The gfx::Image will take ownership. |
123 scoped_nsobject<UIImage> ui_image( | 120 scoped_nsobject<UIImage> ui_image( |
(...skipping 13 matching lines...) Expand all Loading... |
137 | 134 |
138 // Another thread raced the load and has already cached the image. | 135 // Another thread raced the load and has already cached the image. |
139 if (images_.count(resource_id)) | 136 if (images_.count(resource_id)) |
140 return images_[resource_id]; | 137 return images_[resource_id]; |
141 | 138 |
142 images_[resource_id] = image; | 139 images_[resource_id] = image; |
143 return images_[resource_id]; | 140 return images_[resource_id]; |
144 } | 141 } |
145 | 142 |
146 } // namespace ui | 143 } // namespace ui |
OLD | NEW |