Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: ui/base/resource/resource_bundle_ios.mm

Issue 17593006: mac: Update clients of scoped_nsobject.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: iwyu, scoped_nsprotocol Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/mac/bundle_locations.h" 13 #include "base/mac/bundle_locations.h"
14 #include "base/mac/foundation_util.h" 14 #include "base/mac/foundation_util.h"
15 #include "base/mac/scoped_nsobject.h"
15 #include "base/memory/ref_counted_memory.h" 16 #include "base/memory/ref_counted_memory.h"
16 #include "base/memory/scoped_nsobject.h" 17 #include "base/strings/sys_string_conversions.h"
17 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
18 #include "base/strings/sys_string_conversions.h"
19 #include "ui/base/resource/resource_handle.h" 19 #include "ui/base/resource/resource_handle.h"
20 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
21 21
22 namespace ui { 22 namespace ui {
23 23
24 namespace { 24 namespace {
25 25
26 base::FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) { 26 base::FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) {
27 NSString *resource_path; 27 NSString *resource_path;
28 if ([mac_locale length]) { 28 if ([mac_locale length]) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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::GetScaleFactorScale(scale_factor);
129 CGFloat source_scale = is_fallback ? 1.0 : target_scale; 129 CGFloat source_scale = is_fallback ? 1.0 : target_scale;
130 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(
139 CGColorSpaceCreateDeviceRGB()); 139 CGColorSpaceCreateDeviceRGB());
140 base::ScopedCFTypeRef<CGContextRef> context(CGBitmapContextCreate( 140 base::ScopedCFTypeRef<CGContextRef> context(CGBitmapContextCreate(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698