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

Changeset 291733 in webkit


Ignore:
Timestamp:
Mar 22, 2022, 7:06:04 PM (5 years ago)
Author:
Simon Fraser
Message:

Swap all RemoteLayerBackingStore buffers in a single IPC
​https://bugs.webkit.org/show_bug.cgi?id=238210

Reviewed by Tim Horton.

PrepareBuffersForDisplay is a sync IPC (since we need the result before painting), and sync
IPC per-layer has performance impact. So group all the swapping into a single IPC with the
GPU Process.

The PrepareBuffersForDisplay message now takes a vector of
PrepareBackingStoreBuffersInputData, and returns a vector of
PrepareBackingStoreBuffersOutputData. Swapped buffers are applied to the
RemoteLayerBackingStore as before, with a minor change in the place that setNeedsDisplay()
is called in the case where we need a full display.

  • GPUProcess/graphics/RemoteRenderingBackend.cpp:

(WebKit::RemoteRenderingBackend::prepareBuffersForDisplay):
(WebKit::RemoteRenderingBackend::prepareLayerBuffersForDisplay):

  • GPUProcess/graphics/RemoteRenderingBackend.h:
  • GPUProcess/graphics/RemoteRenderingBackend.messages.in:
  • Scripts/webkit/messages.py:

(headers_for_type):

  • Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
  • Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:

(WebKit::RemoteLayerBackingStore::applySwappedBuffers):
(WebKit::RemoteLayerBackingStore::performDelegatedLayerDisplay):
(WebKit::RemoteLayerBackingStore::prepareToDisplay):
(WebKit::RemoteLayerBackingStore::ensureFrontBuffer):
(WebKit::RemoteLayerBackingStore::prepareBuffers):
(WebKit::operator<<): Deleted.

  • Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h:
  • Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm:

(WebKit::RemoteLayerBackingStoreCollection::prepareBackingStoreBuffers): Deleted.

  • Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h:
  • Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm:

(WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::prepareBackingStoresForDisplay):
(WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::prepareBackingStoreBuffers): Deleted.

  • WebKit.xcodeproj/project.pbxproj:
  • WebProcess/GPU/graphics/PrepareBackingStoreBuffersData.h: Added.

(WebKit::PrepareBackingStoreBuffersInputData::encode const):
(WebKit::PrepareBackingStoreBuffersInputData::decode):
(WebKit::PrepareBackingStoreBuffersOutputData::encode const):
(WebKit::PrepareBackingStoreBuffersOutputData::decode):

  • WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:

(WebKit::RemoteRenderingBackendProxy::prepareBuffersForDisplay):

  • WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:
