⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 184011 in webkit


Ignore:
Timestamp:
May 8, 2015, 1:40:32 PM (11 years ago)
Author:
timothy_horton@apple.com
Message:

Flip the direction of the fence in scaleViewAndUpdateGeometryFenced
https://bugs.webkit.org/show_bug.cgi?id=144810

Reviewed by Simon Fraser.

Send the fence from the Web process to the UI process, instead of vice versa.
This means that we won't keep the UI process CAContext blocked for the whole
time that the Web process is doing layout/painting/etc. Instead, we'll start
blocking the Web process CAContext immediately after flushing and before committing,
and send the fence to the UI process to be applied immediately. This minimizes
the amount of time in both processes spent blocked on the fence.

  • Platform/mac/LayerHostingContext.h:
  • Platform/mac/LayerHostingContext.mm:

(WebKit::LayerHostingContext::createFencePort):
Add createFencePort, which creates a MachSendRight wrapping a CA fence port.
Note that you must setFencePort() with this port if you want the LayerHostingContext's
CAContext to block on it!

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::scaleViewAndUpdateGeometryFenced):
(WebKit::WebPageProxy::machSendRightCallback):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:

Create a callback and send it to the Web process along with scaleViewAndUpdateGeometryFenced.

  • UIProcess/mac/WKViewLayoutStrategy.mm:

(-[WKViewDynamicSizeWithMinimumViewSizeLayoutStrategy updateLayout]):
When called back, install the fence port in our CAContext; when the commit goes through,
remove the transient scale as we did previously.

  • WebProcess/WebPage/DrawingArea.h:

(WebKit::DrawingArea::replyWithFenceAfterNextFlush):
(WebKit::DrawingArea::updateGeometry): Deleted.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::scaleViewAndUpdateGeometryFenced):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:

Instead of installing a fence created in the UI process, tell the DrawingArea
to create one and reply to the UI process with it after the next flush.

  • WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
  • WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:

(WebKit::TiledCoreAnimationDrawingArea::flushLayers):
(WebKit::TiledCoreAnimationDrawingArea::replyWithFenceAfterNextFlush):
After flushing, before committing, create a fence and reply to any
callbacks that requested fences, and install it in our context.

