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

Side by Side Diff: ui/gfx/image/image_skia_util_mac.mm

Issue 10824359: Remove ImageSkia::empty and ImageSkia::extractSubset (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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/gfx/image/image_skia.cc ('k') | ui/views/controls/button/image_button.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/gfx/image/image_skia_util_mac.h" 5 #include "ui/gfx/image/image_skia_util_mac.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #import <AppKit/AppKit.h> 10 #import <AppKit/AppKit.h>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 gfx::ImageSkia image_skia; 63 gfx::ImageSkia image_skia;
64 for (size_t i = 0; i < supported_scale_factors.size(); ++i) { 64 for (size_t i = 0; i < supported_scale_factors.size(); ++i) {
65 float scale = ui::GetScaleFactorScale(supported_scale_factors[i]); 65 float scale = ui::GetScaleFactorScale(supported_scale_factors[i]);
66 NSSize desired_size_for_scale = NSMakeSize(desired_size.width * scale, 66 NSSize desired_size_for_scale = NSMakeSize(desired_size.width * scale,
67 desired_size.height * scale); 67 desired_size.height * scale);
68 NSImageRep* ns_image_rep = GetNSImageRepWithPixelSize(image, 68 NSImageRep* ns_image_rep = GetNSImageRepWithPixelSize(image,
69 desired_size_for_scale); 69 desired_size_for_scale);
70 70
71 SkBitmap bitmap(gfx::NSImageRepToSkBitmap(ns_image_rep, 71 SkBitmap bitmap(gfx::NSImageRepToSkBitmap(ns_image_rep,
72 desired_size_for_scale, false)); 72 desired_size_for_scale, false));
73 if (bitmap.isNull() || bitmap.empty()) 73 if (bitmap.isNull())
74 continue; 74 continue;
75 75
76 image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, 76 image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap,
77 supported_scale_factors[i])); 77 supported_scale_factors[i]));
78 } 78 }
79 return image_skia; 79 return image_skia;
80 } 80 }
81 81
82 gfx::ImageSkia ApplicationIconAtSize(int desired_size) { 82 gfx::ImageSkia ApplicationIconAtSize(int desired_size) {
83 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; 83 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
84 return ImageSkiaFromResizedNSImage(image, 84 return ImageSkiaFromResizedNSImage(image,
85 NSMakeSize(desired_size, desired_size)); 85 NSMakeSize(desired_size, desired_size));
86 } 86 }
87 87
88 NSImage* NSImageFromImageSkia(const gfx::ImageSkia& image_skia) { 88 NSImage* NSImageFromImageSkia(const gfx::ImageSkia& image_skia) {
89 if (image_skia.empty()) 89 if (image_skia.isNull())
90 return nil; 90 return nil;
91 91
92 scoped_nsobject<NSImage> image([[NSImage alloc] init]); 92 scoped_nsobject<NSImage> image([[NSImage alloc] init]);
93 93
94 std::vector<gfx::ImageSkiaRep> image_reps = image_skia.GetRepresentations(); 94 std::vector<gfx::ImageSkiaRep> image_reps = image_skia.GetRepresentations();
95 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin(); 95 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin();
96 it != image_reps.end(); ++it) { 96 it != image_reps.end(); ++it) {
97 [image addRepresentation: 97 [image addRepresentation:
98 gfx::SkBitmapToNSBitmapImageRep(it->sk_bitmap())]; 98 gfx::SkBitmapToNSBitmapImageRep(it->sk_bitmap())];
99 } 99 }
100 100
101 [image setSize:NSMakeSize(image_skia.width(), image_skia.height())]; 101 [image setSize:NSMakeSize(image_skia.width(), image_skia.height())];
102 return [image.release() autorelease]; 102 return [image.release() autorelease];
103 } 103 }
104 104
105 NSImage* NSImageFromImageSkiaWithColorSpace(const gfx::ImageSkia& image_skia, 105 NSImage* NSImageFromImageSkiaWithColorSpace(const gfx::ImageSkia& image_skia,
106 CGColorSpaceRef color_space) { 106 CGColorSpaceRef color_space) {
107 if (image_skia.empty()) 107 if (image_skia.isNull())
108 return nil; 108 return nil;
109 109
110 scoped_nsobject<NSImage> image([[NSImage alloc] init]); 110 scoped_nsobject<NSImage> image([[NSImage alloc] init]);
111 111
112 const std::vector<gfx::ImageSkiaRep>& image_reps = 112 const std::vector<gfx::ImageSkiaRep>& image_reps =
113 image_skia.GetRepresentations(); 113 image_skia.GetRepresentations();
114 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin(); 114 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin();
115 it != image_reps.end(); ++it) { 115 it != image_reps.end(); ++it) {
116 [image addRepresentation: 116 [image addRepresentation:
117 gfx::SkBitmapToNSBitmapImageRepWithColorSpace(it->sk_bitmap(), 117 gfx::SkBitmapToNSBitmapImageRepWithColorSpace(it->sk_bitmap(),
118 color_space)]; 118 color_space)];
119 } 119 }
120 120
121 [image setSize:NSMakeSize(image_skia.width(), image_skia.height())]; 121 [image setSize:NSMakeSize(image_skia.width(), image_skia.height())];
122 return [image.release() autorelease]; 122 return [image.release() autorelease];
123 } 123 }
124 124
125 } // namespace gfx 125 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image_skia.cc ('k') | ui/views/controls/button/image_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698