Avoid calling into Objective-C every time we get the scrollbar width
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Jun 2013 20:27:08 +0000 (20:27 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 29 Jun 2013 20:27:08 +0000 (20:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=118216

Reviewed by Geoffrey Garen.

Profiling shows that calling Scrollbar::isOverlayScrollbar() is somewhat
expensive, because it calls down into Objective-C. Fix by caching in
ScrollbarThemeMac whether we're using overlay scrollbars. We update this
cache on creation, and when preferences change; ScrollAnimatorMac::updateScrollerStyle()
is the function that gets called when the user changes the setting in System Preferences.

* platform/ScrollbarTheme.h:
(WebCore::ScrollbarTheme::usesOverlayScrollbarsChanged):
* platform/mac/ScrollAnimatorMac.mm:
(WebCore::ScrollAnimatorMac::updateScrollerStyle):
* platform/mac/ScrollbarThemeMac.h:
* platform/mac/ScrollbarThemeMac.mm:
(WebCore::ScrollbarThemeMac::preferencesChanged):
(WebCore::ScrollbarThemeMac::usesOverlayScrollbars):
(WebCore::ScrollbarThemeMac::usesOverlayScrollbarsChanged):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@152214 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/ScrollbarTheme.h
Source/WebCore/platform/mac/ScrollAnimatorMac.mm
Source/WebCore/platform/mac/ScrollbarThemeMac.h
Source/WebCore/platform/mac/ScrollbarThemeMac.mm

index 2c01280..3cba880 100644 (file)
@@ -1,5 +1,28 @@
 2013-06-29  Simon Fraser  <simon.fraser@apple.com>
 
+        Avoid calling into Objective-C every time we get the scrollbar width
+        https://bugs.webkit.org/show_bug.cgi?id=118216
+
+        Reviewed by Geoffrey Garen.
+
+        Profiling shows that calling Scrollbar::isOverlayScrollbar() is somewhat
+        expensive, because it calls down into Objective-C. Fix by caching in
+        ScrollbarThemeMac whether we're using overlay scrollbars. We update this
+        cache on creation, and when preferences change; ScrollAnimatorMac::updateScrollerStyle()
+        is the function that gets called when the user changes the setting in System Preferences.
+
+        * platform/ScrollbarTheme.h:
+        (WebCore::ScrollbarTheme::usesOverlayScrollbarsChanged):
+        * platform/mac/ScrollAnimatorMac.mm:
+        (WebCore::ScrollAnimatorMac::updateScrollerStyle):
+        * platform/mac/ScrollbarThemeMac.h:
+        * platform/mac/ScrollbarThemeMac.mm:
+        (WebCore::ScrollbarThemeMac::preferencesChanged):
+        (WebCore::ScrollbarThemeMac::usesOverlayScrollbars):
+        (WebCore::ScrollbarThemeMac::usesOverlayScrollbarsChanged):
+
+2013-06-29  Simon Fraser  <simon.fraser@apple.com>
+
         Avoid calling isSimpleContainerCompositingLayer() an extra time
         https://bugs.webkit.org/show_bug.cgi?id=118218
 
index 9f8c567..d68e062 100644 (file)
@@ -57,6 +57,7 @@ public:
 
     virtual bool supportsControlTints() const { return false; }
     virtual bool usesOverlayScrollbars() const { return false; }
+    virtual void usesOverlayScrollbarsChanged() { }
     virtual void updateScrollbarOverlayStyle(ScrollbarThemeClient*) { }
 
     virtual void themeChanged() {}
index 97ae394..81ebca9 100644 (file)
@@ -1212,6 +1212,8 @@ void ScrollAnimatorMac::updateScrollerStyle()
         m_needsScrollerStyleUpdate = false;
         return;
     }
+    
+    macTheme->usesOverlayScrollbarsChanged();
 
     NSScrollerStyle newStyle = [m_scrollbarPainterController.get() scrollerStyle];
 
index 697b4a8..da573af 100644 (file)
@@ -47,6 +47,7 @@ public:
     
     virtual bool supportsControlTints() const { return true; }
     virtual bool usesOverlayScrollbars() const;
+    virtual void usesOverlayScrollbarsChanged() OVERRIDE;
     virtual void updateScrollbarOverlayStyle(ScrollbarThemeClient*);
 
     virtual double initialAutoscrollTimerDelay();
index c511085..121b6a8 100644 (file)
@@ -133,6 +133,7 @@ static int cOuterButtonOverlap = 2;
 static float gInitialButtonDelay = 0.5f;
 static float gAutoscrollButtonDelay = 0.05f;
 static bool gJumpOnTrackClick = false;
+static bool gUsesOverlayScrollbars = false;
 
 static ScrollbarButtonsPlacement gButtonPlacement = ScrollbarButtonsDoubleEnd;
 
@@ -226,6 +227,7 @@ void ScrollbarThemeMac::preferencesChanged()
     gInitialButtonDelay = [defaults floatForKey:@"NSScrollerButtonDelay"];
     gAutoscrollButtonDelay = [defaults floatForKey:@"NSScrollerButtonPeriod"];
     gJumpOnTrackClick = [defaults boolForKey:@"AppleScrollerPagingBehavior"];
+    usesOverlayScrollbarsChanged();
 }
 
 int ScrollbarThemeMac::scrollbarThickness(ScrollbarControlSize controlSize)
@@ -241,10 +243,15 @@ int ScrollbarThemeMac::scrollbarThickness(ScrollbarControlSize controlSize)
 
 bool ScrollbarThemeMac::usesOverlayScrollbars() const
 {
+    return gUsesOverlayScrollbars;
+}
+
+void ScrollbarThemeMac::usesOverlayScrollbarsChanged()
+{
     if (isScrollbarOverlayAPIAvailable())
-        return recommendedScrollerStyle() == NSScrollerStyleOverlay;
+        gUsesOverlayScrollbars = recommendedScrollerStyle() == NSScrollerStyleOverlay;
     else
-        return false;
+        gUsesOverlayScrollbars = false;
 }
 
 void ScrollbarThemeMac::updateScrollbarOverlayStyle(ScrollbarThemeClient* scrollbar)