Commit 7d6cd2e1 authored by sail@chromium.org's avatar sail@chromium.org

Tab audio indicator: Use animation container on Mac

When showning an audio indicator on multiple tabs, the CPU usage on
my machine is:
  1 tab: 1.5%
  2 tab: 2.5%
  3 tab: 3.2%

This CL uses a common animation container for all tabs in a window.
This changes the CPU usage to:
  1 tab: 1.5%
  2 tab: 1.5%
  3 tab: 1.5%

BUG=3541

Review URL: https://chromiumcodereview.appspot.com/13867007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195059 0039d316-1c4b-4281-b951-d872f2087c98
parent 3a322274
......@@ -15,6 +15,9 @@ class WebContents;
}
class TabAudioIndicator;
class TabAudioIndicatorDelegateMac;
namespace ui {
class AnimationContainer;
}
// A view that draws an audio indicator on top of a favicon.
@interface TabAudioIndicatorViewMac : NSView {
......@@ -27,6 +30,8 @@ class TabAudioIndicatorDelegateMac;
- (void)setBackgroundImage:(NSImage*)backgroundImage;
- (void)setAnimationContainer:(ui::AnimationContainer*)animationContainer;
- (BOOL)isAnimating;
@end
......
......@@ -49,6 +49,10 @@ class TabAudioIndicatorDelegateMac : public TabAudioIndicator::Delegate {
tabAudioIndicator_->set_favicon(*image.ToImageSkia());
}
- (void)setAnimationContainer:(ui::AnimationContainer*)animationContainer {
tabAudioIndicator_->SetAnimationContainer(animationContainer);
}
- (BOOL)isAnimating {
return tabAudioIndicator_->IsAnimating();
}
......
......@@ -20,10 +20,12 @@
}
- (id)initWithFrame:(NSRect)rect
backgroundImage:(NSImage*)backgroundImage
projectorImage:(NSImage*)projectorImage
throbImage:(NSImage*)throbImage
durationMS:(int)durationMS;
backgroundImage:(NSImage*)backgroundImage
projectorImage:(NSImage*)projectorImage
throbImage:(NSImage*)throbImage
durationMS:(int)durationMS
animationContainer:(ui::AnimationContainer*)animationContainer;
@end
#endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_PROJECTING_IMAGE_VIEW_H_
......@@ -10,12 +10,14 @@
backgroundImage:(NSImage*)backgroundImage
projectorImage:(NSImage*)projectorImage
throbImage:(NSImage*)throbImage
durationMS:(int)durationMS {
durationMS:(int)durationMS
animationContainer:(ui::AnimationContainer*)animationContainer {
if ((self = [super initWithFrame:rect
backgroundImage:backgroundImage
throbImage:throbImage
durationMS:durationMS
throbPosition:kThrobPositionOverlay])) {
throbPosition:kThrobPositionOverlay
animationContainer:animationContainer])) {
projectorImage_.reset([projectorImage retain]);
}
return self;
......
......@@ -33,11 +33,12 @@ class TabProjectingImageViewTest : public CocoaTest {
[throbImage unlockFocus];
scoped_nsobject<TabProjectingImageView> view([[TabProjectingImageView alloc]
initWithFrame:NSMakeRect(0, 0, 32, 32)
backgroundImage:backgroundImage
projectorImage:projectorImage
throbImage:throbImage
durationMS:20]);
initWithFrame:NSMakeRect(0, 0, 32, 32)
backgroundImage:backgroundImage
projectorImage:projectorImage
throbImage:throbImage
durationMS:20
animationContainer:NULL]);
view_ = view.get();
[[test_window() contentView] addSubview:view_];
}
......
......@@ -27,6 +27,9 @@ class TabStripModel;
namespace content {
class WebContents;
}
namespace ui {
class AnimationContainer;
}
// The interface for the tab strip controller's delegate.
// Delegating TabStripModelObserverBridge's events (in lieu of directly
......@@ -138,6 +141,8 @@ class WebContents;
// Helper for performing tab selection as a result of dragging over a tab.
scoped_ptr<HoverTabSelector> hoverTabSelector_;
scoped_refptr<ui::AnimationContainer> animationContainer_;
}
@property(nonatomic) CGFloat leftIndentForControls;
......
......@@ -65,6 +65,7 @@
#include "grit/ui_resources.h"
#include "skia/ext/skia_utils_mac.h"
#import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h"
#import "ui/base/animation/animation_container.h"
#import "ui/base/cocoa/tracking_area.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/list_selection_model.h"
......@@ -500,6 +501,7 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) {
[[TabStripDragController alloc] initWithTabStripController:self]);
tabContentsArray_.reset([[NSMutableArray alloc] init]);
tabArray_.reset([[NSMutableArray alloc] init]);
animationContainer_ = new ui::AnimationContainer;
NSWindow* browserWindow = [view window];
// Important note: any non-tab subviews not added to |permanentSubviews_|
......@@ -1623,12 +1625,13 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) {
kProjectingIconWidthAndHeight,
kProjectingIconWidthAndHeight);
TabProjectingImageView* projectingView =
[[[TabProjectingImageView alloc] initWithFrame:frame
backgroundImage:[imageView image]
projectorImage:projector
throbImage:projectorGlow
durationMS:kRecordingDurationMs]
autorelease];
[[[TabProjectingImageView alloc]
initWithFrame:frame
backgroundImage:[imageView image]
projectorImage:projector
throbImage:projectorGlow
durationMS:kRecordingDurationMs
animationContainer:animationContainer_] autorelease];
iconView = projectingView;
} else if (theme && chrome::ShouldShowRecordingIndicator(contents)) {
......@@ -1646,7 +1649,8 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) {
backgroundImage:favIconMasked
throbImage:recording
durationMS:kRecordingDurationMs
throbPosition:kThrobPositionBottomRight] autorelease];
throbPosition:kThrobPositionBottomRight
animationContainer:animationContainer_] autorelease];
iconView = recordingView;
} else if (chrome::IsPlayingAudio(contents) ||
......@@ -1656,6 +1660,8 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) {
NSMakeRect(0, 0, kIconWidthAndHeight, kIconWidthAndHeight);
tabAudioIndicatorViewMac = [[[TabAudioIndicatorViewMac alloc]
initWithFrame:frame] autorelease];
[tabAudioIndicatorViewMac
setAnimationContainer:animationContainer_];
}
[tabAudioIndicatorViewMac
setIsPlayingAudio:chrome::IsPlayingAudio(contents)];
......
......@@ -33,10 +33,12 @@ enum ThrobPosition {
}
- (id)initWithFrame:(NSRect)rect
backgroundImage:(NSImage*)backgroundImage
throbImage:(NSImage*)throbImage
durationMS:(int)durationMS
throbPosition:(ThrobPosition)throbPosition;
backgroundImage:(NSImage*)backgroundImage
throbImage:(NSImage*)throbImage
durationMS:(int)durationMS
throbPosition:(ThrobPosition)throbPosition
animationContainer:(ui::AnimationContainer*)animationContainer;
@end
#endif // CHROME_BROWSER_UI_COCOA_TABS_THROBBING_IMAGE_VIEW_H_
......@@ -19,16 +19,18 @@ class ThrobbingImageViewAnimationDelegate : public ui::AnimationDelegate {
@implementation ThrobbingImageView
- (id)initWithFrame:(NSRect)rect
backgroundImage:(NSImage*)backgroundImage
throbImage:(NSImage*)throbImage
durationMS:(int)durationMS
throbPosition:(ThrobPosition)throbPosition {
backgroundImage:(NSImage*)backgroundImage
throbImage:(NSImage*)throbImage
durationMS:(int)durationMS
throbPosition:(ThrobPosition)throbPosition
animationContainer:(ui::AnimationContainer*)animationContainer {
if ((self = [super initWithFrame:rect])) {
backgroundImage_.reset([backgroundImage retain]);
throbImage_.reset([throbImage retain]);
delegate_.reset(new ThrobbingImageViewAnimationDelegate(self));
throbAnimation_.reset(new ui::ThrobAnimation(delegate_.get()));
throbAnimation_->SetContainer(animationContainer);
throbAnimation_->SetThrobDuration(durationMS);
throbAnimation_->StartThrobbing(-1);
......
......@@ -21,11 +21,12 @@ class ThrobbingImageViewTest : public CocoaTest {
[image unlockFocus];
scoped_nsobject<ThrobbingImageView> view([[ThrobbingImageView alloc]
initWithFrame:NSMakeRect(0, 0, 16, 16)
backgroundImage:image
throbImage:image
durationMS:20
throbPosition:kThrobPositionOverlay]);
initWithFrame:NSMakeRect(0, 0, 16, 16)
backgroundImage:image
throbImage:image
durationMS:20
throbPosition:kThrobPositionOverlay
animationContainer:NULL]);
view_ = view.get();
[[test_window() contentView] addSubview:view_];
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment