diff --git a/ui/gl/gl_window.cpp b/ui/gl/gl_window.cpp index 798b533..fb4e0e6 100644 --- a/ui/gl/gl_window.cpp +++ b/ui/gl/gl_window.cpp @@ -23,6 +23,16 @@ namespace Ui::GL { namespace { constexpr auto kUseNativeChild = false;// ::Platform::IsWindows(); + +class RpWindowNoRhi : public RpWindow { +protected: +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + std::optional rhiConfig() const override { + return QPlatformBackingStoreRhiConfig(); + } +#endif // Qt >= 6.4.0 +}; + [[nodiscard]] Fn ChooseBackendWrap( Fn chooseBackend) { return [=](Capabilities capabilities) { @@ -60,7 +70,7 @@ not_null Window::widget() const { std::unique_ptr Window::createWindow( const Fn &chooseBackend) { - auto result = std::make_unique(); + std::unique_ptr result = std::make_unique(); if constexpr (!kUseNativeChild) { _backend = chooseBackend(CheckCapabilities(result.get())); if (_backend != Backend::OpenGL) { diff --git a/ui/platform/mac/ui_window_mac.mm b/ui/platform/mac/ui_window_mac.mm index 2f77042..38334c4 100644 --- a/ui/platform/mac/ui_window_mac.mm +++ b/ui/platform/mac/ui_window_mac.mm @@ -270,7 +270,9 @@ void WindowHelper::Private::enforceStyle() { } void WindowHelper::Private::initOpenGL() { +#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) auto forceOpenGL = std::make_unique(_owner->window()); +#endif // Qt < 6.4.0 } void WindowHelper::Private::resolveWeakPointers() { diff --git a/ui/rp_widget.cpp b/ui/rp_widget.cpp index 053360c..afa77b9 100644 --- a/ui/rp_widget.cpp +++ b/ui/rp_widget.cpp @@ -6,10 +6,45 @@ // #include "ui/rp_widget.h" +#include "base/platform/base_platform_info.h" #include "base/qt_signal_producer.h" +#include "ui/gl/gl_detection.h" #include #include +#include + +class TWidgetPrivate : public QWidgetPrivate { +public: +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + QPlatformBackingStoreRhiConfig rhiConfig() const override { + const auto q = static_cast(q_ptr); + if (!q->testAttribute(Qt::WA_WState_Created)) { + return QWidgetPrivate::rhiConfig(); + } + if (const auto config = q->rhiConfig()) { + return *config; + } + if (::Platform::IsMac10_14OrGreater()) { + return { QPlatformBackingStoreRhiConfig::Metal }; + } + // We can't specify the widget here as q_evaluateRhiConfig is called + // in QWidgetWindow constructor, while windowHandle is set right after + // the constructor is completed + if (::Platform::IsWayland() // old versions of mutter produce flicker without OpenGL + && Ui::GL::ChooseBackendDefault( + Ui::GL::CheckCapabilities(nullptr)) + == Ui::GL::Backend::OpenGL) { + return { QPlatformBackingStoreRhiConfig::OpenGL }; + } + return QWidgetPrivate::rhiConfig(); + } +#endif // Qt >= 6.4.0 +}; + +TWidget::TWidget(QWidget *parent) +: TWidgetHelper(*(new TWidgetPrivate), parent, {}) { +} namespace Ui { namespace { diff --git a/ui/rp_widget.h b/ui/rp_widget.h index 4095c2d..232affb 100644 --- a/ui/rp_widget.h +++ b/ui/rp_widget.h @@ -18,6 +18,10 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) +#include +#endif // Qt >= 6.4.0 + namespace Ui { void ToggleChildrenVisibility(not_null widget, bool visible); @@ -25,6 +29,7 @@ void ToggleChildrenVisibility(not_null widget, bool visible); } // namespace Ui class TWidget; +class TWidgetPrivate; template class TWidgetHelper : public Base { @@ -146,6 +151,12 @@ protected: virtual void enterFromChildEvent(QEvent *e, QWidget *child) { } +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + virtual std::optional rhiConfig() const { + return std::nullopt; + } +#endif // Qt >= 6.4.0 + private: TWidget *tparent() { return qobject_cast(Base::parentWidget()); @@ -157,6 +168,8 @@ private: template friend class TWidgetHelper; + friend class TWidgetPrivate; + }; class TWidget : public TWidgetHelper { @@ -164,8 +177,7 @@ class TWidget : public TWidgetHelper { Q_OBJECT public: - TWidget(QWidget *parent = nullptr) : TWidgetHelper(parent) { - } + TWidget(QWidget *parent = nullptr); // Get the size of the widget as it should be. // Negative return value means no default width.