graphics: add support for swiftshader based software rendering

This commit is contained in:
Simon Fels 2018-05-23 12:56:25 +02:00
commit 161f5674de
5 changed files with 48 additions and 2 deletions

View file

@ -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

View file

@ -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<graphics::GLRendererServer>(renderer_config, window_manager);

View file

@ -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

View file

@ -30,6 +30,8 @@
#include <cstdarg>
#include <stdexcept>
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<w
composer_ = std::make_shared<LayerComposer>(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>{
{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;

View file

@ -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;
};