Changeset 247238 in webkit


Ignore:
Timestamp:
Jul 8, 2019 4:51:43 PM (5 years ago)
Author:
youenn@apple.com
Message:

Hop explicitly to the main thread after generating a frame in ScreenDisplayCaptureSourceMac
https://bugs.webkit.org/show_bug.cgi?id=199581

Reviewed by Eric Carlson.

Instead of locking and setting the current frame from a background thread, hop to the main thread.
This also makes sure the weakThis check is done in the main thread.
Manually tested.

  • platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h:

(WebCore::ScreenDisplayCaptureSourceMac::DisplaySurface::DisplaySurface):

  • platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:

(WebCore::ScreenDisplayCaptureSourceMac::createDisplayStream):
(WebCore::ScreenDisplayCaptureSourceMac::generateFrame):
(WebCore::ScreenDisplayCaptureSourceMac::newFrame):
(WebCore::ScreenDisplayCaptureSourceMac::frameAvailable): Deleted.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r247232 r247238  
     12019-07-08  Youenn Fablet  <youenn@apple.com>
     2
     3        Hop explicitly to the main thread after generating a frame in ScreenDisplayCaptureSourceMac
     4        https://bugs.webkit.org/show_bug.cgi?id=199581
     5
     6        Reviewed by Eric Carlson.
     7
     8        Instead of locking and setting the current frame from a background thread, hop to the main thread.
     9        This also makes sure the weakThis check is done in the main thread.
     10        Manually tested.
     11
     12        * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h:
     13        (WebCore::ScreenDisplayCaptureSourceMac::DisplaySurface::DisplaySurface):
     14        * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:
     15        (WebCore::ScreenDisplayCaptureSourceMac::createDisplayStream):
     16        (WebCore::ScreenDisplayCaptureSourceMac::generateFrame):
     17        (WebCore::ScreenDisplayCaptureSourceMac::newFrame):
     18        (WebCore::ScreenDisplayCaptureSourceMac::frameAvailable): Deleted.
     19
    1202019-07-08  Daniel Bates  <dabates@apple.com>
    221
  • trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h

    r243033 r247238  
    5555    void displayWasReconfigured(CGDirectDisplayID, CGDisplayChangeSummaryFlags);
    5656
    57     void frameAvailable(CGDisplayStreamFrameStatus, uint64_t, IOSurfaceRef, CGDisplayStreamUpdateRef);
    58 
    5957    DisplayCaptureSourceCocoa::DisplayFrameType generateFrame() final;
    6058    RealtimeMediaSourceSettings::DisplaySurfaceType surfaceType() const final { return RealtimeMediaSourceSettings::DisplaySurfaceType::Monitor; }
     
    7573    public:
    7674        DisplaySurface() = default;
     75        explicit DisplaySurface(IOSurfaceRef surface)
     76            : m_surface(surface)
     77        {
     78            if (m_surface)
     79                IOSurfaceIncrementUseCount(m_surface.get());
     80        }
     81
    7782        ~DisplaySurface()
    7883        {
     
    97102    };
    98103
    99     mutable Lock m_currentFrameMutex;
     104    void newFrame(CGDisplayStreamFrameStatus, DisplaySurface&&);
     105
    100106    DisplaySurface m_currentFrame;
    101107    RetainPtr<CGDisplayStreamRef> m_displayStream;
  • trunk/Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm

    r245216 r247238  
    155155        auto weakThis = makeWeakPtr(*this);
    156156        auto frameAvailableBlock = ^(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef) {
    157             if (!weakThis)
     157
     158            if (!frameSurface || !displayTime)
    158159                return;
    159160
    160             weakThis->frameAvailable(status, displayTime, frameSurface, updateRef);
     161            size_t count;
     162            auto* rects = CGDisplayStreamUpdateGetRects(updateRef, kCGDisplayStreamUpdateDirtyRects, &count);
     163            if (!rects || !count)
     164                return;
     165
     166            RunLoop::main().dispatch([weakThis, status, frame = DisplaySurface { frameSurface }]() mutable {
     167                if (!weakThis)
     168                    return;
     169                weakThis->newFrame(status, WTFMove(frame));
     170            });
    161171        };
    162172
     
    204214DisplayCaptureSourceCocoa::DisplayFrameType ScreenDisplayCaptureSourceMac::generateFrame()
    205215{
    206     DisplaySurface currentFrame;
    207     {
    208         LockHolder lock(m_currentFrameMutex);
    209         currentFrame = m_currentFrame.ioSurface();
    210     }
    211 
    212     return DisplayCaptureSourceCocoa::DisplayFrameType { RetainPtr<IOSurfaceRef> { currentFrame.ioSurface() } };
     216    return DisplayCaptureSourceCocoa::DisplayFrameType { RetainPtr<IOSurfaceRef> { m_currentFrame.ioSurface() } };
    213217}
    214218
     
    254258}
    255259
    256 void ScreenDisplayCaptureSourceMac::frameAvailable(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef)
     260void ScreenDisplayCaptureSourceMac::newFrame(CGDisplayStreamFrameStatus status, DisplaySurface&& newFrame)
    257261{
    258262    switch (status) {
     
    272276    }
    273277
    274     if (!frameSurface || !displayTime)
    275         return;
    276 
    277     size_t count;
    278     auto* rects = CGDisplayStreamUpdateGetRects(updateRef, kCGDisplayStreamUpdateDirtyRects, &count);
    279     if (!rects || !count)
    280         return;
    281 
    282     LockHolder lock(m_currentFrameMutex);
    283     m_currentFrame = frameSurface;
     278    m_currentFrame = WTFMove(newFrame);
    284279}
    285280
Note: See TracChangeset for help on using the changeset viewer.