Title: [229707] trunk/Source
Revision
229707
Author
pvol...@apple.com
Date
2018-03-19 11:04:39 -0700 (Mon, 19 Mar 2018)

Log Message

When the WebContent process is blocked from accessing the WindowServer, the call CVDisplayLinkCreateWithCGDisplay will fail.
https://bugs.webkit.org/show_bug.cgi?id=183604
<rdar://problem/38305109>

Reviewed by Brent Fulgham.

Source/WebCore:

The call to CVDisplayLinkCreateWithCGDisplay can instead be made in the UIProcess. Notify the WebContent process
about display updates by sending a message from the UIProcess on each screen update. This patch adds an extra
IPC step when notifying the WebContent process about display updates. However, the MotionMark benchmark shows no
performance regression when running it with this patch. A possible explanation for this is that the high priority
display link thread is now running in the UIProcess instead of the WebContent process, which means there will be
more available CPU resources for the WebContent process. A run loop observer is added to make sure that only one
display callback (for each display observer) is executed in a single iteration of the run loop. This will make
sure we are not filling the IPC message queue with unhandled display link messages.

No new tests, covered by existing tests.

* platform/graphics/DisplayRefreshMonitor.h:
(WebCore::DisplayRefreshMonitor::displayLinkFired):
* platform/graphics/DisplayRefreshMonitorManager.cpp:
(WebCore::DisplayRefreshMonitorManager::displayWasUpdated):
* platform/graphics/DisplayRefreshMonitorManager.h:
* platform/graphics/mac/DisplayRefreshMonitorMac.h:

Source/WebKit:

* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/mac/DisplayLink.cpp: Added.
(WebKit::DisplayLink::DisplayLink):
(WebKit::DisplayLink::~DisplayLink):
(WebKit::DisplayLink::displayLinkCallback):
* UIProcess/mac/DisplayLink.h: Added.
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::startDisplayRefreshMonitor):
(WebKit::WebPageProxy::stopDisplayRefreshMonitor):
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebPage/DrawingArea.cpp:
(WebKit::DrawingArea::createDisplayRefreshMonitor):
* WebProcess/WebPage/DrawingArea.h:
* WebProcess/WebPage/DrawingArea.messages.in:
* WebProcess/WebPage/mac/DrawingAreaMac.cpp: Added.
(WebKit::DisplayRefreshMonitorMac::create):
(WebKit::DisplayRefreshMonitorMac::DisplayRefreshMonitorMac):
(WebKit::DisplayRefreshMonitorMac::~DisplayRefreshMonitorMac):
(WebKit::DisplayRefreshMonitorMac::requestRefreshCallback):
(WebKit::DisplayRefreshMonitorMac::displayLinkFired):
(WebKit::DrawingArea::screenWasRefreshed):
(WebKit::DrawingArea::createDisplayRefreshMonitor):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (229706 => 229707)


--- trunk/Source/WebCore/ChangeLog	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebCore/ChangeLog	2018-03-19 18:04:39 UTC (rev 229707)
@@ -1,3 +1,29 @@
+2018-03-19  Per Arne Vollan  <pvol...@apple.com>
+
+        When the WebContent process is blocked from accessing the WindowServer, the call CVDisplayLinkCreateWithCGDisplay will fail.
+        https://bugs.webkit.org/show_bug.cgi?id=183604
+        <rdar://problem/38305109>
+
+        Reviewed by Brent Fulgham.
+
+        The call to CVDisplayLinkCreateWithCGDisplay can instead be made in the UIProcess. Notify the WebContent process
+        about display updates by sending a message from the UIProcess on each screen update. This patch adds an extra
+        IPC step when notifying the WebContent process about display updates. However, the MotionMark benchmark shows no
+        performance regression when running it with this patch. A possible explanation for this is that the high priority
+        display link thread is now running in the UIProcess instead of the WebContent process, which means there will be
+        more available CPU resources for the WebContent process. A run loop observer is added to make sure that only one
+        display callback (for each display observer) is executed in a single iteration of the run loop. This will make
+        sure we are not filling the IPC message queue with unhandled display link messages.
+
+        No new tests, covered by existing tests. 
+
+        * platform/graphics/DisplayRefreshMonitor.h:
+        (WebCore::DisplayRefreshMonitor::displayLinkFired):
+        * platform/graphics/DisplayRefreshMonitorManager.cpp:
+        (WebCore::DisplayRefreshMonitorManager::displayWasUpdated):
+        * platform/graphics/DisplayRefreshMonitorManager.h:
+        * platform/graphics/mac/DisplayRefreshMonitorMac.h:
+
 2018-03-19  Megan Gardner  <megan_gard...@apple.com>
 
         Ensure local appearance actually mirrors the app's appearance

