Skip to content

Commit

Permalink
[WPE] Add a DisplayLink implementation
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=261816

Reviewed by Alejandro G. Castro.

Add a DisplayLink implementation for WPE using DRM vblank monitor. This
patch also removes the API to change display refresh rate that is no
longer needed.

* Source/WTF/wtf/PlatformHave.h:
* Source/WebKit/PlatformWPE.cmake:
* Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:
(WebKit::ThreadedCompositor::targetRefreshRateDidChange): Deleted.
* Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:
* Source/WebKit/SourcesWPE.txt:
* Source/WebKit/UIProcess/API/wpe/WPEView.cpp:
(WKWPE::m_backend):
* Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp:
(WebKit::DrawingAreaProxyCoordinatedGraphics::targetRefreshRateDidChange): Deleted.
* Source/WebKit/UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.h:
* Source/WebKit/UIProcess/DrawingAreaProxy.h:
(WebKit::DrawingAreaProxy::targetRefreshRateDidChange): Deleted.
* Source/WebKit/UIProcess/glib/DisplayVBlankMonitorDRM.cpp:
(WebKit::findCrtc):
(WebKit::DisplayVBlankMonitorDRM::create):
* Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.cpp:
(WebKit::DrawingAreaCoordinatedGraphics::targetRefreshRateDidChange): Deleted.
* Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/DrawingAreaCoordinatedGraphics.h:
* Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.cpp:
(WebKit::LayerTreeHost::targetRefreshRateDidChange): Deleted.
* Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/LayerTreeHost.h:
(WebKit::LayerTreeHost::sizeDidChange):
(WebKit::LayerTreeHost::targetRefreshRateDidChange): Deleted.
* Source/WebKit/WebProcess/WebPage/DrawingArea.h:
(WebKit::DrawingArea::updateBackingStoreState):
(WebKit::DrawingArea::targetRefreshRateDidChange): Deleted.

Canonical link: https://commits.webkit.org/268722@main
  • Loading branch information
carlosgcampos committed Oct 2, 2023
1 parent adca80d commit f170513
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Source/WTF/wtf/PlatformHave.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
#define HAVE_IOSURFACE 1
#endif

#if PLATFORM(MAC) || PLATFORM(GTK)
#if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(WPE)
#define HAVE_DISPLAY_LINK 1
#endif

Expand Down
10 changes: 10 additions & 0 deletions Source/WebKit/PlatformWPE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ list(APPEND WebKit_PRIVATE_INCLUDE_DIRECTORIES
"${WEBKIT_DIR}/UIProcess/Launcher/libwpe"
"${WEBKIT_DIR}/UIProcess/Notifications/glib/"
"${WEBKIT_DIR}/UIProcess/geoclue"
"${WEBKIT_DIR}/UIProcess/glib"
"${WEBKIT_DIR}/UIProcess/gstreamer"
"${WEBKIT_DIR}/UIProcess/linux"
"${WEBKIT_DIR}/UIProcess/soup"
Expand Down Expand Up @@ -434,6 +435,15 @@ else ()
)
endif ()

if (USE_LIBDRM)
list(APPEND WebKit_SYSTEM_INCLUDE_DIRECTORIES
${LIBDRM_INCLUDE_DIR}
)
list(APPEND WebKit_LIBRARIES
${LIBDRM_LIBRARIES}
)
endif ()

list(APPEND WebKit_INTERFACE_INCLUDE_DIRECTORIES
${FORWARDING_HEADERS_WPE_DIR}
${WebKit_DERIVED_SOURCES_DIR}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,19 +354,6 @@ void ThreadedCompositor::frameComplete()
sceneUpdateFinished();
}

#if !PLATFORM(GTK)
void ThreadedCompositor::targetRefreshRateDidChange(unsigned rate)
{
ASSERT(RunLoop::isMain());

if (!rate)
rate = c_defaultRefreshRate;
m_compositingRunLoop->performTaskSync([this, protectedThis = Ref { *this }, rate] {
m_display.displayUpdate = { 0, rate / 1000 };
});
}
#endif

#if !HAVE(DISPLAY_LINK)
void ThreadedCompositor::displayUpdateFired()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ class ThreadedCompositor : public CoordinatedGraphicsSceneClient, public ThreadS
#endif

void frameComplete();
#if !PLATFORM(GTK)
void targetRefreshRateDidChange(unsigned);
#endif

