Skip to content

Commit

Permalink
REGRESSION(271747@main): [Win][GPUP] Rendering artifact of AC mode
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=266329

Reviewed by Don Olmstead.

After 271747@main removed RemoteImageBufferProxy::createFlusher
implementation, repainting a window caused a rendering artifact for
Windows port. 271803@main and 271892@main were the previous attempt to
fix the problem. But they were wrong fixes.

This problem can be resoved just by using newly added
RemoteImageBufferSetProxy::flushFrontBufferAsync even though Windows
port doesn't use RemoteImageBufferSetProxy yet. Because both
RemoteImageBufferSet and RemoteImageBuffer are using a same
StreamWorkQueue, flushing RemoteImageBufferSet command also ensures
that preceding RemoteImageBuffer commands are also flushed.

* Source/WebKit/WebProcess/WebPage/wc/DrawingAreaWC.cpp:
* Source/WebKit/WebProcess/WebPage/wc/DrawingAreaWC.h:

Canonical link: https://commits.webkit.org/272141@main
  • Loading branch information
fujii authored and donny-dont committed Dec 15, 2023
1 parent 17788c3 commit 9af7d54
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
61 changes: 44 additions & 17 deletions Source/WebKit/WebProcess/WebPage/wc/DrawingAreaWC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "WebPageInlines.h"
#include "WebPreferencesKeys.h"
#include "WebProcess.h"
#include <RemoteImageBufferSetProxy.h>
#include <WebCore/ImageBuffer.h>
#include <WebCore/LocalFrame.h>
#include <WebCore/LocalFrameView.h>
Expand All @@ -52,6 +53,7 @@ using namespace WebCore;
DrawingAreaWC::DrawingAreaWC(WebPage& webPage, const WebPageCreationParameters& parameters)
: DrawingArea(DrawingAreaType::WC, parameters.drawingAreaIdentifier, webPage)
, m_remoteWCLayerTreeHostProxy(makeUniqueWithoutRefCountedCheck<RemoteWCLayerTreeHostProxy>(webPage, parameters.usesOffscreenRendering))
, m_flusher(webPage.ensureRemoteRenderingBackendProxy().createRemoteImageBufferSet())
, m_layerFactory(*this)
, m_updateRenderingTimer(*this, &DrawingAreaWC::updateRendering)
, m_commitQueue(WorkQueue::create("DrawingAreaWC CommitQueue"_s))
Expand Down Expand Up @@ -276,16 +278,26 @@ void DrawingAreaWC::sendUpdateAC()
if (rootLayer.viewOverlayRootLayer)
rootLayer.viewOverlayRootLayer->flushCompositingState(visibleRect);

m_remoteWCLayerTreeHostProxy->update(std::exchange(m_updateInfo, { }), [this, weakThis = WeakPtr(*this), stateID = m_backingStoreStateID, willCallDisplayDidRefresh](std::optional<UpdateInfo> updateInfo) {
if (!weakThis)
return;
if (updateInfo && stateID == m_backingStoreStateID) {
ASSERT(willCallDisplayDidRefresh);
send(Messages::DrawingAreaProxy::Update(m_backingStoreStateID, WTFMove(*updateInfo)));
return;
}
if (willCallDisplayDidRefresh)
displayDidRefresh();
auto flusher = m_flusher->flushFrontBufferAsync();

m_commitQueue->dispatch([this, weakThis = WeakPtr(*this), stateID = m_backingStoreStateID, updateInfo = std::exchange(m_updateInfo, { }), flusher = WTFMove(flusher), willCallDisplayDidRefresh]() mutable {
if (flusher)
flusher->flush();
RunLoop::main().dispatch([this, weakThis = WTFMove(weakThis), stateID, updateInfo = WTFMove(updateInfo), willCallDisplayDidRefresh]() mutable {
if (!weakThis)
return;
m_remoteWCLayerTreeHostProxy->update(WTFMove(updateInfo), [this, weakThis = WTFMove(weakThis), stateID, willCallDisplayDidRefresh](std::optional<UpdateInfo> updateInfo) {
if (!weakThis)
return;
if (updateInfo && stateID == m_backingStoreStateID) {
ASSERT(willCallDisplayDidRefresh);
send(Messages::DrawingAreaProxy::Update(m_backingStoreStateID, WTFMove(*updateInfo)));
return;
}
if (willCallDisplayDidRefresh)
displayDidRefresh();
});
});
});
}
}
Expand Down Expand Up @@ -345,15 +357,30 @@ void DrawingAreaWC::sendUpdateNonAC()
graphicsContext.translate(-bounds.x(), -bounds.y());
for (const auto& rect : rects)
webPage->drawRect(image->context(), rect);
image->flushDrawingContext();
image->flushDrawingContextAsync();

auto* sharing = image->toBackendSharing();
if (is<ImageBufferBackendHandleSharing>(sharing)) {
if (auto handle = downcast<ImageBufferBackendHandleSharing>(*sharing).createBackendHandle())
updateInfo.bitmapHandle = std::get<ShareableBitmap::Handle>(WTFMove(*handle));
}
auto flusher = m_flusher->flushFrontBufferAsync();

m_commitQueue->dispatch([this, weakThis = WeakPtr(*this), stateID = m_backingStoreStateID, updateInfo = WTFMove(updateInfo), image = WTFMove(image), flusher = WTFMove(flusher)]() mutable {
if (flusher)
flusher->flush();
RunLoop::main().dispatch([this, weakThis = WTFMove(weakThis), stateID, updateInfo = WTFMove(updateInfo), image = WTFMove(image)]() mutable {
if (!weakThis)
return;
if (stateID != m_backingStoreStateID) {
displayDidRefresh();
return;
}

send(Messages::DrawingAreaProxy::Update(m_backingStoreStateID, WTFMove(updateInfo)));
auto* sharing = image->toBackendSharing();
if (is<ImageBufferBackendHandleSharing>(sharing)) {
if (auto handle = downcast<ImageBufferBackendHandleSharing>(*sharing).createBackendHandle())
updateInfo.bitmapHandle = std::get<ShareableBitmap::Handle>(WTFMove(*handle));
}

send(Messages::DrawingAreaProxy::Update(stateID, WTFMove(updateInfo)));
});
});
}

void DrawingAreaWC::graphicsLayerAdded(GraphicsLayerWC& layer)
Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit/WebProcess/WebPage/wc/DrawingAreaWC.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

namespace WebKit {

class RemoteImageBufferSetProxy;

class DrawingAreaWC final
: public DrawingArea
, public GraphicsLayerWC::Observer {
Expand Down Expand Up @@ -88,6 +90,7 @@ class DrawingAreaWC final

WebCore::GraphicsLayerClient m_rootLayerClient;
std::unique_ptr<RemoteWCLayerTreeHostProxy> m_remoteWCLayerTreeHostProxy;
RefPtr<RemoteImageBufferSetProxy> m_flusher;
WCLayerFactory m_layerFactory;
DoublyLinkedList<GraphicsLayerWC> m_liveGraphicsLayers;
WebCore::Timer m_updateRenderingTimer;
Expand Down

0 comments on commit 9af7d54

Please sign in to comment.