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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 134753008: Performance fixes for CoreAnimation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use observer Created 6 years, 10 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 | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | 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) 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 #include "content/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <QuartzCore/QuartzCore.h> 8 #include <QuartzCore/QuartzCore.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 CFArrayRef inputSources = TISCreateASCIICapableInputSourceList(); 315 CFArrayRef inputSources = TISCreateASCIICapableInputSourceList();
316 TSMSetDocumentProperty(0, kTSMDocumentEnabledInputSourcesPropertyTag, 316 TSMSetDocumentProperty(0, kTSMDocumentEnabledInputSourcesPropertyTag,
317 sizeof(CFArrayRef), &inputSources); 317 sizeof(CFArrayRef), &inputSources);
318 CFRelease(inputSources); 318 CFRelease(inputSources);
319 } 319 }
320 320
321 void DisablePasswordInput() { 321 void DisablePasswordInput() {
322 TSMRemoveDocumentProperty(0, kTSMDocumentEnabledInputSourcesPropertyTag); 322 TSMRemoveDocumentProperty(0, kTSMDocumentEnabledInputSourcesPropertyTag);
323 } 323 }
324 324
325 // Calls to [NSScreen screens], required by FlipYFromRectToScreen and
326 // FlipNSRectToRectScreen, can take several milliseconds. Only re-compute this
327 // value when screen info changes.
328 // TODO(ccameron): An observer on every RWHVCocoa will set this to false
329 // on NSApplicationDidChangeScreenParametersNotification. Only one observer
330 // is necessary.
331 bool g_screen_info_up_to_date = false;
332
333 float FlipYFromRectToScreen(float y, float rect_height) {
334 TRACE_EVENT0("browser", "FlipYFromRectToScreen");
335 static CGFloat screen_zero_height = 0;
336 if (!g_screen_info_up_to_date) {
337 if ([[NSScreen screens] count] > 0) {
338 screen_zero_height =
339 [[[NSScreen screens] objectAtIndex:0] frame].size.height;
340 g_screen_info_up_to_date = true;
341 } else {
342 return y;
343 }
344 }
345 return screen_zero_height - y - rect_height;
346 }
347
325 // Adjusts an NSRect in Cocoa screen coordinates to have an origin in the upper 348 // Adjusts an NSRect in Cocoa screen coordinates to have an origin in the upper
326 // left of the primary screen (Carbon coordinates), and stuffs it into a 349 // left of the primary screen (Carbon coordinates), and stuffs it into a
327 // gfx::Rect. 350 // gfx::Rect.
328 gfx::Rect FlipNSRectToRectScreen(const NSRect& rect) { 351 gfx::Rect FlipNSRectToRectScreen(const NSRect& rect) {
329 gfx::Rect new_rect(NSRectToCGRect(rect)); 352 gfx::Rect new_rect(NSRectToCGRect(rect));
330 if ([[NSScreen screens] count] > 0) { 353 new_rect.set_y(FlipYFromRectToScreen(new_rect.y(), new_rect.height()));
331 new_rect.set_y([[[NSScreen screens] objectAtIndex:0] frame].size.height -
332 new_rect.y() - new_rect.height());
333 }
334 return new_rect; 354 return new_rect;
335 } 355 }
336 356
337 // Returns the window that visually contains the given view. This is different 357 // Returns the window that visually contains the given view. This is different
338 // from [view window] in the case of tab dragging, where the view's owning 358 // from [view window] in the case of tab dragging, where the view's owning
339 // window is a floating panel attached to the actual browser window that the tab 359 // window is a floating panel attached to the actual browser window that the tab
340 // is visually part of. 360 // is visually part of.
341 NSWindow* ApparentWindowForView(NSView* view) { 361 NSWindow* ApparentWindowForView(NSView* view) {
342 // TODO(shess): In case of !window, the view has been removed from 362 // TODO(shess): In case of !window, the view has been removed from
343 // the view hierarchy because the tab isn't main. Could retrieve 363 // the view hierarchy because the tab isn't main. Could retrieve
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 if (compositing_iosurface_) { 505 if (compositing_iosurface_) {
486 if (!CreateCompositedIOSurfaceLayer()) { 506 if (!CreateCompositedIOSurfaceLayer()) {
487 LOG(ERROR) << "Failed to create CALayer for existing IOSurface"; 507 LOG(ERROR) << "Failed to create CALayer for existing IOSurface";
488 GotAcceleratedCompositingError(); 508 GotAcceleratedCompositingError();
489 return; 509 return;
490 } 510 }
491 } 511 }
492 } 512 }
493 513
494 bool RenderWidgetHostViewMac::CreateCompositedIOSurface() { 514 bool RenderWidgetHostViewMac::CreateCompositedIOSurface() {
495 int current_window_number = window_number(); 515 int current_window_number = use_core_animation_ ?
516 CompositingIOSurfaceContext::kOffscreenContextWindowNumber :
517 window_number();
496 bool new_surface_needed = !compositing_iosurface_; 518 bool new_surface_needed = !compositing_iosurface_;
497 bool new_context_needed = 519 bool new_context_needed =
498 !compositing_iosurface_context_ || 520 !compositing_iosurface_context_ ||
499 (compositing_iosurface_context_ && 521 (compositing_iosurface_context_ &&
500 compositing_iosurface_context_->window_number() != 522 compositing_iosurface_context_->window_number() !=
501 current_window_number); 523 current_window_number);
502 524
503 if (!new_surface_needed && !new_context_needed) 525 if (!new_surface_needed && !new_context_needed)
504 return true; 526 return true;
505 527
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 } 632 }
611 633
612 void RenderWidgetHostViewMac::InitAsPopup( 634 void RenderWidgetHostViewMac::InitAsPopup(
613 RenderWidgetHostView* parent_host_view, 635 RenderWidgetHostView* parent_host_view,
614 const gfx::Rect& pos) { 636 const gfx::Rect& pos) {
615 bool activatable = popup_type_ == blink::WebPopupTypeNone; 637 bool activatable = popup_type_ == blink::WebPopupTypeNone;
616 [cocoa_view_ setCloseOnDeactivate:YES]; 638 [cocoa_view_ setCloseOnDeactivate:YES];
617 [cocoa_view_ setCanBeKeyView:activatable ? YES : NO]; 639 [cocoa_view_ setCanBeKeyView:activatable ? YES : NO];
618 640
619 NSPoint origin_global = NSPointFromCGPoint(pos.origin().ToCGPoint()); 641 NSPoint origin_global = NSPointFromCGPoint(pos.origin().ToCGPoint());
620 if ([[NSScreen screens] count] > 0) { 642 origin_global.y = FlipYFromRectToScreen(origin_global.y, pos.height());
621 origin_global.y = [[[NSScreen screens] objectAtIndex:0] frame].size.height -
622 pos.height() - origin_global.y;
623 }
624 643
625 popup_window_.reset([[RenderWidgetPopupWindow alloc] 644 popup_window_.reset([[RenderWidgetPopupWindow alloc]
626 initWithContentRect:NSMakeRect(origin_global.x, origin_global.y, 645 initWithContentRect:NSMakeRect(origin_global.x, origin_global.y,
627 pos.width(), pos.height()) 646 pos.width(), pos.height())
628 styleMask:NSBorderlessWindowMask 647 styleMask:NSBorderlessWindowMask
629 backing:NSBackingStoreBuffered 648 backing:NSBackingStoreBuffered
630 defer:NO]); 649 defer:NO]);
631 [popup_window_ setLevel:NSPopUpMenuWindowLevel]; 650 [popup_window_ setLevel:NSPopUpMenuWindowLevel];
632 [popup_window_ setReleasedWhenClosed:NO]; 651 [popup_window_ setReleasedWhenClosed:NO];
633 [popup_window_ makeKeyAndOrderFront:nil]; 652 [popup_window_ makeKeyAndOrderFront:nil];
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 794
776 // Ignore the position of |rect| for non-popup rwhvs. This is because 795 // Ignore the position of |rect| for non-popup rwhvs. This is because
777 // background tabs do not have a window, but the window is required for the 796 // background tabs do not have a window, but the window is required for the
778 // coordinate conversions. Popups are always for a visible tab. 797 // coordinate conversions. Popups are always for a visible tab.
779 if (IsPopup()) { 798 if (IsPopup()) {
780 // The position of |rect| is screen coordinate system and we have to 799 // The position of |rect| is screen coordinate system and we have to
781 // consider Cocoa coordinate system is upside-down and also multi-screen. 800 // consider Cocoa coordinate system is upside-down and also multi-screen.
782 NSPoint origin_global = NSPointFromCGPoint(rect.origin().ToCGPoint()); 801 NSPoint origin_global = NSPointFromCGPoint(rect.origin().ToCGPoint());
783 NSSize size = NSMakeSize(rect.width(), rect.height()); 802 NSSize size = NSMakeSize(rect.width(), rect.height());
784 size = [cocoa_view_ convertSize:size toView:nil]; 803 size = [cocoa_view_ convertSize:size toView:nil];
785 if ([[NSScreen screens] count] > 0) { 804 origin_global.y = FlipYFromRectToScreen(origin_global.y, size.height);
786 NSScreen* screen =
787 static_cast<NSScreen*>([[NSScreen screens] objectAtIndex:0]);
788 origin_global.y =
789 NSHeight([screen frame]) - size.height - origin_global.y;
790 }
791 [popup_window_ setFrame:NSMakeRect(origin_global.x, origin_global.y, 805 [popup_window_ setFrame:NSMakeRect(origin_global.x, origin_global.y,
792 size.width, size.height) 806 size.width, size.height)
793 display:YES]; 807 display:YES];
794 } else { 808 } else {
795 DCHECK([[cocoa_view_ superview] isKindOfClass:[BaseView class]]); 809 DCHECK([[cocoa_view_ superview] isKindOfClass:[BaseView class]]);
796 BaseView* superview = static_cast<BaseView*>([cocoa_view_ superview]); 810 BaseView* superview = static_cast<BaseView*>([cocoa_view_ superview]);
797 gfx::Rect rect2 = [superview flipNSRectToRect:[cocoa_view_ frame]]; 811 gfx::Rect rect2 = [superview flipNSRectToRect:[cocoa_view_ frame]];
798 rect2.set_width(rect.width()); 812 rect2.set_width(rect.width());
799 rect2.set_height(rect.height()); 813 rect2.set_height(rect.height());
800 [cocoa_view_ setFrame:[superview flipRectToNSRect:rect2]]; 814 [cocoa_view_ setFrame:[superview flipRectToNSRect:rect2]];
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 if ([self respondsToSelector: 2018 if ([self respondsToSelector:
2005 @selector(setWantsBestResolutionOpenGLSurface:)]) { 2019 @selector(setWantsBestResolutionOpenGLSurface:)]) {
2006 [self setWantsBestResolutionOpenGLSurface:YES]; 2020 [self setWantsBestResolutionOpenGLSurface:YES];
2007 } 2021 }
2008 handlingGlobalFrameDidChange_ = NO; 2022 handlingGlobalFrameDidChange_ = NO;
2009 [[NSNotificationCenter defaultCenter] 2023 [[NSNotificationCenter defaultCenter]
2010 addObserver:self 2024 addObserver:self
2011 selector:@selector(globalFrameDidChange:) 2025 selector:@selector(globalFrameDidChange:)
2012 name:NSViewGlobalFrameDidChangeNotification 2026 name:NSViewGlobalFrameDidChangeNotification
2013 object:self]; 2027 object:self];
2028 [[NSNotificationCenter defaultCenter]
2029 addObserver:self
2030 selector:@selector(didChangeScreenParameters:)
2031 name:NSApplicationDidChangeScreenParametersNotification
2032 object:nil];
2014 } 2033 }
2015 return self; 2034 return self;
2016 } 2035 }
2017 2036
2018 - (void)dealloc { 2037 - (void)dealloc {
2019 // Unbind the GL context from this view. If this is not done before super's 2038 // Unbind the GL context from this view. If this is not done before super's
2020 // dealloc is called then the GL context will crash when it reaches into 2039 // dealloc is called then the GL context will crash when it reaches into
2021 // the view in its destructor. 2040 // the view in its destructor.
2022 // http://crbug.com/255608 2041 // http://crbug.com/255608
2023 if (renderWidgetHostView_) 2042 if (renderWidgetHostView_)
2024 renderWidgetHostView_->AcceleratedSurfaceRelease(); 2043 renderWidgetHostView_->AcceleratedSurfaceRelease();
2025 2044
2026 if (responderDelegate_ && 2045 if (responderDelegate_ &&
2027 [responderDelegate_ respondsToSelector:@selector(viewGone:)]) 2046 [responderDelegate_ respondsToSelector:@selector(viewGone:)])
2028 [responderDelegate_ viewGone:self]; 2047 [responderDelegate_ viewGone:self];
2029 responderDelegate_.reset(); 2048 responderDelegate_.reset();
2030 2049
2031 [[NSNotificationCenter defaultCenter] removeObserver:self]; 2050 [[NSNotificationCenter defaultCenter] removeObserver:self];
2032 2051
2033 [super dealloc]; 2052 [super dealloc];
2034 } 2053 }
2035 2054
2055 - (void)didChangeScreenParameters:(NSNotification*)notify {
2056 g_screen_info_up_to_date = false;
2057 }
2058
2036 - (void)setResponderDelegate: 2059 - (void)setResponderDelegate:
2037 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate { 2060 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate {
2038 DCHECK(!responderDelegate_); 2061 DCHECK(!responderDelegate_);
2039 responderDelegate_.reset([delegate retain]); 2062 responderDelegate_.reset([delegate retain]);
2040 } 2063 }
2041 2064
2042 - (void)resetCursorRects { 2065 - (void)resetCursorRects {
2043 if (currentCursor_) { 2066 if (currentCursor_) {
2044 [self addCursorRect:[self visibleRect] cursor:currentCursor_]; 2067 [self addCursorRect:[self visibleRect] cursor:currentCursor_];
2045 [currentCursor_ setOnMouseEntered:YES]; 2068 [currentCursor_ setOnMouseEntered:YES];
(...skipping 1966 matching lines...) Expand 10 before | Expand all | Expand 10 after
4012 return YES; 4035 return YES;
4013 } 4036 }
4014 4037
4015 - (BOOL)isOpaque { 4038 - (BOOL)isOpaque {
4016 if (renderWidgetHostView_->use_core_animation_) 4039 if (renderWidgetHostView_->use_core_animation_)
4017 return YES; 4040 return YES;
4018 return [super isOpaque]; 4041 return [super isOpaque];
4019 } 4042 }
4020 4043
4021 @end 4044 @end
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698