void suspend();
void resume();
Expand Down
5 changes: 4 additions & 1 deletion Source/WebKit/SourcesWPE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Shared/CoordinatedGraphics/SimpleViewportController.cpp

Shared/CoordinatedGraphics/threadedcompositor/CompositingRunLoop.cpp
Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp
Shared/CoordinatedGraphics/threadedcompositor/ThreadedDisplayRefreshMonitor.cpp

Shared/cairo/ShareableBitmapCairo.cpp

Expand Down Expand Up @@ -220,6 +219,10 @@ UIProcess/Gamepad/libwpe/UIGamepadProviderLibWPE.cpp

UIProcess/geoclue/GeoclueGeolocationProvider.cpp

UIProcess/glib/DisplayLinkGLib.cpp
UIProcess/glib/DisplayVBlankMonitor.cpp
UIProcess/glib/DisplayVBlankMonitorDRM.cpp
UIProcess/glib/DisplayVBlankMonitorTimer.cpp
UIProcess/glib/WebPageProxyGLib.cpp
UIProcess/glib/WebProcessPoolGLib.cpp
UIProcess/glib/WebProcessProxyGLib.cpp
Expand Down
5 changes: 1 addition & 4 deletions Source/WebKit/UIProcess/API/wpe/WPEView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,8 @@ View::View(struct wpe_view_backend* backend, const API::PageConfiguration& baseC
},
#if WPE_CHECK_VERSION(1, 13, 2)
// target_refresh_rate_changed
[](void* data, uint32_t rate)
[](void*, uint32_t)
{
auto& view = *reinterpret_cast<View*>(data);
if (view.page().drawingArea())
view.page().drawingArea()->targetRefreshRateDidChange(rate);
},
#else
// padding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,6 @@ void DrawingAreaProxyCoordinatedGraphics::updateAcceleratedCompositingMode(uint6
updateAcceleratedCompositingMode(layerTreeContext);
}

#if !PLATFORM(GTK)
void DrawingAreaProxyCoordinatedGraphics::targetRefreshRateDidChange(unsigned rate)
{
protectedWebPageProxy()->send(Messages::DrawingArea::TargetRefreshRateDidChange(rate), m_identifier);
}
#endif

bool DrawingAreaProxyCoordinatedGraphics::alwaysUseCompositing() const
{
return m_webPageProxy->preferences().acceleratedCompositingEnabled() && m_webPageProxy->preferences().forceCompositingMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ class DrawingAreaProxyCoordinatedGraphics final : public DrawingAreaProxy {
void enterAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext&) override;
void exitAcceleratedCompositingMode(uint64_t backingStoreStateID, UpdateInfo&&) override;
void updateAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext&) override;
#if !PLATFORM(GTK)
void targetRefreshRateDidChange(unsigned) override;
#endif

bool shouldSendWheelEventsToEventDispatcher() const override { return true; }

Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/UIProcess/DisplayLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <CoreVideo/CVDisplayLink.h>
#endif

#if PLATFORM(GTK)
#if PLATFORM(GTK) || PLATFORM(WPE)
#include "DisplayVBlankMonitor.h"
#endif

