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

Side by Side Diff: chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.mm

Issue 244043002: CoreAnimation: Reduce VA usage by extra layers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add disabler Created 6 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/cocoa/tab_contents/tab_contents_controller.h" 5 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h"
9 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
10 #include "chrome/browser/devtools/devtools_window.h" 11 #include "chrome/browser/devtools/devtools_window.h"
11 #import "chrome/browser/themes/theme_properties.h" 12 #import "chrome/browser/themes/theme_properties.h"
12 #import "chrome/browser/themes/theme_service.h" 13 #import "chrome/browser/themes/theme_service.h"
13 #import "chrome/browser/ui/cocoa/themed_window.h" 14 #import "chrome/browser/ui/cocoa/themed_window.h"
14 #include "content/public/browser/render_view_host.h" 15 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/render_widget_host_view.h" 16 #include "content/public/browser/render_widget_host_view.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_observer.h" 18 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/browser/web_contents_view.h" 19 #include "content/public/browser/web_contents_view.h"
20 #include "ui/base/cocoa/animation_utils.h"
21 #include "ui/base/ui_base_switches.h"
19 #include "ui/gfx/geometry/rect.h" 22 #include "ui/gfx/geometry/rect.h"
20 23
21 using content::WebContents; 24 using content::WebContents;
22 using content::WebContentsObserver; 25 using content::WebContentsObserver;
23 26
24 // FullscreenObserver is used by TabContentsController to monitor for the 27 // FullscreenObserver is used by TabContentsController to monitor for the
25 // showing/destruction of fullscreen render widgets. When notified, 28 // showing/destruction of fullscreen render widgets. When notified,
26 // TabContentsController will alter its child view hierarchy to either embed a 29 // TabContentsController will alter its child view hierarchy to either embed a
27 // fullscreen render widget view or restore the normal WebContentsView render 30 // fullscreen render widget view or restore the normal WebContentsView render
28 // view. The embedded fullscreen render widget will fill the user's screen in 31 // view. The embedded fullscreen render widget will fill the user's screen in
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 - (NSRect)frameForContentsView; 69 - (NSRect)frameForContentsView;
67 @end 70 @end
68 71
69 // An NSView with special-case handling for when the contents view does not 72 // An NSView with special-case handling for when the contents view does not
70 // expand to fill the entire tab contents area. See 'AutoEmbedFullscreen mode' 73 // expand to fill the entire tab contents area. See 'AutoEmbedFullscreen mode'
71 // in header file comments. 74 // in header file comments.
72 @interface TabContentsContainerView : NSView { 75 @interface TabContentsContainerView : NSView {
73 @private 76 @private
74 TabContentsController* delegate_; // weak 77 TabContentsController* delegate_; // weak
75 } 78 }
79
80 - (NSColor*)computeBackgroundColor;
76 @end 81 @end
77 82
78 @implementation TabContentsContainerView 83 @implementation TabContentsContainerView
79 84
80 - (id)initWithDelegate:(TabContentsController*)delegate { 85 - (id)initWithDelegate:(TabContentsController*)delegate {
81 if ((self = [super initWithFrame:NSZeroRect])) { 86 if ((self = [super initWithFrame:NSZeroRect])) {
82 delegate_ = delegate; 87 delegate_ = delegate;
88 if (!CommandLine::ForCurrentProcess()->HasSwitch(
89 switches::kDisableCoreAnimation)) {
90 ScopedCAActionDisabler disabler;
91 base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]);
92 [layer setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
93 [self setLayer:layer];
94 [self setWantsLayer:YES];
95 }
83 } 96 }
84 return self; 97 return self;
85 } 98 }
86 99
87 // Called by the delegate during dealloc to invalidate the pointer held by this 100 // Called by the delegate during dealloc to invalidate the pointer held by this
88 // view. 101 // view.
89 - (void)delegateDestroyed { 102 - (void)delegateDestroyed {
90 delegate_ = nil; 103 delegate_ = nil;
91 } 104 }
92 105
106 // Fill with a dark tint of the new tab page's background color. This is
107 // only seen when the subview is sized specially for fullscreen tab capture.
108 - (NSColor*)computeBackgroundColor {
109 NSColor* bgColor = nil;
110 ThemeService* const theme =
111 static_cast<ThemeService*>([[self window] themeProvider]);
112 if (theme)
113 bgColor = theme->GetNSColor(ThemeProperties::COLOR_NTP_BACKGROUND);
114 if (!bgColor)
115 bgColor = [[self window] backgroundColor];
116 const float kDarknessFraction = 0.80f;
117 return [bgColor blendedColorWithFraction:kDarknessFraction
118 ofColor:[NSColor blackColor]];
119 }
120
93 // Override -drawRect to fill the view with a solid color outside of the 121 // Override -drawRect to fill the view with a solid color outside of the
94 // subview's frame. 122 // subview's frame.
95 - (void)drawRect:(NSRect)dirtyRect { 123 - (void)drawRect:(NSRect)dirtyRect {
96 NSView* const contentsView = 124 NSView* const contentsView =
97 [[self subviews] count] > 0 ? [[self subviews] objectAtIndex:0] : nil; 125 [[self subviews] count] > 0 ? [[self subviews] objectAtIndex:0] : nil;
98 if (!contentsView || !NSContainsRect([contentsView frame], dirtyRect)) { 126 if (!contentsView || !NSContainsRect([contentsView frame], dirtyRect)) {
99 // Fill with a dark tint of the new tab page's background color. This is 127 [[self computeBackgroundColor] setFill];
100 // only seen when the subview is sized specially for fullscreen tab capture.
101 NSColor* bgColor = nil;
102 ThemeService* const theme =
103 static_cast<ThemeService*>([[self window] themeProvider]);
104 if (theme)
105 bgColor = theme->GetNSColor(ThemeProperties::COLOR_NTP_BACKGROUND);
106 if (!bgColor)
107 bgColor = [[self window] backgroundColor];
108 const float kDarknessFraction = 0.80f;
109 [[bgColor blendedColorWithFraction:kDarknessFraction
110 ofColor:[NSColor blackColor]] setFill];
111 NSRectFill(dirtyRect); 128 NSRectFill(dirtyRect);
112 } 129 }
113 [super drawRect:dirtyRect]; 130 [super drawRect:dirtyRect];
114 } 131 }
115 132
116 // Override auto-resizing logic to query the delegate for the exact frame to 133 // Override auto-resizing logic to query the delegate for the exact frame to
117 // use for the contents view. 134 // use for the contents view.
118 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { 135 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize {
119 NSView* const contentsView = 136 NSView* const contentsView =
120 [[self subviews] count] > 0 ? [[self subviews] objectAtIndex:0] : nil; 137 [[self subviews] count] > 0 ? [[self subviews] objectAtIndex:0] : nil;
121 if (!contentsView || [contentsView autoresizingMask] == NSViewNotSizable || 138 if (!contentsView || [contentsView autoresizingMask] == NSViewNotSizable ||
122 !delegate_) { 139 !delegate_) {
123 return; 140 return;
124 } 141 }
125 [contentsView setFrame:[delegate_ frameForContentsView]]; 142 [contentsView setFrame:[delegate_ frameForContentsView]];
126 } 143 }
127 144
145 // Update the background layer's color whenever the view needs to repaint.
146 - (void)setNeedsDisplayInRect:(NSRect)rect {
147 [super setNeedsDisplayInRect:rect];
148
ccameron 2014/04/19 02:45:29 [NSColor CGColor] is a 10.8+ function. Not sure i
Avi (use Gerrit) 2014/04/19 19:30:49 That's fine. With 10.6, they changed things so tha
149 // Convert from an NSColor to a CGColorRef.
150 NSColor* nsBackgroundColor = [self computeBackgroundColor];
151 NSColorSpace* nsColorSpace = [nsBackgroundColor colorSpace];
152 CGColorSpaceRef cgColorSpace = [nsColorSpace CGColorSpace];
153 const NSInteger numberOfComponents = [nsBackgroundColor numberOfComponents];
154 CGFloat components[numberOfComponents];
155 [nsBackgroundColor getComponents:components];
156 CGColorRef cgBackgroundColor = CGColorCreate(cgColorSpace, components);
Avi (use Gerrit) 2014/04/19 19:30:49 ScopedCFObject if you must go this route.
ccameron 2014/04/19 22:21:39 Done.
157
158 ScopedCAActionDisabler disabler;
159 [[self layer] setBackgroundColor:cgBackgroundColor];
160 CGColorRelease(cgBackgroundColor);
161 }
162
128 @end // @implementation TabContentsContainerView 163 @end // @implementation TabContentsContainerView
129 164
130 @implementation TabContentsController 165 @implementation TabContentsController
131 @synthesize webContents = contents_; 166 @synthesize webContents = contents_;
132 167
133 - (id)initWithContents:(WebContents*)contents 168 - (id)initWithContents:(WebContents*)contents
134 andAutoEmbedFullscreen:(BOOL)enableEmbeddedFullscreen { 169 andAutoEmbedFullscreen:(BOOL)enableEmbeddedFullscreen {
135 if ((self = [super initWithNibName:nil bundle:nil])) { 170 if ((self = [super initWithNibName:nil bundle:nil])) {
136 if (enableEmbeddedFullscreen) 171 if (enableEmbeddedFullscreen)
137 fullscreenObserver_.reset(new FullscreenObserver(self)); 172 fullscreenObserver_.reset(new FullscreenObserver(self));
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } else { 341 } else {
307 rect.ClampToCenteredSize(gfx::Size( 342 rect.ClampToCenteredSize(gfx::Size(
308 static_cast<int>(x / captureSize.height()), rect.height())); 343 static_cast<int>(x / captureSize.height()), rect.height()));
309 } 344 }
310 } 345 }
311 346
312 return NSRectFromCGRect(rect.ToCGRect()); 347 return NSRectFromCGRect(rect.ToCGRect());
313 } 348 }
314 349
315 @end 350 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698