OLD | NEW |
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 "skia/ext/skia_utils_ios.h" | 5 #include "skia/ext/skia_utils_ios.h" |
6 | 6 |
7 #import <ImageIO/ImageIO.h> | 7 #import <ImageIO/ImageIO.h> |
8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
12 #include "third_party/skia/include/utils/mac/SkCGUtils.h" | 12 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
13 | 13 |
14 namespace gfx { | 14 namespace gfx { |
15 | 15 |
16 SkBitmap CGImageToSkBitmap(CGImageRef image, CGSize size, bool is_opaque) { | 16 SkBitmap CGImageToSkBitmap(CGImageRef image, CGSize size, bool is_opaque) { |
17 SkBitmap bitmap; | 17 SkBitmap bitmap; |
18 if (!image) | 18 if (!image) |
19 return bitmap; | 19 return bitmap; |
20 | 20 |
21 if (!bitmap.tryAllocN32Pixels(size.width, size.height, is_opaque)) | 21 if (!bitmap.allocN32Pixels(size.width, size.height, is_opaque)) |
22 return bitmap; | 22 return bitmap; |
23 | 23 |
24 void* data = bitmap.getPixels(); | 24 void* data = bitmap.getPixels(); |
25 | 25 |
26 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple | 26 // Allocate a bitmap context with 4 components per pixel (BGRA). Apple |
27 // recommends these flags for improved CG performance. | 27 // recommends these flags for improved CG performance. |
28 #define HAS_ARGB_SHIFTS(a, r, g, b) \ | 28 #define HAS_ARGB_SHIFTS(a, r, g, b) \ |
29 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \ | 29 (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \ |
30 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b)) | 30 && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b)) |
31 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) | 31 #if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 if (!bitmap.empty()) | 92 if (!bitmap.empty()) |
93 frames.push_back(bitmap); | 93 frames.push_back(bitmap); |
94 } | 94 } |
95 | 95 |
96 DLOG_IF(WARNING, frames.size() != count) << "Only decoded " << frames.size() | 96 DLOG_IF(WARNING, frames.size() != count) << "Only decoded " << frames.size() |
97 << " frames for " << count << " expected."; | 97 << " frames for " << count << " expected."; |
98 return frames; | 98 return frames; |
99 } | 99 } |
100 | 100 |
101 } // namespace gfx | 101 } // namespace gfx |
OLD | NEW |