Compare commits

...

1 Commits

Author SHA1 Message Date
Ian Chua
3e42067171 fix: wayland startup gl/imgui prewarm timing 2026-05-15 17:34:13 +08:00

View File

@@ -23,9 +23,11 @@
#include "slic3r/GUI/I18N.hpp" #include "slic3r/GUI/I18N.hpp"
#include <algorithm> #include <algorithm>
#include <functional>
#include <iterator> #include <iterator>
#include <exception> #include <exception>
#include <cstdlib> #include <cstdlib>
#include <memory>
#include <regex> #include <regex>
#include <thread> #include <thread>
#include <string_view> #include <string_view>
@@ -778,41 +780,89 @@ void GUI_App::post_init()
plater_->canvas3D()->enable_render(false); plater_->canvas3D()->enable_render(false);
mainframe->select_tab(size_t(MainFrame::tp3DEditor)); mainframe->select_tab(size_t(MainFrame::tp3DEditor));
plater_->select_view_3D("3D"); plater_->select_view_3D("3D");
//BBS init the opengl resource here
//#ifdef __linux__ auto restore_startup_tab = [this]() {
if (plater_->canvas3D()->get_wxglcanvas()->IsShownOnScreen()&&plater_->canvas3D()->make_current_for_postinit()) { if (is_editor())
//#endif mainframe->select_tab(size_t(0));
Size canvas_size = plater_->canvas3D()->get_canvas_size(); if (app_config->get("default_page") == "1")
mainframe->select_tab(size_t(1));
};
auto load_gl_resources = [this, slow_bootup]() -> bool {
GLCanvas3D* canvas = plater_->canvas3D();
if (canvas == nullptr || canvas->get_wxglcanvas() == nullptr ||
!canvas->get_wxglcanvas()->IsShownOnScreen() || !canvas->make_current_for_postinit())
return false;
Size canvas_size = canvas->get_canvas_size();
wxGetApp().imgui()->set_display_size(static_cast<float>(canvas_size.get_width()), static_cast<float>(canvas_size.get_height())); wxGetApp().imgui()->set_display_size(static_cast<float>(canvas_size.get_width()), static_cast<float>(canvas_size.get_height()));
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", start to init opengl"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", start to init opengl";
wxGetApp().init_opengl(); wxGetApp().init_opengl();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished init opengl"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished init opengl";
plater_->canvas3D()->init(); canvas->init();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished init canvas3D"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished init canvas3D";
wxGetApp().imgui()->new_frame(); wxGetApp().imgui()->new_frame();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished init imgui frame"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished init imgui frame";
plater_->canvas3D()->enable_render(true); canvas->enable_render(true);
if (!slow_bootup) { if (!slow_bootup) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", start to render a first frame for test"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", start to render a first frame for test";
plater_->canvas3D()->render(false); canvas->render(false);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished rendering a first frame for test"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished rendering a first frame for test";
} }
//#ifdef __linux__ return true;
};
//BBS init the opengl resource here
if (load_gl_resources()) {
restore_startup_tab();
} }
#if defined(__linux__) && defined(__WXGTK__)
else {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << "Found glcontext not ready, postpone the init";
if (is_running_on_wayland()) {
constexpr int max_attempts = 8;
auto attempts = std::make_shared<int>(0);
auto retry = std::make_shared<std::function<void()>>();
*retry = [this, attempts, retry, restore_startup_tab, load_gl_resources]() {
if (load_gl_resources()) {
restore_startup_tab();
*retry = nullptr;
return;
}
++(*attempts);
if (*attempts < max_attempts) {
CallAfter(*retry);
return;
}
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << "Found glcontext not ready after deferred attempts, postpone the init";
plater_->canvas3D()->enable_render(true);
plater_->canvas3D()->set_as_dirty();
restore_startup_tab();
*retry = nullptr;
};
CallAfter(*retry);
} else {
plater_->canvas3D()->enable_render(true);
plater_->canvas3D()->set_as_dirty();
restore_startup_tab();
}
}
#else
else { else {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << "Found glcontext not ready, postpone the init"; BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << "Found glcontext not ready, postpone the init";
plater_->canvas3D()->enable_render(true); plater_->canvas3D()->enable_render(true);
plater_->canvas3D()->set_as_dirty(); plater_->canvas3D()->set_as_dirty();
restore_startup_tab();
} }
//#endif #endif
if (is_editor())
mainframe->select_tab(size_t(0));
if (app_config->get("default_page") == "1")
mainframe->select_tab(size_t(1));
#ifndef __linux__ #ifndef __linux__
mainframe->Thaw(); mainframe->Thaw();
#endif #endif
@@ -3460,7 +3510,7 @@ void GUI_App::select_machine(const std::string& agent_id)
} }
// Get config source (preset or physical printer) // Get config source (preset or physical printer)
const auto& preset = preset_bundle->printers.get_edited_preset(); auto& preset = preset_bundle->printers.get_edited_preset();
const DynamicPrintConfig* host_cfg = &preset.config; const DynamicPrintConfig* host_cfg = &preset.config;
std::string print_host = host_cfg->opt_string("print_host"); std::string print_host = host_cfg->opt_string("print_host");
@@ -3493,7 +3543,9 @@ void GUI_App::select_machine(const std::string& agent_id)
// We use dev_id as dev_ip to store the address (host:port) // We use dev_id as dev_ip to store the address (host:port)
machine.dev_ip = dev_id; machine.dev_ip = dev_id;
machine.dev_name = dev_id; machine.dev_name = dev_id;
machine.printer_type = preset.config.opt_string("printer_model"); machine.printer_type = preset.get_printer_type(preset_bundle);
if (machine.printer_type.empty())
machine.printer_type = preset.config.opt_string("printer_model");
auto access_code = preset.config.opt_string("printhost_apikey"); auto access_code = preset.config.opt_string("printhost_apikey");
// Orca expect non empty access code // Orca expect non empty access code
if (access_code.empty()) { if (access_code.empty()) {