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

Side by Side Diff: chrome/browser/cocoa/throbber_view.mm

Issue 171110: Essentially revert r16636. We get no speedup from using CIImage and we are su... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/throbber_view.h" 5 #import "chrome/browser/cocoa/throbber_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 static const float kAnimationIntervalSeconds = 0.03; // 30ms, same as windows 9 static const float kAnimationIntervalSeconds = 0.03; // 30ms, same as windows
10 10
11 @interface ThrobberView(PrivateMethods) 11 @interface ThrobberView(PrivateMethods)
12 - (id)initWithFrame:(NSRect)frame delegate:(id<ThrobberDataDelegate>)delegate; 12 - (id)initWithFrame:(NSRect)frame delegate:(id<ThrobberDataDelegate>)delegate;
13 - (void)animate; 13 - (void)animate;
14 @end 14 @end
15 15
16 @protocol ThrobberDataDelegate <NSObject> 16 @protocol ThrobberDataDelegate <NSObject>
17 // Is the current frame the last frame of the animation? 17 // Is the current frame the last frame of the animation?
18 - (BOOL)animationIsComplete; 18 - (BOOL)animationIsComplete;
19 19
20 // Draw the current frame into the current graphics context. 20 // Draw the current frame into the current graphics context.
21 - (void)drawFrameInRect:(NSRect)rect; 21 - (void)drawFrameInRect:(NSRect)rect;
22 22
23 // Update the frame counter. 23 // Update the frame counter.
24 - (void)advanceFrame; 24 - (void)advanceFrame;
25 @end 25 @end
26 26
27 @interface ThrobberFilmstripDelegate : NSObject 27 @interface ThrobberFilmstripDelegate : NSObject
28 <ThrobberDataDelegate> { 28 <ThrobberDataDelegate> {
29 scoped_nsobject<CIImage> image_; 29 scoped_nsobject<NSImage> image_;
30 unsigned int numFrames_; // Number of frames in this animation. 30 unsigned int numFrames_; // Number of frames in this animation.
31 unsigned int animationFrame_; // Current frame of the animation, 31 unsigned int animationFrame_; // Current frame of the animation,
32 // [0..numFrames_) 32 // [0..numFrames_)
33 } 33 }
34 34
35 - (id)initWithImage:(NSImage*)image; 35 - (id)initWithImage:(NSImage*)image;
36 36
37 @end 37 @end
38 38
39 @implementation ThrobberFilmstripDelegate 39 @implementation ThrobberFilmstripDelegate
40 40
41 // Stores the internal representation of the image from |image|. We use 41 // Stores the internal representation of the image from |image|. We use
42 // CoreImage for speed (though this doesn't seem to help perf issues). We 42 // CoreImage for speed (though this doesn't seem to help perf issues). We
43 // validate that the image is of the appropriate ratio. 43 // validate that the image is of the appropriate ratio.
44 - (id)initWithImage:(NSImage*)image { 44 - (id)initWithImage:(NSImage*)image {
45 if ((self = [super init])) { 45 if ((self = [super init])) {
46 // Reset the animation counter so there's no chance we are off the end. 46 // Reset the animation counter so there's no chance we are off the end.
47 animationFrame_ = 0; 47 animationFrame_ = 0;
48 48
49 // Ensure that the height divides evenly into the width. Cache the 49 // Ensure that the height divides evenly into the width. Cache the
50 // number of frames in the animation for later. 50 // number of frames in the animation for later.
51 NSSize imageSize = [image size]; 51 NSSize imageSize = [image size];
52 DCHECK(imageSize.height && imageSize.width); 52 DCHECK(imageSize.height && imageSize.width);
53 if (!imageSize.height) 53 if (!imageSize.height)
54 return nil; 54 return nil;
55 DCHECK((int)imageSize.width % (int)imageSize.height == 0); 55 DCHECK((int)imageSize.width % (int)imageSize.height == 0);
56 numFrames_ = (int)imageSize.width / (int)imageSize.height; 56 numFrames_ = (int)imageSize.width / (int)imageSize.height;
57 DCHECK(numFrames_); 57 DCHECK(numFrames_);
58 58 image_.reset([image retain]);
59 // First check if we have a bitmap image rep and use it, otherwise fall
60 // back to creating one.
61 NSBitmapImageRep* rep = [[image representations] objectAtIndex:0];
62 if (![rep isKindOfClass:[NSBitmapImageRep class]]) {
63 [image lockFocus];
64 NSRect imageRect = NSMakeRect(0, 0, imageSize.width, imageSize.height);
65 rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:imageRect]
66 autorelease];
67 [image unlockFocus];
68 }
69 image_.reset([[CIImage alloc] initWithBitmapImageRep:rep]);
70 } 59 }
71 return self; 60 return self;
72 } 61 }
73 62
74 - (BOOL)animationIsComplete { 63 - (BOOL)animationIsComplete {
75 return NO; 64 return NO;
76 } 65 }
77 66
78 - (void)drawFrameInRect:(NSRect)rect { 67 - (void)drawFrameInRect:(NSRect)rect {
79 float imageDimension = [image_ extent].size.height; 68 float imageDimension = [image_ size].height;
80 float xOffset = animationFrame_ * imageDimension; 69 float xOffset = animationFrame_ * imageDimension;
81 NSRect sourceImageRect = 70 NSRect sourceImageRect =
82 NSMakeRect(xOffset, 0, imageDimension, imageDimension); 71 NSMakeRect(xOffset, 0, imageDimension, imageDimension);
83 [image_ drawInRect:rect 72 [image_ drawInRect:rect
84 fromRect:sourceImageRect 73 fromRect:sourceImageRect
85 operation:NSCompositeSourceOver 74 operation:NSCompositeSourceOver
86 fraction:1.0]; 75 fraction:1.0];
87 } 76 }
88 77
89 - (void)advanceFrame { 78 - (void)advanceFrame {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 timer_ = nil; 242 timer_ = nil;
254 } 243 }
255 } 244 }
256 245
257 // Overridden to draw the appropriate frame in the image strip. 246 // Overridden to draw the appropriate frame in the image strip.
258 - (void)drawRect:(NSRect)rect { 247 - (void)drawRect:(NSRect)rect {
259 [dataDelegate_ drawFrameInRect:[self bounds]]; 248 [dataDelegate_ drawFrameInRect:[self bounds]];
260 } 249 }
261 250
262 @end 251 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698