2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Allow to choose ANGLE backend.

This commit is contained in:
John Preston
2021-07-01 10:47:29 +03:00
parent e71fc60d22
commit 18b48df9ce
7 changed files with 99 additions and 23 deletions

View File

@@ -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<Ui::VerticalLayout*> container) {
}, container->lifetime());
}
void SetupANGLE(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> 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<Ui::GenericBox*> 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<ConfirmBox>(
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<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
@@ -550,7 +623,9 @@ void SetupPerformance(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
SetupAnimations(container);
if (!Platform::IsMac()) {
if constexpr (Platform::IsWindows()) {
SetupANGLE(controller, container);
} else if constexpr (Platform::IsLinux()) {
SetupOpenGL(controller, container);
}
}