diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e011e67..1969035 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -128,6 +128,23 @@ parts: - bin/lxc-ls - bin/lxc-top + swiftshader: + plugin: cmake + source: https://github.com/google/swiftshader.git + source-type: git + source-commit: cbb80f5f0078a9941f3ec43e83e52c3d15a43bea + override-build: | + git submodule update --init + snapcraftctl build + artifacts: + - libEGL.so + - libGLES_CM.so + - libGLESv2.so + organize: + libEGL.so: lib/anbox/swiftshader/libEGL.so + libGLES_CM.so: lib/anbox/swiftshader/libGLES_CM.so + libGLESv2.so: lib/anbox/swiftshader/libGLESv2.so + anbox-scripts: plugin: dump source: scripts diff --git a/src/anbox/cmds/session_manager.cpp b/src/anbox/cmds/session_manager.cpp index 7df1b99..e53af53 100644 --- a/src/anbox/cmds/session_manager.cpp +++ b/src/anbox/cmds/session_manager.cpp @@ -109,6 +109,9 @@ anbox::cmds::SessionManager::SessionManager() flag(cli::make_flag(cli::Name{"use-system-dbus"}, cli::Description{"Use system instead of session DBus"}, use_system_dbus_)); + flag(cli::make_flag(cli::Name{"software-rendering"}, + cli::Description{"Use software rendering instead of hardware accelerated GL rendering"}, + use_software_rendering_)); action([this](const cli::Command::Context &) { auto trap = core::posix::trap_signals_for_process( @@ -169,8 +172,12 @@ anbox::cmds::SessionManager::SessionManager() using_single_window = true; } + auto gl_driver = graphics::GLRendererServer::Config::Driver::Host; + if (use_software_rendering_) + gl_driver = graphics::GLRendererServer::Config::Driver::Software; + graphics::GLRendererServer::Config renderer_config { - graphics::GLRendererServer::Config::Driver::Host, + gl_driver, single_window_ }; auto gl_server = std::make_shared(renderer_config, window_manager); diff --git a/src/anbox/cmds/session_manager.h b/src/anbox/cmds/session_manager.h index a273fe8..abaf1b2 100644 --- a/src/anbox/cmds/session_manager.h +++ b/src/anbox/cmds/session_manager.h @@ -49,6 +49,7 @@ class SessionManager : public cli::CommandWithFlagsAndAction { bool standalone_ = false; bool experimental_ = false; bool use_system_dbus_ = false; + bool use_software_rendering_ = false; }; } // namespace cmds } // namespace anbox diff --git a/src/anbox/graphics/gl_renderer_server.cpp b/src/anbox/graphics/gl_renderer_server.cpp index c0570fa..beb2cbe 100644 --- a/src/anbox/graphics/gl_renderer_server.cpp +++ b/src/anbox/graphics/gl_renderer_server.cpp @@ -30,6 +30,8 @@ #include #include +namespace fs = boost::filesystem; + namespace { void logger_write(const emugl::LogLevel &level, const char *format, ...) { (void)level; @@ -77,6 +79,18 @@ GLRendererServer::GLRendererServer(const Config &config, const std::shared_ptr(renderer_, composer_strategy); auto gl_libs = emugl::default_gl_libraries(); + if (config.driver == Config::Driver::Software) { + const auto snap_path = utils::get_env_value("SNAP"); + if (snap_path.empty()) + throw std::runtime_error("Software rendering is not available outside of a snap build"); + + auto swiftshader_path = fs::path(snap_path) / "lib" / "anbox" / "swiftshader"; + gl_libs = std::vector{ + {emugl::GLLibrary::Type::EGL, (swiftshader_path / "libEGL.so").string()}, + {emugl::GLLibrary::Type::GLESv1, (swiftshader_path / "libGLES_CM.so").string()}, + {emugl::GLLibrary::Type::GLESv2, (swiftshader_path / "libGLESv2.so").string()}, + }; + } emugl_logger_struct log_funcs; log_funcs.coarse = logger_write; diff --git a/src/anbox/graphics/gl_renderer_server.h b/src/anbox/graphics/gl_renderer_server.h index b6a90ce..9c1060f 100644 --- a/src/anbox/graphics/gl_renderer_server.h +++ b/src/anbox/graphics/gl_renderer_server.h @@ -35,7 +35,14 @@ class LayerComposer; class GLRendererServer { public: struct Config { - enum class Driver { Host }; + enum class Driver { + // Use the GL driver provided by the host operating system + Host, + + // Use a builtin software based GL driver implementation without any support + // for hardware acceleration. + Software, + }; Driver driver; bool single_window; };