Modified: trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.h (229706 => 229707)


--- trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.h	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitor.h	2018-03-19 18:04:39 UTC (rev 229707)
@@ -42,7 +42,9 @@
 public:
     static RefPtr<DisplayRefreshMonitor> create(DisplayRefreshMonitorClient&);
     WEBCORE_EXPORT virtual ~DisplayRefreshMonitor();
-    
+
+    virtual void displayLinkFired() { }
+
     // Return true if callback request was scheduled, false if it couldn't be
     // (e.g., hardware refresh is not available)
     virtual bool requestRefreshCallback() = 0;
@@ -66,6 +68,8 @@
     WEBCORE_EXPORT explicit DisplayRefreshMonitor(PlatformDisplayID);
     WEBCORE_EXPORT static void handleDisplayRefreshedNotificationOnMainThread(void* data);
 
+    friend class DisplayRefreshMonitorManager;
+    
     Lock& mutex() { return m_mutex; }
 
     bool isActive() const { return m_active; }

Modified: trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.cpp (229706 => 229707)


--- trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.cpp	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.cpp	2018-03-19 18:04:39 UTC (rev 229707)
@@ -125,6 +125,14 @@
         scheduleAnimation(client);
 }
 
+void DisplayRefreshMonitorManager::displayWasUpdated()
+{
+    for (auto monitor : m_monitors) {
+        if (monitor->isScheduled())
+            monitor->displayLinkFired();
+    }
 }
 
+}
+
 #endif // USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)

Modified: trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.h (229706 => 229707)


--- trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.h	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.h	2018-03-19 18:04:39 UTC (rev 229707)
@@ -38,7 +38,7 @@
 class DisplayRefreshMonitorManager {
     friend class NeverDestroyed<DisplayRefreshMonitorManager>;
 public:
-    static DisplayRefreshMonitorManager& sharedManager();
+    WEBCORE_EXPORT static DisplayRefreshMonitorManager& sharedManager();
     
     void registerClient(DisplayRefreshMonitorClient&);
     void unregisterClient(DisplayRefreshMonitorClient&);
@@ -46,6 +46,8 @@
     bool scheduleAnimation(DisplayRefreshMonitorClient&);
     void windowScreenDidChange(PlatformDisplayID, DisplayRefreshMonitorClient&);
 
+    WEBCORE_EXPORT void displayWasUpdated();
+    
 private:
     friend class DisplayRefreshMonitor;
     void displayDidRefresh(DisplayRefreshMonitor&);

Modified: trunk/Source/WebCore/platform/graphics/ios/DisplayRefreshMonitorIOS.h (229706 => 229707)


--- trunk/Source/WebCore/platform/graphics/ios/DisplayRefreshMonitorIOS.h	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebCore/platform/graphics/ios/DisplayRefreshMonitorIOS.h	2018-03-19 18:04:39 UTC (rev 229707)
@@ -43,7 +43,7 @@
     
     virtual ~DisplayRefreshMonitorIOS();
 
-    void displayLinkFired();
+    void displayLinkFired() override;
     bool requestRefreshCallback() override;
 
 private:

Modified: trunk/Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.h (229706 => 229707)


--- trunk/Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.h	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.h	2018-03-19 18:04:39 UTC (rev 229707)
@@ -43,7 +43,7 @@
     
     virtual ~DisplayRefreshMonitorMac();
 
-    void displayLinkFired();
+    void displayLinkFired() override;
     bool requestRefreshCallback() override;
 
 private:

Modified: trunk/Source/WebKit/ChangeLog (229706 => 229707)


--- trunk/Source/WebKit/ChangeLog	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebKit/ChangeLog	2018-03-19 18:04:39 UTC (rev 229707)
@@ -1,3 +1,35 @@
+2018-03-19  Per Arne Vollan  <pvol...@apple.com>
+
+        When the WebContent process is blocked from accessing the WindowServer, the call CVDisplayLinkCreateWithCGDisplay will fail.
+        https://bugs.webkit.org/show_bug.cgi?id=183604
+        <rdar://problem/38305109>
+
+        Reviewed by Brent Fulgham.
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/mac/DisplayLink.cpp: Added.
+        (WebKit::DisplayLink::DisplayLink):
+        (WebKit::DisplayLink::~DisplayLink):
+        (WebKit::DisplayLink::displayLinkCallback):
+        * UIProcess/mac/DisplayLink.h: Added.
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::startDisplayRefreshMonitor):
+        (WebKit::WebPageProxy::stopDisplayRefreshMonitor):
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/WebPage/DrawingArea.cpp:
+        (WebKit::DrawingArea::createDisplayRefreshMonitor):
+        * WebProcess/WebPage/DrawingArea.h:
+        * WebProcess/WebPage/DrawingArea.messages.in:
+        * WebProcess/WebPage/mac/DrawingAreaMac.cpp: Added.
+        (WebKit::DisplayRefreshMonitorMac::create):
+        (WebKit::DisplayRefreshMonitorMac::DisplayRefreshMonitorMac):
+        (WebKit::DisplayRefreshMonitorMac::~DisplayRefreshMonitorMac):
+        (WebKit::DisplayRefreshMonitorMac::requestRefreshCallback):
+        (WebKit::DisplayRefreshMonitorMac::displayLinkFired):
+        (WebKit::DrawingArea::screenWasRefreshed):
+        (WebKit::DrawingArea::createDisplayRefreshMonitor):
+
 2018-03-17  Jiewen Tan  <jiewen_...@apple.com>
 
         [WebAuthN] Implement authenticatorMakeCredential

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (229706 => 229707)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2018-03-19 18:04:39 UTC (rev 229707)
@@ -120,6 +120,10 @@
 #include <WebCore/WebMediaSessionManagerClient.h>
 #endif
 
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+#include "DisplayLink.h"
+#endif
+
 #if ENABLE(MEDIA_SESSION)
 namespace WebCore {
 class MediaSessionMetadata;
@@ -1721,6 +1725,11 @@
     void didRemoveAttachment(const String& identifier);
 #endif
 
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+    void startDisplayLink(unsigned observerID);
+    void stopDisplayLink(unsigned observerID);
+#endif
+
     void reportPageLoadResult(const WebCore::ResourceError& = { });
 
     PageClient& m_pageClient;
@@ -2121,6 +2130,10 @@
 
     HashMap<String, Ref<WebURLSchemeHandler>> m_urlSchemeHandlersByScheme;
     HashMap<uint64_t, Ref<WebURLSchemeHandler>> m_urlSchemeHandlersByIdentifier;
+        
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+    std::unique_ptr<DisplayLink> m_displayLink;
+#endif
 
     std::optional<MonotonicTime> m_pageLoadStart;
 };

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (229706 => 229707)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2018-03-19 18:04:39 UTC (rev 229707)
@@ -515,4 +515,9 @@
     DidInsertAttachment(String identifier, String source)
     DidRemoveAttachment(String identifier)
 #endif
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+    StartDisplayLink(unsigned observerID)
+    StopDisplayLink(unsigned observerID)
+#endif
 }

