diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 629dd54d8d..a20f6d64ed 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -452,6 +452,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_performance" = "Performance"; "lng_settings_enable_animations" = "Enable animations"; "lng_settings_enable_opengl" = "Enable OpenGL rendering for media"; +"lng_settings_angle_backend" = "ANGLE graphics backend"; +"lng_settings_angle_backend_auto" = "Auto"; +"lng_settings_angle_backend_d3d9" = "Direct3D 9"; +"lng_settings_angle_backend_d3d11" = "Direct3D 11"; +"lng_settings_angle_backend_d3d11on12" = "D3D11on12"; +"lng_settings_angle_backend_opengl" = "OpenGL"; +"lng_settings_angle_backend_disabled" = "Disabled"; "lng_settings_sensitive_title" = "Sensitive content"; "lng_settings_sensitive_disable_filtering" = "Disable filtering"; "lng_settings_sensitive_about" = "Display sensitive media in public channels on all your Telegram devices."; diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 4214cd2c36..04b2ec5eea 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -58,6 +58,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_lock_widgets.h" #include "history/history_location_manager.h" #include "ui/widgets/tooltip.h" +#include "ui/gl/gl_detection.h" #include "ui/image/image.h" #include "ui/text/text_options.h" #include "ui/emoji_config.h" @@ -281,8 +282,7 @@ void Application::run() { LOG(("Shortcuts Error: %1").arg(error)); } - if (!Platform::IsMac() - && Ui::Integration::Instance().openglLastCheckFailed()) { + if (!Platform::IsMac() && Ui::GL::LastCrashCheckFailed()) { showOpenGLCrashNotification(); } @@ -297,14 +297,14 @@ void Application::run() { void Application::showOpenGLCrashNotification() { const auto enable = [=] { Ui::GL::ForceDisable(false); - Ui::Integration::Instance().openglCheckFinish(); + Ui::GL::CrashCheckFinish(); Core::App().settings().setDisableOpenGL(false); Local::writeSettings(); App::restart(); }; const auto keepDisabled = [=] { Ui::GL::ForceDisable(true); - Ui::Integration::Instance().openglCheckFinish(); + Ui::GL::CrashCheckFinish(); Core::App().settings().setDisableOpenGL(true); Local::writeSettings(); }; diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index f17c2c6a66..cb876256eb 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -549,7 +549,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { _disableOpenGL = (disableOpenGL == 1); if (!Platform::IsMac()) { Ui::GL::ForceDisable(_disableOpenGL - || Ui::Integration::Instance().openglLastCheckFailed()); + || Ui::GL::LastCrashCheckFailed()); } _groupCallNoiseSuppression = (groupCallNoiseSuppression == 1); const auto uncheckedWorkMode = static_cast(workMode); diff --git a/Telegram/SourceFiles/core/ui_integration.cpp b/Telegram/SourceFiles/core/ui_integration.cpp index 0639c928e9..24ceb2a6c2 100644 --- a/Telegram/SourceFiles/core/ui_integration.cpp +++ b/Telegram/SourceFiles/core/ui_integration.cpp @@ -88,6 +88,10 @@ const auto kBadPrefix = u"http://"_q; return cWorkingDir() + "tdata/opengl_crash_check"; } +[[nodiscard]] QString ANGLEBackendFilePath() { + return cWorkingDir() + "tdata/angle_backend"; +} + } // namespace void UiIntegration::postponeCall(FnMut &&callable) { @@ -106,20 +110,12 @@ QString UiIntegration::emojiCacheFolder() { return cWorkingDir() + "tdata/emoji"; } -void UiIntegration::openglCheckStart() { - auto f = QFile(OpenGLCheckFilePath()); - if (f.open(QIODevice::WriteOnly)) { - f.write("1", 1); - f.close(); - } +QString UiIntegration::openglCheckFilePath() { + return OpenGLCheckFilePath(); } -void UiIntegration::openglCheckFinish() { - QFile::remove(OpenGLCheckFilePath()); -} - -bool UiIntegration::openglLastCheckFailed() { - return OpenGLLastCheckFailed(); +QString UiIntegration::angleBackendFilePath() { + return ANGLEBackendFilePath(); } void UiIntegration::textActionsUpdated() { diff --git a/Telegram/SourceFiles/core/ui_integration.h b/Telegram/SourceFiles/core/ui_integration.h index c685540189..a1fcf44ca6 100644 --- a/Telegram/SourceFiles/core/ui_integration.h +++ b/Telegram/SourceFiles/core/ui_integration.h @@ -37,10 +37,8 @@ public: void unregisterLeaveSubscription(not_null widget) override; QString emojiCacheFolder() override; - - void openglCheckStart() override; - void openglCheckFinish() override; - bool openglLastCheckFailed() override; + QString openglCheckFilePath() override; + QString angleBackendFilePath() override; void textActionsUpdated() override; void activationFromTopPanel() override; diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index a8434963fb..01182d4bdd 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -14,8 +14,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/labels.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" +#include "ui/gl/gl_detection.h" #include "ui/text/text_utilities.h" // Ui::Text::ToUpper #include "ui/text/format_values.h" +#include "ui/boxes/single_choice_box.h" #include "boxes/connection_box.h" #include "boxes/about_box.h" #include "boxes/confirm_box.h" @@ -512,6 +514,77 @@ void SetupAnimations(not_null container) { }, container->lifetime()); } +void SetupANGLE( + not_null controller, + not_null container) { + using ANGLE = Ui::GL::ANGLE; + const auto options = std::vector{ + tr::lng_settings_angle_backend_auto(tr::now), + tr::lng_settings_angle_backend_d3d11(tr::now), + tr::lng_settings_angle_backend_d3d9(tr::now), + tr::lng_settings_angle_backend_d3d11on12(tr::now), + tr::lng_settings_angle_backend_opengl(tr::now), + tr::lng_settings_angle_backend_disabled(tr::now), + }; + const auto backendIndex = [] { + if (Core::App().settings().disableOpenGL()) { + return 5; + } else switch (Ui::GL::CurrentANGLE()) { + case ANGLE::Auto: return 0; + case ANGLE::D3D11: return 1; + case ANGLE::D3D9: return 2; + case ANGLE::D3D11on12: return 3; + case ANGLE::OpenGL: return 4; + } + Unexpected("Ui::GL::CurrentANGLE value in SetupANGLE."); + }(); + const auto button = AddButtonWithLabel( + container, + tr::lng_settings_angle_backend(), + rpl::single(options[backendIndex]), + st::settingsButton); + button->addClickHandler([=] { + controller->show(Box([=](not_null box) { + const auto save = [=](int index) { + if (index == backendIndex) { + return; + } + const auto confirmed = crl::guard(button, [=] { + const auto nowDisabled = (index == 5); + if (!nowDisabled) { + Ui::GL::ChangeANGLE([&] { + switch (index) { + case 0: return ANGLE::Auto; + case 1: return ANGLE::D3D11; + case 2: return ANGLE::D3D9; + case 3: return ANGLE::D3D11on12; + case 4: return ANGLE::OpenGL; + } + Unexpected("Index in SetupANGLE."); + }()); + } + const auto wasDisabled = (backendIndex == 5); + if (nowDisabled != wasDisabled) { + Core::App().settings().setDisableOpenGL(nowDisabled); + Local::writeSettings(); + } + App::restart(); + }); + controller->show(Box( + tr::lng_settings_need_restart(tr::now), + tr::lng_settings_restart_now(tr::now), + confirmed)); + }; + SingleChoiceBox(box, { + .title = tr::lng_settings_angle_backend(), + .options = options, + .initialSelection = backendIndex, + .callback = save, + }); + })); + }); +} + void SetupOpenGL( not_null controller, not_null container) { @@ -550,7 +623,9 @@ void SetupPerformance( not_null controller, not_null container) { SetupAnimations(container); - if (!Platform::IsMac()) { + if constexpr (Platform::IsWindows()) { + SetupANGLE(controller, container); + } else if constexpr (Platform::IsLinux()) { SetupOpenGL(controller, container); } } diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 7577f063a6..ac97c608c8 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 7577f063a6c6075dcee5556de9e1f96d07b2a12d +Subproject commit ac97c608c851cb3099aa98332354c179b4821e39