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

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

Issue 16917011: mac: Replace base::mac::ScopedCFTypeRef with base::ScopedCFTypeRef. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with fixed off-by-1 in git-clang-format Created 7 years, 6 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
« no previous file with comments | « ui/base/clipboard/clipboard_mac.mm ('k') | ui/gfx/blit.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( 138 base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
139 CGColorSpaceCreateDeviceRGB()); 139 CGColorSpaceCreateDeviceRGB());
140 base::mac::ScopedCFTypeRef<CGContextRef> context( 140 base::ScopedCFTypeRef<CGContextRef> context(CGBitmapContextCreate(
141 CGBitmapContextCreate( 141 NULL,
142 NULL, 142 target_size.width,
143 target_size.width, target_size.height, 143 target_size.height,
144 8, target_size.width * 4, 144 8,
145 color_space, 145 target_size.width * 4,
146 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host)); 146 color_space,
147 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
147 148
148 CGRect target_rect = CGRectMake(0, 0, 149 CGRect target_rect = CGRectMake(0, 0,
149 target_size.width, target_size.height); 150 target_size.width, target_size.height);
150 CGContextSetBlendMode(context, kCGBlendModeCopy); 151 CGContextSetBlendMode(context, kCGBlendModeCopy);
151 CGContextDrawImage(context, target_rect, [ui_image CGImage]); 152 CGContextDrawImage(context, target_rect, [ui_image CGImage]);
152 153
153 if (ShouldHighlightMissingScaledResources()) { 154 if (ShouldHighlightMissingScaledResources()) {
154 CGContextSetFillColorSpace(context, color_space); 155 CGContextSetFillColorSpace(context, color_space);
155 CGFloat components[4] = { 1.0, 0.0, 0.0, 0.3 }; // Translucent red. 156 CGFloat components[4] = { 1.0, 0.0, 0.0, 0.3 }; // Translucent red.
156 CGContextSetFillColor(context, components); 157 CGContextSetFillColor(context, components);
157 CGContextSetBlendMode(context, kCGBlendModeNormal); 158 CGContextSetBlendMode(context, kCGBlendModeNormal);
158 CGContextFillRect(context, target_rect); 159 CGContextFillRect(context, target_rect);
159 } 160 }
160 161
161 base::mac::ScopedCFTypeRef<CGImageRef> cg_image( 162 base::ScopedCFTypeRef<CGImageRef> cg_image(
162 CGBitmapContextCreateImage(context)); 163 CGBitmapContextCreateImage(context));
163 ui_image.reset([[UIImage alloc] initWithCGImage:cg_image 164 ui_image.reset([[UIImage alloc] initWithCGImage:cg_image
164 scale:target_scale 165 scale:target_scale
165 orientation:UIImageOrientationUp]); 166 orientation:UIImageOrientationUp]);
166 } 167 }
167 168
168 if (!ui_image.get()) { 169 if (!ui_image.get()) {
169 LOG(WARNING) << "Unable to load image with id " << resource_id; 170 LOG(WARNING) << "Unable to load image with id " << resource_id;
170 NOTREACHED(); // Want to assert in debug mode. 171 NOTREACHED(); // Want to assert in debug mode.
171 return GetEmptyImage(); 172 return GetEmptyImage();
172 } 173 }
173 174
174 // The gfx::Image takes ownership. 175 // The gfx::Image takes ownership.
175 image = gfx::Image(ui_image.release()); 176 image = gfx::Image(ui_image.release());
176 } 177 }
177 178
178 base::AutoLock lock(*images_and_fonts_lock_); 179 base::AutoLock lock(*images_and_fonts_lock_);
179 180
180 // Another thread raced the load and has already cached the image. 181 // Another thread raced the load and has already cached the image.
181 if (images_.count(resource_id)) 182 if (images_.count(resource_id))
182 return images_[resource_id]; 183 return images_[resource_id];
183 184
184 images_[resource_id] = image; 185 images_[resource_id] = image;
185 return images_[resource_id]; 186 return images_[resource_id];
186 } 187 }
187 188
188 } // namespace ui 189 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_mac.mm ('k') | ui/gfx/blit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698