Location:
trunk/Source/WebKit2
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r184010 r184011  
     12015-05-08  Timothy Horton  <timothy_horton@apple.com>
     2
     3        Flip the direction of the fence in scaleViewAndUpdateGeometryFenced
     4        https://bugs.webkit.org/show_bug.cgi?id=144810
     5
     6        Reviewed by Simon Fraser.
     7
     8        Send the fence from the Web process to the UI process, instead of vice versa.
     9        This means that we won't keep the UI process CAContext blocked for the whole
     10        time that the Web process is doing layout/painting/etc. Instead, we'll start
     11        blocking the Web process CAContext immediately after flushing and before committing,
     12        and send the fence to the UI process to be applied immediately. This minimizes
     13        the amount of time in both processes spent blocked on the fence.
     14
     15        * Platform/mac/LayerHostingContext.h:
     16        * Platform/mac/LayerHostingContext.mm:
     17        (WebKit::LayerHostingContext::createFencePort):
     18        Add createFencePort, which creates a MachSendRight wrapping a CA fence port.
     19        Note that you must setFencePort() with this port if you want the LayerHostingContext's
     20        CAContext to block on it!
     21
     22        * UIProcess/WebPageProxy.cpp:
     23        (WebKit::WebPageProxy::scaleViewAndUpdateGeometryFenced):
     24        (WebKit::WebPageProxy::machSendRightCallback):
     25        * UIProcess/WebPageProxy.h:
     26        * UIProcess/WebPageProxy.messages.in:
     27        Create a callback and send it to the Web process along with scaleViewAndUpdateGeometryFenced.
     28
     29        * UIProcess/mac/WKViewLayoutStrategy.mm:
     30        (-[WKViewDynamicSizeWithMinimumViewSizeLayoutStrategy updateLayout]):
     31        When called back, install the fence port in our CAContext; when the commit goes through,
     32        remove the transient scale as we did previously.
     33
     34        * WebProcess/WebPage/DrawingArea.h:
     35        (WebKit::DrawingArea::replyWithFenceAfterNextFlush):
     36        (WebKit::DrawingArea::updateGeometry): Deleted.
     37        * WebProcess/WebPage/WebPage.cpp:
     38        (WebKit::WebPage::scaleViewAndUpdateGeometryFenced):
     39        * WebProcess/WebPage/WebPage.h:
     40        * WebProcess/WebPage/WebPage.messages.in:
     41        Instead of installing a fence created in the UI process, tell the DrawingArea
     42        to create one and reply to the UI process with it after the next flush.
     43
     44        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
     45        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
     46        (WebKit::TiledCoreAnimationDrawingArea::flushLayers):
     47        (WebKit::TiledCoreAnimationDrawingArea::replyWithFenceAfterNextFlush):
     48        After flushing, before committing, create a fence and reply to any
     49        callbacks that requested fences, and install it in our context.
     50
    1512015-05-08  Michael Catanzaro  <mcatanzaro@igalia.com>, Martin Robinson <mrobinson@igalia.com>
    252
  • trunk/Source/WebKit2/Platform/mac/LayerHostingContext.h

    r183841 r184011  
    6363    CGColorSpaceRef colorSpace() const;
    6464
    65     // This only works on iOS and OS 10.10+
     65    // Fences only work on iOS and OS 10.10+.
    6666    void setFencePort(mach_port_t);
     67
     68    // createFencePort does not install the fence port on the LayerHostingContext's
     69    // CAContext; call setFencePort() with the newly created port if synchronization
     70    // with this context is desired.
     71    WebCore::MachSendRight createFencePort();
    6772
    6873private:
  • trunk/Source/WebKit2/Platform/mac/LayerHostingContext.mm

    r183846 r184011  
    108108    [m_context setFencePort:fencePort];
    109109}
     110
     111MachSendRight LayerHostingContext::createFencePort()
     112{
     113    return MachSendRight::adopt([m_context createFencePort]);
     114}
    110115#else
    111116NO_RETURN_DUE_TO_ASSERT void LayerHostingContext::setFencePort(mach_port_t fencePort)
     117{
     118    ASSERT_NOT_REACHED();
     119}
     120
     121NO_RETURN_DUE_TO_ASSERT const MachSendRight& LayerHostingContext::createFencePort()
    112122{
    113123    ASSERT_NOT_REACHED();
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r183841 r184011  
    22492249
    22502250#if PLATFORM(COCOA)
    2251 void WebPageProxy::scaleViewAndUpdateGeometryFenced(double scale, IntSize viewSize, const MachSendRight& fencePort)
    2252 {
    2253     if (!isValid())
    2254         return;
     2251void WebPageProxy::scaleViewAndUpdateGeometryFenced(double scale, IntSize viewSize, std::function<void (const MachSendRight&, CallbackBase::Error)> callback)
     2252{
     2253    if (!isValid()) {
     2254        callback(MachSendRight(), CallbackBase::Error::OwnerWasInvalidated);
     2255        return;
     2256    }
    22552257
    22562258    m_viewScaleFactor = scale;
    22572259    if (m_drawingArea)
    22582260        m_drawingArea->willSendUpdateGeometry();
    2259     m_process->send(Messages::WebPage::ScaleViewAndUpdateGeometryFenced(scale, viewSize, fencePort), m_pageID);
     2261    uint64_t callbackID = m_callbacks.put(WTF::move(callback), m_process->throttler().backgroundActivityToken());
     2262    m_process->send(Messages::WebPage::ScaleViewAndUpdateGeometryFenced(scale, viewSize, callbackID), m_pageID);
    22602263}
    22612264#endif
     
    46564659    callback->performCallbackWithReturnValue(range);
    46574660}
     4661
     4662#if PLATFORM(COCOA)
     4663void WebPageProxy::machSendRightCallback(const MachSendRight& sendRight, uint64_t callbackID)
     4664{
     4665    auto callback = m_callbacks.take<MachSendRightCallback>(callbackID);
     4666    if (!callback)
     4667        return;
     4668
     4669    callback->performCallbackWithReturnValue(sendRight);
     4670}
     4671#endif
    46584672
    46594673static bool shouldLogDiagnosticMessage(bool shouldSample)
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r183909 r184011  
    243243#endif
    244244
     245#if PLATFORM(COCOA)
     246typedef GenericCallback<const WebCore::MachSendRight&> MachSendRightCallback;
     247#endif
     248
    245249struct WebPageConfiguration {
    246250    WebPageGroup* pageGroup = nullptr;
     
    650654    void scaleView(double scale);
    651655#if PLATFORM(COCOA)
    652     void scaleViewAndUpdateGeometryFenced(double scale, WebCore::IntSize viewSize, const WebCore::MachSendRight& fencePort);
     656    void scaleViewAndUpdateGeometryFenced(double scale, WebCore::IntSize viewSize, std::function<void (const WebCore::MachSendRight&, CallbackBase::Error)>);
    653657#endif
    654658
     
    13141318    void unsignedCallback(uint64_t, uint64_t);
    13151319    void editingRangeCallback(const EditingRange&, uint64_t);
     1320#if PLATFORM(COCOA)
     1321    void machSendRightCallback(const WebCore::MachSendRight&, uint64_t);
     1322#endif
    13161323    void rectForCharacterRangeCallback(const WebCore::IntRect&, const EditingRange&, uint64_t);
    13171324#if PLATFORM(MAC)
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r183698 r184011  
    195195    PrintFinishedCallback(WebCore::ResourceError error, uint64_t callbackID)
    196196#endif
     197#if PLATFORM(COCOA)
     198    MachSendRightCallback(WebCore::MachSendRight sendRight, uint64_t callbackID)
     199#endif
    197200
    198201    PageScaleFactorDidChange(double scaleFactor)
  • trunk/Source/WebKit2/UIProcess/mac/WKViewLayoutStrategy.mm

    r183889 r184011  
    294294    } else if (scale != _page->viewScaleFactor()) {
    295295#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
    296         CAContext *context = [_wkView.layer context];
    297         MachSendRight fencePort = MachSendRight::adopt([context createFencePort]);
    298         _page->scaleViewAndUpdateGeometryFenced(scale, IntSize(_wkView.frame.size), fencePort);
    299         [context setFencePort:fencePort.sendRight() commitHandler:^{
    300             _wkView._rootLayer.transform = CATransform3DIdentity;
    301         }];
     296        RetainPtr<CAContext> context = [_wkView.layer context];
     297        RetainPtr<WKView> retainedWKView = _wkView;
     298        _page->scaleViewAndUpdateGeometryFenced(scale, IntSize(_wkView.frame.size), [retainedWKView, context] (const WebCore::MachSendRight& fencePort, CallbackBase::Error) {
     299            [context setFencePort:fencePort.sendRight() commitHandler:^{
     300                [retainedWKView _rootLayer].transform = CATransform3DIdentity;
     301            }];
     302        });
    302303#else
    303304        _page->scaleView(scale);
  • trunk/Source/WebKit2/WebProcess/WebPage/DrawingArea.h

    r183841 r184011  
    130130    // Used by TiledCoreAnimationDrawingArea.
    131131    virtual void updateGeometry(const WebCore::IntSize& viewSize, const WebCore::IntSize& layerPosition, bool flushSynchronously) { }
     132
     133    virtual void replyWithFenceAfterNextFlush(uint64_t callbackID) { ASSERT_NOT_REACHED(); }
    132134#endif
    133135
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r183969 r184011  
    14501450
    14511451#if PLATFORM(COCOA)
    1452 void WebPage::scaleViewAndUpdateGeometryFenced(double scale, IntSize viewSize, const MachSendRight& fencePort)
     1452void WebPage::scaleViewAndUpdateGeometryFenced(double scale, IntSize viewSize, uint64_t callbackID)
    14531453{
    14541454    scaleView(scale);
    14551455    m_drawingArea->updateGeometry(viewSize, IntSize(), false);
    1456     m_drawingArea->addFence(fencePort);
     1456    m_drawingArea->replyWithFenceAfterNextFlush(callbackID);
    14571457}
    14581458#endif
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r183909 r184011  
    363363    void scaleView(double scale);
    364364#if PLATFORM(COCOA)
    365     void scaleViewAndUpdateGeometryFenced(double scale, WebCore::IntSize viewSize, const WebCore::MachSendRight& fencePort);
     365    void scaleViewAndUpdateGeometryFenced(double scale, WebCore::IntSize viewSize, uint64_t callbackID);
    366366#endif
    367367
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r183909 r184011  
    204204    ScaleView(double scale)
    205205#if PLATFORM(COCOA)
    206     ScaleViewAndUpdateGeometryFenced(double scale, WebCore::IntSize viewSize, WebCore::MachSendRight fencePort)
     206    ScaleViewAndUpdateGeometryFenced(double scale, WebCore::IntSize viewSize, uint64_t callbackID)
    207207#endif
    208208
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h

    r183841 r184011  
    8787    virtual void attachViewOverlayGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*) override;
    8888
     89    virtual void replyWithFenceAfterNextFlush(uint64_t callbackID) override;
     90
    8991    // WebCore::LayerFlushSchedulerClient
    9092    virtual bool flushLayers() override;
     
    147149
    148150    WebCore::GraphicsLayer* m_viewOverlayRootLayer;
     151
     152    Vector<uint64_t> m_fenceCallbacksForAfterNextFlush;
    149153};
    150154
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm

    r183841 r184011  
    330330            applyTransientZoomToLayers(m_transientZoomScale, m_transientZoomOrigin);
    331331
     332        if (!m_fenceCallbacksForAfterNextFlush.isEmpty()) {
     333            MachSendRight fencePort = m_layerHostingContext->createFencePort();
     334
     335            for (auto callbackID : m_fenceCallbacksForAfterNextFlush)
     336                m_webPage.send(Messages::WebPageProxy::MachSendRightCallback(fencePort, callbackID));
     337            m_fenceCallbacksForAfterNextFlush.clear();
     338
     339            m_layerHostingContext->setFencePort(fencePort.sendRight());
     340        }
     341
    332342        return returnValue;
    333343    }
     
    747757}
    748758
     759void TiledCoreAnimationDrawingArea::replyWithFenceAfterNextFlush(uint64_t callbackID)
     760{
     761    m_fenceCallbacksForAfterNextFlush.append(callbackID);
     762}
     763
    749764} // namespace WebKit
    750765
Note: See TracChangeset for help on using the changeset viewer.