| 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 gfx::Image image; | 102 gfx::Image image; |
| 103 if (delegate_) | 103 if (delegate_) |
| 104 image = delegate_->GetNativeImageNamed(resource_id); | 104 image = delegate_->GetNativeImageNamed(resource_id); |
| 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 ui::ScaleFactor scale_factor = GetMaxScaleFactor(); | 110 ui::ScaleFactor scale_factor = GetMaxScaleFactor(); |
| 111 | 111 |
| 112 scoped_refptr<base::RefCountedStaticMemory> data( | 112 scoped_refptr<base::RefCountedMemory> data( |
| 113 LoadDataResourceBytesForScale(resource_id, scale_factor)); | 113 LoadDataResourceBytesForScale(resource_id, scale_factor)); |
| 114 | 114 |
| 115 if (!data.get()) { | 115 if (!data.get()) { |
| 116 LOG(WARNING) << "Unable to load image with id " << resource_id; | 116 LOG(WARNING) << "Unable to load image with id " << resource_id; |
| 117 return GetEmptyImage(); | 117 return GetEmptyImage(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Create a data object from the raw bytes. | 120 // Create a data object from the raw bytes. |
| 121 base::scoped_nsobject<NSData> ns_data( | 121 base::scoped_nsobject<NSData> ns_data( |
| 122 [[NSData alloc] initWithBytes:data->front() length:data->size()]); | 122 [[NSData alloc] initWithBytes:data->front() length:data->size()]); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 // Another thread raced the load and has already cached the image. | 171 // Another thread raced the load and has already cached the image. |
| 172 if (images_.count(resource_id)) | 172 if (images_.count(resource_id)) |
| 173 return images_[resource_id]; | 173 return images_[resource_id]; |
| 174 | 174 |
| 175 images_[resource_id] = image; | 175 images_[resource_id] = image; |
| 176 return images_[resource_id]; | 176 return images_[resource_id]; |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace ui | 179 } // namespace ui |
| OLD | NEW |