OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_mac.h" | 5 #include "skia/ext/skia_utils_mac.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
11 #include "base/memory/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "skia/ext/bitmap_platform_device_mac.h" | 13 #include "skia/ext/bitmap_platform_device_mac.h" |
14 #include "third_party/skia/include/core/SkRegion.h" | 14 #include "third_party/skia/include/core/SkRegion.h" |
15 #include "third_party/skia/include/utils/mac/SkCGUtils.h" | 15 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Draws an NSImage or an NSImageRep with a given size into a SkBitmap. | 19 // Draws an NSImage or an NSImageRep with a given size into a SkBitmap. |
20 SkBitmap NSImageOrNSImageRepToSkBitmap( | 20 SkBitmap NSImageOrNSImageRepToSkBitmap( |
21 NSImage* image, | 21 NSImage* image, |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 221 } |
222 | 222 |
223 NSBitmapImageRep* SkBitmapToNSBitmapImageRepWithColorSpace( | 223 NSBitmapImageRep* SkBitmapToNSBitmapImageRepWithColorSpace( |
224 const SkBitmap& skiaBitmap, | 224 const SkBitmap& skiaBitmap, |
225 CGColorSpaceRef colorSpace) { | 225 CGColorSpaceRef colorSpace) { |
226 // First convert SkBitmap to CGImageRef. | 226 // First convert SkBitmap to CGImageRef. |
227 base::ScopedCFTypeRef<CGImageRef> cgimage( | 227 base::ScopedCFTypeRef<CGImageRef> cgimage( |
228 SkCreateCGImageRefWithColorspace(skiaBitmap, colorSpace)); | 228 SkCreateCGImageRefWithColorspace(skiaBitmap, colorSpace)); |
229 | 229 |
230 // Now convert to NSBitmapImageRep. | 230 // Now convert to NSBitmapImageRep. |
231 scoped_nsobject<NSBitmapImageRep> bitmap( | 231 base::scoped_nsobject<NSBitmapImageRep> bitmap( |
232 [[NSBitmapImageRep alloc] initWithCGImage:cgimage]); | 232 [[NSBitmapImageRep alloc] initWithCGImage:cgimage]); |
233 return [bitmap.release() autorelease]; | 233 return [bitmap.release() autorelease]; |
234 } | 234 } |
235 | 235 |
236 NSImage* SkBitmapToNSImageWithColorSpace(const SkBitmap& skiaBitmap, | 236 NSImage* SkBitmapToNSImageWithColorSpace(const SkBitmap& skiaBitmap, |
237 CGColorSpaceRef colorSpace) { | 237 CGColorSpaceRef colorSpace) { |
238 if (skiaBitmap.isNull()) | 238 if (skiaBitmap.isNull()) |
239 return nil; | 239 return nil; |
240 | 240 |
241 scoped_nsobject<NSImage> image([[NSImage alloc] init]); | 241 base::scoped_nsobject<NSImage> image([[NSImage alloc] init]); |
242 [image addRepresentation: | 242 [image addRepresentation: |
243 SkBitmapToNSBitmapImageRepWithColorSpace(skiaBitmap, colorSpace)]; | 243 SkBitmapToNSBitmapImageRepWithColorSpace(skiaBitmap, colorSpace)]; |
244 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; | 244 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; |
245 return [image.release() autorelease]; | 245 return [image.release() autorelease]; |
246 } | 246 } |
247 | 247 |
248 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { | 248 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { |
249 base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( | 249 base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( |
250 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); | 250 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); |
251 return SkBitmapToNSImageWithColorSpace(skiaBitmap, colorSpace.get()); | 251 return SkBitmapToNSImageWithColorSpace(skiaBitmap, colorSpace.get()); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 // Apply content matrix. | 408 // Apply content matrix. |
409 SkMatrix skMatrix = canvas_->getTotalMatrix(); | 409 SkMatrix skMatrix = canvas_->getTotalMatrix(); |
410 skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY)); | 410 skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY)); |
411 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); | 411 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); |
412 CGContextConcatCTM(cgContext_, affine); | 412 CGContextConcatCTM(cgContext_, affine); |
413 | 413 |
414 return cgContext_; | 414 return cgContext_; |
415 } | 415 } |
416 | 416 |
417 } // namespace gfx | 417 } // namespace gfx |
OLD | NEW |