diff --git a/CMakeLists.txt b/CMakeLists.txt index 3901428..df9d6fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,8 @@ include(CTest) include(GNUInstallDirs) if (NOT CMAKE_BUILD_TYPE) - message(STATUS "No build type selected, default to release") - set(CMAKE_BUILD_TYPE "release") + message(STATUS "No build type selected, default to RelWithDebInfo") + set(CMAKE_BUILD_TYPE "RelWithDebInfo") endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) diff --git a/debian/compat b/debian/compat index 7f8f011..ec63514 100644 --- a/debian/compat +++ b/debian/compat @@ -1 +1 @@ -7 +9 diff --git a/debian/control b/debian/control index 8696f8e..72e3872 100644 --- a/debian/control +++ b/debian/control @@ -2,8 +2,8 @@ Source: anbox Section: misc Priority: optional Maintainer: Simon Fels -Build-Depends: debhelper (>= 7), dkms, dh-systemd -Standards-Version: 3.9.7 +Build-Depends: debhelper (>= 9), dkms, dh-systemd +Standards-Version: 4.1.3 Homepage: http://anbox.io Vcs-Browser: https://github.com/anbox/anbox Vcs-Git: https://github.com/anbox/anbox.git diff --git a/external/android-emugl/host/libs/Translator/GLES_V2/.GLESv2Imp.cpp.swp b/external/android-emugl/host/libs/Translator/GLES_V2/.GLESv2Imp.cpp.swp deleted file mode 100644 index 8102470..0000000 Binary files a/external/android-emugl/host/libs/Translator/GLES_V2/.GLESv2Imp.cpp.swp and /dev/null differ diff --git a/external/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp b/external/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp index c49d4b7..91ff0b1 100644 --- a/external/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp +++ b/external/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp @@ -1048,8 +1048,10 @@ GL_APICALL void GL_APIENTRY glGetIntegerv(GLenum pname, GLint* params){ if (ctx->glGetIntegerv(pname,params)) { if (destroyCtx) + { deleteGLESContext(ctx); return; + } } bool es2 = ctx->getCaps()->GL_ARB_ES2_COMPATIBILITY; diff --git a/external/android-emugl/host/tools/emugen/ApiGen.cpp b/external/android-emugl/host/tools/emugen/ApiGen.cpp index cd3d67b..f912cb5 100644 --- a/external/android-emugl/host/tools/emugen/ApiGen.cpp +++ b/external/android-emugl/host/tools/emugen/ApiGen.cpp @@ -753,6 +753,10 @@ int ApiGen::genDecoderHeader(const std::string &filename) fprintf(fp, "#include \"IOStream.h\" \n"); fprintf(fp, "#include \"%s_%s_context.h\"\n\n\n", m_basename.c_str(), sideString(SERVER_SIDE)); + if (strcmp(classname.c_str(), "gles2_decoder_context_t") == 0) { + fprintf(fp, "\n#include \n"); + fprintf(fp, "\n#include \n"); + } fprintf(fp, "\n#include \"emugl/common/logging.h\"\n"); for (size_t i = 0; i < m_decoderHeaders.size(); i++) { @@ -763,6 +767,17 @@ int ApiGen::genDecoderHeader(const std::string &filename) fprintf(fp, "struct %s : public %s_%s_context_t {\n\n", classname.c_str(), m_basename.c_str(), sideString(SERVER_SIDE)); fprintf(fp, "\tsize_t decode(void *buf, size_t bufsize, IOStream *stream);\n"); + if (strcmp(classname.c_str(), "gles2_decoder_context_t") == 0){ + fprintf(fp, + "\tvoid freeShader(); \n\ + \tvoid freeProgram(); \n\ + \tstd::map m_programs; \n\ + \tstd::map m_shaders; \n\ + \tstd::mutex m_lock; \n\ + "); + + + } fprintf(fp, "\n};\n\n"); fprintf(fp, "#endif // GUARD_%s\n", classname.c_str()); @@ -835,6 +850,35 @@ int ApiGen::genDecoderImpl(const std::string &filename) // helper templates fprintf(fp, "using namespace emugl;\n\n"); + // glsl shader/program free; + if (strcmp(classname.c_str(), "gles2_decoder_context_t") == 0) { + fprintf(fp, "void %s::freeShader(){\n", classname.c_str()); + fprintf(fp, + " \n\ +\tauto it = m_shaders.begin();\n\ +\tm_lock.lock();\n\ +\twhile(it != m_shaders.end()) \n\ +\t{\n\ +\t\tthis->glDeleteShader(it->first);\n\ +\t\tit++;\n\ +\t}\n\ +\tm_lock.unlock();\n\ +}\n\n"); + + fprintf(fp, "void %s::freeProgram(){\n", classname.c_str()); + fprintf(fp, + " \n\ +\tauto it = m_programs.begin(); \n\ +\tm_lock.lock();\n\ +\twhile(it != m_programs.end()) \n\ +\t{\n\ +\t\tthis->glDeleteProgram(it->first);\n\ +\t\tit++;\n\ +\t}\n\ +\tm_lock.unlock();\n\ +}\n\n"); + } + // decoder switch; fprintf(fp, "size_t %s::decode(void *buf, size_t len, IOStream *stream)\n{\n", classname.c_str()); fprintf(fp, @@ -1114,8 +1158,7 @@ int ApiGen::genDecoderImpl(const std::string &filename) varoffset.c_str(), varoffset.c_str(), varoffset.c_str(), - classname.c_str(), - e->name().c_str() + classname.c_str() ); varoffset += " + 4"; @@ -1161,6 +1204,37 @@ int ApiGen::genDecoderImpl(const std::string &filename) } // pass; fprintf(fp, "\t\t\tSET_LASTCALL(\"%s\");\n", e->name().c_str()); + if (strcmp(m_basename.c_str(), "gles2") == 0) { + if (strcmp(e->name().c_str(), "glAttachShader") == 0){ + fprintf(fp, "\n\ + \t\t\tm_lock.lock();\n\ + m_shaders.insert({var_shader, 1});\n\ + m_lock.unlock();\n"); + } else if(strcmp(e->name().c_str(), "glDeleteProgram") == 0){ + fprintf(fp, + "\t\t\tm_lock.lock(); \n" + "\t\t\tauto pro = m_programs.find(var_program); \n" + "\t\t\tif (pro != m_programs.end()) \n" + "\t\t\t{ \n" + "\t\t\t\tm_programs.erase(pro); \n" + "\t\t\t}\n" + "\t\t\tm_lock.unlock();\n"); + } else if(strcmp(e->name().c_str(), "glDeleteShader") == 0){ + fprintf(fp, + "\t\t\tm_lock.lock(); \n\ + \t\t\tauto shader = m_shaders.find(var_shader); \n\ + \t\t\tif (shader != m_shaders.end()) \n\ + \t\t\t{ \n\ + \t\t\t\tm_shaders.erase(shader); \n\ + \t\t\t} \n\ + \t\t\tm_lock.unlock(); \n"); + } else if(strcmp(e->name().c_str(), "glLinkProgram") == 0){ + fprintf(fp, " \n\ + \t\t\tm_lock.lock();\n\ + \t\t\tm_programs.insert({var_program, 1});\n\ + \t\t\tm_lock.unlock();\n"); + } + } fprintf(fp, "\t\t\tbreak;\n"); fprintf(fp, "\t\t}\n"); diff --git a/external/android-emugl/host/tools/emugen/EntryPoint.cpp b/external/android-emugl/host/tools/emugen/EntryPoint.cpp index cc3bef1..8f91c83 100644 --- a/external/android-emugl/host/tools/emugen/EntryPoint.cpp +++ b/external/android-emugl/host/tools/emugen/EntryPoint.cpp @@ -99,7 +99,7 @@ bool EntryPoint::parse(unsigned int lc, const std::string & str) std::string vartype, varname; if (!parseParameterDeclaration(field, &vartype, &varname, &error)) { fprintf(stderr, - "line: %d: Parsing error in field <%s>\n", + "line: %d: Parsing error in field <%s>, error: %s\n", lc, field.c_str(), error.c_str()); diff --git a/external/process-cpp-minimal/src/core/posix/signal.cpp b/external/process-cpp-minimal/src/core/posix/signal.cpp index fd90047..43c10e0 100644 --- a/external/process-cpp-minimal/src/core/posix/signal.cpp +++ b/external/process-cpp-minimal/src/core/posix/signal.cpp @@ -204,7 +204,7 @@ private: } std::shared_ptr core::posix::trap_signals_for_process( - std::initializer_list blocked_signals) + std::initializer_list blocked_signals) { return std::make_shared( impl::SignalTrap::Scope::process, diff --git a/scripts/clean-build.sh b/scripts/clean-build.sh index d1041a4..3e1e766 100755 --- a/scripts/clean-build.sh +++ b/scripts/clean-build.sh @@ -56,8 +56,8 @@ cleanup mkdir build || rm -rf build/* cd build cmake .. -make -j10 -make test +VERBOSE=1 make -j10 +VERBOSE=1 make test cd .. cleanup diff --git a/scripts/snap-wrapper.sh b/scripts/snap-wrapper.sh index 0ca2d83..b1f1e3b 100755 --- a/scripts/snap-wrapper.sh +++ b/scripts/snap-wrapper.sh @@ -35,6 +35,11 @@ export LD_LIBRARY_PATH="$SNAP_LIBRARY_PATH:$LD_LIBRARY_PATH" # Ref.: https://bugs.launchpad.net/snappy/+bug/1588192 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/var/lib/snapd/lib/gl +# With recent builds on Ubuntu 16.04 the snap does not find the path to +# libpulsecommon-8.0.so anymore so we have to teach the linker manually +# where it can be found +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/usr/lib/$ARCH/pulseaudio + # We set XDG_DATA_HOME to SNAP_USER_COMMON here as this will be the location we will # create all our application launchers in. The system application launcher will # be configured by our installer to look into this directory for available diff --git a/src/anbox/cmds/session_manager.cpp b/src/anbox/cmds/session_manager.cpp index 4988967..165c043 100644 --- a/src/anbox/cmds/session_manager.cpp +++ b/src/anbox/cmds/session_manager.cpp @@ -176,7 +176,7 @@ anbox::cmds::SessionManager::SessionManager() input_manager, display_frame, single_window_); - if (!platform) + if (!platform) return EXIT_FAILURE; auto app_db = std::make_shared(); diff --git a/src/anbox/container/management_api_stub.cpp b/src/anbox/container/management_api_stub.cpp index 1806daf..ebe7632 100644 --- a/src/anbox/container/management_api_stub.cpp +++ b/src/anbox/container/management_api_stub.cpp @@ -24,6 +24,9 @@ namespace anbox { namespace container { + +const std::chrono::milliseconds ManagementApiStub::stop_waiting_timeout{3000}; + ManagementApiStub::ManagementApiStub( const std::shared_ptr &channel) : channel_(channel) {} @@ -75,7 +78,9 @@ void ManagementApiStub::stop_container() { channel_->call_method("stop_container", &message, c->response.get(), google::protobuf::NewCallback(this, &ManagementApiStub::container_stopped, c.get())); - c->wh.wait_for_all(); + // If container manager dies before session manager, the session manager + // cannot exit if it waits for all, so just wait for 3 seconds. + c->wh.wait_for_pending(stop_waiting_timeout); if (c->response->has_error()) throw std::runtime_error(c->response->error()); } diff --git a/src/anbox/container/management_api_stub.h b/src/anbox/container/management_api_stub.h index 11ebeeb..e40df94 100644 --- a/src/anbox/container/management_api_stub.h +++ b/src/anbox/container/management_api_stub.h @@ -56,6 +56,7 @@ class ManagementApiStub : public DoNotCopyOrMove { mutable std::mutex mutex_; std::shared_ptr channel_; + static const std::chrono::milliseconds stop_waiting_timeout; }; } // namespace container } // namespace anbox diff --git a/src/anbox/graphics/emugl/RenderControl.cpp b/src/anbox/graphics/emugl/RenderControl.cpp index 26e9559..2a2c453 100644 --- a/src/anbox/graphics/emugl/RenderControl.cpp +++ b/src/anbox/graphics/emugl/RenderControl.cpp @@ -26,9 +26,9 @@ #include "external/android-emugl/shared/OpenglCodecCommon/ChecksumCalculatorThreadInfo.h" #include "external/android-emugl/host/include/OpenGLESDispatch/EGLDispatch.h" - #include #include +#include static const GLint rendererVersion = 1; static std::shared_ptr composer; @@ -55,53 +55,61 @@ static EGLint rcGetEGLVersion(EGLint *major, EGLint *minor) { return EGL_TRUE; } -static EGLint rcQueryEGLString(EGLenum name, void *buffer, EGLint bufferSize) { +static std::string filter_extensions(const std::string& extensions, const std::vector& whitelist) { + std::stringstream approved_extensions; + auto extension_list = anbox::utils::string_split(extensions, ' '); + for (const auto& ext : extension_list) { + if (std::find(whitelist.begin(), whitelist.end(), ext) == whitelist.end()) + continue; + + if (approved_extensions.tellp() > 0) + approved_extensions << " "; + + approved_extensions << ext; + } + return approved_extensions.str(); +} + +static EGLint rcQueryEGLString(EGLenum name, void* buffer, EGLint bufferSize) { if (!renderer) return 0; - auto result = s_egl.eglQueryString(renderer->getDisplay(), name); - if (!result) + std::string result = s_egl.eglQueryString(renderer->getDisplay(), name); + if (result.empty()) return 0; - std::string approved_result = result; - - // We need to drop a few extensions from the list reported by the driver - // as not all are well enough support by our EGL/GLES stack. if (name == EGL_EXTENSIONS) { - std::vector common_unsupported_extensions = { - // Leads to crashes on the Android side when SurfaceFlinger initializes - // EGL/GLES and it queries surfaces for available attributes. - "EGL_EXT_buffer_age" + // We need to drop a few extensions from the list reported by the driver + // as not all are well enough support by our EGL implementation. + std::vector whitelisted_extensions = { + "EGL_KHR_image_base", + "EGL_KHR_gl_texture_2D_image", }; - - for (const auto &extension : common_unsupported_extensions) { - size_t start_pos = approved_result.find(extension); - if (start_pos == std::string::npos) continue; - approved_result.replace(start_pos, extension.length(), ""); - } + result = filter_extensions(result, whitelisted_extensions); } - int len = approved_result.length() + 1; + int len = result.length() + 1; if (!buffer || len > bufferSize) { return -len; } - strcpy(static_cast(buffer), approved_result.c_str()); + strcpy(static_cast(buffer), result.c_str()); return len; } -static EGLint rcGetGLString(EGLenum name, void *buffer, EGLint bufferSize) { - RenderThreadInfo *tInfo = RenderThreadInfo::get(); +static EGLint rcGetGLString(EGLenum name, void* buffer, EGLint bufferSize) { + RenderThreadInfo* tInfo = RenderThreadInfo::get(); std::string result; if (tInfo && tInfo->currContext) { - const char *str = nullptr; + const char* str = nullptr; if (tInfo->currContext->isGL2()) - str = reinterpret_cast(s_gles2.glGetString(name)); + str = reinterpret_cast(s_gles2.glGetString(name)); else - str = reinterpret_cast(s_gles1.glGetString(name)); + str = reinterpret_cast(s_gles1.glGetString(name)); - if (str) result += str; + if (str) + result += str; } // We're forcing version 2.0 no matter what the host provides as @@ -113,27 +121,37 @@ static EGLint rcGetGLString(EGLenum name, void *buffer, EGLint bufferSize) { if (name == GL_VERSION) result = "OpenGL ES 2.0"; else if (name == GL_EXTENSIONS) { - std::string approved_extensions = result; - std::vector unsupported_extensions = { - // Leaving this enabled gives crippeled text rendering when - // using the host mesa GLES drivers. - "GL_EXT_unpack_subimage", + // We need to drop a few extensions from the list reported by the driver + // as not all are well enough support by our GL implementation. + std::vector whitelisted_extensions = { + "GL_OES_EGL_image", + "GL_OES_EGL_image_external", + "GL_OES_depth24", + "GL_OES_depth32", + "GL_OES_element_index_uint", + "GL_OES_texture_float", + "GL_OES_texture_float_linear", + "GL_OES_compressed_paletted_texture", + "GL_OES_compressed_ETC1_RGB8_texture", + "GL_OES_depth_texture", + "GL_OES_texture_half_float", + "GL_OES_texture_half_float_linear", + "GL_OES_packed_depth_stencil", + "GL_OES_vertex_half_float", + "GL_OES_standard_derivatives", + "GL_OES_texture_npot", + "GL_OES_rgb8_rgba8", }; - for (const auto &extension : unsupported_extensions) { - size_t start_pos = approved_extensions.find(extension); - if (start_pos == std::string::npos) continue; - approved_extensions.replace(start_pos, extension.length(), ""); - } - - result = approved_extensions; + result = filter_extensions(result, whitelisted_extensions); } int nextBufferSize = result.size() + 1; - if (!buffer || nextBufferSize > bufferSize) return -nextBufferSize; + if (!buffer || nextBufferSize > bufferSize) + return -nextBufferSize; - snprintf(static_cast(buffer), nextBufferSize, "%s", result.c_str()); + snprintf(static_cast(buffer), nextBufferSize, "%s", result.c_str()); return nextBufferSize; } diff --git a/src/anbox/graphics/emugl/RenderThread.cpp b/src/anbox/graphics/emugl/RenderThread.cpp index 7e6dff7..7c8e4e6 100644 --- a/src/anbox/graphics/emugl/RenderThread.cpp +++ b/src/anbox/graphics/emugl/RenderThread.cpp @@ -84,8 +84,12 @@ intptr_t RenderThread::main() { } } while (progress); + } + threadInfo.m_gl2Dec.freeShader(); + threadInfo.m_gl2Dec.freeProgram(); + // Release references to the current thread's context/surfaces if any renderer_->bindContext(0, 0, 0); if (threadInfo.currContext || threadInfo.currDrawSurf || threadInfo.currReadSurf) diff --git a/src/anbox/graphics/emugl/Renderer.cpp b/src/anbox/graphics/emugl/Renderer.cpp index a807131..98d26cc 100644 --- a/src/anbox/graphics/emugl/Renderer.cpp +++ b/src/anbox/graphics/emugl/Renderer.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#define GLM_ENABLE_EXPERIMENTAL #include "anbox/graphics/emugl/Renderer.h" #include "anbox/graphics/emugl/DispatchTables.h" #include "anbox/graphics/emugl/RenderThreadInfo.h" diff --git a/src/anbox/qemu/qemud_message_processor.cpp b/src/anbox/qemu/qemud_message_processor.cpp index d9ee009..b47f078 100644 --- a/src/anbox/qemu/qemud_message_processor.cpp +++ b/src/anbox/qemu/qemud_message_processor.cpp @@ -70,7 +70,7 @@ void QemudMessageProcessor::process_commands() { void QemudMessageProcessor::send_header(const size_t &size) { char header[header_size + 1]; - std::snprintf(header, header_size + 1, "%04lx", size); + std::snprintf(header, header_size + 1, "%04zx", size); messenger_->send(header, header_size); } diff --git a/src/anbox/runtime.cpp b/src/anbox/runtime.cpp index cbfefa7..90c6768 100644 --- a/src/anbox/runtime.cpp +++ b/src/anbox/runtime.cpp @@ -53,7 +53,13 @@ std::shared_ptr Runtime::create(std::uint32_t pool_size) { Runtime::Runtime(std::uint32_t pool_size) : pool_size_{pool_size}, + + #if BOOST_VERSION >= 106600 + service_{static_cast(pool_size_)}, + #else service_{pool_size_}, + #endif + strand_{service_}, keep_alive_{service_} {} diff --git a/src/anbox/runtime.h b/src/anbox/runtime.h index 43065be..ea521e3 100644 --- a/src/anbox/runtime.h +++ b/src/anbox/runtime.h @@ -19,6 +19,7 @@ #define ANBOX_RUNTIME_H_ #include +#include #include #include