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

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: 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
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::UIImageToSkBitmap(image, desired_size_for_scale, false)); 27 SkBitmap bitmap(gfx::UIImageToSkBitmap(image, desired_size_for_scale, false));
35 if (!bitmap.isNull()) 28 if (!bitmap.isNull())
36 image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale_factor)); 29 image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale_factor));
37 return image_skia; 30 return image_skia;
38 } 31 }
39 32
40 UIImage* UIImageFromImageSkia(const gfx::ImageSkia& image_skia) { 33 UIImage* UIImageFromImageSkia(const gfx::ImageSkia& image_skia) {
41 if (image_skia.isNull()) 34 if (image_skia.isNull())
42 return nil; 35 return nil;
43 36
44 // iOS only supports one scale factor. 37 ui::ScaleFactor scale_factor = ui::GetMaxScaleFactor();
45 std::vector<ui::ScaleFactor> supported_scale_factors =
46 ui::GetSupportedScaleFactors();
47 DCHECK_EQ(1U, supported_scale_factors.size());
48 if (supported_scale_factors.size() < 1)
49 return nil;
50
51 ui::ScaleFactor scale_factor = supported_scale_factors[0];
52 float scale = ui::GetScaleFactorScale(scale_factor); 38 float scale = ui::GetScaleFactorScale(scale_factor);
53 image_skia.EnsureRepsForSupportedScaleFactors(); 39 image_skia.EnsureRepsForSupportedScaleFactors();
54 const ImageSkiaRep& rep = 40 const ImageSkiaRep& rep = image_skia.GetRepresentation(scale_factor);
55 image_skia.GetRepresentation(supported_scale_factors[0]);
56 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space( 41 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space(
57 CGColorSpaceCreateDeviceRGB()); 42 CGColorSpaceCreateDeviceRGB());
58 return gfx::SkBitmapToUIImageWithColorSpace(rep.sk_bitmap(), scale, 43 return gfx::SkBitmapToUIImageWithColorSpace(rep.sk_bitmap(), scale,
59 color_space); 44 color_space);
60 } 45 }
61 46
62 } // namespace gfx 47 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698