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

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

Issue 10928093: Adds an iOS implementation of gfx::Image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@skia
Patch Set: Moar GYP and TODOs. Created 8 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
« no previous file with comments | « ui/gfx/image/image_skia_util_ios.h ('k') | 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/gfx/image/image_skia_util_ios.h"
6
7 #include <UIKit/UIKit.h>
8
9 #include "base/logging.h"
10 #include "base/mac/scoped_cftyperef.h"
11 #include "skia/ext/skia_utils_ios.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "ui/gfx/image/image_skia.h"
14
15 namespace gfx {
16
17 gfx::ImageSkia ImageSkiaFromUIImage(UIImage* image) {
18 gfx::ImageSkia image_skia;
19 if (!image)
20 return image_skia;
21
22 // iOS only supports one scale factor.
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);
31 CGSize size = image.size;
32 CGSize desired_size_for_scale =
33 CGSizeMake(size.width * scale, size.height * scale);
34 SkBitmap bitmap(gfx::UIImageToSkBitmap(image, desired_size_for_scale, false));
35 if (!bitmap.isNull())
36 image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale_factor));
37 return image_skia;
38 }
39
40 UIImage* UIImageFromImageSkia(const gfx::ImageSkia& image_skia) {
41 if (image_skia.isNull())
42 return nil;
43
44 // iOS only supports one scale factor.
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 image_skia.EnsureRepsForSupportedScaleFactors();
52 const ImageSkiaRep& rep =
53 image_skia.GetRepresentation(supported_scale_factors[0]);
54 base::mac::ScopedCFTypeRef<CGColorSpaceRef> color_space(
55 CGColorSpaceCreateDeviceRGB());
56 return gfx::SkBitmapToUIImageWithColorSpace(rep.sk_bitmap(), color_space);
57 }
58
59 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image_skia_util_ios.h ('k') | ui/gfx/image/image_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698