Added: trunk/Source/WebKit/UIProcess/mac/DisplayLink.cpp (0 => 229707)


--- trunk/Source/WebKit/UIProcess/mac/DisplayLink.cpp	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/mac/DisplayLink.cpp	2018-03-19 18:04:39 UTC (rev 229707)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DisplayLink.h"
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+
+#include "DrawingAreaMessages.h"
+#include "WebPageProxy.h"
+#include "WebProcessProxy.h"
+
+namespace WebKit {
+    
+DisplayLink::DisplayLink(WebCore::PlatformDisplayID displayID, WebPageProxy& webPageProxy)
+    : m_webPageProxy(webPageProxy)
+{
+    CVReturn error = CVDisplayLinkCreateWithCGDisplay(displayID, &m_displayLink);
+    if (error) {
+        WTFLogAlways("Could not create a display link: %d", error);
+        return;
+    }
+    
+    error = CVDisplayLinkSetOutputCallback(m_displayLink, displayLinkCallback, &webPageProxy);
+    if (error) {
+        WTFLogAlways("Could not set the display link output callback: %d", error);
+        return;
+    }
+
+    error = CVDisplayLinkStart(m_displayLink);
+    if (error)
+        WTFLogAlways("Could not start the display link: %d", error);
+}
+
+DisplayLink::~DisplayLink()
+{
+    ASSERT(m_displayLink);
+    if (!m_displayLink)
+        return;
+
+    CVDisplayLinkStop(m_displayLink);
+    CVDisplayLinkRelease(m_displayLink);
+}
+
+void DisplayLink::addObserver(unsigned observerID)
+{
+    m_observers.add(observerID);
+}
+
+void DisplayLink::removeObserver(unsigned observerID)
+{
+    m_observers.remove(observerID);
+}
+
+bool DisplayLink::hasObservers() const
+{
+    return !m_observers.isEmpty();
+}
+
+CVReturn DisplayLink::displayLinkCallback(CVDisplayLinkRef displayLinkRef, const CVTimeStamp*, const CVTimeStamp*, CVOptionFlags, CVOptionFlags*, void* data)
+{
+    WebPageProxy* webPageProxy = reinterpret_cast<WebPageProxy*>(data);
+    callOnMainThread([webPageProxy = makeRefPtr(webPageProxy)] {
+        webPageProxy->process().send(Messages::DrawingArea::DisplayWasRefreshed(), webPageProxy->pageID());
+    });
+    return kCVReturnSuccess;
+}
+
+}
+
+#endif

Added: trunk/Source/WebKit/UIProcess/mac/DisplayLink.h (0 => 229707)


--- trunk/Source/WebKit/UIProcess/mac/DisplayLink.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/mac/DisplayLink.h	2018-03-19 18:04:39 UTC (rev 229707)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+
+#include <CoreVideo/CVDisplayLink.h>
+
+#include <WebCore/PlatformScreen.h>
+#include <wtf/HashSet.h>
+
+namespace WebKit {
+
+class WebPageProxy;
+    
+class DisplayLink {
+public:
+    DisplayLink(WebCore::PlatformDisplayID, WebPageProxy&);
+    ~DisplayLink();
+    
+    void addObserver(unsigned observerID);
+    void removeObserver(unsigned observerID);
+    bool hasObservers() const;
+
+private:
+    static CVReturn displayLinkCallback(CVDisplayLinkRef, const CVTimeStamp*, const CVTimeStamp*, CVOptionFlags, CVOptionFlags*, void* data);
+    
+    CVDisplayLinkRef m_displayLink { nullptr };
+    Ref<WebPageProxy> m_webPageProxy;
+    HashSet<unsigned> m_observers;
+};
+
+}
+
+#endif
+

Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (229706 => 229707)


