Skip to content

Commit 0ecadc1

Browse files
committed
Address safer CPP failures in DisplayLink.h
https://bugs.webkit.org/show_bug.cgi?id=290238 Reviewed by Geoffrey Garen. * Source/WebKit/SaferCPPExpectations/NoUnretainedMemberCheckerExpectations: * Source/WebKit/UIProcess/DisplayLink.h: (WTF::DefaultRefDerefTraits<__CVDisplayLink>::refIfNotNull): (WTF::DefaultRefDerefTraits<__CVDisplayLink>::derefIfNotNull): * Source/WebKit/UIProcess/mac/DisplayLinkMac.cpp: (WebKit::createDisplayLinkWithDisplay): (WebKit::DisplayLink::platformInitialize): (WebKit::DisplayLink::platformFinalize): (WebKit::DisplayLink::platformIsRunning const): (WebKit::DisplayLink::platformStart): (WebKit::DisplayLink::platformStop): Canonical link: https://commits.webkit.org/292565@main
1 parent fa88418 commit 0ecadc1

3 files changed

Lines changed: 34 additions & 15 deletions

File tree

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.mm
2-
UIProcess/DisplayLink.h
32
UIProcess/mac/PageClientImplMac.h
43
WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm
54
WebProcess/InjectedBundle/InjectedBundle.h

Source/WebKit/UIProcess/DisplayLink.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@
4848
struct wpe_playstation_display;
4949
#endif
5050

51+
namespace WTF {
52+
#if PLATFORM(MAC)
53+
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
54+
template<> struct DefaultRefDerefTraits<__CVDisplayLink> {
55+
static CVDisplayLinkRef refIfNotNull(CVDisplayLinkRef displayLink) { return CVDisplayLinkRetain(displayLink); }
56+
static void derefIfNotNull(CVDisplayLinkRef displayLink) { CVDisplayLinkRelease(displayLink); }
57+
};
58+
ALLOW_DEPRECATED_DECLARATIONS_END
59+
#endif // PLATFORM(MAC)
60+
}
61+
5162
namespace WebKit {
5263

5364
class DisplayLink {
@@ -113,7 +124,7 @@ class DisplayLink {
113124
};
114125

115126
#if PLATFORM(MAC)
116-
CVDisplayLinkRef m_displayLink { nullptr };
127+
RefPtr<__CVDisplayLink> m_displayLink;
117128
#endif
118129
#if PLATFORM(GTK) || PLATFORM(WPE)
119130
std::unique_ptr<DisplayVBlankMonitor> m_vblankMonitor;

Source/WebKit/UIProcess/mac/DisplayLinkMac.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,37 @@ namespace WebKit {
3636

3737
using namespace WebCore;
3838

39+
static RefPtr<__CVDisplayLink> createDisplayLinkWithDisplay(CGDirectDisplayID displayID)
40+
{
41+
CVDisplayLinkRef displayLink = nullptr;
42+
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
43+
CVReturn error = CVDisplayLinkCreateWithCGDisplay(displayID, &displayLink);
44+
ALLOW_DEPRECATED_DECLARATIONS_END
45+
if (error) {
46+
RELEASE_LOG_FAULT(DisplayLink, "Could not create a display link for display %u: error %d", displayID, error);
47+
return nullptr;
48+
}
49+
return adoptRef(displayLink);
50+
}
51+
3952
void DisplayLink::platformInitialize()
4053
{
4154
// FIXME: We can get here with displayID == 0 (webkit.org/b/212120), in which case CVDisplayLinkCreateWithCGDisplay()
4255
// probably defaults to the main screen.
4356
ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
44-
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
45-
CVReturn error = CVDisplayLinkCreateWithCGDisplay(m_displayID, &m_displayLink);
46-
ALLOW_DEPRECATED_DECLARATIONS_END
47-
if (error) {
48-
RELEASE_LOG_FAULT(DisplayLink, "Could not create a display link for display %u: error %d", m_displayID, error);
57+
m_displayLink = createDisplayLinkWithDisplay(m_displayID);
58+
if (!m_displayLink)
4959
return;
50-
}
5160

5261
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
53-
error = CVDisplayLinkSetOutputCallback(m_displayLink, displayLinkCallback, this);
62+
auto error = CVDisplayLinkSetOutputCallback(m_displayLink.get(), displayLinkCallback, this);
5463
ALLOW_DEPRECATED_DECLARATIONS_END
5564
if (error) {
5665
RELEASE_LOG_FAULT(DisplayLink, "DisplayLink: Could not set the display link output callback for display %u: error %d", m_displayID, error);
5766
return;
5867
}
5968

60-
m_displayNominalFramesPerSecond = nominalFramesPerSecondFromDisplayLink(m_displayLink);
69+
m_displayNominalFramesPerSecond = nominalFramesPerSecondFromDisplayLink(m_displayLink.get());
6170
}
6271

6372
void DisplayLink::platformFinalize()
@@ -68,8 +77,8 @@ void DisplayLink::platformFinalize()
6877
return;
6978

7079
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
71-
CVDisplayLinkStop(m_displayLink);
72-
CVDisplayLinkRelease(m_displayLink);
80+
CVDisplayLinkStop(m_displayLink.get());
81+
m_displayLink = nullptr;
7382
ALLOW_DEPRECATED_DECLARATIONS_END
7483
}
7584

@@ -88,14 +97,14 @@ ALLOW_DEPRECATED_DECLARATIONS_END
8897
bool DisplayLink::platformIsRunning() const
8998
{
9099
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
91-
return CVDisplayLinkIsRunning(m_displayLink);
100+
return CVDisplayLinkIsRunning(m_displayLink.get());
92101
ALLOW_DEPRECATED_DECLARATIONS_END
93102
}
94103

95104
void DisplayLink::platformStart()
96105
{
97106
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
98-
CVReturn error = CVDisplayLinkStart(m_displayLink);
107+
CVReturn error = CVDisplayLinkStart(m_displayLink.get());
99108
ALLOW_DEPRECATED_DECLARATIONS_END
100109
if (error)
101110
RELEASE_LOG_FAULT(DisplayLink, "DisplayLink: Could not start the display link: %d", error);
@@ -104,7 +113,7 @@ ALLOW_DEPRECATED_DECLARATIONS_END
104113
void DisplayLink::platformStop()
105114
{
106115
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
107-
CVDisplayLinkStop(m_displayLink);
116+
CVDisplayLinkStop(m_displayLink.get());
108117
ALLOW_DEPRECATED_DECLARATIONS_END
109118
}
110119

0 commit comments

Comments
 (0)