OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/mac_util.h" | 5 #include "base/mac_util.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 // Constant used by WebKit; what exactly it means is unknown. | 472 // Constant used by WebKit; what exactly it means is unknown. |
473 const int magic_session_constant = -2; | 473 const int magic_session_constant = -2; |
474 OSErr err = | 474 OSErr err = |
475 ls_set_application_information_item_func(magic_session_constant, asn, | 475 ls_set_application_information_item_func(magic_session_constant, asn, |
476 ls_display_name_key, | 476 ls_display_name_key, |
477 process_name, | 477 process_name, |
478 NULL /* optional out param */); | 478 NULL /* optional out param */); |
479 LOG_IF(ERROR, err) << "Call to set process name failed, err " << err; | 479 LOG_IF(ERROR, err) << "Call to set process name failed, err " << err; |
480 } | 480 } |
481 | 481 |
| 482 // Converts a NSImage to a CGImageRef. Normally, the system frameworks can do |
| 483 // this fine, especially on 10.6. On 10.5, however, CGImage cannot handle |
| 484 // converting a PDF-backed NSImage into a CGImageRef. This function will |
| 485 // rasterize the PDF into a bitmap CGImage. The caller is responsible for |
| 486 // releasing the return value. |
| 487 CGImageRef CopyNSImageToCGImage(NSImage* image) { |
| 488 // This is based loosely on http://www.cocoadev.com/index.pl?CGImageRef . |
| 489 NSSize size = [image size]; |
| 490 scoped_cftyperef<CGContextRef> context( |
| 491 CGBitmapContextCreate(NULL, // Allow CG to allocate memory. |
| 492 size.width, |
| 493 size.height, |
| 494 8, // bitsPerComponent |
| 495 0, // bytesPerRow - CG will calculate by default. |
| 496 [[NSColorSpace genericRGBColorSpace] CGColorSpace], |
| 497 kCGBitmapByteOrder32Host | |
| 498 kCGImageAlphaPremultipliedFirst)); |
| 499 if (!context.get()) |
| 500 return NULL; |
| 501 |
| 502 [NSGraphicsContext saveGraphicsState]; |
| 503 [NSGraphicsContext setCurrentContext: |
| 504 [NSGraphicsContext graphicsContextWithGraphicsPort:context.get() |
| 505 flipped:NO]]; |
| 506 [image drawInRect:NSMakeRect(0,0, size.width, size.height) |
| 507 fromRect:NSZeroRect |
| 508 operation:NSCompositeCopy |
| 509 fraction:1.0]; |
| 510 [NSGraphicsContext restoreGraphicsState]; |
| 511 |
| 512 return CGBitmapContextCreateImage(context); |
| 513 } |
| 514 |
482 } // namespace mac_util | 515 } // namespace mac_util |
OLD | NEW |