--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2018-03-19 18:04:39 UTC (rev 229707)
@@ -605,6 +605,27 @@
 }
 #endif
 
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+void WebPageProxy::startDisplayLink(unsigned observerID)
+{
+    if (!m_displayLink) {
+        uint32_t displayID = [[[[platformWindow() screen] deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
+        m_displayLink = std::make_unique<DisplayLink>(displayID, *this);
+    }
+    m_displayLink->addObserver(observerID);
+}
+
+void WebPageProxy::stopDisplayLink(unsigned observerID)
+{
+    if (!m_displayLink)
+        return;
+    
+    m_displayLink->removeObserver(observerID);
+    if (!m_displayLink->hasObservers())
+        m_displayLink = nullptr;
+}
+#endif
+
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (229706 => 229707)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2018-03-19 18:04:39 UTC (rev 229707)
@@ -1983,6 +1983,9 @@
 		C0E3AA7A1209E83000A49D01 /* ModuleCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0E3AA481209E45000A49D01 /* ModuleCF.cpp */; };
 		C0E3AA7B1209E83500A49D01 /* Module.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0E3AA451209E2BA00A49D01 /* Module.cpp */; };
 		C0E3AA7C1209E83C00A49D01 /* Module.h in Headers */ = {isa = PBXBuildFile; fileRef = C0E3AA441209E2BA00A49D01 /* Module.h */; };
+		C181735F205839F600DFDA65 /* DrawingAreaMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C181735E205839F600DFDA65 /* DrawingAreaMac.cpp */; };
+		C18173612058424700DFDA65 /* DisplayLink.h in Headers */ = {isa = PBXBuildFile; fileRef = C18173602058424700DFDA65 /* DisplayLink.h */; };
+		C1817363205844A900DFDA65 /* DisplayLink.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C1817362205844A900DFDA65 /* DisplayLink.cpp */; };
 		C517388112DF8F4F00EE3F47 /* DragControllerAction.h in Headers */ = {isa = PBXBuildFile; fileRef = C517388012DF8F4F00EE3F47 /* DragControllerAction.h */; };
 		C5237F6012441CA300780472 /* WebEditorClientMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C5237F5F12441CA300780472 /* WebEditorClientMac.mm */; };
 		C54256B518BEC18C00DE4179 /* WKFormInputControl.h in Headers */ = {isa = PBXBuildFile; fileRef = C54256AF18BEC18B00DE4179 /* WKFormInputControl.h */; };
