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
11 changes: 11 additions & 0 deletions qwlroots/src/render/qwrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ extern "C" {
#include <wlr/render/pass.h>
#undef static
#include <wlr/util/box.h>
#if WLR_HAVE_VULKAN_RENDERER
#include <wlr/render/vulkan.h>
#endif
}

struct wlr_renderer;
Expand All @@ -37,6 +40,14 @@ class QW_CLASS_OBJECT(renderer)
QW_FUNC_MEMBER(renderer, init_wl_shm, bool, wl_display *wl_display)
QW_FUNC_MEMBER(renderer, get_drm_fd, int)
QW_FUNC_MEMBER(renderer, get_texture_formats, const wlr_drm_format_set *, uint32_t buffer_caps)
#if WLR_HAVE_VULKAN_RENDERER
// Access the wlroots-adopted Vulkan device handles. Used by compositors
// (e.g. waylib) that adopt the wlroots VkDevice into Qt RHI.
QW_FUNC_MEMBER(vk_renderer, get_instance, VkInstance)

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.

不应该加到这个class里,要有应该是个新的 vk_renderer 类型

QW_FUNC_MEMBER(vk_renderer, get_physical_device, VkPhysicalDevice)
QW_FUNC_MEMBER(vk_renderer, get_device, VkDevice)
QW_FUNC_MEMBER(vk_renderer, get_queue_family, uint32_t)
#endif

protected:
QW_FUNC_MEMBER(renderer, destroy, void)
Expand Down
7 changes: 7 additions & 0 deletions qwlroots/src/render/qwtexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

extern "C" {
#include <wlr/render/wlr_texture.h>
#if WLR_HAVE_VULKAN_RENDERER
#include <wlr/render/vulkan.h>
#endif
}

QW_BEGIN_NAMESPACE
Expand All @@ -17,6 +20,10 @@ class QW_CLASS_REINTERPRET_CAST(texture)
QW_FUNC_STATIC(texture, from_pixels, qw_texture *, wlr_renderer *renderer, uint32_t fmt, uint32_t stride, uint32_t width, uint32_t height, const void *data)
QW_FUNC_STATIC(texture, from_dmabuf, qw_texture *, wlr_renderer *renderer, wlr_dmabuf_attributes *attribs)
QW_FUNC_STATIC(texture, from_buffer, qw_texture *, wlr_renderer *renderer, wlr_buffer *buffer)
#if WLR_HAVE_VULKAN_RENDERER
QW_FUNC_MEMBER(vk_texture, get_image_attribs, void, wlr_vk_image_attribs *attribs)

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.

同上

QW_FUNC_MEMBER(vk_texture, has_alpha, bool)
#endif

QW_FUNC_MEMBER(texture, update_from_buffer, bool, wlr_buffer *buffer, const pixman_region32_t *damage)

Expand Down
3 changes: 2 additions & 1 deletion src/core/qml/Animations/NewAnimation.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Item {
required property var direction
property int duration: 400 * Helper.animationSpeed
property var enableBlur: false
property bool liveSource: direction === NewAnimation.Direction.Show

x: target.x
y: target.y
Expand Down Expand Up @@ -60,7 +61,7 @@ Item {
width: root.target.width + 100
height: root.target.height + 100
anchors.centerIn: parent
live: direction === NewAnimation.Direction.Show
live: root.liveSource
hideSource: true
sourceItem: root.target
sourceRect: Qt.rect(effect.x, effect.y, effect.width, effect.height)
Expand Down
5 changes: 4 additions & 1 deletion src/core/qml/PrimaryOutput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ OutputItem {
required property QtObject outputCursor
readonly property point rawPosition: parent.mapFromGlobal(cursor.position.x, cursor.position.y)
readonly property real effectiveScale: rootOutputItem.devicePixelRatio || 1.0
readonly property bool useCursorOutputLayer: GraphicsInfo.api !== GraphicsInfo.Vulkan
&& GraphicsInfo.api !== GraphicsInfo.VulkanRhi
&& !outputCursor.output.forceSoftwareCursor

// Align cursor position to pixel grid to prevent blur on fractional DPR displays
function alignToPixelGrid(value) {
Expand All @@ -35,7 +38,7 @@ OutputItem {
x: position.x - hotSpot.x
y: position.y - hotSpot.y
visible: valid && outputCursor.visible
OutputLayer.enabled: !outputCursor.output.forceSoftwareCursor
OutputLayer.enabled: useCursorOutputLayer
OutputLayer.keepLayer: true
OutputLayer.outputs: [screenViewport]
OutputLayer.flags: OutputLayer.Cursor
Expand Down
14 changes: 12 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
#include <qwbuffer.h>
#include <qwlogging.h>

#include <DGuiApplicationHelper>

Check warning on line 12 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 13 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 15 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 16 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 17 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 18 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.

#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
# include <private/qgenericunixtheme_p.h>
Expand Down Expand Up @@ -54,7 +55,15 @@
});
// 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的渲染引擎。

const QByteArray wlrRenderer = qgetenv("WLR_RENDERER");
const bool hasExplicitWlrRenderer = !wlrRenderer.isEmpty() && wlrRenderer != "auto";
if (wlrRenderer != "vulkan")
QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);
if (hasExplicitWlrRenderer) {
WRenderHelper::setupRendererBackend();
if (wlrRenderer == "vulkan")
qunsetenv("QSG_RHI_BACKEND");
}
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
QGuiApplication::setQuitOnLastWindowClosed(false);
Expand All @@ -77,7 +86,8 @@
#endif
DLogManager::registerJournalAppender();

WRenderHelper::setupRendererBackend();
if (!hasExplicitWlrRenderer)
WRenderHelper::setupRendererBackend();
if (CmdLine::ref().tryExec())
return 0;
Q_ASSERT(qw_buffer::get_objects().isEmpty());
Expand Down
22 changes: 20 additions & 2 deletions src/output/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
#include <wxdgpopupsurface.h>
#include <wxdgpopupsurfaceitem.h>

#include <qwlayershellv1.h>

Check warning on line 29 in src/output/output.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 30 in src/output/output.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <QQuickWindow>

Check warning on line 32 in src/output/output.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.
#include <QQmlEngine>

Check warning on line 33 in src/output/output.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <algorithm>
#include <optional>
Expand All @@ -38,14 +40,28 @@
#define DIFF_APP_OFFSET_FACTOR 2.0
#define POPUP_EDGE_MARGIN 10

namespace {

bool shouldForceSoftwareCursorForVulkanRhi()
{
const auto graphicsApi = QQuickWindow::graphicsApi();
return qgetenv("WLR_RENDERER") == "vulkan"
&& graphicsApi == QSGRendererInterface::Vulkan;
}

}

Output *Output::create(WOutput *output, QQmlEngine *engine, QObject *parent)
{
auto isSoftwareCursor = [](WOutput *output) -> bool {
return output->handle()->is_x11() || Helper::instance()->globalConfig()->forceSoftwareCursor();
return output->handle()->is_x11()
|| Helper::instance()->globalConfig()->forceSoftwareCursor()
|| shouldForceSoftwareCursorForVulkanRhi();
};
QQmlComponent delegate(engine, "Treeland", "PrimaryOutput");
const bool forceSoftwareCursor = isSoftwareCursor(output);
QObject *obj = delegate.beginCreate(engine->rootContext());
delegate.setInitialProperties(obj, { { "forceSoftwareCursor", isSoftwareCursor(output) } });
delegate.setInitialProperties(obj, { { "forceSoftwareCursor", forceSoftwareCursor } });
delegate.completeCreate();
WOutputItem *outputItem = qobject_cast<WOutputItem *>(obj);
Q_ASSERT(outputItem);
Expand All @@ -54,6 +70,7 @@
auto contentItem = Helper::instance()->window()->contentItem();
outputItem->setParentItem(contentItem);
outputItem->setOutput(output);
output->setForceSoftwareCursor(forceSoftwareCursor);

connect(Helper::instance()->globalConfig(),
&TreelandConfig::forceSoftwareCursorChanged,
Expand All @@ -62,6 +79,7 @@
auto forceSoftwareCursor = isSoftwareCursor(output);
qCInfo(lcTlOutput) << "forceSoftwareCursor changed to" << forceSoftwareCursor;
obj->setProperty("forceSoftwareCursor", forceSoftwareCursor);
output->setForceSoftwareCursor(forceSoftwareCursor);
});

auto o = new Output(outputItem, parent);
Expand Down
24 changes: 24 additions & 0 deletions src/surface/surfacewrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <qwbuffer.h>
#include <qwlayershellv1.h>
#include <qwrenderer.h>

#include <QColor>
#include <QVariant>
Expand All @@ -33,6 +34,21 @@
#define CLOSE_ANIMATION 2
#define ALWAYSONTOPLAYER 1

namespace {
bool isVulkanRendererBackend()
{
#ifdef ENABLE_VULKAN_RENDER
auto *helper = Helper::instance();
if (!helper || !helper->window() || !helper->window()->renderer())
return false;

return wlr_renderer_is_vk(helper->window()->renderer()->handle());
#else
return false;
#endif
}
}

SurfaceWrapper::SurfaceWrapper(QmlEngine *qmlEngine,
WToplevelSurface *shellSurface,
Type type,
Expand Down Expand Up @@ -609,6 +625,7 @@ void SurfaceWrapper::startPrelaunchSplashHideSequence()
const QRectF toGeometry(toTopLeft, targetImplicitSize);
m_geometryAnimation =
m_engine->createGeometryAnimation(this, fromGeometry, toGeometry, container());
Q_EMIT animationRunningChanged();

bool ok = connect(m_geometryAnimation,
SIGNAL(ready()),
Expand Down Expand Up @@ -647,6 +664,7 @@ void SurfaceWrapper::onPrelaunchGeometryAnimationFinished()
m_geometryAnimation->disconnect(this);
m_geometryAnimation->deleteLater();
m_geometryAnimation = nullptr;
Q_EMIT animationRunningChanged();

if (m_decoration)
m_decoration->setVisible(true);
Expand Down Expand Up @@ -1004,6 +1022,7 @@ void SurfaceWrapper::setSurfaceState(State newSurfaceState)
m_geometryAnimation->disconnect(this);
m_geometryAnimation->deleteLater();
m_geometryAnimation = nullptr;
Q_EMIT animationRunningChanged();
}

doSetSurfaceState(newSurfaceState);
Expand Down Expand Up @@ -1270,6 +1289,8 @@ void SurfaceWrapper::createNewOrClose(uint direction)
case Type::XWayland: {
m_windowAnimation = m_engine->createNewAnimation(this, container(), direction);
m_windowAnimation->setProperty("enableBlur", m_blur);
if (m_type == Type::SplashScreen && isVulkanRendererBackend())
m_windowAnimation->setProperty("liveSource", false);

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.

这是为啥?为什么vulkan backend时liveSource需要是false?

} break;
case Type::Layer: {
auto scope = QString(static_cast<WLayerSurfaceItem *>(m_surfaceItem)
Expand Down Expand Up @@ -1413,6 +1434,7 @@ void SurfaceWrapper::onAnimationReady()
m_geometryAnimation->disconnect(this);
m_geometryAnimation->deleteLater();
m_geometryAnimation = nullptr;
Q_EMIT animationRunningChanged();
return;
}

Expand All @@ -1429,6 +1451,7 @@ void SurfaceWrapper::onAnimationFinished()
m_geometryAnimation->disconnect(this);
m_geometryAnimation->deleteLater();
m_geometryAnimation = nullptr;
Q_EMIT animationRunningChanged();
}

bool SurfaceWrapper::startStateChangeAnimation(State targetState, const QRectF &targetGeometry)
Expand All @@ -1438,6 +1461,7 @@ bool SurfaceWrapper::startStateChangeAnimation(State targetState, const QRectF &

m_geometryAnimation =
m_engine->createGeometryAnimation(this, geometry(), targetGeometry, container());
Q_EMIT animationRunningChanged();
m_geometryAnimation->setProperty("enableBlur", m_blur);
m_pendingState = targetState;
m_pendingGeometry = targetGeometry;
Expand Down
2 changes: 2 additions & 0 deletions src/surface/surfacewrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class SurfaceWrapper : public QQuickItem
// through treeland_dde_shell_surface_v1.set_surface_position
Q_PROPERTY(QPoint clientRequstPos READ clientRequstPos NOTIFY clientRequstPosChanged FINAL)
Q_PROPERTY(bool blur READ blur NOTIFY blurChanged FINAL)
Q_PROPERTY(bool isAnimationRunning READ isAnimationRunning NOTIFY animationRunningChanged FINAL)
Q_PROPERTY(bool isWindowAnimationRunning READ isWindowAnimationRunning NOTIFY windowAnimationRunningChanged FINAL)
Q_PROPERTY(bool coverEnabled READ coverEnabled NOTIFY coverEnabledChanged FINAL)
Q_PROPERTY(bool acceptKeyboardFocus READ acceptKeyboardFocus NOTIFY acceptKeyboardFocusChanged FINAL)
Expand Down Expand Up @@ -350,6 +351,7 @@ public Q_SLOTS:
void autoPlaceYOffsetChanged();
void clientRequstPosChanged();
void blurChanged();
void animationRunningChanged();
void windowAnimationRunningChanged();
void coverEnabledChanged();
void aboutToBeInvalidated();
Expand Down
2 changes: 1 addition & 1 deletion waylib/src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(WAYLIB_INCLUDE_INSTALL_DIR
if(Qt6_VERSION VERSION_GREATER_EQUAL 6.10)
find_package(Qt6 REQUIRED COMPONENTS GuiPrivate QuickPrivate)
endif()
find_package(Qt6 COMPONENTS Core Gui Quick REQUIRED)
find_package(Qt6 COMPONENTS Core Gui Quick ShaderTools REQUIRED)

qt_standard_project_setup(REQUIRES 6.8)

Expand Down
Loading
Loading