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

Side by Side Diff: base/mac_util.mm

Issue 3072005: Move NSImage-to-CGImageRef conversion code into a common helper function in base/mac_util.h. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Fix test Created 10 years, 4 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 unified diff | Download patch
« no previous file with comments | « base/mac_util.h ('k') | base/mac_util_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « base/mac_util.h ('k') | base/mac_util_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698