3 static std::vector<std::string> get_gpu_names(std::string binary, std::string filename)
5 // Execute the GPU listing program and redirect its output to a file
6 if (std::system((binary + " > " + filename).c_str()) < 0) {
10 std::vector<std::string> gpu_names;
11 std::ifstream file(filename);
15 while (std::getline(file, line))
16 gpu_names.push_back(line);
23 class GpuList : public wxPanel
26 GpuList(wxPanel* parent) : wxPanel(parent, wxID_ANY), selection(0) {
27 comboBox = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(400, -1));
28 comboBox->Bind(wxEVT_COMBOBOX, &GpuList::OnComboBox, this);
31 wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
33 sizer->Add(comboBox, 0, wxALIGN_CENTER_VERTICAL); // Vertically center the comboBox
35 this->SetSizerAndFit(sizer);
38 auto cfg = Config::instance();
39 auto lister_binary = cfg->gpu_binary_location() + "/" + "gpu_lister";
40 auto lister_file = cfg->gpu_binary_location () + "/" + "gpus.txt";
41 if (boost::filesystem::exists(lister_binary)) {
42 auto gpu_names = get_gpu_names(lister_binary, lister_file);
45 for (const auto& name : gpu_names)
46 comboBox->Append(name);
50 int getSelection(void) {
53 void setSelection(int sel) {
54 if ((int)comboBox->GetCount() > sel)
55 comboBox->SetSelection(sel);
59 void OnComboBox(wxCommandEvent&)
61 selection = comboBox->GetSelection();
62 if (selection != wxNOT_FOUND)
63 Config::instance ()->set_selected_gpu(selection);
70 class GPUPage : public Page
73 GPUPage (wxSize panel_size, int border)
74 : Page (panel_size, border),
75 _enable_gpu(nullptr), _binary_location(nullptr), _gpu_list_control(nullptr)
78 wxString GetName () const override
84 wxBitmap GetLargeIcon () const override
86 return wxBitmap(icon_path("tms"), wxBITMAP_TYPE_PNG);
91 void setup () override
93 auto config = Config::instance ();
95 _enable_gpu = new CheckBox(_panel, _("Enable GPU acceleration"));
96 _panel->GetSizer()->Add (_enable_gpu, 0, wxALL | wxEXPAND, _border);
98 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
99 table->AddGrowableCol (1, 1);
100 _panel->GetSizer()->Add (table, 1, wxALL | wxEXPAND, _border);
102 add_label_to_sizer(table, _panel, _("Acceleration binary folder"), true, 0, wxLEFT | wxLEFT | wxALIGN_CENTRE_VERTICAL);
103 _binary_location = new wxDirPickerCtrl (_panel, wxDD_DIR_MUST_EXIST);
104 table->Add (_binary_location, 1, wxEXPAND);
106 add_label_to_sizer(table, _panel, _("GPU selection"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
107 _gpu_list_control = new GpuList(_panel);
108 table->Add (_gpu_list_control, 1, wxEXPAND);
110 add_label_to_sizer(table, _panel, _("License server"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
111 _server = new wxTextCtrl (_panel, wxID_ANY);
112 table->Add (_server, 1, wxEXPAND | wxALL);
114 add_label_to_sizer (table, _panel, _("Port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
115 _port = new wxSpinCtrl (_panel, wxID_ANY);
116 _port->SetRange (0, 65535);
119 add_label_to_sizer (table, _panel, _("License"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL);
120 _license = new PasswordEntry (_panel);
121 table->Add (_license->get_panel(), 1, wxEXPAND | wxALL);
123 _enable_gpu->bind(&GPUPage::enable_gpu_changed, this);
124 _binary_location->Bind (wxEVT_DIRPICKER_CHANGED, boost::bind (&GPUPage::binary_location_changed, this));
125 _server->Bind (wxEVT_TEXT, boost::bind(&GPUPage::server_changed, this));
126 _port->Bind (wxEVT_SPINCTRL, boost::bind(&GPUPage::port_changed, this));
127 _license->Changed.connect (boost::bind(&GPUPage::license_changed, this));
129 _binary_location->Enable(config->enable_gpu());
130 _gpu_list_control->Enable(config->enable_gpu());
131 _server->Enable(config->enable_gpu());
132 _port->Enable(config->enable_gpu());
133 _license->get_panel()->Enable(config->enable_gpu());
137 void config_changed () override
139 auto config = Config::instance ();
141 checked_set (_enable_gpu, config->enable_gpu());
142 _binary_location->SetPath(config->gpu_binary_location ());
143 _gpu_list_control->update();
144 _gpu_list_control->setSelection(config->selected_gpu());
145 checked_set (_server, config->gpu_license_server());
146 checked_set (_port, config->gpu_license_port());
147 checked_set (_license, config->gpu_license());
150 void enable_gpu_changed ()
152 auto config = Config::instance ();
154 config->set_enable_gpu (_enable_gpu->GetValue());
155 _binary_location->Enable(config->enable_gpu());
156 _gpu_list_control->Enable(config->enable_gpu());
157 _server->Enable(config->enable_gpu());
158 _port->Enable(config->enable_gpu());
159 _license->get_panel()->Enable(config->enable_gpu());
162 void binary_location_changed ()
164 Config::instance()->set_gpu_binary_location (wx_to_std (_binary_location->GetPath ()));
165 _gpu_list_control->update();
168 void server_changed ()
170 Config::instance()->set_gpu_license_server(wx_to_std(_server->GetValue()));
175 Config::instance()->set_gpu_license_port(_port->GetValue());
178 void license_changed ()
180 Config::instance()->set_gpu_license(_license->get());
183 CheckBox* _enable_gpu;
184 wxDirPickerCtrl* _binary_location;
185 GpuList *_gpu_list_control;
188 PasswordEntry* _license;