Location:
trunk/Source/WebKit
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r291732 r291733  
     12022-03-22  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Swap all RemoteLayerBackingStore buffers in a single IPC
     4        https://bugs.webkit.org/show_bug.cgi?id=238210
     5
     6        Reviewed by Tim Horton.
     7
     8        PrepareBuffersForDisplay is a sync IPC (since we need the result before painting), and sync
     9        IPC per-layer has performance impact. So group all the swapping into a single IPC with the
     10        GPU Process.
     11
     12        The PrepareBuffersForDisplay message now takes a vector of
     13        PrepareBackingStoreBuffersInputData, and returns a vector of
     14        PrepareBackingStoreBuffersOutputData. Swapped buffers are applied to the
     15        RemoteLayerBackingStore as before, with a minor change in the place that setNeedsDisplay()
     16        is called in the case where we need a full display.
     17
     18        * GPUProcess/graphics/RemoteRenderingBackend.cpp:
     19        (WebKit::RemoteRenderingBackend::prepareBuffersForDisplay):
     20        (WebKit::RemoteRenderingBackend::prepareLayerBuffersForDisplay):
     21        * GPUProcess/graphics/RemoteRenderingBackend.h:
     22        * GPUProcess/graphics/RemoteRenderingBackend.messages.in:
     23        * Scripts/webkit/messages.py:
     24        (headers_for_type):
     25        * Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
     26        * Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
     27        (WebKit::RemoteLayerBackingStore::applySwappedBuffers):
     28        (WebKit::RemoteLayerBackingStore::performDelegatedLayerDisplay):
     29        (WebKit::RemoteLayerBackingStore::prepareToDisplay):
     30        (WebKit::RemoteLayerBackingStore::ensureFrontBuffer):
     31        (WebKit::RemoteLayerBackingStore::prepareBuffers):
     32        (WebKit::operator<<): Deleted.
     33        * Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h:
     34        * Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm:
     35        (WebKit::RemoteLayerBackingStoreCollection::prepareBackingStoreBuffers): Deleted.
     36        * Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h:
     37        * Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm:
     38        (WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::prepareBackingStoresForDisplay):
     39        (WebKit::RemoteLayerWithRemoteRenderingBackingStoreCollection::prepareBackingStoreBuffers): Deleted.
     40        * WebKit.xcodeproj/project.pbxproj:
     41        * WebProcess/GPU/graphics/PrepareBackingStoreBuffersData.h: Added.
     42        (WebKit::PrepareBackingStoreBuffersInputData::encode const):
     43        (WebKit::PrepareBackingStoreBuffersInputData::decode):
     44        (WebKit::PrepareBackingStoreBuffersOutputData::encode const):
     45        (WebKit::PrepareBackingStoreBuffersOutputData::decode):
     46        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
     47        (WebKit::RemoteRenderingBackendProxy::prepareBuffersForDisplay):
     48        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:
     49
    1502022-03-22  Sihui Liu  <sihui_liu@apple.com>
    251
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp

    r291243 r291733  
    400400}
    401401
     402void RemoteRenderingBackend::prepareBuffersForDisplay(Vector<PrepareBackingStoreBuffersInputData> swapBuffersInput, CompletionHandler<void(const Vector<PrepareBackingStoreBuffersOutputData>&)>&& completionHandler)
     403{
     404    Vector<PrepareBackingStoreBuffersOutputData> outputData;
     405    outputData.resizeToFit(swapBuffersInput.size());
     406
     407    for (unsigned i = 0; i < swapBuffersInput.size(); ++i)
     408        prepareLayerBuffersForDisplay(swapBuffersInput[i], outputData[i]);
     409
     410    completionHandler(outputData);
     411}
     412
    402413// This is the GPU Process version of RemoteLayerBackingStore::prepareBuffers().
    403 void RemoteRenderingBackend::prepareBuffersForDisplay(const BufferIdentifierSet& bufferSet, bool supportsPartialRepaint, bool hasEmptyDirtyRegion, CompletionHandler<void(const BufferIdentifierSet& swappedBufferSet, std::optional<ImageBufferBackendHandle>&& frontBufferHandle, SwapBuffersDisplayRequirement prepareResult)>&& completionHandler)
     414void RemoteRenderingBackend::prepareLayerBuffersForDisplay(const PrepareBackingStoreBuffersInputData& inputData, PrepareBackingStoreBuffersOutputData& outputData)
    404415{
    405416    auto fetchBuffer = [&](std::optional<RenderingResourceIdentifier> identifier) -> ImageBuffer* {
    … …  
    413424    };
    414425
    415     auto frontBuffer = fetchBuffer(bufferSet.front);
    416     auto backBuffer = fetchBuffer(bufferSet.back);
    417     auto secondaryBackBuffer = fetchBuffer(bufferSet.secondaryBack);
     426    auto frontBuffer = fetchBuffer(inputData.bufferSet.front);
     427    auto backBuffer = fetchBuffer(inputData.bufferSet.back);
     428    auto secondaryBackBuffer = fetchBuffer(inputData.bufferSet.secondaryBack);
    418429
    419430    LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "GPU Process: RemoteRenderingBackend::prepareBuffersForDisplay - front "
    420         << bufferSet.front << " (in-use " << (frontBuffer && frontBuffer->isInUse()) << ") "
    421         << bufferSet.back << " (in-use " << (backBuffer && backBuffer->isInUse()) << ") "
    422         << bufferSet.secondaryBack << " (in-use " << (secondaryBackBuffer && secondaryBackBuffer->isInUse()) << ") ");
     431        << inputData.bufferSet.front << " (in-use " << (frontBuffer && frontBuffer->isInUse()) << ") "
     432        << inputData.bufferSet.back << " (in-use " << (backBuffer && backBuffer->isInUse()) << ") "
     433        << inputData.bufferSet.secondaryBack << " (in-use " << (secondaryBackBuffer && secondaryBackBuffer->isInUse()) << ") ");
    423434
    424435    bool needsFullDisplay = false;
    … …  
    430441    }
    431442
    432     if (frontBuffer && !needsFullDisplay && hasEmptyDirtyRegion) {
     443    if (frontBuffer && !needsFullDisplay && inputData.hasEmptyDirtyRegion) {
    433444        // No swap necessary, but we do need to return the front buffer handle.
    434         auto frontBufferHandle = handleFromBuffer(*frontBuffer);
    435         auto resultBufferSet = BufferIdentifierSet { bufferIdentifer(frontBuffer), bufferIdentifer(backBuffer), bufferIdentifer(secondaryBackBuffer) };
    436         completionHandler(resultBufferSet, WTFMove(frontBufferHandle), SwapBuffersDisplayRequirement::NeedsNoDisplay);
     445        outputData.frontBufferHandle = handleFromBuffer(*frontBuffer);
     446        outputData.bufferSet = BufferIdentifierSet { bufferIdentifer(frontBuffer), bufferIdentifer(backBuffer), bufferIdentifer(secondaryBackBuffer) };
     447        outputData.displayRequirement = SwapBuffersDisplayRequirement::NeedsNoDisplay;
    437448        return;
    438449    }
    439450   
    440     if (!frontBuffer || !supportsPartialRepaint)
     451    if (!frontBuffer || !inputData.supportsPartialRepaint)
    441452        needsFullDisplay = true;
    442453
    … …  
    453464    std::swap(frontBuffer, backBuffer);
    454465
    455     std::optional<ImageBufferBackendHandle> frontBufferHandle;
     466    outputData.bufferSet = BufferIdentifierSet { bufferIdentifer(frontBuffer), bufferIdentifer(backBuffer), bufferIdentifer(secondaryBackBuffer) };
    456467    if (frontBuffer) {
    457468        auto previousState = frontBuffer->setNonVolatile();
    … …  
    459470            needsFullDisplay = true;
    460471
    461         frontBufferHandle = handleFromBuffer(*frontBuffer);
    462     }
    463 
    464     auto resultBufferSet = BufferIdentifierSet { bufferIdentifer(frontBuffer), bufferIdentifer(backBuffer), bufferIdentifer(secondaryBackBuffer) };
     472        outputData.frontBufferHandle = handleFromBuffer(*frontBuffer);
     473    } else
     474        needsFullDisplay = true;
    465475
    466476    LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "GPU Process: prepareBuffersForDisplay - swapped from ["
    467         << bufferSet.front << ", " << bufferSet.back << ", " << bufferSet.secondaryBack << "] to ["
    468         << resultBufferSet.front << ", " << resultBufferSet.back << ", " << resultBufferSet.secondaryBack << "]");
    469 
    470     auto displayRequirement = needsFullDisplay ? SwapBuffersDisplayRequirement::NeedsFullDisplay : SwapBuffersDisplayRequirement::NeedsNormalDisplay;
    471     completionHandler(resultBufferSet, WTFMove(frontBufferHandle), displayRequirement);
     477        << inputData.bufferSet.front << ", " << inputData.bufferSet.back << ", " << inputData.bufferSet.secondaryBack << "] to ["
     478        << outputData.bufferSet.front << ", " << outputData.bufferSet.back << ", " << outputData.bufferSet.secondaryBack << "]");
     479
     480    outputData.displayRequirement = needsFullDisplay ? SwapBuffersDisplayRequirement::NeedsFullDisplay : SwapBuffersDisplayRequirement::NeedsNormalDisplay;
    472481}
    473482
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h

    r291243 r291733  
    6969class RemoteDisplayListRecorder;
    7070struct BufferIdentifierSet;
     71struct PrepareBackingStoreBuffersInputData;
     72struct PrepareBackingStoreBuffersOutputData;
    7173struct RemoteRenderingBackendCreationParameters;
    7274enum class SwapBuffersDisplayRequirement : uint8_t;
    … …  
    121123    void finalizeRenderingUpdate(RenderingUpdateID);
    122124    void markSurfacesVolatile(const Vector<WebCore::RenderingResourceIdentifier>&, CompletionHandler<void(const Vector<WebCore::RenderingResourceIdentifier>& markedVolatileBufferIdentifiers)>&&);
    123 
    124     void prepareBuffersForDisplay(const BufferIdentifierSet& bufferSet, bool supportsPartialRepaint, bool hasEmptyDirtyRegion, CompletionHandler<void(const BufferIdentifierSet& swappedBufferSet, std::optional<ImageBufferBackendHandle>&& frontBufferHandle, SwapBuffersDisplayRequirement prepareResult)>&&);
     125    void prepareBuffersForDisplay(Vector<PrepareBackingStoreBuffersInputData> swapBuffersInput, CompletionHandler<void(const Vector<PrepareBackingStoreBuffersOutputData>&)>&&);
    125126
    126127    // Received messages translated to use QualifiedRenderingResourceIdentifier.
    … …  
    133134    void releaseRemoteResourceWithQualifiedIdentifier(QualifiedRenderingResourceIdentifier);
    134135    void cacheFontWithQualifiedIdentifier(Ref<WebCore::Font>&&, QualifiedRenderingResourceIdentifier);
     136
     137    void prepareLayerBuffersForDisplay(const PrepareBackingStoreBuffersInputData&, PrepareBackingStoreBuffersOutputData&);
    135138
    136139    Ref<IPC::StreamConnectionWorkQueue> m_workQueue;
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in

    r291243 r291733  
    3838    ReleaseRemoteResource(WebCore::RenderingResourceIdentifier renderingResourceIdentifier)
    3939
    40     PrepareBuffersForDisplay(struct WebKit::BufferIdentifierSet bufferSet, bool supportsPartialRepaint, bool hasEmptyDirtyRegion) -> (struct WebKit::BufferIdentifierSet swappedBufferSet, std::optional<WebKit::ImageBufferBackendHandle> frontBufferHandle, enum:uint8_t WebKit::SwapBuffersDisplayRequirement prepareResult) Synchronous NotStreamEncodable NotStreamEncodableReply
     40    PrepareBuffersForDisplay(Vector<WebKit::PrepareBackingStoreBuffersInputData> swapBuffersInput) -> (Vector<WebKit::PrepareBackingStoreBuffersOutputData> swapBuffersOutput) Synchronous NotStreamEncodable NotStreamEncodableReply
    4141
    4242    MarkSurfacesVolatile(Vector<WebCore::RenderingResourceIdentifier> renderingResourceIdentifiers) -> (Vector<WebCore::RenderingResourceIdentifier> markedVolatileBufferIdentifiers) Synchronous
  • trunk/Source/WebKit/Scripts/webkit/messages.py

    r291136 r291733  
    890890        'WebKit::PaymentSetupConfiguration': ['"PaymentSetupConfigurationWebKit.h"'],
    891891        'WebKit::PaymentSetupFeatures': ['"ApplePayPaymentSetupFeaturesWebKit.h"'],
     892        'WebKit::PrepareBackingStoreBuffersInputData': ['"PrepareBackingStoreBuffersData.h"'],
     893        'WebKit::PrepareBackingStoreBuffersOutputData': ['"PrepareBackingStoreBuffersData.h"'],
    892894        'WebKit::RespectSelectionAnchor': ['"GestureTypes.h"'],
    893895        'WebKit::RemoteVideoFrameReadReference': ['"RemoteVideoFrameIdentifier.h"'],
  • trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h

    r291599 r291733  
    6868    void setContents(WTF::MachSendRight&& surfaceHandle);
    6969
    70     SwapBuffersDisplayRequirement prepareBuffers(bool hasEmptyDirtyRegion);
    71 
    7270    // Returns true if we need encode the buffer.
    7371    bool layerWillBeDisplayed();
    7472    bool needsDisplay() const;
    7573
     74    bool performDelegatedLayerDisplay();
    7675    void prepareToDisplay();
    7776    void paintContents();
    … …  
    10099
    101100    // Just for RemoteBackingStoreCollection.
    102     void applySwappedBuffers(RefPtr<WebCore::ImageBuffer>&& front, RefPtr<WebCore::ImageBuffer>&& back, RefPtr<WebCore::ImageBuffer>&& secondaryBack);
     101    void applySwappedBuffers(RefPtr<WebCore::ImageBuffer>&& front, RefPtr<WebCore::ImageBuffer>&& back, RefPtr<WebCore::ImageBuffer>&& secondaryBack, SwapBuffersDisplayRequirement);
    103102    WebCore::SetNonVolatileResult swapToValidFrontBuffer();
    104103
    … …  
    144143    bool setBufferVolatile(Buffer&);
    145144    WebCore::SetNonVolatileResult setBufferNonVolatile(Buffer&);
     145   
     146    SwapBuffersDisplayRequirement prepareBuffers();
     147    void ensureFrontBuffer();
     148    void dirtyRepaintCounterIfNecessary();
    146149
    147150    PlatformCALayerRemote* m_layer;
  • trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm

    r291599 r291733  
    250250
    251251// Called after buffer swapping in the GPU process.
    252 void RemoteLayerBackingStore::applySwappedBuffers(RefPtr<WebCore::ImageBuffer>&& front, RefPtr<WebCore::ImageBuffer>&& back, RefPtr<WebCore::ImageBuffer>&& secondaryBack)
     252void RemoteLayerBackingStore::applySwappedBuffers(RefPtr<WebCore::ImageBuffer>&& front, RefPtr<WebCore::ImageBuffer>&& back, RefPtr<WebCore::ImageBuffer>&& secondaryBack, SwapBuffersDisplayRequirement displayRequirement)
    253253{
    254254    ASSERT(WebProcess::singleton().shouldUseRemoteRenderingFor(WebCore::RenderingPurpose::DOM));
     255    m_contentsBufferHandle = std::nullopt;
    255256
    256257    m_frontBuffer.imageBuffer = WTFMove(front);
    257258    m_backBuffer.imageBuffer = WTFMove(back);
    258259    m_secondaryBackBuffer.imageBuffer = WTFMove(secondaryBack);
     260
     261    if (displayRequirement == SwapBuffersDisplayRequirement::NeedsNoDisplay)
     262        return;
     263
     264    if (displayRequirement == SwapBuffersDisplayRequirement::NeedsFullDisplay)
     265        setNeedsDisplay();
     266
     267    dirtyRepaintCounterIfNecessary();
     268    ensureFrontBuffer();
    259269}
    260270
    … …  
    273283}
    274284
    275 #if !LOG_DISABLED
    276 static TextStream& operator<<(TextStream& ts, SwapBuffersDisplayRequirement result)
    277 {
    278     switch (result) {
    279     case SwapBuffersDisplayRequirement::NeedsFullDisplay: ts << "full display"; break;
    280     case SwapBuffersDisplayRequirement::NeedsNormalDisplay: ts << "normal display"; break;
    281     case SwapBuffersDisplayRequirement::NeedsNoDisplay: ts << "no display"; break;
    282     }
    283     return ts;
    284 }
    285 #endif
    286 
    287285bool RemoteLayerBackingStore::needsDisplay() const
    288286{
    … …  
    303301}
    304302
    305 void RemoteLayerBackingStore::prepareToDisplay()
    306 {
    307     ASSERT(!m_frontBufferFlushers.size());
    308 
    309     auto* collection = backingStoreCollection();
    310     if (!collection) {
    311         ASSERT_NOT_REACHED();
    312         return;
    313     }
    314 
    315     ASSERT(collection->backingStoreNeedsDisplay(*this));
    316 
    317     LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStore " << m_layer->layerID() << " prepareToDisplay()");
    318 
     303bool RemoteLayerBackingStore::performDelegatedLayerDisplay()
     304{
    319305    auto& layerOwner = *m_layer->owner();
    320306    if (layerOwner.platformCALayerDelegatesDisplay(m_layer)) {
    … …  
    322308        layerOwner.platformCALayerLayerDisplay(m_layer);
    323309        layerOwner.platformCALayerLayerDidDisplay(m_layer);
    324         return;
    325     }
    326 
    327     m_contentsBufferHandle = std::nullopt;
    328 
    329     auto displayRequirement = collection->prepareBackingStoreBuffers(*this);
    330 
    331     LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStore " << m_layer->layerID() << " prepareToDisplay() - " << displayRequirement);
    332 
    333     ASSERT(displayRequirement != SwapBuffersDisplayRequirement::NeedsNoDisplay);
     310        return true;
     311    }
     312   
     313    return false;
     314}
     315
     316void RemoteLayerBackingStore::prepareToDisplay()
     317{
     318    ASSERT(!WebProcess::singleton().shouldUseRemoteRenderingFor(WebCore::RenderingPurpose::DOM));
     319    ASSERT(!m_frontBufferFlushers.size());
     320
     321    auto* collection = backingStoreCollection();
     322    if (!collection) {
     323        ASSERT_NOT_REACHED();
     324        return;
     325    }
     326
     327    ASSERT(collection->backingStoreNeedsDisplay(*this));
     328
     329    LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStore " << m_layer->layerID() << " prepareToDisplay()");
     330
     331    if (performDelegatedLayerDisplay())
     332        return;
     333
     334    auto displayRequirement = prepareBuffers();
     335    if (displayRequirement == SwapBuffersDisplayRequirement::NeedsNoDisplay)
     336        return;
    334337
    335338    if (displayRequirement == SwapBuffersDisplayRequirement::NeedsFullDisplay)
    336339        setNeedsDisplay();
    337340
    338     if (layerOwner.platformCALayerShowRepaintCounter(m_layer)) {
     341    dirtyRepaintCounterIfNecessary();
     342    ensureFrontBuffer();
     343}
     344
     345void RemoteLayerBackingStore::dirtyRepaintCounterIfNecessary()
     346{
     347    if (m_layer->owner()->platformCALayerShowRepaintCounter(m_layer)) {
    339348        WebCore::IntRect indicatorRect(0, 0, 52, 27);
    340349        m_dirtyRegion.unite(indicatorRect);
    341350    }
    342 
     351}
     352
     353void RemoteLayerBackingStore::ensureFrontBuffer()
     354{
     355    if (m_frontBuffer.imageBuffer)
     356        return;
     357
     358    auto* collection = backingStoreCollection();
     359    if (!collection) {
     360        ASSERT_NOT_REACHED();
     361        return;
     362    }
     363
     364    m_frontBuffer.imageBuffer = collection->allocateBufferForBackingStore(*this);
     365
     366#if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
     367    if (m_includeDisplayList == IncludeDisplayList::Yes)
     368        m_frontBuffer.displayListImageBuffer = WebCore::ConcreteImageBuffer<CGDisplayListImageBufferBackend>::create(m_size, m_scale, WebCore::DestinationColorSpace::SRGB(), pixelFormat(), nullptr);
     369#endif
     370}
     371
     372#if !LOG_DISABLED
     373static TextStream& operator<<(TextStream& ts, SwapBuffersDisplayRequirement result)
     374{
     375    switch (result) {
     376    case SwapBuffersDisplayRequirement::NeedsFullDisplay: ts << "full display"; break;
     377    case SwapBuffersDisplayRequirement::NeedsNormalDisplay: ts << "normal display"; break;
     378    case SwapBuffersDisplayRequirement::NeedsNoDisplay: ts << "no display"; break;
     379    }
     380    return ts;
     381}
     382#endif
     383
     384SwapBuffersDisplayRequirement RemoteLayerBackingStore::prepareBuffers()
     385{
     386    ASSERT(!WebProcess::singleton().shouldUseRemoteRenderingFor(WebCore::RenderingPurpose::DOM));
     387    m_contentsBufferHandle = std::nullopt;
     388
     389    auto displayRequirement = SwapBuffersDisplayRequirement::NeedsNoDisplay;
     390
     391    // Make the previous front buffer non-volatile early, so that we can dirty the whole layer if it comes back empty.
     392    if (!hasFrontBuffer() || setFrontBufferNonVolatile() == WebCore::SetNonVolatileResult::Empty)
     393        displayRequirement = SwapBuffersDisplayRequirement::NeedsFullDisplay;
     394    else if (!hasEmptyDirtyRegion())
     395        displayRequirement = SwapBuffersDisplayRequirement::NeedsNormalDisplay;
     396
     397    if (displayRequirement == SwapBuffersDisplayRequirement::NeedsNoDisplay)
     398        return displayRequirement;
     399
     400    if (!supportsPartialRepaint())
     401        displayRequirement = SwapBuffersDisplayRequirement::NeedsFullDisplay;
     402
     403    auto result = swapToValidFrontBuffer();
     404    if (!hasFrontBuffer() || result == WebCore::SetNonVolatileResult::Empty)
     405        displayRequirement = SwapBuffersDisplayRequirement::NeedsFullDisplay;
     406
     407    LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStore " << m_layer->layerID() << " prepareBuffers() - " << displayRequirement);
     408    return displayRequirement;
     409}
     410
     411void RemoteLayerBackingStore::paintContents()
     412{
    343413    if (!m_frontBuffer.imageBuffer) {
    344         m_frontBuffer.imageBuffer = collection->allocateBufferForBackingStore(*this);
    345 
    346 #if ENABLE(CG_DISPLAY_LIST_BACKED_IMAGE_BUFFER)
    347         if (m_includeDisplayList == IncludeDisplayList::Yes)
    348             m_frontBuffer.displayListImageBuffer = WebCore::ConcreteImageBuffer<CGDisplayListImageBufferBackend>::create(m_size, m_scale, WebCore::DestinationColorSpace::SRGB(), pixelFormat(), nullptr);
    349 #endif
    350     }
    351 }
    352 
    353 SwapBuffersDisplayRequirement RemoteLayerBackingStore::prepareBuffers(bool hasEmptyDirtyRegion)
    354 {
    355     ASSERT(!WebProcess::singleton().shouldUseRemoteRenderingFor(WebCore::RenderingPurpose::DOM));
    356 
    357     bool needsFullDisplay = false;
    358 
    359     // Make the previous front buffer non-volatile early, so that we can dirty the whole layer if it comes back empty.
    360     if (setFrontBufferNonVolatile() == WebCore::SetNonVolatileResult::Empty)
    361         needsFullDisplay = true;
    362 
    363     if (!needsFullDisplay && hasEmptyDirtyRegion)
    364         return SwapBuffersDisplayRequirement::NeedsNoDisplay;
    365 
    366     if (!hasFrontBuffer() || !supportsPartialRepaint())
    367         needsFullDisplay = true;
    368 
    369     auto result = swapToValidFrontBuffer();
    370     if (result == WebCore::SetNonVolatileResult::Empty)
    371         needsFullDisplay = true;
    372 
    373     return needsFullDisplay ? SwapBuffersDisplayRequirement::NeedsFullDisplay : SwapBuffersDisplayRequirement::NeedsNormalDisplay;
    374 }
    375 
    376 void RemoteLayerBackingStore::paintContents()
    377 {
    378     if (!m_frontBuffer.imageBuffer)
    379         return;
     414        ASSERT(m_layer->owner()->platformCALayerDelegatesDisplay(m_layer));
     415        return;
     416    }
    380417
    381418    LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteLayerBackingStore " << m_layer->layerID() << " paintContents() - has dirty region " << !hasEmptyDirtyRegion());
  • trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.h

    r291599 r291733  
    6262    virtual bool backingStoreNeedsDisplay(const RemoteLayerBackingStore&);
    6363
    64     virtual SwapBuffersDisplayRequirement prepareBackingStoreBuffers(RemoteLayerBackingStore&);
    65 
    66     void prepareBackingStoresForDisplay(RemoteLayerTreeTransaction&);
     64    virtual void prepareBackingStoresForDisplay(RemoteLayerTreeTransaction&);
    6765    void paintReachableBackingStoreContents();
    6866
  • trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStoreCollection.mm

    r291599 r291733  
    164164}
    165165
    166 SwapBuffersDisplayRequirement RemoteLayerBackingStoreCollection::prepareBackingStoreBuffers(RemoteLayerBackingStore& backingStore)
    167 {
    168     return backingStore.prepareBuffers(backingStore.hasEmptyDirtyRegion());
    169 }
    170 
    171166bool RemoteLayerBackingStoreCollection::markBackingStoreVolatile(RemoteLayerBackingStore& backingStore, OptionSet<VolatilityMarkingBehavior> markingBehavior, MonotonicTime now)
    172167{
  • trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.h

    r291599 r291733  
    4545
    4646    bool backingStoreNeedsDisplay(const RemoteLayerBackingStore&) final;
    47     SwapBuffersDisplayRequirement prepareBackingStoreBuffers(RemoteLayerBackingStore&) final;
     47    void prepareBackingStoresForDisplay(RemoteLayerTreeTransaction&) final;
    4848
    4949    bool collectBackingStoreBufferIdentifiersToMarkVolatile(RemoteLayerBackingStore&, OptionSet<VolatilityMarkingBehavior>, MonotonicTime now, Vector<WebCore::RenderingResourceIdentifier>&);
  • trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerWithRemoteRenderingBackingStoreCollection.mm

    r291599 r291733  
    6565}
    6666
    67 SwapBuffersDisplayRequirement RemoteLayerWithRemoteRenderingBackingStoreCollection::prepareBackingStoreBuffers(RemoteLayerBackingStore& backingStore)
    68 {
     67void RemoteLayerWithRemoteRenderingBackingStoreCollection::prepareBackingStoresForDisplay(RemoteLayerTreeTransaction& transaction)
     68{
     69    Vector<RemoteRenderingBackendProxy::LayerPrepareBuffersData> prepareBuffersData;
     70    prepareBuffersData.reserveInitialCapacity(m_backingStoresNeedingDisplay.size());
     71
     72    Vector<RemoteLayerBackingStore*> backingStoreList;
     73    backingStoreList.reserveInitialCapacity(m_backingStoresNeedingDisplay.size());
     74
     75    for (auto* backingStore : m_backingStoresNeedingDisplay) {
     76        backingStore->layer()->properties().notePropertiesChanged(RemoteLayerTreeTransaction::BackingStoreChanged);
     77        transaction.layerPropertiesChanged(*backingStore->layer());
     78
     79        if (backingStore->performDelegatedLayerDisplay())
     80            continue;
     81
     82        prepareBuffersData.uncheckedAppend({
     83            {
     84                backingStore->bufferForType(RemoteLayerBackingStore::BufferType::Front),
     85                backingStore->bufferForType(RemoteLayerBackingStore::BufferType::Back),
     86                backingStore->bufferForType(RemoteLayerBackingStore::BufferType::SecondaryBack)
     87            },
     88            backingStore->supportsPartialRepaint(),
     89            backingStore->hasEmptyDirtyRegion(),
     90        });
     91       
     92        backingStoreList.uncheckedAppend(backingStore);
     93    }
     94
    6995    auto& remoteRenderingBackend = layerTreeContext().ensureRemoteRenderingBackendProxy();
    70 
    71     auto identifiers = RemoteRenderingBackendProxy::BufferSet {
    72         backingStore.bufferForType(RemoteLayerBackingStore::BufferType::Front),
    73         backingStore.bufferForType(RemoteLayerBackingStore::BufferType::Back),
    74         backingStore.bufferForType(RemoteLayerBackingStore::BufferType::SecondaryBack)
    75     };
    76 
    77     auto swapResult = remoteRenderingBackend.prepareBuffersForDisplay(WTFMove(identifiers), backingStore.supportsPartialRepaint(), backingStore.hasEmptyDirtyRegion());
    78 
    79     backingStore.applySwappedBuffers(WTFMove(swapResult.buffers.front), WTFMove(swapResult.buffers.back), WTFMove(swapResult.buffers.secondaryBack));
    80     return swapResult.displayRequirement;
     96    auto swapResult = remoteRenderingBackend.prepareBuffersForDisplay(WTFMove(prepareBuffersData));
     97
     98    RELEASE_ASSERT(swapResult.size() == backingStoreList.size());
     99    for (unsigned i = 0; i < swapResult.size(); ++i) {
     100        auto& backingStoreSwapResult = swapResult[i];
     101        auto* backingStore = backingStoreList[i];
     102        backingStore->applySwappedBuffers(WTFMove(backingStoreSwapResult.buffers.front), WTFMove(backingStoreSwapResult.buffers.back), WTFMove(backingStoreSwapResult.buffers.secondaryBack), backingStoreSwapResult.displayRequirement);
     103    }
    81104}
    82105
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r291684 r291733  
    26222622                0F5E200218E77051003EC3E5 /* PlatformCAAnimationRemote.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCAAnimationRemote.h; sourceTree = "<group>"; };
    26232623                0F65956727DB1D5800EE874B /* SwapBuffersDisplayRequirement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwapBuffersDisplayRequirement.h; sourceTree = "<group>"; };
     2624                0F65956C27E10C2C00EE874B /* PrepareBackingStoreBuffersData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrepareBackingStoreBuffersData.h; sourceTree = "<group>"; };
    26242625                0F707C771A1FEE8300DA7A45 /* RemoteLayerTreeScrollingPerformanceData.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RemoteLayerTreeScrollingPerformanceData.mm; sourceTree = "<group>"; };
    26252626                0F707C791A1FEEA300DA7A45 /* RemoteLayerTreeScrollingPerformanceData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteLayerTreeScrollingPerformanceData.h; sourceTree = "<group>"; };
    … …  
    99019902                                727A7F38240788F0004D2931 /* PlatformImageBufferShareableBackend.h */,
    99029903                                7227800B2408BD7D007D376B /* PlatformRemoteImageBufferProxy.h */,
     9904                                0F65956C27E10C2C00EE874B /* PrepareBackingStoreBuffersData.h */,
    99039905                                F48BB8DE26F9635D001C1C40 /* RemoteDisplayListRecorderProxy.cpp */,
    99049906                                F48BB8DD26F9635D001C1C40 /* RemoteDisplayListRecorderProxy.h */,
  • trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp

    r291243 r291733  
    268268}
    269269
    270 auto RemoteRenderingBackendProxy::prepareBuffersForDisplay(const BufferSet& buffers, bool supportsPartialRepaint, bool hasEmptyDirtyRegion) -> SwapBuffersResult
     270auto RemoteRenderingBackendProxy::prepareBuffersForDisplay(const Vector<LayerPrepareBuffersData>& prepareBuffersInput) -> Vector<SwapBuffersResult>
    271271{
    272272    auto bufferIdentifier = [](ImageBuffer* buffer) -> std::optional<RenderingResourceIdentifier> {
    … …  
    287287    };
    288288
    289     // Clear all the buffer's MachSendRights to avoid all the surfaces appearing to be in-use.
    290     // We get back the new front buffer's MachSendRight in the reply.
    291     clearBackendHandle(buffers.front.get());
    292     clearBackendHandle(buffers.back.get());
    293     clearBackendHandle(buffers.secondaryBack.get());
    294 
    295     auto bufferSet = BufferIdentifierSet {
    296         bufferIdentifier(buffers.front.get()),
    297         bufferIdentifier(buffers.back.get()),
    298         bufferIdentifier(buffers.secondaryBack.get())
    299     };
    300 
    301     BufferIdentifierSet swappedBufferSet;
    302     std::optional<ImageBufferBackendHandle> frontBufferHandle;
    303     auto displayRequirement = SwapBuffersDisplayRequirement::NeedsNoDisplay;
    304 
    305     sendSyncToStream(Messages::RemoteRenderingBackend::PrepareBuffersForDisplay(bufferSet, supportsPartialRepaint, hasEmptyDirtyRegion),
    306         Messages::RemoteRenderingBackend::PrepareBuffersForDisplay::Reply(swappedBufferSet, frontBufferHandle, displayRequirement));
    307 
    308     LOG_WITH_STREAM(RemoteRenderingBufferVolatility, stream << "RemoteRenderingBackendProxy::prepareBuffersForDisplay swapped to " << swappedBufferSet.front << " " << swappedBufferSet.back << " " << swappedBufferSet.secondaryBack);
     289    Vector<PrepareBackingStoreBuffersInputData> inputData;
     290    inputData.reserveInitialCapacity(prepareBuffersInput.size());
     291
     292    for (const auto& perLayerData : prepareBuffersInput) {
     293        // Clear all the buffer's MachSendRights to avoid all the surfaces appearing to be in-use.
     294        // We get back the new front buffer's MachSendRight in the reply.
     295        clearBackendHandle(perLayerData.buffers.front.get());
     296        clearBackendHandle(perLayerData.buffers.back.get());
     297        clearBackendHandle(perLayerData.buffers.secondaryBack.get());
     298
     299        inputData.uncheckedAppend({
     300            {
     301                bufferIdentifier(perLayerData.buffers.front.get()),
     302                bufferIdentifier(perLayerData.buffers.back.get()),
     303                bufferIdentifier(perLayerData.buffers.secondaryBack.get())
     304            },
     305            perLayerData.supportsPartialRepaint,
     306            perLayerData.hasEmptyDirtyRegion
     307        });
     308    }
     309
     310    Vector<PrepareBackingStoreBuffersOutputData> outputData;
     311    sendSyncToStream(Messages::RemoteRenderingBackend::PrepareBuffersForDisplay(inputData), Messages::RemoteRenderingBackend::PrepareBuffersForDisplay::Reply(outputData));
     312    RELEASE_ASSERT(inputData.size() == outputData.size());
    309313
    310314    auto fetchBufferWithIdentifier = [&](std::optional<RenderingResourceIdentifier> identifier, std::optional<ImageBufferBackendHandle>&& handle = std::nullopt, bool isFrontBuffer = false) -> RefPtr<ImageBuffer> {
    … …  
    332336    };
    333337
    334     return {
    335         {
    336             fetchBufferWithIdentifier(swappedBufferSet.front, WTFMove(frontBufferHandle), true),
    337             fetchBufferWithIdentifier(swappedBufferSet.back),
    338             fetchBufferWithIdentifier(swappedBufferSet.secondaryBack)
    339         },
    340         displayRequirement
    341     };
     338    Vector<SwapBuffersResult> result;
     339    result.reserveInitialCapacity(outputData.size());
     340
     341    for (auto& perLayerOutputData : outputData) {
     342        result.uncheckedAppend({
     343            {
     344                fetchBufferWithIdentifier(perLayerOutputData.bufferSet.front, WTFMove(perLayerOutputData.frontBufferHandle), true),
     345                fetchBufferWithIdentifier(perLayerOutputData.bufferSet.back),
     346                fetchBufferWithIdentifier(perLayerOutputData.bufferSet.secondaryBack)
     347            },
     348            perLayerOutputData.displayRequirement
     349        });
     350    }
     351
     352    return result;
    342353}
    343354
  • trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h

    r291243 r291733  
    102102    };
    103103   
     104    struct LayerPrepareBuffersData {
     105        BufferSet buffers;
     106        bool supportsPartialRepaint { true };
     107        bool hasEmptyDirtyRegion { false };
     108    };
     109   
    104110    struct SwapBuffersResult {
    105111        BufferSet buffers;
    106112        SwapBuffersDisplayRequirement displayRequirement;
    107113    };
    108     SwapBuffersResult prepareBuffersForDisplay(const BufferSet&, bool supportsPartialRepaint, bool hasEmptyDirtyRegion);
     114
     115    Vector<SwapBuffersResult> prepareBuffersForDisplay(const Vector<LayerPrepareBuffersData>&);
    109116
    110117    void finalizeRenderingUpdate();
Note: See TracChangeset for help on using the changeset viewer.