Take advantage of RHI
Use Metal with Qt 6.4+ and macOS 10.14+, OpenGL for Wayland whenever enabled
This commit is contained in:
parent
80505c1216
commit
f5fb567052
4 changed files with 62 additions and 3 deletions
|
|
@ -23,6 +23,16 @@ namespace Ui::GL {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kUseNativeChild = false;// ::Platform::IsWindows();
|
constexpr auto kUseNativeChild = false;// ::Platform::IsWindows();
|
||||||
|
|
||||||
|
class RpWindowNoRhi : public RpWindow {
|
||||||
|
protected:
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
|
||||||
|
std::optional<QPlatformBackingStoreRhiConfig> rhiConfig() const override {
|
||||||
|
return QPlatformBackingStoreRhiConfig();
|
||||||
|
}
|
||||||
|
#endif // Qt >= 6.4.0
|
||||||
|
};
|
||||||
|
|
||||||
[[nodiscard]] Fn<Backend(Capabilities)> ChooseBackendWrap(
|
[[nodiscard]] Fn<Backend(Capabilities)> ChooseBackendWrap(
|
||||||
Fn<Backend(Capabilities)> chooseBackend) {
|
Fn<Backend(Capabilities)> chooseBackend) {
|
||||||
return [=](Capabilities capabilities) {
|
return [=](Capabilities capabilities) {
|
||||||
|
|
@ -60,7 +70,7 @@ not_null<RpWidget*> Window::widget() const {
|
||||||
|
|
||||||
std::unique_ptr<RpWindow> Window::createWindow(
|
std::unique_ptr<RpWindow> Window::createWindow(
|
||||||
const Fn<Backend(Capabilities)> &chooseBackend) {
|
const Fn<Backend(Capabilities)> &chooseBackend) {
|
||||||
auto result = std::make_unique<RpWindow>();
|
std::unique_ptr<RpWindow> result = std::make_unique<RpWindowNoRhi>();
|
||||||
if constexpr (!kUseNativeChild) {
|
if constexpr (!kUseNativeChild) {
|
||||||
_backend = chooseBackend(CheckCapabilities(result.get()));
|
_backend = chooseBackend(CheckCapabilities(result.get()));
|
||||||
if (_backend != Backend::OpenGL) {
|
if (_backend != Backend::OpenGL) {
|
||||||
|
|
|
||||||
|
|
@ -270,7 +270,9 @@ void WindowHelper::Private::enforceStyle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowHelper::Private::initOpenGL() {
|
void WindowHelper::Private::initOpenGL() {
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
||||||
auto forceOpenGL = std::make_unique<QOpenGLWidget>(_owner->window());
|
auto forceOpenGL = std::make_unique<QOpenGLWidget>(_owner->window());
|
||||||
|
#endif // Qt < 6.4.0
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowHelper::Private::resolveWeakPointers() {
|
void WindowHelper::Private::resolveWeakPointers() {
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,45 @@
|
||||||
//
|
//
|
||||||
#include "ui/rp_widget.h"
|
#include "ui/rp_widget.h"
|
||||||
|
|
||||||
|
#include "base/platform/base_platform_info.h"
|
||||||
#include "base/qt_signal_producer.h"
|
#include "base/qt_signal_producer.h"
|
||||||
|
#include "ui/gl/gl_detection.h"
|
||||||
|
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
#include <QtGui/QtEvents>
|
#include <QtGui/QtEvents>
|
||||||
|
#include <private/qwidget_p.h>
|
||||||
|
|
||||||
|
class TWidgetPrivate : public QWidgetPrivate {
|
||||||
|
public:
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
|
||||||
|
QPlatformBackingStoreRhiConfig rhiConfig() const override {
|
||||||
|
const auto q = static_cast<TWidget*>(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<QWidget>(*(new TWidgetPrivate), parent, {}) {
|
||||||
|
}
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@
|
||||||
#include <QtCore/QPointer>
|
#include <QtCore/QPointer>
|
||||||
#include <QtGui/QtEvents>
|
#include <QtGui/QtEvents>
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
|
||||||
|
#include <qpa/qplatformbackingstore.h>
|
||||||
|
#endif // Qt >= 6.4.0
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
void ToggleChildrenVisibility(not_null<QWidget*> widget, bool visible);
|
void ToggleChildrenVisibility(not_null<QWidget*> widget, bool visible);
|
||||||
|
|
@ -25,6 +29,7 @@ void ToggleChildrenVisibility(not_null<QWidget*> widget, bool visible);
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
class TWidget;
|
class TWidget;
|
||||||
|
class TWidgetPrivate;
|
||||||
|
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
class TWidgetHelper : public Base {
|
class TWidgetHelper : public Base {
|
||||||
|
|
@ -146,6 +151,12 @@ protected:
|
||||||
virtual void enterFromChildEvent(QEvent *e, QWidget *child) {
|
virtual void enterFromChildEvent(QEvent *e, QWidget *child) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
|
||||||
|
virtual std::optional<QPlatformBackingStoreRhiConfig> rhiConfig() const {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
#endif // Qt >= 6.4.0
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TWidget *tparent() {
|
TWidget *tparent() {
|
||||||
return qobject_cast<TWidget*>(Base::parentWidget());
|
return qobject_cast<TWidget*>(Base::parentWidget());
|
||||||
|
|
@ -157,6 +168,8 @@ private:
|
||||||
template <typename OtherBase>
|
template <typename OtherBase>
|
||||||
friend class TWidgetHelper;
|
friend class TWidgetHelper;
|
||||||
|
|
||||||
|
friend class TWidgetPrivate;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TWidget : public TWidgetHelper<QWidget> {
|
class TWidget : public TWidgetHelper<QWidget> {
|
||||||
|
|
@ -164,8 +177,7 @@ class TWidget : public TWidgetHelper<QWidget> {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TWidget(QWidget *parent = nullptr) : TWidgetHelper<QWidget>(parent) {
|
TWidget(QWidget *parent = nullptr);
|
||||||
}
|
|
||||||
|
|
||||||
// Get the size of the widget as it should be.
|
// Get the size of the widget as it should be.
|
||||||
// Negative return value means no default width.
|
// Negative return value means no default width.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue