Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions qwlroots/src/types/qwlinuxdmabufv1.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ extern "C" {
#include <wlr/types/wlr_linux_dmabuf_v1.h>
}

struct wlr_renderer;

QW_BEGIN_NAMESPACE

class QW_CLASS_BOX(linux_dmabuf_feedback_v1)
Expand All @@ -32,6 +34,7 @@ class QW_CLASS_OBJECT(linux_dmabuf_v1)

public:
QW_FUNC_STATIC(linux_dmabuf_v1, create, qw_linux_dmabuf_v1 *, wl_display *display, uint32_t version, const wlr_linux_dmabuf_feedback_v1 *default_feedback)
QW_FUNC_STATIC(linux_dmabuf_v1, create_with_renderer, qw_linux_dmabuf_v1 *, wl_display *display, uint32_t version, wlr_renderer *renderer)
};

QW_END_NAMESPACE
8 changes: 4 additions & 4 deletions qwlroots/src/types/qwpresentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class QW_CLASS_OBJECT(presentation)
Q_OBJECT

public:
QW_FUNC_STATIC(presentation, create, qw_presentation *, wl_display *display, wlr_backend *backend)
QW_FUNC_STATIC(presentation, create, qw_presentation *, wl_display *display, wlr_backend *backend, uint32_t version)

QW_FUNC_MEMBER(presentation, surface_sampled, wlr_presentation_feedback *, wlr_surface *surface)
QW_FUNC_MEMBER(presentation, surface_textured_on_output, void, wlr_surface *surface, wlr_output *output)
QW_FUNC_MEMBER(presentation, surface_scanned_out_on_output, void, wlr_surface *surface, wlr_output *output)
QW_FUNC_STATIC(presentation, surface_sampled, wlr_presentation_feedback *, wlr_surface *surface)
QW_FUNC_STATIC(presentation, surface_textured_on_output, void, wlr_surface *surface, wlr_output *output)
QW_FUNC_STATIC(presentation, surface_scanned_out_on_output, void, wlr_surface *surface, wlr_output *output)
};

class QW_CLASS_REINTERPRET_CAST(presentation_event)
Expand Down
9 changes: 6 additions & 3 deletions src/core/qml/PrimaryOutput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ OutputItem {
id: cursorItem

required property QtObject outputCursor
readonly property point rawPosition: parent.mapFromGlobal(cursor.position.x, cursor.position.y)
readonly property bool detachedCursorLayer: OutputLayer.enabled
readonly property point rawPosition: detachedCursorLayer
? Qt.point(0, 0)
: parent.mapFromGlobal(cursor.position.x, cursor.position.y)
readonly property real effectiveScale: rootOutputItem.devicePixelRatio || 1.0

// Align cursor position to pixel grid to prevent blur on fractional DPR displays
Expand All @@ -32,8 +35,8 @@ OutputItem {

cursor: outputCursor.cursor
output: outputCursor.output.output
x: position.x - hotSpot.x
y: position.y - hotSpot.y
x: detachedCursorLayer ? 0 : position.x - hotSpot.x
y: detachedCursorLayer ? 0 : position.y - hotSpot.y
visible: valid && outputCursor.visible
OutputLayer.enabled: !outputCursor.output.forceSoftwareCursor
OutputLayer.keepLayer: true
Expand Down
15 changes: 14 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "core/treeland.h"
#include "common/treelandlogging.h"
#include "utils/cmdline.h"

#include <wrenderhelper.h>

Check warning on line 8 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <wrenderhelper.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <qwbuffer.h>
#include <qwlogging.h>

#include <DGuiApplicationHelper>

Check warning on line 13 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DGuiApplicationHelper> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DLog>

Check warning on line 14 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DLog> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QByteArray>

Check warning on line 16 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QByteArray> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QGuiApplication>

Check warning on line 17 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QGuiApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMetaType>

Check warning on line 18 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMetaType> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPalette>

Check warning on line 19 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPalette> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QQuickWindow>

Check warning on line 20 in src/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QQuickWindow> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
# include <private/qgenericunixtheme_p.h>
Expand Down Expand Up @@ -46,6 +49,9 @@
int main(int argc, char *argv[])
{
qw_log::init();
const QByteArray wlrRenderer = qgetenv("WLR_RENDERER");
const bool explicitVulkanRenderer = wlrRenderer == "vulkan";

DTK_GUI_NAMESPACE::DGuiApplicationHelper::setAttribute(
DTK_GUI_NAMESPACE::DGuiApplicationHelper::DontSaveApplicationTheme,
true);
Expand All @@ -54,7 +60,11 @@
});
// QQuickStyle::setStyle("Material");

QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这行应该可以直接删掉,WRenderHelper::setupRendererBackend(); 会找到合适的backend

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的设置不要紧,只是告诉Qt如果用opengl,应该用gles版本,不会影响treeland和QtQuick的渲染引擎。

if (explicitVulkanRenderer)
QQuickWindow::setGraphicsApi(QSGRendererInterface::Vulkan);
else
QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);

QGuiApplication::setHighDpiScaleFactorRoundingPolicy(
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
QGuiApplication::setQuitOnLastWindowClosed(false);
Expand All @@ -76,6 +86,9 @@
}
#endif
DLogManager::registerJournalAppender();
if (explicitVulkanRenderer) {
qCInfo(lcTlCore) << "Explicit Vulkan renderer requested; Qt::AA_UseOpenGLES was not set";
}

WRenderHelper::setupRendererBackend();
if (CmdLine::ref().tryExec())
Expand Down
14 changes: 13 additions & 1 deletion src/seat/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@
#include <xcb/xcb.h>
#include <xcb/xproto.h>

#include <WBackend>

Check warning on line 68 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <WBackend> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <WForeignToplevel>

Check warning on line 69 in src/seat/helper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <WForeignToplevel> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <WLinuxDmabufV1>
#include <WOutput>
#include <WPresentation>
#include <WServer>
#include <WSurfaceItem>
#include <WXdgOutput>
Expand Down Expand Up @@ -1622,7 +1624,17 @@
}

m_allocator = qw_allocator::autocreate(*m_backend->handle(), *m_renderer);
m_renderer->init_wl_display(*m_server->handle());
if (!m_renderer->init_wl_shm(*m_server->handle()))
qCFatal(lcTlCore) << "Failed to initialize wl_shm for renderer";

qCInfo(lcTlCore) << "Initialized wl_shm for renderer";
m_server->attach<WLinuxDmabufV1>(m_renderer);
if (WRenderHelper::getGraphicsApi() == QSGRendererInterface::Vulkan) {
auto *presentation = m_server->attach<WPresentation>(m_backend->handle());
m_renderWindow->setPresentation(presentation);
qCInfo(lcTlCore) << "Attached presentation-time protocol for Vulkan renderer";
}

qw_drm::create(*m_server->handle(), *m_renderer);

// free follow display
Expand Down
18 changes: 18 additions & 0 deletions waylib/src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ pkg_search_module(PIXMAN REQUIRED IMPORTED_TARGET pixman-1)
pkg_search_module(XKBCOMMON REQUIRED IMPORTED_TARGET xkbcommon)
pkg_search_module(XCB REQUIRED IMPORTED_TARGET xcb)
pkg_search_module(EGL REQUIRED IMPORTED_TARGET egl)
pkg_get_variable(WAYLIB_WLR_HAVE_VULKAN_RENDERER wlroots-0.19 have_vulkan_renderer)

if(WAYLIB_WLR_HAVE_VULKAN_RENDERER)
find_package(Vulkan REQUIRED)
endif()

add_compile_definitions(WLR_PRIVATE=)

Expand Down Expand Up @@ -197,6 +202,8 @@ set(SOURCES
protocols/ext_foreign_toplevel_image_capture_source.c #TODO: Remove after wlroots 0.20
protocols/wcursorshapemanagerv1.cpp
protocols/woutputmanagerv1.cpp
protocols/wlinuxdmabufv1.cpp
protocols/wpresentation.cpp
protocols/wextforeigntoplevellistv1.cpp
protocols/wxdgdialogmanagerv1.cpp
protocols/wsecuritycontextmanager.cpp
Expand Down Expand Up @@ -294,6 +301,10 @@ set(HEADERS
protocols/WCursorShapeManagerV1
protocols/woutputmanagerv1.h
protocols/WOutputManagerV1
protocols/wlinuxdmabufv1.h
protocols/WLinuxDmabufV1
protocols/wpresentation.h
protocols/WPresentation
protocols/wlayershell.h
protocols/WLayerShell
protocols/wxwayland.h
Expand Down Expand Up @@ -408,6 +419,13 @@ target_link_libraries(${TARGET}
PkgConfig::EGL
)

if(TARGET Vulkan::Vulkan)
target_link_libraries(${TARGET}
PRIVATE
Vulkan::Vulkan
)
endif()

target_link_libraries(${TARGET}
PUBLIC
QWlroots::QWlroots
Expand Down
39 changes: 32 additions & 7 deletions waylib/src/server/kernel/woutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,14 @@ static bool test_swapchain(struct wlr_output *output,

static bool wlr_output_configure_primary_swapchain(struct wlr_output *output, int width, int height,
uint32_t format, struct wlr_swapchain **swapchain_ptr,
bool test) {
bool test, struct wlr_swapchain **replaced_swapchain_ptr) {
wlr_output_state empty_state;
wlr_output_state_init(&empty_state);
wlr_output_state *state = &empty_state;

if (replaced_swapchain_ptr)
*replaced_swapchain_ptr = nullptr;

// Re-use the existing swapchain if possible
struct wlr_swapchain *old_swapchain = *swapchain_ptr;
if (old_swapchain != NULL &&
Expand Down Expand Up @@ -371,7 +374,11 @@ static bool wlr_output_configure_primary_swapchain(struct wlr_output *output, in
}
}

wlr_swapchain_destroy(*swapchain_ptr);
if (replaced_swapchain_ptr) {
*replaced_swapchain_ptr = *swapchain_ptr;
} else if (*swapchain_ptr) {
wlr_swapchain_destroy(*swapchain_ptr);
}
*swapchain_ptr = swapchain;
return true;
}
Expand All @@ -397,21 +404,33 @@ static bool output_pick_cursor_format(struct wlr_output *output,
// End

bool WOutput::configurePrimarySwapchain(const QSize &size, uint32_t format,
qw_swapchain **swapchain, bool doTest)
qw_swapchain **swapchain, bool doTest,
qw_swapchain **replacedSwapchain)
{
Q_ASSERT(!size.isEmpty());
wlr_swapchain *sc = (*swapchain)->handle();
if (replacedSwapchain)
*replacedSwapchain = nullptr;

wlr_swapchain *sc = *swapchain ? (*swapchain)->handle() : nullptr;
wlr_swapchain *replacedSc = nullptr;
bool ok = wlr_output_configure_primary_swapchain(nativeHandle(), size.width(), size.height(),
format, &sc, doTest);
format, &sc, doTest,
replacedSwapchain ? &replacedSc : nullptr);
if (!ok)
return false;
*swapchain = qw_swapchain::from(sc);
if (replacedSwapchain)
*replacedSwapchain = qw_swapchain::from(replacedSc);
return true;
}

bool WOutput::configureCursorSwapchain(const QSize &size, uint32_t drmFormat, qw_swapchain **swapchain)
bool WOutput::configureCursorSwapchain(const QSize &size, uint32_t drmFormat, qw_swapchain **swapchain,
qw_swapchain **replacedSwapchain)
{
Q_ASSERT(!size.isEmpty());
if (replacedSwapchain)
*replacedSwapchain = nullptr;

auto sc = *swapchain;
if (!sc || sc->handle()->width != size.width() || sc->handle()->height != size.height()) {
wlr_drm_format format = {};
Expand All @@ -420,13 +439,19 @@ bool WOutput::configureCursorSwapchain(const QSize &size, uint32_t drmFormat, qw
return false;
}

delete sc;
auto oldSc = sc;
sc = qw_swapchain::create(*allocator(), size.width(), size.height(), &format);
wlr_drm_format_finish(&format);
if (!sc) {
qCDebug(lcWlOutputBuffer) << "Failed to create cursor swapchain with selected format";
return false;
}

if (replacedSwapchain) {
*replacedSwapchain = oldSc;
} else {
delete oldSc;
}
}

*swapchain = sc;
Expand Down
6 changes: 4 additions & 2 deletions waylib/src/server/kernel/woutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ class WAYLIB_SERVER_EXPORT WOutput : public WWrapObject
QW_NAMESPACE::qw_allocator *allocator() const;
bool configurePrimarySwapchain(const QSize &size, uint32_t format,
QW_NAMESPACE::qw_swapchain **swapchain,
bool doTest = true);
bool doTest = true,
QW_NAMESPACE::qw_swapchain **replacedSwapchain = nullptr);
bool configureCursorSwapchain(const QSize &size, uint32_t format,
QW_NAMESPACE::qw_swapchain **swapchain);
QW_NAMESPACE::qw_swapchain **swapchain,
QW_NAMESPACE::qw_swapchain **replacedSwapchain = nullptr);

QW_NAMESPACE::qw_output *handle() const;
wlr_output *nativeHandle() const;
Expand Down
1 change: 1 addition & 0 deletions waylib/src/server/protocols/WLinuxDmabufV1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "wlinuxdmabufv1.h"
1 change: 1 addition & 0 deletions waylib/src/server/protocols/WPresentation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "wpresentation.h"
81 changes: 81 additions & 0 deletions waylib/src/server/protocols/wlinuxdmabufv1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (C) 2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "wlinuxdmabufv1.h"

#include "wayliblogging.h"

#include <qwdisplay.h>
#include <qwlinuxdmabufv1.h>
#include <qwrenderer.h>

QW_USE_NAMESPACE
WAYLIB_SERVER_BEGIN_NAMESPACE

constexpr uint32_t LinuxDmabufV1Version = 4;

WLinuxDmabufV1::WLinuxDmabufV1(qw_renderer *renderer, QObject *parent)
: QObject(parent)
, m_renderer(renderer)
{
}

qw_linux_dmabuf_v1 *WLinuxDmabufV1::handle() const
{
return nativeInterface<qw_linux_dmabuf_v1>();
}

QByteArrayView WLinuxDmabufV1::interfaceName() const
{
return "zwp_linux_dmabuf_v1";
}

void WLinuxDmabufV1::create(WServer *server)
{
if (m_handle)
return;

if (!m_renderer || !m_renderer->handle()) {
qCWarning(lcWlLinuxDmabuf) << "Cannot create linux-dmabuf global without renderer";
return;
}

const auto *formats = m_renderer->get_texture_formats(WLR_BUFFER_CAP_DMABUF);
if (!formats) {
qCInfo(lcWlLinuxDmabuf) << "Skipping linux-dmabuf global: renderer does not expose DMA-BUF texture formats";
return;
}

const int drmFd = m_renderer->get_drm_fd();
if (drmFd < 0) {
qCInfo(lcWlLinuxDmabuf) << "Skipping linux-dmabuf global: renderer has no DRM fd";
return;
}

m_handle = qw_linux_dmabuf_v1::create_with_renderer(*server->handle(),
LinuxDmabufV1Version,
*m_renderer);
if (!m_handle) {
qCWarning(lcWlLinuxDmabuf) << "Failed to create renderer-backed linux-dmabuf global";
return;
}

qCInfo(lcWlLinuxDmabuf) << "Created renderer-backed linux-dmabuf global"
<< "version" << LinuxDmabufV1Version
<< "drm fd" << drmFd;
}

void WLinuxDmabufV1::destroy([[maybe_unused]] WServer *server)
{
// wlroots owns this global and destroys it from the display destroy listener.
}

wl_global *WLinuxDmabufV1::global() const
{
if (auto *native = handle())
return native->handle()->global;

return nullptr;
}

WAYLIB_SERVER_END_NAMESPACE
Loading
Loading