From 0f6f95c00b4ef0301447e739e6b8915bf085c300 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 7 Jul 2023 17:48:17 +0200 Subject: [PATCH] Move some of gpu_config_panel.h to a .cc. --- src/wx/gpu_config_panel.cc | 215 +++++++++++++++++++++++++++++++++++++ src/wx/gpu_config_panel.h | 195 +++------------------------------ src/wx/wscript | 1 + 3 files changed, 232 insertions(+), 179 deletions(-) create mode 100644 src/wx/gpu_config_panel.cc diff --git a/src/wx/gpu_config_panel.cc b/src/wx/gpu_config_panel.cc new file mode 100644 index 000000000..a9207ee3c --- /dev/null +++ b/src/wx/gpu_config_panel.cc @@ -0,0 +1,215 @@ + +#include "check_box.h" +#include "gpu_config_panel.h" +#include "password_entry.h" +#include +#include + +#include +#include +#include + + +static std::vector +get_gpu_names(std::string binary, std::string filename) +{ + // Execute the GPU listing program and redirect its output to a file + std::system((binary + " > " + filename).c_str()); + + std::vector gpu_names; + std::ifstream file(filename); + if (file.is_open()) { + std::string line; + while (std::getline(file, line)) { + gpu_names.push_back(line); + } + file.close(); + } + + return gpu_names; +} + + +class GPUList : public wxPanel +{ +public: + GPUList(wxPanel* parent) + : wxPanel(parent, wxID_ANY) + , _selection(0) + { + _combo_box = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(400, -1)); + _combo_box->Bind(wxEVT_COMBOBOX, &GPUList::on_combo_box, this); + update(); + + wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); + + sizer->Add(_combo_box, 0, wxALIGN_CENTER_VERTICAL); // Vertically center the comboBox + + this->SetSizerAndFit(sizer); + } + + void update() + { + auto cfg = Config::instance(); + auto lister_binary = cfg->gpu_binary_location() + "/" + "gpu_lister"; + auto lister_file = cfg->gpu_binary_location() + "/" + "gpus.txt"; + if (boost::filesystem::exists(lister_binary)) { + auto gpu_names = get_gpu_names(lister_binary, lister_file); + + _combo_box->Clear(); + for (const auto& name : gpu_names) { + _combo_box->Append(name); + } + } + } + + int get_selection() + { + return _selection; + } + + void set_selection(int sel) + { + if ((int)_combo_box->GetCount() > sel) { + _combo_box->SetSelection(sel); + } + } + +private: + void on_combo_box([[maybe_unused]] wxCommandEvent& event) + { + _selection = _combo_box->GetSelection(); + if (_selection != wxNOT_FOUND) { + Config::instance()->set_selected_gpu(_selection); + } + } + + wxComboBox* _combo_box; + int _selection; +}; + + +GPUPage::GPUPage(wxSize panel_size, int border) + : Page(panel_size, border) + , _enable_gpu(nullptr) + , _binary_location(nullptr) + , _gpu_list_control(nullptr) +{ + +} + + +wxString +GPUPage::GetName() const +{ + return _("GPU"); +} + + +#ifdef DCPOMATIC_OSX +wxBitmap +GPUPage::GetLargeIcon() const +{ + return wxBitmap(icon_path("tms"), wxBITMAP_TYPE_PNG); +} +#endif + + +void +GPUPage::setup() +{ + auto config = Config::instance(); + + _enable_gpu = new CheckBox(_panel, _("Enable GPU Acceleration")); + _panel->GetSizer()->Add(_enable_gpu, 0, wxALL | wxEXPAND, _border); + + wxFlexGridSizer* table = new wxFlexGridSizer(2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); + table->AddGrowableCol(1, 1); + _panel->GetSizer()->Add(table, 1, wxALL | wxEXPAND, _border); + + add_label_to_sizer(table, _panel, _("Acceleration Binary Folder"), true, 0, wxLEFT | wxLEFT | wxALIGN_CENTRE_VERTICAL); + _binary_location = new wxDirPickerCtrl(_panel, wxDD_DIR_MUST_EXIST); + table->Add(_binary_location, 1, wxEXPAND); + + add_label_to_sizer(table, _panel, _("GPU Selection"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); + _gpu_list_control = new GPUList(_panel); + table->Add(_gpu_list_control, 1, wxEXPAND); + + add_label_to_sizer(table, _panel, _("License Server"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); + _server = new wxTextCtrl(_panel, wxID_ANY); + table->Add(_server, 1, wxEXPAND | wxALL); + + add_label_to_sizer(table, _panel, _("Port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); + _port = new wxSpinCtrl(_panel, wxID_ANY); + _port->SetRange(0, 65535); + table->Add(_port); + + add_label_to_sizer(table, _panel, _("License"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); + _license = new PasswordEntry(_panel); + table->Add(_license->get_panel(), 1, wxEXPAND | wxALL); + + _enable_gpu->bind(&GPUPage::enable_gpu_changed, this); + _binary_location->Bind(wxEVT_DIRPICKER_CHANGED, boost::bind(&GPUPage::binary_location_changed, this)); + _server->Bind(wxEVT_TEXT, boost::bind(&GPUPage::server_changed, this)); + _port->Bind(wxEVT_SPINCTRL, boost::bind(&GPUPage::port_changed, this)); + _license->Changed.connect(boost::bind(&GPUPage::license_changed, this)); + + _binary_location->Enable(config->enable_gpu()); + _gpu_list_control->Enable(config->enable_gpu()); + _server->Enable(config->enable_gpu()); + _port->Enable(config->enable_gpu()); + _license->get_panel()->Enable(config->enable_gpu()); +} + + +void GPUPage::config_changed() +{ + auto config = Config::instance(); + + checked_set(_enable_gpu, config->enable_gpu()); + _binary_location->SetPath(config->gpu_binary_location()); + _gpu_list_control->update(); + _gpu_list_control->set_selection(config->selected_gpu()); + checked_set(_server, config->gpu_license_server()); + checked_set(_port, config->gpu_license_port()); + checked_set(_license, config->gpu_license()); +} + + +void GPUPage::enable_gpu_changed() +{ + auto config = Config::instance(); + + config->set_enable_gpu(_enable_gpu->GetValue()); + _binary_location->Enable(config->enable_gpu()); + _gpu_list_control->Enable(config->enable_gpu()); + _server->Enable(config->enable_gpu()); + _port->Enable(config->enable_gpu()); + _license->get_panel()->Enable(config->enable_gpu()); +} + + +void GPUPage::binary_location_changed() +{ + Config::instance()->set_gpu_binary_location(wx_to_std(_binary_location->GetPath())); + _gpu_list_control->update(); +} + + +void GPUPage::server_changed() +{ + Config::instance()->set_gpu_license_server(wx_to_std(_server->GetValue())); +} + + +void GPUPage::port_changed() +{ + Config::instance()->set_gpu_license_port(_port->GetValue()); +} + + +void GPUPage::license_changed() +{ + Config::instance()->set_gpu_license(_license->get()); +} + diff --git a/src/wx/gpu_config_panel.h b/src/wx/gpu_config_panel.h index 0fa75b5e4..375b5487e 100644 --- a/src/wx/gpu_config_panel.h +++ b/src/wx/gpu_config_panel.h @@ -1,200 +1,37 @@ -#pragma once - -static std::vector -get_gpu_names(std::string binary, std::string filename) -{ - // Execute the GPU listing program and redirect its output to a file - std::system((binary + " > " + filename).c_str()); - - std::vector gpu_names; - std::ifstream file(filename); - if (file.is_open()) { - std::string line; - while (std::getline(file, line)) { - gpu_names.push_back(line); - } - file.close(); - } - - return gpu_names; -} - -class GpuList : public wxPanel -{ -public: - GpuList(wxPanel* parent) - : wxPanel(parent, wxID_ANY) - , _selection(0) - { - _combo_box = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(400, -1)); - _combo_box->Bind(wxEVT_COMBOBOX, &GpuList::on_combo_box, this); - update(); +#include "config_dialog.h" - wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(_combo_box, 0, wxALIGN_CENTER_VERTICAL); // Vertically center the comboBox - - this->SetSizerAndFit(sizer); - } - - void update() - { - auto cfg = Config::instance(); - auto lister_binary = cfg->gpu_binary_location() + "/" + "gpu_lister"; - auto lister_file = cfg->gpu_binary_location() + "/" + "gpus.txt"; - if (boost::filesystem::exists(lister_binary)) { - auto gpu_names = get_gpu_names(lister_binary, lister_file); - - _combo_box->Clear(); - for (const auto& name : gpu_names) { - _combo_box->Append(name); - } - } - } - - int get_selection() - { - return _selection; - } +#pragma once - void set_selection(int sel) - { - if ((int)_combo_box->GetCount() > sel) { - _combo_box->SetSelection(sel); - } - } -private: - void on_combo_box([[maybe_unused]] wxCommandEvent& event) - { - _selection = _combo_box->GetSelection(); - if (_selection != wxNOT_FOUND) { - Config::instance()->set_selected_gpu(_selection); - } - } +class CheckBox; +class GPUList; +class wxTextCtrl; - wxComboBox* _combo_box; - int _selection; -}; class GPUPage : public Page { public: - GPUPage(wxSize panel_size, int border) - : Page(panel_size, border) - , _enable_gpu(nullptr) - , _binary_location(nullptr) - , _gpu_list_control(nullptr) - { - } + GPUPage(wxSize panel_size, int border); - wxString GetName() const override - { - return _("GPU"); - } + wxString GetName() const override; #ifdef DCPOMATIC_OSX - wxBitmap GetLargeIcon() const override - { - return wxBitmap(icon_path("tms"), wxBITMAP_TYPE_PNG); - } + wxBitmap GetLargeIcon() const override; #endif private: - void setup() override - { - auto config = Config::instance(); - - _enable_gpu = new CheckBox(_panel, _("Enable GPU Acceleration")); - _panel->GetSizer()->Add(_enable_gpu, 0, wxALL | wxEXPAND, _border); - - wxFlexGridSizer* table = new wxFlexGridSizer(2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); - table->AddGrowableCol(1, 1); - _panel->GetSizer()->Add(table, 1, wxALL | wxEXPAND, _border); - - add_label_to_sizer(table, _panel, _("Acceleration Binary Folder"), true, 0, wxLEFT | wxLEFT | wxALIGN_CENTRE_VERTICAL); - _binary_location = new wxDirPickerCtrl(_panel, wxDD_DIR_MUST_EXIST); - table->Add(_binary_location, 1, wxEXPAND); - - add_label_to_sizer(table, _panel, _("GPU Selection"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _gpu_list_control = new GpuList(_panel); - table->Add(_gpu_list_control, 1, wxEXPAND); - - add_label_to_sizer(table, _panel, _("License Server"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _server = new wxTextCtrl(_panel, wxID_ANY); - table->Add(_server, 1, wxEXPAND | wxALL); - - add_label_to_sizer(table, _panel, _("Port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _port = new wxSpinCtrl(_panel, wxID_ANY); - _port->SetRange(0, 65535); - table->Add(_port); - - add_label_to_sizer(table, _panel, _("License"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _license = new PasswordEntry(_panel); - table->Add(_license->get_panel(), 1, wxEXPAND | wxALL); - - _enable_gpu->bind(&GPUPage::enable_gpu_changed, this); - _binary_location->Bind(wxEVT_DIRPICKER_CHANGED, boost::bind(&GPUPage::binary_location_changed, this)); - _server->Bind(wxEVT_TEXT, boost::bind(&GPUPage::server_changed, this)); - _port->Bind(wxEVT_SPINCTRL, boost::bind(&GPUPage::port_changed, this)); - _license->Changed.connect(boost::bind(&GPUPage::license_changed, this)); - - _binary_location->Enable(config->enable_gpu()); - _gpu_list_control->Enable(config->enable_gpu()); - _server->Enable(config->enable_gpu()); - _port->Enable(config->enable_gpu()); - _license->get_panel()->Enable(config->enable_gpu()); - } - - void config_changed() override - { - auto config = Config::instance(); - - checked_set(_enable_gpu, config->enable_gpu()); - _binary_location->SetPath(config->gpu_binary_location()); - _gpu_list_control->update(); - _gpu_list_control->set_selection(config->selected_gpu()); - checked_set(_server, config->gpu_license_server()); - checked_set(_port, config->gpu_license_port()); - checked_set(_license, config->gpu_license()); - } - - void enable_gpu_changed() - { - auto config = Config::instance(); - - config->set_enable_gpu(_enable_gpu->GetValue()); - _binary_location->Enable(config->enable_gpu()); - _gpu_list_control->Enable(config->enable_gpu()); - _server->Enable(config->enable_gpu()); - _port->Enable(config->enable_gpu()); - _license->get_panel()->Enable(config->enable_gpu()); - } - - void binary_location_changed() - { - Config::instance()->set_gpu_binary_location(wx_to_std(_binary_location->GetPath())); - _gpu_list_control->update(); - } - - void server_changed() - { - Config::instance()->set_gpu_license_server(wx_to_std(_server->GetValue())); - } - - void port_changed() - { - Config::instance()->set_gpu_license_port(_port->GetValue()); - } - - void license_changed() - { - Config::instance()->set_gpu_license(_license->get()); - } + void setup() override; + void config_changed() override; + void enable_gpu_changed(); + void binary_location_changed(); + void server_changed(); + void port_changed(); + void license_changed(); CheckBox* _enable_gpu; wxDirPickerCtrl* _binary_location; - GpuList* _gpu_list_control; + GPUList* _gpu_list_control; wxTextCtrl* _server; wxSpinCtrl* _port; PasswordEntry* _license; diff --git a/src/wx/wscript b/src/wx/wscript index 3e5483647..e590cca4f 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -84,6 +84,7 @@ sources = """ gain_calculator_dialog.cc gdc_certificate_panel.cc gl_video_view.cc + gpu_config_panel.cc hints_dialog.cc html_dialog.cc i18n_hook.cc -- 2.30.2