Chromium Code Reviews| 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" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 scoped_nsobject<NSBitmapImageRep> bitmap( | 228 scoped_nsobject<NSBitmapImageRep> bitmap( |
| 229 [[NSBitmapImageRep alloc] initWithCGImage:cgimage]); | 229 [[NSBitmapImageRep alloc] initWithCGImage:cgimage]); |
| 230 return [bitmap.release() autorelease]; | 230 return [bitmap.release() autorelease]; |
| 231 } | 231 } |
| 232 | 232 |
| 233 NSImage* SkBitmapToNSImageWithColorSpace(const SkBitmap& skiaBitmap, | 233 NSImage* SkBitmapToNSImageWithColorSpace(const SkBitmap& skiaBitmap, |
| 234 CGColorSpaceRef colorSpace) { | 234 CGColorSpaceRef colorSpace) { |
| 235 if (skiaBitmap.isNull()) | 235 if (skiaBitmap.isNull()) |
| 236 return nil; | 236 return nil; |
| 237 | 237 |
| 238 // First convert SkBitmap to CGImageRef. | |
| 239 base::mac::ScopedCFTypeRef<CGImageRef> cgimage( | |
| 240 SkCreateCGImageRefWithColorspace(skiaBitmap, colorSpace)); | |
| 241 | |
| 242 // Now convert to NSImage. | |
| 243 scoped_nsobject<NSBitmapImageRep> bitmap( | |
| 244 [[NSBitmapImageRep alloc] initWithCGImage:cgimage]); | |
| 245 scoped_nsobject<NSImage> image([[NSImage alloc] init]); | 238 scoped_nsobject<NSImage> image([[NSImage alloc] init]); |
| 246 [image addRepresentation:bitmap]; | 239 [image addRepresentation: |
| 240 SkBitmapToNSBitmapImageRepWithColorSpace(skiaBitmap, colorSpace)]; | |
|
Avi (use Gerrit)
2012/12/14 21:46:26
Nice change, but I'm not sure how it relates to cu
Nico
2012/12/14 21:49:37
I was reading this file while working on this chan
| |
| 247 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; | 241 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; |
| 248 return [image.release() autorelease]; | 242 return [image.release() autorelease]; |
| 249 } | 243 } |
| 250 | 244 |
| 251 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { | 245 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { |
| 252 base::mac::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( | 246 base::mac::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( |
| 253 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); | 247 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); |
| 254 return SkBitmapToNSImageWithColorSpace(skiaBitmap, colorSpace.get()); | 248 return SkBitmapToNSImageWithColorSpace(skiaBitmap, colorSpace.get()); |
| 255 } | 249 } |
| 256 | 250 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 // Apply content matrix. | 403 // Apply content matrix. |
| 410 SkMatrix skMatrix = canvas_->getTotalMatrix(); | 404 SkMatrix skMatrix = canvas_->getTotalMatrix(); |
| 411 skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY)); | 405 skMatrix.postTranslate(-SkIntToScalar(pt.fX), -SkIntToScalar(pt.fY)); |
| 412 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); | 406 CGAffineTransform affine = SkMatrixToCGAffineTransform(skMatrix); |
| 413 CGContextConcatCTM(cgContext_, affine); | 407 CGContextConcatCTM(cgContext_, affine); |
| 414 | 408 |
| 415 return cgContext_; | 409 return cgContext_; |
| 416 } | 410 } |
| 417 | 411 |
| 418 } // namespace gfx | 412 } // namespace gfx |
| OLD | NEW |