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

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

Issue 11293147: Always add 100P scale format in the supported format list. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding TODO. Created 8 years, 1 month 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
« no previous file with comments | « ui/gfx/image/image_ios.mm ('k') | ui/gfx/image/image_unittest_util.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/gfx/image/image_skia_util_ios.h" 5 #include "ui/gfx/image/image_skia_util_ios.h"
6 6
7 #include <UIKit/UIKit.h> 7 #include <UIKit/UIKit.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/scoped_cftyperef.h" 10 #include "base/mac/scoped_cftyperef.h"
11 #include "skia/ext/skia_utils_ios.h" 11 #include "skia/ext/skia_utils_ios.h"
12 #include "third_party/skia/include/core/SkBitmap.h" 12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "ui/gfx/image/image_skia.h" 13 #include "ui/gfx/image/image_skia.h"
14 14
15 namespace gfx { 15 namespace gfx {
16 16
17 gfx::ImageSkia ImageSkiaFromUIImage(UIImage* image) { 17 gfx::ImageSkia ImageSkiaFromUIImage(UIImage* image) {
18 gfx::ImageSkia image_skia; 18 gfx::ImageSkia image_skia;
19 if (!image) 19 if (!image)
20 return image_skia; 20 return image_skia;
21 21
22 // iOS only supports one scale factor. 22 ui::ScaleFactor scale_factor = ui::GetMaxScaleFactor();
23 std::vector<ui::ScaleFactor> supported_scale_factors =
24 ui::GetSupportedScaleFactors();
25 DCHECK_EQ(1U, supported_scale_factors.size());
26 if (supported_scale_factors.size() < 1)
27 return image_skia;
28
29 ui::ScaleFactor scale_factor = supported_scale_factors[0];
30 float scale = ui::GetScaleFactorScale(scale_factor); 23 float scale = ui::GetScaleFactorScale(scale_factor);
31 CGSize size = image.size; 24 CGSize size = image.size;
32 CGSize desired_size_for_scale = 25 CGSize desired_size_for_scale =
33 CGSizeMake(size.width * scale, size.height * scale); 26 CGSizeMake(size.width * scale, size.height * scale);
34 SkBitmap bitmap(gfx::CGImageToSkBitmap(image.CGImage, 27 SkBitmap bitmap(gfx::CGImageToSkBitmap(image.CGImage,
35 desired_size_for_scale, 28 desired_size_for_scale,
36 false)); 29 false));
37 if (!bitmap.isNull()) 30 if (!bitmap.isNull())
38 image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale_factor)); 31 image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale_factor));
39 return image_skia; 32 return image_skia;
40 } 33 }
41 34
42 UIImage* UIImageFromImageSkia(const gfx::ImageSkia& image_skia) { 35 UIImage* UIImageFromImageSkia(const gfx::ImageSkia& image_skia) {
43 if (image_skia.isNull()) 36 if (image_skia.isNull())
44 return nil; 37 return nil;
45 38
46 // iOS only supports one scale factor. 39 ui::ScaleFactor scale_factor = ui::GetMaxScaleFactor();
47 std::vector<ui::ScaleFactor> supported_scale_factors =
48 ui::GetSupportedScaleFactors();
49 DCHECK_EQ(1U, supported_scale_factors.size());
50 if (supported_scale_factors.size() < 1)
51 return nil;
52
53 ui::ScaleFactor scale_factor = supported_scale_factors[0];
54 float scale = ui::GetScaleFactorScale(scale_factor); 40 float scale = ui::GetScaleFactorScale(scale_factor);
55 image_skia.EnsureRepsForSupportedScaleFactors(); 41 image_skia.EnsureRepsForSupportedScaleFactors();
56 const ImageSkiaRep& rep = 42 const ImageSkiaRep& rep = image_skia.GetRepresentation(scale_factor);
57 image_skia.GetRepresentation(supported_scale_factors[0]);
58 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( 43 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space(
59 CGColorSpaceCreateDeviceRGB()); 44 CGColorSpaceCreateDeviceRGB());
60 return gfx::SkBitmapToUIImageWithColorSpace(rep.sk_bitmap(), scale, 45 return gfx::SkBitmapToUIImageWithColorSpace(rep.sk_bitmap(), scale,
61 color_space); 46 color_space);
62 } 47 }
63 48
64 } // namespace gfx 49 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image_ios.mm ('k') | ui/gfx/image/image_unittest_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698