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

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: Cleanup. 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
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 "skia/ext/skia_utils_ios.h"
11 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "ui/gfx/image/image_skia.h"
13
14 namespace gfx {
15
16 gfx::ImageSkia ImageSkiaFromUIImage(UIImage* image) {
17 gfx::ImageSkia image_skia;
18 if (!image)
19 return image_skia;
20
21 // iOS only supports one scale factor.
22 std::vector<ui::ScaleFactor> supported_scale_factors =
23 ui::GetSupportedScaleFactors();
24 DCHECK_EQ(1U, supported_scale_factors.size());
25 if (supported_scale_factors.size() < 1)
26 return image_skia;
27
28 ui::ScaleFactor scale_factor = supported_scale_factors[0];
29 float scale = ui::GetScaleFactorScale(scale_factor);
30 CGSize size = image.size;
31 CGSize desired_size_for_scale =
32 CGSizeMake(size.width * scale, size.height * scale);
33 SkBitmap bitmap(gfx::UIImageToSkBitmap(image, desired_size_for_scale, false));
34 if (!bitmap.isNull())
35 image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale_factor));
36 return image_skia;
37 }
38
39 UIImage* UIImageFromImageSkia(const gfx::ImageSkia& image_skia) {
40 if (image_skia.isNull())
41 return nil;
42
43 // iOS only supports one scale factor.
44 std::vector<ui::ScaleFactor> supported_scale_factors =
45 ui::GetSupportedScaleFactors();
46 DCHECK_EQ(1U, supported_scale_factors.size());
47 if (supported_scale_factors.size() < 1)
48 return nil;
49
50 image_skia.EnsureRepsForSupportedScaleFactors();
51 const ImageSkiaRep& rep =
52 image_skia.GetRepresentation(supported_scale_factors[0]);
53 return gfx::SkBitmapToUIImage(rep.sk_bitmap());
54 }
55
56 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698