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

Unified Diff: skia/ext/skia_utils_ios.mm

Issue 2011713003: Roll skia to 8cc209111876b7c78b5ec577c9221d8ed5e21024 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « skia/ext/skia_utils_ios.h ('k') | skia/ext/skia_utils_ios_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/skia_utils_ios.mm
diff --git a/skia/ext/skia_utils_ios.mm b/skia/ext/skia_utils_ios.mm
deleted file mode 100644
index 5655d22a5627ef98a19b4d07739d2fa86447346d..0000000000000000000000000000000000000000
--- a/skia/ext/skia_utils_ios.mm
+++ /dev/null
@@ -1,126 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "skia/ext/skia_utils_ios.h"
-
-#import <ImageIO/ImageIO.h>
-#import <UIKit/UIKit.h>
-
-#include "base/ios/ios_util.h"
-#include "base/logging.h"
-#include "base/mac/scoped_cftyperef.h"
-#include "base/macros.h"
-#include "third_party/skia/include/utils/mac/SkCGUtils.h"
-
-namespace {
-
-const uint8 kICOHeaderMagic[4] = {0x00, 0x00, 0x01, 0x00};
-
-// Returns whether the data encodes an ico image.
-bool EncodesIcoImage(NSData* image_data) {
- if (image_data.length < arraysize(kICOHeaderMagic))
- return false;
- return memcmp(kICOHeaderMagic, image_data.bytes,
- arraysize(kICOHeaderMagic)) == 0;
-}
-
-} // namespace
-
-namespace gfx {
-
-SkBitmap CGImageToSkBitmap(CGImageRef image, CGSize size, bool is_opaque) {
- SkBitmap bitmap;
- if (!image)
- return bitmap;
-
- if (!bitmap.tryAllocN32Pixels(size.width, size.height, is_opaque))
- return bitmap;
-
- void* data = bitmap.getPixels();
-
- // Allocate a bitmap context with 4 components per pixel (BGRA). Apple
- // recommends these flags for improved CG performance.
-#define HAS_ARGB_SHIFTS(a, r, g, b) \
- (SK_A32_SHIFT == (a) && SK_R32_SHIFT == (r) \
- && SK_G32_SHIFT == (g) && SK_B32_SHIFT == (b))
-#if defined(SK_CPU_LENDIAN) && HAS_ARGB_SHIFTS(24, 16, 8, 0)
- base::ScopedCFTypeRef<CGColorSpaceRef> color_space(
- CGColorSpaceCreateDeviceRGB());
- base::ScopedCFTypeRef<CGContextRef> context(CGBitmapContextCreate(
- data,
- size.width,
- size.height,
- 8,
- size.width * 4,
- color_space,
- kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
-#else
-#error We require that Skia's and CoreGraphics's recommended \
- image memory layout match.
-#endif
-#undef HAS_ARGB_SHIFTS
-
- DCHECK(context);
- if (!context)
- return bitmap;
-
- CGRect imageRect = CGRectMake(0.0, 0.0, size.width, size.height);
- CGContextSetBlendMode(context, kCGBlendModeCopy);
- CGContextDrawImage(context, imageRect, image);
-
- return bitmap;
-}
-
-UIImage* SkBitmapToUIImageWithColorSpace(const SkBitmap& skia_bitmap,
- CGFloat scale,
- CGColorSpaceRef color_space) {
- if (skia_bitmap.isNull())
- return nil;
-
- // First convert SkBitmap to CGImageRef.
- base::ScopedCFTypeRef<CGImageRef> cg_image(
- SkCreateCGImageRefWithColorspace(skia_bitmap, color_space));
-
- // Now convert to UIImage.
- return [UIImage imageWithCGImage:cg_image.get()
- scale:scale
- orientation:UIImageOrientationUp];
-}
-
-std::vector<SkBitmap> ImageDataToSkBitmaps(NSData* image_data) {
- DCHECK(image_data);
-
- // On iOS 8.1.1 |CGContextDrawImage| crashes when processing images included
- // in .ico files that are 88x88 pixels or larger (http://crbug.com/435068).
- bool skip_images_88x88_or_larger =
- base::ios::IsRunningOnOrLater(8, 1, 1) && EncodesIcoImage(image_data);
-
- base::ScopedCFTypeRef<CFDictionaryRef> empty_dictionary(
- CFDictionaryCreate(NULL, NULL, NULL, 0, NULL, NULL));
- std::vector<SkBitmap> frames;
-
- base::ScopedCFTypeRef<CGImageSourceRef> source(
- CGImageSourceCreateWithData((CFDataRef)image_data, empty_dictionary));
-
- size_t count = CGImageSourceGetCount(source);
- for (size_t index = 0; index < count; ++index) {
- base::ScopedCFTypeRef<CGImageRef> cg_image(
- CGImageSourceCreateImageAtIndex(source, index, empty_dictionary));
-
- CGSize size = CGSizeMake(CGImageGetWidth(cg_image),
- CGImageGetHeight(cg_image));
- if (size.width >= 88 && size.height >= 88 && skip_images_88x88_or_larger)
- continue;
-
- const SkBitmap bitmap = CGImageToSkBitmap(cg_image, size, false);
- if (!bitmap.empty())
- frames.push_back(bitmap);
- }
-
- DLOG_IF(WARNING, frames.size() != count) << "Only decoded " << frames.size()
- << " frames for " << count << " expected.";
- return frames;
-}
-
-} // namespace gfx
« no previous file with comments | « skia/ext/skia_utils_ios.h ('k') | skia/ext/skia_utils_ios_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698