Expand Down Expand Up @@ -104,7 +104,7 @@ class DisplayLink {
#if PLATFORM(MAC)
CVDisplayLinkRef m_displayLink { nullptr };
#endif
#if PLATFORM(GTK)
#if PLATFORM(GTK) || PLATFORM(WPE)
std::unique_ptr<DisplayVBlankMonitor> m_vblankMonitor;
#endif
Lock m_clientsLock;
Expand Down
4 changes: 0 additions & 4 deletions Source/WebKit/UIProcess/DrawingAreaProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ class DrawingAreaProxy : public IPC::MessageReceiver {
const WebCore::IntSize& size() const { return m_size; }
bool setSize(const WebCore::IntSize&, const WebCore::IntSize& scrollOffset = { });

#if !PLATFORM(GTK) && (USE(COORDINATED_GRAPHICS) || USE(TEXTURE_MAPPER))
virtual void targetRefreshRateDidChange(unsigned) { }
#endif

virtual void minimumSizeForAutoLayoutDidChange() { }
virtual void sizeToContentAutoSizeMaximumSizeDidChange() { }
virtual void windowKindDidChange() { }
Expand Down
84 changes: 72 additions & 12 deletions Source/WebKit/UIProcess/glib/DisplayVBlankMonitorDRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#if USE(LIBDRM)

#include "Logging.h"
#include <WebCore/PlatformDisplay.h>
#include <fcntl.h>
#include <wtf/Threading.h>
#include <wtf/Vector.h>
Expand All @@ -37,7 +38,6 @@

#if PLATFORM(GTK)
#include "ScreenManager.h"
#include <WebCore/PlatformDisplay.h>
#include <WebCore/PlatformScreen.h>
#include <gtk/gtk.h>
#endif
Expand Down Expand Up @@ -99,17 +99,66 @@ static std::optional<uint32_t> findCrtc(int fd, GdkMonitor* monitor)

return returnValue;
}
#elif PLATFORM(WPE)
static std::optional<std::pair<uint32_t, uint32_t>> findCrtc(int fd)
{
drmModeRes* resources = drmModeGetResources(fd);
if (!resources)
return std::nullopt;

// Get the first active connector.
drmModeConnector* connector = nullptr;
for (int i = 0; i < resources->count_connectors; ++i) {
connector = drmModeGetConnector(fd, resources->connectors[i]);
if (!connector)
continue;

if (connector->connection == DRM_MODE_CONNECTED && connector->encoder_id && connector->count_modes)
break;

drmModeFreeConnector(connector);
connector = nullptr;
}

if (!connector) {
drmModeFreeResources(resources);
return std::nullopt;
}

auto modeRefreshRate = [](const drmModeModeInfo* info) -> uint32_t {
uint64_t refresh = (info->clock * 1000000LL / info->htotal + info->vtotal / 2) / info->vtotal;
if (info->flags & DRM_MODE_FLAG_INTERLACE)
refresh *= 2;
if (info->flags & DRM_MODE_FLAG_DBLSCAN)
refresh /= 2;
if (info->vscan > 1)
refresh /= info->vscan;
return refresh;
};

std::optional<std::pair<uint32_t, uint32_t>> returnValue;
if (drmModeEncoder* encoder = drmModeGetEncoder(fd, connector->encoder_id)) {
for (int i = 0; i < resources->count_crtcs; ++i) {
if (resources->crtcs[i] == encoder->crtc_id) {
if (drmModeCrtc* crtc = drmModeGetCrtc(fd, resources->crtcs[i])) {
returnValue = { i, modeRefreshRate(&crtc->mode) };
drmModeFreeCrtc(crtc);
break;
}
}
}
drmModeFreeEncoder(encoder);
}

drmModeFreeConnector(connector);
drmModeFreeResources(resources);

return returnValue;
}
#endif

std::unique_ptr<DisplayVBlankMonitor> DisplayVBlankMonitorDRM::create(PlatformDisplayID displayID)
{
#if PLATFORM(GTK)
auto* monitor = ScreenManager::singleton().monitor(displayID ? displayID : WebCore::primaryScreenDisplayID());
if (!monitor) {
RELEASE_LOG_FAULT(DisplayLink, "Could not create a vblank monitor for display %u: no monitor found", displayID);
return nullptr;
}

auto filename = WebCore::PlatformDisplay::sharedDisplay().drmDeviceFile();
if (filename.isEmpty()) {
RELEASE_LOG_FAULT(DisplayLink, "Could not create a vblank monitor for display %u: no DRM device found", displayID);
Expand All @@ -122,17 +171,28 @@ std::unique_ptr<DisplayVBlankMonitor> DisplayVBlankMonitorDRM::create(PlatformDi
return nullptr;
}

#if PLATFORM(GTK)
auto* monitor = ScreenManager::singleton().monitor(displayID ? displayID : WebCore::primaryScreenDisplayID());
if (!monitor) {
RELEASE_LOG_FAULT(DisplayLink, "Could not create a vblank monitor for display %u: no monitor found", displayID);
return nullptr;
}

auto crtcIndex = findCrtc(fd.value(), monitor);
if (!crtcIndex) {
RELEASE_LOG_FAULT(DisplayLink, "Could not create a vblank monitor for display %u: no CRTC found", displayID);
return nullptr;
}

return makeUnique<DisplayVBlankMonitorDRM>(gdk_monitor_get_refresh_rate(monitor) / 1000, WTFMove(fd), crtcIndex.value());
#else
// FIXME: implement for WPE.
UNUSED_PARAM(displayID);
return nullptr;
#elif PLATFORM(WPE)
auto crtcInfo = findCrtc(fd.value());
if (!crtcInfo) {
RELEASE_LOG_FAULT(DisplayLink, "Could not create a vblank monitor for display %u: no CRTC found", displayID);
return nullptr;
}

return makeUnique<DisplayVBlankMonitorDRM>(crtcInfo->second / 1000, WTFMove(fd), crtcInfo->first);
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,6 @@ void DrawingAreaCoordinatedGraphics::updateGeometry(const IntSize& size, Complet
completionHandler();
}

#if !PLATFORM(GTK)
void DrawingAreaCoordinatedGraphics::targetRefreshRateDidChange(unsigned rate)
{
UNUSED_PARAM(rate);
#if !USE(GRAPHICS_LAYER_TEXTURE_MAPPER)
if (m_layerTreeHost)
m_layerTreeHost->targetRefreshRateDidChange(rate);
#endif
}
#endif

void DrawingAreaCoordinatedGraphics::displayDidRefresh()
{
// We might get didUpdate messages from the UI process even after we've
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ class DrawingAreaCoordinatedGraphics final : public DrawingArea {

// IPC message handlers.
void updateGeometry(const WebCore::IntSize&, CompletionHandler<void()>&&) override;
#if !PLATFORM(GTK)
void targetRefreshRateDidChange(unsigned rate) override;
#endif
void displayDidRefresh() override;
void setDeviceScaleFactor(float) override;
void forceUpdate() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,6 @@ void LayerTreeHost::sizeDidChange(const IntSize& size)
didChangeViewport();
}

#if !PLATFORM(GTK)
void LayerTreeHost::targetRefreshRateDidChange(uint32_t rate)
{
m_compositor->targetRefreshRateDidChange(rate);
}
#endif

void LayerTreeHost::pauseRendering()
{
m_isSuspended = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ class LayerTreeHost
void forceRepaint();
void forceRepaintAsync(CompletionHandler<void()>&&);
void sizeDidChange(const WebCore::IntSize& newSize);
#if !PLATFORM(GTK)
void targetRefreshRateDidChange(unsigned);
#endif

void pauseRendering();
void resumeRendering();
Expand Down Expand Up @@ -217,7 +214,6 @@ inline void LayerTreeHost::scrollNonCompositedContents(const WebCore::IntRect&)
inline void LayerTreeHost::forceRepaint() { }
inline void LayerTreeHost::forceRepaintAsync(CompletionHandler<void()>&&) { }
inline void LayerTreeHost::sizeDidChange(const WebCore::IntSize&) { }
inline void LayerTreeHost::targetRefreshRateDidChange(unsigned) { }
inline void LayerTreeHost::pauseRendering() { }
inline void LayerTreeHost::resumeRendering() { }
inline WebCore::GraphicsLayerFactory* LayerTreeHost::graphicsLayerFactory() { return nullptr; }
Expand Down
1 change: 0 additions & 1 deletion Source/WebKit/WebProcess/WebPage/DrawingArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ class DrawingArea : public IPC::MessageReceiver, public WebCore::DisplayRefreshM
#if USE(COORDINATED_GRAPHICS) || USE(TEXTURE_MAPPER)
virtual void updateBackingStoreState(uint64_t /*backingStoreStateID*/, bool /*respondImmediately*/, float /*deviceScaleFactor*/, const WebCore::IntSize& /*size*/,
const WebCore::IntSize& /*scrollOffset*/) { }
virtual void targetRefreshRateDidChange(unsigned /*rate*/) { }
virtual void setDeviceScaleFactor(float) { }
virtual void forceUpdate() { }
virtual void didDiscardBackingStore() { }
Expand Down
3 changes: 0 additions & 3 deletions Source/WebKit/WebProcess/WebPage/DrawingArea.messages.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
messages -> DrawingArea NotRefCounted {
#if USE(COORDINATED_GRAPHICS) || USE(TEXTURE_MAPPER)
UpdateGeometry(WebCore::IntSize size) -> ()
#if !PLATFORM(GTK)
TargetRefreshRateDidChange(unsigned rate)
#endif
SetDeviceScaleFactor(float deviceScaleFactor)
ForceUpdate()
DidDiscardBackingStore()
Expand Down

0 comments on commit f170513

Please sign in to comment.