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

Side by Side Diff: skia/ext/skia_utils_ios.mm

Issue 960873002: Update from https://crrev.com/318214 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 | « skia/config/SkUserConfig.h ('k') | skia/ext/skia_utils_ios_unittest.mm » ('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 "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/ios/ios_util.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_cftyperef.h"
13 #include "base/macros.h"
12 #include "third_party/skia/include/utils/mac/SkCGUtils.h" 14 #include "third_party/skia/include/utils/mac/SkCGUtils.h"
13 15
16 namespace {
17
18 const uint8 kICOHeaderMagic[4] = {0x00, 0x00, 0x01, 0x00};
19
20 // Returns whether the data encodes an ico image.
21 bool EncodesIcoImage(NSData* image_data) {
22 if (image_data.length < arraysize(kICOHeaderMagic))
23 return false;
24 return memcmp(kICOHeaderMagic, image_data.bytes,
25 arraysize(kICOHeaderMagic)) == 0;
26 }
27
28 } // namespace
29
14 namespace gfx { 30 namespace gfx {
15 31
16 SkBitmap CGImageToSkBitmap(CGImageRef image, CGSize size, bool is_opaque) { 32 SkBitmap CGImageToSkBitmap(CGImageRef image, CGSize size, bool is_opaque) {
17 SkBitmap bitmap; 33 SkBitmap bitmap;
18 if (!image) 34 if (!image)
19 return bitmap; 35 return bitmap;
20 36
21 if (!bitmap.tryAllocN32Pixels(size.width, size.height, is_opaque)) 37 if (!bitmap.tryAllocN32Pixels(size.width, size.height, is_opaque))
22 return bitmap; 38 return bitmap;
23 39
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 SkCreateCGImageRefWithColorspace(skia_bitmap, color_space)); 83 SkCreateCGImageRefWithColorspace(skia_bitmap, color_space));
68 84
69 // Now convert to UIImage. 85 // Now convert to UIImage.
70 return [UIImage imageWithCGImage:cg_image.get() 86 return [UIImage imageWithCGImage:cg_image.get()
71 scale:scale 87 scale:scale
72 orientation:UIImageOrientationUp]; 88 orientation:UIImageOrientationUp];
73 } 89 }
74 90
75 std::vector<SkBitmap> ImageDataToSkBitmaps(NSData* image_data) { 91 std::vector<SkBitmap> ImageDataToSkBitmaps(NSData* image_data) {
76 DCHECK(image_data); 92 DCHECK(image_data);
93
94 // On iOS 8.1.1 |CGContextDrawImage| crashes when processing images included
95 // in .ico files that are 88x88 pixels or larger (http://crbug.com/435068).
96 bool skip_images_88x88_or_larger =
97 base::ios::IsRunningOnOrLater(8, 1, 1) && EncodesIcoImage(image_data);
98
77 base::ScopedCFTypeRef<CFDictionaryRef> empty_dictionary( 99 base::ScopedCFTypeRef<CFDictionaryRef> empty_dictionary(
78 CFDictionaryCreate(NULL, NULL, NULL, 0, NULL, NULL)); 100 CFDictionaryCreate(NULL, NULL, NULL, 0, NULL, NULL));
79 std::vector<SkBitmap> frames; 101 std::vector<SkBitmap> frames;
80 102
81 base::ScopedCFTypeRef<CGImageSourceRef> source( 103 base::ScopedCFTypeRef<CGImageSourceRef> source(
82 CGImageSourceCreateWithData((CFDataRef)image_data, empty_dictionary)); 104 CGImageSourceCreateWithData((CFDataRef)image_data, empty_dictionary));
83 105
84 size_t count = CGImageSourceGetCount(source); 106 size_t count = CGImageSourceGetCount(source);
85 for (size_t index = 0; index < count; ++index) { 107 for (size_t index = 0; index < count; ++index) {
86 base::ScopedCFTypeRef<CGImageRef> cg_image( 108 base::ScopedCFTypeRef<CGImageRef> cg_image(
87 CGImageSourceCreateImageAtIndex(source, index, empty_dictionary)); 109 CGImageSourceCreateImageAtIndex(source, index, empty_dictionary));
88 110
89 CGSize size = CGSizeMake(CGImageGetWidth(cg_image), 111 CGSize size = CGSizeMake(CGImageGetWidth(cg_image),
90 CGImageGetHeight(cg_image)); 112 CGImageGetHeight(cg_image));
113 if (size.width >= 88 && size.height >= 88 && skip_images_88x88_or_larger)
114 continue;
115
91 const SkBitmap bitmap = CGImageToSkBitmap(cg_image, size, false); 116 const SkBitmap bitmap = CGImageToSkBitmap(cg_image, size, false);
92 if (!bitmap.empty()) 117 if (!bitmap.empty())
93 frames.push_back(bitmap); 118 frames.push_back(bitmap);
94 } 119 }
95 120
96 DLOG_IF(WARNING, frames.size() != count) << "Only decoded " << frames.size() 121 DLOG_IF(WARNING, frames.size() != count) << "Only decoded " << frames.size()
97 << " frames for " << count << " expected."; 122 << " frames for " << count << " expected.";
98 return frames; 123 return frames;
99 } 124 }
100 125
101 } // namespace gfx 126 } // namespace gfx
OLDNEW
« no previous file with comments | « skia/config/SkUserConfig.h ('k') | skia/ext/skia_utils_ios_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698