| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/scoped_cftyperef.h" | 10 #include "base/scoped_cftyperef.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "skia/ext/bitmap_platform_device_mac.h" | 12 #include "skia/ext/bitmap_platform_device_mac.h" |
| 13 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
| 13 | 14 |
| 14 namespace gfx { | 15 namespace gfx { |
| 15 | 16 |
| 16 CGAffineTransform SkMatrixToCGAffineTransform(const SkMatrix& matrix) { | 17 CGAffineTransform SkMatrixToCGAffineTransform(const SkMatrix& matrix) { |
| 17 // CGAffineTransforms don't support perspective transforms, so make sure | 18 // CGAffineTransforms don't support perspective transforms, so make sure |
| 18 // we don't get those. | 19 // we don't get those. |
| 19 DCHECK(matrix[SkMatrix::kMPersp0] == 0.0f); | 20 DCHECK(matrix[SkMatrix::kMPersp0] == 0.0f); |
| 20 DCHECK(matrix[SkMatrix::kMPersp1] == 0.0f); | 21 DCHECK(matrix[SkMatrix::kMPersp1] == 0.0f); |
| 21 DCHECK(matrix[SkMatrix::kMPersp2] == 1.0f); | 22 DCHECK(matrix[SkMatrix::kMPersp2] == 1.0f); |
| 22 | 23 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 fromRect:NSZeroRect | 159 fromRect:NSZeroRect |
| 159 operation:NSCompositeCopy | 160 operation:NSCompositeCopy |
| 160 fraction:1.0]; | 161 fraction:1.0]; |
| 161 | 162 |
| 162 // Done drawing, restore context. | 163 // Done drawing, restore context. |
| 163 [NSGraphicsContext setCurrentContext:current_context]; | 164 [NSGraphicsContext setCurrentContext:current_context]; |
| 164 | 165 |
| 165 return bitmap; | 166 return bitmap; |
| 166 } | 167 } |
| 167 | 168 |
| 169 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { |
| 170 // First convert SkBitmap to CGImageRef. |
| 171 CGImageRef cgimage = SkCreateCGImageRef(skiaBitmap); |
| 172 |
| 173 // Now convert to NSImage. |
| 174 NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc] |
| 175 initWithCGImage:cgimage] autorelease]; |
| 176 CFRelease(cgimage); |
| 177 NSImage* image = [[[NSImage alloc] init] autorelease]; |
| 178 [image addRepresentation:bitmap]; |
| 179 return image; |
| 180 } |
| 181 |
| 168 } // namespace gfx | 182 } // namespace gfx |
| OLD | NEW |