When the WebContent process is blocked from accessing the WindowServer, the call...
authorpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Mar 2018 18:04:39 +0000 (18:04 +0000)
committerpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Mar 2018 18:04:39 +0000 (18:04 +0000)
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):

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

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/DisplayRefreshMonitor.h
Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.cpp
Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.h
Source/WebCore/platform/graphics/ios/DisplayRefreshMonitorIOS.h
Source/WebCore/platform/graphics/mac/DisplayRefreshMonitorMac.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/UIProcess/mac/DisplayLink.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/mac/DisplayLink.h [new file with mode: 0644]
Source/WebKit/UIProcess/mac/WebPageProxyMac.mm
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/WebProcess/WebPage/DrawingArea.cpp
Source/WebKit/WebProcess/WebPage/DrawingArea.h
Source/WebKit/WebProcess/WebPage/DrawingArea.messages.in
Source/WebKit/WebProcess/WebPage/mac/DrawingAreaMac.cpp [new file with mode: 0644]

index aa36545..b68dcac 100644 (file)
@@ -1,3 +1,29 @@
+2018-03-19  Per Arne Vollan  <pvollan@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_gardner@apple.com>
 
         Ensure local appearance actually mirrors the app's appearance
index 1e705c0..4f1af0a 100644 (file)
@@ -42,7 +42,9 @@ class DisplayRefreshMonitor : public RefCounted<DisplayRefreshMonitor> {
 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 @@ protected:
     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; }
index c93984d..d3655cf 100644 (file)
@@ -125,6 +125,14 @@ void DisplayRefreshMonitorManager::windowScreenDidChange(PlatformDisplayID displ
         scheduleAnimation(client);
 }
 
+void DisplayRefreshMonitorManager::displayWasUpdated()
+{
+    for (auto monitor : m_monitors) {
+        if (monitor->isScheduled())
+            monitor->displayLinkFired();
+    }
+}
+
 }
 
 #endif // USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
index 12bdeb4..74e2af6 100644 (file)
@@ -38,7 +38,7 @@ namespace WebCore {
 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 @@ public:
     bool scheduleAnimation(DisplayRefreshMonitorClient&);
     void windowScreenDidChange(PlatformDisplayID, DisplayRefreshMonitorClient&);
 
+    WEBCORE_EXPORT void displayWasUpdated();
+    
 private:
     friend class DisplayRefreshMonitor;
     void displayDidRefresh(DisplayRefreshMonitor&);
index d000f4a..4ff7f96 100644 (file)
@@ -43,7 +43,7 @@ public:
     
     virtual ~DisplayRefreshMonitorIOS();
 
-    void displayLinkFired();
+    void displayLinkFired() override;
     bool requestRefreshCallback() override;
 
 private:
index 0fdcd9e..3f7ccdf 100644 (file)
@@ -43,7 +43,7 @@ public:
     
     virtual ~DisplayRefreshMonitorMac();
 
-    void displayLinkFired();
+    void displayLinkFired() override;
     bool requestRefreshCallback() override;
 
 private:
index 251115b..2b6cafa 100644 (file)
@@ -1,3 +1,35 @@
+2018-03-19  Per Arne Vollan  <pvollan@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_tan@apple.com>
 
         [WebAuthN] Implement authenticatorMakeCredential
index ef42a7a..0a9c99e 100644 (file)
@@ -120,6 +120,10 @@ OBJC_CLASS _WKRemoteObjectRegistry;
 #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 @@ private:
     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 @@ private:
 
     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;
 };
index 30f1e0a..061fea0 100644 (file)
@@ -515,4 +515,9 @@ messages -> WebPageProxy {
     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
 }
diff --git a/Source/WebKit/UIProcess/mac/DisplayLink.cpp b/Source/WebKit/UIProcess/mac/DisplayLink.cpp
new file mode 100644 (file)
index 0000000..c3a2836
--- /dev/null
@@ -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
diff --git a/Source/WebKit/UIProcess/mac/DisplayLink.h b/Source/WebKit/UIProcess/mac/DisplayLink.h
new file mode 100644 (file)
index 0000000..10a17b7
--- /dev/null
@@ -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
+
index 0b6e769..c0759c1 100644 (file)
@@ -605,6 +605,27 @@ _WKRemoteObjectRegistry *WebPageProxy::remoteObjectRegistry()
 }
 #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)
index 2977958..96d1a68 100644 (file)
                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 */; };
                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>"; };
                BC963D6C113DD19500574BE2 /* mac */ = {
                        isa = PBXGroup;
                        children = (
+                               C181735E205839F600DFDA65 /* DrawingAreaMac.cpp */,
                                7C6D37FA172F555F009D2847 /* PageBannerMac.mm */,
                                1AAF263714687C39004A1E8A /* TiledCoreAnimationDrawingArea.h */,
                                1AAF263614687C39004A1E8A /* TiledCoreAnimationDrawingArea.mm */,
                        children = (
                                B878B613133428DC006888E9 /* CorrectionPanel.h */,
                                B878B614133428DC006888E9 /* CorrectionPanel.mm */,
+                               C1817362205844A900DFDA65 /* DisplayLink.cpp */,
+                               C18173602058424700DFDA65 /* DisplayLink.h */,
                                1AFDE65B1954E8D500C48FFA /* LegacySessionStateCoding.cpp */,
                                0FCB4E5818BBE3D9000FCFC9 /* PageClientImplMac.h */,
                                0FCB4E5918BBE3D9000FCFC9 /* PageClientImplMac.mm */,
                                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 */,
                                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 */,
                                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 */,
index a5be52c..3c0f971 100644 (file)
@@ -88,7 +88,7 @@ void DrawingArea::dispatchAfterEnsuringUpdatedScrollPosition(WTF::Function<void
     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;
index f7cdaf9..b653e35 100644 (file)
@@ -145,6 +145,10 @@ public:
     virtual void deviceOrPageScaleFactorChanged() = 0;
 #endif
 
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+    void displayWasRefreshed();
+#endif
+
 protected:
     DrawingArea(DrawingAreaType, WebPage&);
 
index bc675e5..aa615e7 100644 (file)
@@ -44,4 +44,8 @@ messages -> DrawingArea {
     SetNativeSurfaceHandleForCompositing(uint64_t handle)
     DestroyNativeSurfaceHandleForCompositing() -> (bool handled)
 #endif
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+    DisplayWasRefreshed()
+#endif
 }
diff --git a/Source/WebKit/WebProcess/WebPage/mac/DrawingAreaMac.cpp b/Source/WebKit/WebProcess/WebPage/mac/DrawingAreaMac.cpp
new file mode 100644 (file)
index 0000000..0b5668e
--- /dev/null
@@ -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
+
+}