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

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

Issue 24262008: Revert 224473 "Remove dependency on ui::ScaleFactor from ui/gfx" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 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 | « trunk/src/ui/gfx/image/image_skia_util_ios.mm ('k') | trunk/src/ui/gfx/image/image_unittest.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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 gfx::ImageSkia ImageSkiaFromResizedNSImage(NSImage* image, 50 gfx::ImageSkia ImageSkiaFromResizedNSImage(NSImage* image,
51 NSSize desired_size) { 51 NSSize desired_size) {
52 // Resize and convert to ImageSkia simultaneously to save on computation. 52 // Resize and convert to ImageSkia simultaneously to save on computation.
53 // TODO(pkotwicz): Separate resizing NSImage and converting to ImageSkia. 53 // TODO(pkotwicz): Separate resizing NSImage and converting to ImageSkia.
54 // Convert to ImageSkia by finding the most appropriate NSImageRep for 54 // Convert to ImageSkia by finding the most appropriate NSImageRep for
55 // each supported scale factor and resizing if necessary. 55 // each supported scale factor and resizing if necessary.
56 56
57 if (IsNSImageEmpty(image)) 57 if (IsNSImageEmpty(image))
58 return gfx::ImageSkia(); 58 return gfx::ImageSkia();
59 59
60 std::vector<float> supported_scales = ImageSkia::GetSupportedScales(); 60 std::vector<ui::ScaleFactor> supported_scale_factors =
61 ui::GetSupportedScaleFactors();
61 62
62 gfx::ImageSkia image_skia; 63 gfx::ImageSkia image_skia;
63 for (size_t i = 0; i < supported_scales.size(); ++i) { 64 for (size_t i = 0; i < supported_scale_factors.size(); ++i) {
64 float scale = supported_scales[i]; 65 float scale = ui::GetScaleFactorScale(supported_scale_factors[i]);
65 NSSize desired_size_for_scale = NSMakeSize(desired_size.width * scale, 66 NSSize desired_size_for_scale = NSMakeSize(desired_size.width * scale,
66 desired_size.height * scale); 67 desired_size.height * scale);
67 NSImageRep* ns_image_rep = GetNSImageRepWithPixelSize(image, 68 NSImageRep* ns_image_rep = GetNSImageRepWithPixelSize(image,
68 desired_size_for_scale); 69 desired_size_for_scale);
69 70
70 SkBitmap bitmap(gfx::NSImageRepToSkBitmap(ns_image_rep, 71 SkBitmap bitmap(gfx::NSImageRepToSkBitmap(ns_image_rep,
71 desired_size_for_scale, false)); 72 desired_size_for_scale, false));
72 if (bitmap.isNull()) 73 if (bitmap.isNull())
73 continue; 74 continue;
74 75
75 image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); 76 image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap,
77 supported_scale_factors[i]));
76 } 78 }
77 return image_skia; 79 return image_skia;
78 } 80 }
79 81
80 gfx::ImageSkia ApplicationIconAtSize(int desired_size) { 82 gfx::ImageSkia ApplicationIconAtSize(int desired_size) {
81 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; 83 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
82 return ImageSkiaFromResizedNSImage(image, 84 return ImageSkiaFromResizedNSImage(image,
83 NSMakeSize(desired_size, desired_size)); 85 NSMakeSize(desired_size, desired_size));
84 } 86 }
85 87
86 NSImage* NSImageFromImageSkia(const gfx::ImageSkia& image_skia) { 88 NSImage* NSImageFromImageSkia(const gfx::ImageSkia& image_skia) {
87 if (image_skia.isNull()) 89 if (image_skia.isNull())
88 return nil; 90 return nil;
89 91
90 base::scoped_nsobject<NSImage> image([[NSImage alloc] init]); 92 base::scoped_nsobject<NSImage> image([[NSImage alloc] init]);
91 image_skia.EnsureRepsForSupportedScales(); 93 image_skia.EnsureRepsForSupportedScaleFactors();
92 std::vector<gfx::ImageSkiaRep> image_reps = image_skia.image_reps(); 94 std::vector<gfx::ImageSkiaRep> image_reps = image_skia.image_reps();
93 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin(); 95 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin();
94 it != image_reps.end(); ++it) { 96 it != image_reps.end(); ++it) {
95 [image addRepresentation: 97 [image addRepresentation:
96 gfx::SkBitmapToNSBitmapImageRep(it->sk_bitmap())]; 98 gfx::SkBitmapToNSBitmapImageRep(it->sk_bitmap())];
97 } 99 }
98 100
99 [image setSize:NSMakeSize(image_skia.width(), image_skia.height())]; 101 [image setSize:NSMakeSize(image_skia.width(), image_skia.height())];
100 return [image.release() autorelease]; 102 return [image.release() autorelease];
101 } 103 }
102 104
103 NSImage* NSImageFromImageSkiaWithColorSpace(const gfx::ImageSkia& image_skia, 105 NSImage* NSImageFromImageSkiaWithColorSpace(const gfx::ImageSkia& image_skia,
104 CGColorSpaceRef color_space) { 106 CGColorSpaceRef color_space) {
105 if (image_skia.isNull()) 107 if (image_skia.isNull())
106 return nil; 108 return nil;
107 109
108 base::scoped_nsobject<NSImage> image([[NSImage alloc] init]); 110 base::scoped_nsobject<NSImage> image([[NSImage alloc] init]);
109 image_skia.EnsureRepsForSupportedScales(); 111 image_skia.EnsureRepsForSupportedScaleFactors();
110 std::vector<gfx::ImageSkiaRep> image_reps = image_skia.image_reps(); 112 std::vector<gfx::ImageSkiaRep> image_reps = image_skia.image_reps();
111 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin(); 113 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin();
112 it != image_reps.end(); ++it) { 114 it != image_reps.end(); ++it) {
113 [image addRepresentation: 115 [image addRepresentation:
114 gfx::SkBitmapToNSBitmapImageRepWithColorSpace(it->sk_bitmap(), 116 gfx::SkBitmapToNSBitmapImageRepWithColorSpace(it->sk_bitmap(),
115 color_space)]; 117 color_space)];
116 } 118 }
117 119
118 [image setSize:NSMakeSize(image_skia.width(), image_skia.height())]; 120 [image setSize:NSMakeSize(image_skia.width(), image_skia.height())];
119 return [image.release() autorelease]; 121 return [image.release() autorelease];
120 } 122 }
121 123
122 } // namespace gfx 124 } // namespace gfx
OLDNEW
« no previous file with comments | « trunk/src/ui/gfx/image/image_skia_util_ios.mm ('k') | trunk/src/ui/gfx/image/image_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698