Changeset 241232 in webkit
- Timestamp:
- Feb 8, 2019 8:36:57 PM (5 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r241224 r241232 1 2019-02-08 Chris Dumez <cdumez@apple.com> 2 3 [WK2][macOS] Avoid creating new CVDisplayLink objects for each WebProcess 4 https://bugs.webkit.org/show_bug.cgi?id=194463 5 6 Reviewed by Tim Horton. 7 8 Avoid creating new CVDisplayLink objects for each WebProcess. We really only need one per 9 display, creating such object is expensive and it is even worse in a PSON world where we 10 swap process on navigation. 11 12 This patch moves the DisplayLink storing from WebProcessProxy to WebProcessPool. Also, 13 a DisplayLink can now be associated to several IPC connections instead of having a 1:1 14 mapping. When a DisplayLink no longer has any observers, we now merely stop it instead 15 of destroying it. 16 17 * UIProcess/Cocoa/WebProcessPoolCocoa.mm: 18 (WebKit::WebProcessPool::startDisplayLink): 19 (WebKit::WebProcessPool::stopDisplayLink): 20 (WebKit::WebProcessPool::stopDisplayLinks): 21 * UIProcess/WebProcessPool.h: 22 * UIProcess/WebProcessProxy.cpp: 23 (WebKit::WebProcessProxy::~WebProcessProxy): 24 (WebKit::WebProcessProxy::processWillShutDown): 25 (WebKit::WebProcessProxy::shutDown): 26 * UIProcess/WebProcessProxy.h: 27 * UIProcess/mac/DisplayLink.cpp: 28 (WebKit::DisplayLink::DisplayLink): 29 (WebKit::DisplayLink::addObserver): 30 (WebKit::DisplayLink::removeObserver): 31 (WebKit::DisplayLink::removeObservers): 32 (WebKit::DisplayLink::hasObservers const): 33 (WebKit::DisplayLink::displayLinkCallback): 34 * UIProcess/mac/DisplayLink.h: 35 * UIProcess/mac/WebProcessProxyMac.mm: 36 (WebKit::WebProcessProxy::startDisplayLink): 37 (WebKit::WebProcessProxy::stopDisplayLink): 38 1 39 2019-02-08 Alexander Mikhaylenko <exalm7659@gmail.com> 2 40 -
trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
r241224 r241232 1 1 /* 2 * Copyright (C) 2010-201 8Apple Inc. All rights reserved.2 * Copyright (C) 2010-2019 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 469 469 } 470 470 471 #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) 472 void WebProcessPool::startDisplayLink(IPC::Connection& connection, unsigned observerID, uint32_t displayID) 473 { 474 for (auto& displayLink : m_displayLinks) { 475 if (displayLink->displayID() == displayID) { 476 displayLink->addObserver(connection, observerID); 477 return; 478 } 479 } 480 auto displayLink = std::make_unique<DisplayLink>(displayID); 481 displayLink->addObserver(connection, observerID); 482 m_displayLinks.append(WTFMove(displayLink)); 483 } 484 485 void WebProcessPool::stopDisplayLink(IPC::Connection& connection, unsigned observerID, uint32_t displayID) 486 { 487 for (auto& displayLink : m_displayLinks) { 488 if (displayLink->displayID() == displayID) { 489 displayLink->removeObserver(connection, observerID); 490 return; 491 } 492 } 493 } 494 495 void WebProcessPool::stopDisplayLinks(IPC::Connection& connection) 496 { 497 for (auto& displayLink : m_displayLinks) 498 displayLink->removeObservers(connection); 499 } 500 #endif 501 471 502 // FIXME: Deprecated. Left here until a final decision is made. 472 503 void WebProcessPool::setCookieStoragePartitioningEnabled(bool enabled) -
trunk/Source/WebKit/UIProcess/WebProcessPool.h
r241223 r241232 72 72 #endif 73 73 74 #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) 75 #include "DisplayLink.h" 76 #endif 77 74 78 namespace API { 75 79 class AutomationClient; … … 207 211 void clearPluginClientPolicies(); 208 212 const HashMap<String, HashMap<String, HashMap<String, uint8_t>>>& pluginLoadClientPolicies() const { return m_pluginLoadClientPolicies; } 213 #endif 214 215 #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) 216 void startDisplayLink(IPC::Connection&, unsigned observerID, uint32_t displayID); 217 void stopDisplayLink(IPC::Connection&, unsigned observerID, uint32_t displayID); 218 void stopDisplayLinks(IPC::Connection&); 209 219 #endif 210 220 … … 731 741 HashMap<String, std::unique_ptr<WebCore::PrewarmInformation>> m_prewarmInformationPerRegistrableDomain; 732 742 743 #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) 744 Vector<std::unique_ptr<DisplayLink>> m_displayLinks; 745 #endif 746 733 747 #if PLATFORM(GTK) || PLATFORM(WPE) 734 748 bool m_sandboxEnabled { false }; -
trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp
r241132 r241232 163 163 WebPasteboardProxy::singleton().removeWebProcessProxy(*this); 164 164 165 #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) 166 if (state() == State::Running) 167 processPool().stopDisplayLinks(*connection()); 168 #endif 169 165 170 if (m_webConnection) 166 171 m_webConnection->invalidate(); … … 240 245 { 241 246 ASSERT_UNUSED(connection, this->connection() == &connection); 247 248 #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) 249 processPool().stopDisplayLinks(connection); 250 #endif 242 251 243 252 for (auto& page : m_pageMap.values()) -
trunk/Source/WebKit/UIProcess/WebProcessProxy.h
r241113 r241232 51 51 #include <wtf/RefPtr.h> 52 52 53 #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)54 #include "DisplayLink.h"55 #endif56 57 53 namespace API { 58 54 class Navigation; … … 422 418 ProcessThrottler::BackgroundActivityToken m_backgroundActivityTokenForFullscreenFormControls; 423 419 #endif 424 425 #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)426 Vector<std::unique_ptr<DisplayLink>> m_displayLinks;427 #endif428 420 }; 429 421 -
trunk/Source/WebKit/UIProcess/mac/DisplayLink.cpp
r239747 r241232 1 1 /* 2 * Copyright (C) 2018 Apple Inc. All rights reserved.2 * Copyright (C) 2018-2019 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) 30 30 31 #include "DrawingAreaMessages.h"32 31 #include "WebProcessMessages.h" 33 #include "WebProcessProxy.h"34 32 #include <wtf/ProcessPrivilege.h> 35 33 36 34 namespace WebKit { 37 35 38 DisplayLink::DisplayLink(WebCore::PlatformDisplayID displayID, WebProcessProxy& webProcessProxy) 39 : m_connection(webProcessProxy.connection()) 40 , m_displayID(displayID) 36 DisplayLink::DisplayLink(WebCore::PlatformDisplayID displayID) 37 : m_displayID(displayID) 41 38 { 42 39 ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer)); … … 52 49 return; 53 50 } 54 55 error = CVDisplayLinkStart(m_displayLink);56 if (error)57 WTFLogAlways("Could not start the display link: %d", error);58 51 } 59 52 … … 69 62 } 70 63 71 void DisplayLink::addObserver( unsigned observerID)64 void DisplayLink::addObserver(IPC::Connection& connection, unsigned observerID) 72 65 { 73 m_observers.add(observerID); 66 ASSERT(RunLoop::isMain()); 67 bool isRunning = !m_observers.isEmpty(); 68 69 { 70 LockHolder locker(m_observersLock); 71 m_observers.ensure(&connection, [] { 72 return Vector<unsigned> { }; 73 }).iterator->value.append(observerID); 74 } 75 76 if (!isRunning) { 77 CVReturn error = CVDisplayLinkStart(m_displayLink); 78 if (error) 79 WTFLogAlways("Could not start the display link: %d", error); 80 } 74 81 } 75 82 76 void DisplayLink::removeObserver( unsigned observerID)83 void DisplayLink::removeObserver(IPC::Connection& connection, unsigned observerID) 77 84 { 78 m_observers.remove(observerID); 85 ASSERT(RunLoop::isMain()); 86 87 { 88 LockHolder locker(m_observersLock); 89 90 auto it = m_observers.find(&connection); 91 if (it == m_observers.end()) 92 return; 93 bool removed = it->value.removeFirst(observerID); 94 ASSERT_UNUSED(removed, removed); 95 if (it->value.isEmpty()) 96 m_observers.remove(it); 97 } 98 99 if (m_observers.isEmpty()) 100 CVDisplayLinkStop(m_displayLink); 101 } 102 103 void DisplayLink::removeObservers(IPC::Connection& connection) 104 { 105 ASSERT(RunLoop::isMain()); 106 107 { 108 LockHolder locker(m_observersLock); 109 m_observers.remove(&connection); 110 } 111 112 if (m_observers.isEmpty()) 113 CVDisplayLinkStop(m_displayLink); 79 114 } 80 115 81 116 bool DisplayLink::hasObservers() const 82 117 { 118 ASSERT(RunLoop::isMain()); 83 119 return !m_observers.isEmpty(); 84 120 } … … 86 122 CVReturn DisplayLink::displayLinkCallback(CVDisplayLinkRef displayLinkRef, const CVTimeStamp*, const CVTimeStamp*, CVOptionFlags, CVOptionFlags*, void* data) 87 123 { 88 DisplayLink* displayLink = static_cast<DisplayLink*>(data); 89 displayLink->m_connection->send(Messages::WebProcess::DisplayWasRefreshed(displayLink->m_displayID), 0); 124 auto* displayLink = static_cast<DisplayLink*>(data); 125 LockHolder locker(displayLink->m_observersLock); 126 for (auto& connection : displayLink->m_observers.keys()) 127 connection->send(Messages::WebProcess::DisplayWasRefreshed(displayLink->m_displayID), 0); 90 128 return kCVReturnSuccess; 91 129 } 92 130 93 } 131 } // namespace WebKit 94 132 95 133 #endif -
trunk/Source/WebKit/UIProcess/mac/DisplayLink.h
r241129 r241232 1 1 /* 2 * Copyright (C) 2018 Apple Inc. All rights reserved.2 * Copyright (C) 2018-2019 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 29 29 30 30 #include <CoreVideo/CVDisplayLink.h> 31 32 31 #include <WebCore/PlatformScreen.h> 33 #include <wtf/HashSet.h> 32 #include <wtf/HashMap.h> 33 #include <wtf/Lock.h> 34 34 35 35 namespace IPC { … … 38 38 39 39 namespace WebKit { 40 41 class WebProcessProxy;42 40 43 41 class DisplayLink { 44 42 WTF_MAKE_FAST_ALLOCATED; 45 43 public: 46 DisplayLink(WebCore::PlatformDisplayID, WebProcessProxy&);44 explicit DisplayLink(WebCore::PlatformDisplayID); 47 45 ~DisplayLink(); 48 46 49 void addObserver(unsigned observerID); 50 void removeObserver(unsigned observerID); 47 void addObserver(IPC::Connection&, unsigned observerID); 48 void removeObserver(IPC::Connection&, unsigned observerID); 49 void removeObservers(IPC::Connection&); 51 50 bool hasObservers() const; 52 51 … … 57 56 58 57 CVDisplayLinkRef m_displayLink { nullptr }; 59 HashSet<unsigned> m_observers;60 RefPtr<IPC::Connection> m_connection;61 WebCore::PlatformDisplayID m_displayID { 0 };58 Lock m_observersLock; 59 HashMap<RefPtr<IPC::Connection>, Vector<unsigned>> m_observers; 60 WebCore::PlatformDisplayID m_displayID; 62 61 }; 63 62 64 } 63 } // namespace WebKit 65 64 66 65 #endif -
trunk/Source/WebKit/UIProcess/mac/WebProcessProxyMac.mm
r238434 r241232 75 75 { 76 76 ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer)); 77 for (auto& displayLink : m_displayLinks) { 78 if (displayLink->displayID() == displayID) { 79 displayLink->addObserver(observerID); 80 return; 81 } 82 } 83 auto displayLink = std::make_unique<DisplayLink>(displayID, *this); 84 displayLink->addObserver(observerID); 85 m_displayLinks.append(WTFMove(displayLink)); 77 ASSERT(connection()); 78 processPool().startDisplayLink(*connection(), observerID, displayID); 86 79 } 87 80 88 81 void WebProcessProxy::stopDisplayLink(unsigned observerID, uint32_t displayID) 89 82 { 90 size_t pos = 0; 91 for (auto& displayLink : m_displayLinks) { 92 if (displayLink->displayID() == displayID) { 93 displayLink->removeObserver(observerID); 94 if (!displayLink->hasObservers()) 95 m_displayLinks.remove(pos); 96 return; 97 } 98 pos++; 99 } 83 ASSERT(connection()); 84 processPool().stopDisplayLink(*connection(), observerID, displayID); 100 85 } 101 86 #endif
Note: See TracChangeset
for help on using the changeset viewer.