| 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 #import "chrome/browser/cocoa/animatable_image.h" | 5 #import "chrome/browser/cocoa/animatable_image.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac_util.h" |
| 8 #include "base/scoped_cftyperef.h" | 9 #include "base/scoped_cftyperef.h" |
| 9 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 10 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
| 10 | 11 |
| 11 @interface AnimatableImage (Private) | 12 @interface AnimatableImage (Private) |
| 12 - (void)setLayerContents:(CALayer*)layer; | 13 - (void)setLayerContents:(CALayer*)layer; |
| 13 @end | 14 @end |
| 14 | 15 |
| 15 @implementation AnimatableImage | 16 @implementation AnimatableImage |
| 16 | 17 |
| 17 @synthesize startFrame = startFrame_; | 18 @synthesize startFrame = startFrame_; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 [layer addAnimation:positionAnimation forKey:@"position"]; | 125 [layer addAnimation:positionAnimation forKey:@"position"]; |
| 125 [layer addAnimation:opacityAnimation forKey:@"opacity"]; | 126 [layer addAnimation:opacityAnimation forKey:@"opacity"]; |
| 126 [CATransaction commit]; | 127 [CATransaction commit]; |
| 127 } | 128 } |
| 128 | 129 |
| 129 // CALayer expects a CGImageRef contents. If the image is a PDF, 10.5 CGImage | 130 // CALayer expects a CGImageRef contents. If the image is a PDF, 10.5 CGImage |
| 130 // cannot handle the conversion to bitmap. To get it to work, rasterize the | 131 // cannot handle the conversion to bitmap. To get it to work, rasterize the |
| 131 // image into a bitmap CGImageRef. This is based loosely on | 132 // image into a bitmap CGImageRef. This is based loosely on |
| 132 // http://www.cocoadev.com/index.pl?CGImageRef. | 133 // http://www.cocoadev.com/index.pl?CGImageRef. |
| 133 - (void)setLayerContents:(CALayer*)layer { | 134 - (void)setLayerContents:(CALayer*)layer { |
| 134 NSSize size = [image_ size]; | 135 scoped_cftyperef<CGImageRef> image( |
| 135 CGContextRef context = | 136 mac_util::CopyNSImageToCGImage(image_.get())); |
| 136 CGBitmapContextCreate(NULL, // Allow CG to allocate memory. | |
| 137 size.width, | |
| 138 size.height, | |
| 139 8, // bitsPerComponent | |
| 140 0, // bytesPerRow - CG will calculate by default. | |
| 141 [[NSColorSpace genericRGBColorSpace] CGColorSpace], | |
| 142 kCGBitmapByteOrder32Host | | |
| 143 kCGImageAlphaPremultipliedFirst); | |
| 144 | |
| 145 [NSGraphicsContext saveGraphicsState]; | |
| 146 [NSGraphicsContext setCurrentContext: | |
| 147 [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO]]; | |
| 148 [image_ drawInRect:NSMakeRect(0,0, size.width, size.height) | |
| 149 fromRect:NSZeroRect | |
| 150 operation:NSCompositeCopy | |
| 151 fraction:1.0]; | |
| 152 [NSGraphicsContext restoreGraphicsState]; | |
| 153 | |
| 154 scoped_cftyperef<CGImageRef> cgImage(CGBitmapContextCreateImage(context)); | |
| 155 CGContextRelease(context); | |
| 156 | |
| 157 // Create the layer that will be animated. | 137 // Create the layer that will be animated. |
| 158 [layer setContents:(id)cgImage.get()]; | 138 [layer setContents:(id)image.get()]; |
| 159 } | 139 } |
| 160 | 140 |
| 161 // CAAnimation delegate method called when the animation is complete. | 141 // CAAnimation delegate method called when the animation is complete. |
| 162 - (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)flag { | 142 - (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)flag { |
| 163 // Close the window, releasing self. | 143 // Close the window, releasing self. |
| 164 [self close]; | 144 [self close]; |
| 165 } | 145 } |
| 166 | 146 |
| 167 @end | 147 @end |
| OLD | NEW |