@@ -4506,6 +4509,9 @@
 		C0E3AA441209E2BA00A49D01 /* Module.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Module.h; sourceTree = "<group>"; };
 		C0E3AA451209E2BA00A49D01 /* Module.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Module.cpp; sourceTree = "<group>"; };
 		C0E3AA481209E45000A49D01 /* ModuleCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ModuleCF.cpp; sourceTree = "<group>"; };
+		C181735E205839F600DFDA65 /* DrawingAreaMac.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DrawingAreaMac.cpp; sourceTree = "<group>"; };
+		C18173602058424700DFDA65 /* DisplayLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayLink.h; sourceTree = "<group>"; };
+		C1817362205844A900DFDA65 /* DisplayLink.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayLink.cpp; sourceTree = "<group>"; };
 		C517388012DF8F4F00EE3F47 /* DragControllerAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragControllerAction.h; sourceTree = "<group>"; };
 		C5237F5F12441CA300780472 /* WebEditorClientMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebEditorClientMac.mm; sourceTree = "<group>"; };
 		C54256AF18BEC18B00DE4179 /* WKFormInputControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKFormInputControl.h; path = ios/forms/WKFormInputControl.h; sourceTree = "<group>"; };
@@ -7951,6 +7957,7 @@
 		BC963D6C113DD19500574BE2 /* mac */ = {
 			isa = PBXGroup;
 			children = (
+				C181735E205839F600DFDA65 /* DrawingAreaMac.cpp */,
 				7C6D37FA172F555F009D2847 /* PageBannerMac.mm */,
 				1AAF263714687C39004A1E8A /* TiledCoreAnimationDrawingArea.h */,
 				1AAF263614687C39004A1E8A /* TiledCoreAnimationDrawingArea.mm */,
@@ -8024,6 +8031,8 @@
 			children = (
 				B878B613133428DC006888E9 /* CorrectionPanel.h */,
 				B878B614133428DC006888E9 /* CorrectionPanel.mm */,
+				C1817362205844A900DFDA65 /* DisplayLink.cpp */,
+				C18173602058424700DFDA65 /* DisplayLink.h */,
 				1AFDE65B1954E8D500C48FFA /* LegacySessionStateCoding.cpp */,
 				0FCB4E5818BBE3D9000FCFC9 /* PageClientImplMac.h */,
 				0FCB4E5918BBE3D9000FCFC9 /* PageClientImplMac.mm */,
@@ -8853,6 +8862,7 @@
 				1AC75380183BE50F0072CB15 /* DataReference.h in Headers */,
 				BC032DA610F437D10058C15A /* Decoder.h in Headers */,
 				83891B6C1A68C30B0030F386 /* DiagnosticLoggingClient.h in Headers */,
+				C18173612058424700DFDA65 /* DisplayLink.h in Headers */,
 				5C1427021C23F84C00D41183 /* Download.h in Headers */,
 				A1DF631318E0B7C8003A3E2A /* DownloadClient.h in Headers */,
 				5C1427051C23F84C00D41183 /* DownloadID.h in Headers */,
@@ -10503,6 +10513,7 @@
 				1AC7537F183BE50F0072CB15 /* DataReference.cpp in Sources */,
 				BC032DA510F437D10058C15A /* Decoder.cpp in Sources */,
 				83891B6D1A68C30B0030F386 /* DiagnosticLoggingClient.mm in Sources */,
+				C1817363205844A900DFDA65 /* DisplayLink.cpp in Sources */,
 				5C1427011C23F84C00D41183 /* Download.cpp in Sources */,
 				A1DF631218E0B7C8003A3E2A /* DownloadClient.mm in Sources */,
 				5C1427131C23F89E00D41183 /* DownloadCocoa.mm in Sources */,
@@ -10512,6 +10523,7 @@
 				1AB7D6191288B9D900CFD08C /* DownloadProxyMessageReceiver.cpp in Sources */,
 				F496A4321F58A272004C1757 /* DragDropInteractionState.mm in Sources */,
 				BC8452A71162C80900CAB9B5 /* DrawingArea.cpp in Sources */,
+				C181735F205839F600DFDA65 /* DrawingAreaMac.cpp in Sources */,
 				1A64229912DD029200CAAE2C /* DrawingAreaMessageReceiver.cpp in Sources */,
 				BC2652161182608100243E12 /* DrawingAreaProxy.cpp in Sources */,
 				1A64230812DD09EB00CAAE2C /* DrawingAreaProxyMessageReceiver.cpp in Sources */,

Modified: trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.cpp (229706 => 229707)


--- trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.cpp	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.cpp	2018-03-19 18:04:39 UTC (rev 229707)
@@ -88,7 +88,7 @@
     function();
 }
 
-#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
+#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) && !(PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400)
 RefPtr<WebCore::DisplayRefreshMonitor> DrawingArea::createDisplayRefreshMonitor(PlatformDisplayID)
 {
     return nullptr;

Modified: trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.h (229706 => 229707)


--- trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.h	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.h	2018-03-19 18:04:39 UTC (rev 229707)
@@ -145,6 +145,10 @@
     virtual void deviceOrPageScaleFactorChanged() = 0;
 #endif
 
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+    void displayWasRefreshed();
+#endif
+
 protected:
     DrawingArea(DrawingAreaType, WebPage&);
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.messages.in (229706 => 229707)


--- trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.messages.in	2018-03-19 17:29:57 UTC (rev 229706)
+++ trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.messages.in	2018-03-19 18:04:39 UTC (rev 229707)
@@ -44,4 +44,8 @@
     SetNativeSurfaceHandleForCompositing(uint64_t handle)
     DestroyNativeSurfaceHandleForCompositing() -> (bool handled)
 #endif
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+    DisplayWasRefreshed()
+#endif
 }

Added: trunk/Source/WebKit/WebProcess/WebPage/mac/DrawingAreaMac.cpp (0 => 229707)


--- trunk/Source/WebKit/WebProcess/WebPage/mac/DrawingAreaMac.cpp	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/WebPage/mac/DrawingAreaMac.cpp	2018-03-19 18:04:39 UTC (rev 229707)
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DrawingArea.h"
+
+#include "WebPage.h"
+#include "WebPageProxy.h"
+#include "WebPageProxyMessages.h"
+
+#include <WebCore/DisplayRefreshMonitor.h>
+#include <WebCore/DisplayRefreshMonitorManager.h>
+#include <WebCore/RunLoopObserver.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+
+class DisplayRefreshMonitorMac : public DisplayRefreshMonitor {
+public:
+    static Ref<DisplayRefreshMonitorMac> create(PlatformDisplayID displayID, WebPage& webPage)
+    {
+        return adoptRef(*new DisplayRefreshMonitorMac(displayID, webPage));
+    }
+    
+    virtual ~DisplayRefreshMonitorMac();
+    
+    void displayLinkFired() override;
+    bool requestRefreshCallback() override;
+    
+private:
+    explicit DisplayRefreshMonitorMac(PlatformDisplayID, WebPage&);
+    
+    Ref<WebPage> m_webPage;
+    bool m_hasSentMessage { false };
+    unsigned m_observerID;
+    static unsigned m_counterID;
+    std::unique_ptr<RunLoopObserver> m_runLoopObserver;
+    bool m_firstCallbackInCurrentRunloop { false };
+};
+
+unsigned DisplayRefreshMonitorMac::m_counterID = 0;
+
+DisplayRefreshMonitorMac::DisplayRefreshMonitorMac(PlatformDisplayID displayID, WebPage& webPage)
+    : DisplayRefreshMonitor(displayID)
+    , m_webPage(webPage)
+    , m_observerID(++m_counterID)
+{
+}
+
+DisplayRefreshMonitorMac::~DisplayRefreshMonitorMac()
+{
+    m_webPage->send(Messages::WebPageProxy::StopDisplayLink(m_observerID));
+}
+
+bool DisplayRefreshMonitorMac::requestRefreshCallback()
+{
+    if (!isActive())
+        return false;
+
+    if (!m_hasSentMessage) {
+        m_webPage->send(Messages::WebPageProxy::StartDisplayLink(m_observerID));
+        m_hasSentMessage = true;
+        m_runLoopObserver = std::make_unique<RunLoopObserver>(kCFRunLoopEntry, [this]() {
+            this->m_firstCallbackInCurrentRunloop = true;
+        });
+        m_runLoopObserver->schedule(CFRunLoopGetCurrent());
+    }
+    
+    setIsScheduled(true);
+
+    return true;
+}
+
+void DisplayRefreshMonitorMac::displayLinkFired()
+{
+    ASSERT(isMainThread());
+    if (!m_firstCallbackInCurrentRunloop)
+        return;
+    m_firstCallbackInCurrentRunloop = false;
+
+    // Since we are on the main thread, we can just call handleDisplayRefreshedNotificationOnMainThread here.
+    handleDisplayRefreshedNotificationOnMainThread(this);
+}
+
+void DrawingArea::displayWasRefreshed()
+{
+    DisplayRefreshMonitorManager::sharedManager().displayWasUpdated();
+}
+
+RefPtr<WebCore::DisplayRefreshMonitor> DrawingArea::createDisplayRefreshMonitor(PlatformDisplayID displayID)
+{
+    return DisplayRefreshMonitorMac::create(displayID, m_webPage);
+}
+#endif
+
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to