From 4fde30b7b667ef0fc3cb8175eabb1547bae6598d Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Sun, 14 May 2017 20:52:12 +0200 Subject: [PATCH] Correct emugl includes and move to std::{mutex,shared_ptr} where possible --- src/anbox/graphics/emugl/ColorBuffer.cpp | 21 +++-- src/anbox/graphics/emugl/ColorBuffer.h | 3 +- src/anbox/graphics/emugl/ReadBuffer.cpp | 7 +- src/anbox/graphics/emugl/ReadBuffer.h | 3 +- src/anbox/graphics/emugl/RenderApi.cpp | 13 ++-- src/anbox/graphics/emugl/RenderApi.h | 2 +- src/anbox/graphics/emugl/RenderContext.cpp | 3 +- src/anbox/graphics/emugl/RenderContext.h | 8 +- src/anbox/graphics/emugl/RenderControl.cpp | 20 ++--- src/anbox/graphics/emugl/RenderControl.h | 2 + src/anbox/graphics/emugl/RenderThread.cpp | 36 ++++----- src/anbox/graphics/emugl/RenderThread.h | 11 +-- src/anbox/graphics/emugl/RenderThreadInfo.cpp | 6 +- src/anbox/graphics/emugl/RenderThreadInfo.h | 12 ++- src/anbox/graphics/emugl/Renderable.cpp | 2 +- src/anbox/graphics/emugl/Renderer.cpp | 78 +++++++++++-------- src/anbox/graphics/emugl/Renderer.h | 17 ++-- src/anbox/graphics/emugl/RendererConfig.cpp | 7 +- src/anbox/graphics/emugl/TextureDraw.cpp | 8 +- src/anbox/graphics/emugl/TextureResize.cpp | 7 +- src/anbox/graphics/emugl/TextureResize.h | 1 + src/anbox/graphics/emugl/TimeUtils.cpp | 3 +- src/anbox/graphics/emugl/TimeUtils.h | 1 + src/anbox/graphics/emugl/WindowSurface.cpp | 13 ++-- src/anbox/graphics/emugl/WindowSurface.h | 8 +- .../graphics/opengles_message_processor.cpp | 4 +- .../graphics/opengles_message_processor.h | 11 ++- 27 files changed, 160 insertions(+), 147 deletions(-) diff --git a/src/anbox/graphics/emugl/ColorBuffer.cpp b/src/anbox/graphics/emugl/ColorBuffer.cpp index c1efb6e..9cace59 100644 --- a/src/anbox/graphics/emugl/ColorBuffer.cpp +++ b/src/anbox/graphics/emugl/ColorBuffer.cpp @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "ColorBuffer.h" - -#include "DispatchTables.h" -#include "RenderThreadInfo.h" -#include "TextureDraw.h" -#include "TextureResize.h" - -#include "OpenGLESDispatch/EGLDispatch.h" +#include "anbox/graphics/emugl/ColorBuffer.h" +#include "anbox/graphics/emugl/DispatchTables.h" +#include "anbox/graphics/emugl/RenderThreadInfo.h" +#include "anbox/graphics/emugl/TextureDraw.h" +#include "anbox/graphics/emugl/TextureResize.h" #include "anbox/logger.h" +#include "external/android-emugl/host/include/OpenGLESDispatch/EGLDispatch.h" + #include namespace { @@ -251,7 +250,7 @@ void ColorBuffer::subUpdate(int x, int y, int width, int height, bool ColorBuffer::blitFromCurrentReadBuffer() { RenderThreadInfo* tInfo = RenderThreadInfo::get(); - if (!tInfo->currContext.Ptr()) { + if (!tInfo->currContext) { // no Current context return false; } @@ -312,7 +311,7 @@ bool ColorBuffer::bindToTexture() { return false; } RenderThreadInfo* tInfo = RenderThreadInfo::get(); - if (!tInfo->currContext.Ptr()) { + if (!tInfo->currContext) { return false; } if (tInfo->currContext->isGL2()) { @@ -328,7 +327,7 @@ bool ColorBuffer::bindToRenderbuffer() { return false; } RenderThreadInfo* tInfo = RenderThreadInfo::get(); - if (!tInfo->currContext.Ptr()) { + if (!tInfo->currContext) { return false; } if (tInfo->currContext->isGL2()) { diff --git a/src/anbox/graphics/emugl/ColorBuffer.h b/src/anbox/graphics/emugl/ColorBuffer.h index 793a671..19bf44c 100644 --- a/src/anbox/graphics/emugl/ColorBuffer.h +++ b/src/anbox/graphics/emugl/ColorBuffer.h @@ -19,7 +19,6 @@ #include #include #include -#include "emugl/common/smart_ptr.h" #include @@ -135,6 +134,6 @@ class ColorBuffer { TextureResize* m_resizer; }; -typedef emugl::SmartPtr ColorBufferPtr; +typedef std::shared_ptr ColorBufferPtr; #endif diff --git a/src/anbox/graphics/emugl/ReadBuffer.cpp b/src/anbox/graphics/emugl/ReadBuffer.cpp index 3ff151d..d7bff7b 100644 --- a/src/anbox/graphics/emugl/ReadBuffer.cpp +++ b/src/anbox/graphics/emugl/ReadBuffer.cpp @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "ReadBuffer.h" + +#include "anbox/graphics/emugl/ReadBuffer.h" +#include "anbox/logger.h" + #include #include #include -#include "anbox/logger.h" - ReadBuffer::ReadBuffer(size_t bufsize) { m_size = bufsize; m_buf = static_cast(malloc(m_size * sizeof(unsigned char))); diff --git a/src/anbox/graphics/emugl/ReadBuffer.h b/src/anbox/graphics/emugl/ReadBuffer.h index 86a486f..68c7545 100644 --- a/src/anbox/graphics/emugl/ReadBuffer.h +++ b/src/anbox/graphics/emugl/ReadBuffer.h @@ -16,7 +16,7 @@ #ifndef _READ_BUFFER_H #define _READ_BUFFER_H -#include "IOStream.h" +#include "external/android-emugl/host/include/libOpenglRender/IOStream.h" class ReadBuffer { public: @@ -34,4 +34,5 @@ class ReadBuffer { size_t m_size; size_t m_validData; }; + #endif diff --git a/src/anbox/graphics/emugl/RenderApi.cpp b/src/anbox/graphics/emugl/RenderApi.cpp index dc07604..69fce23 100644 --- a/src/anbox/graphics/emugl/RenderApi.cpp +++ b/src/anbox/graphics/emugl/RenderApi.cpp @@ -14,15 +14,14 @@ * limitations under the License. */ -#include "RenderApi.h" +#include "anbox/graphics/emugl/RenderApi.h" +#include "anbox/graphics/emugl/DispatchTables.h" -#include "DispatchTables.h" +#include "external/android-emugl/host/include/OpenGLESDispatch/EGLDispatch.h" +#include "external/android-emugl/host/include/OpenGLESDispatch/GLESv1Dispatch.h" +#include "external/android-emugl/host/include/OpenGLESDispatch/GLESv2Dispatch.h" -#include "OpenGLESDispatch/EGLDispatch.h" -#include "OpenGLESDispatch/GLESv1Dispatch.h" -#include "OpenGLESDispatch/GLESv2Dispatch.h" - -#include "emugl/common/crash_reporter.h" +#include "external/android-emugl/shared/emugl/common/crash_reporter.h" #include diff --git a/src/anbox/graphics/emugl/RenderApi.h b/src/anbox/graphics/emugl/RenderApi.h index 65cab84..150fdd6 100644 --- a/src/anbox/graphics/emugl/RenderApi.h +++ b/src/anbox/graphics/emugl/RenderApi.h @@ -21,7 +21,7 @@ #include -#include "emugl/common/logging.h" +#include "external/android-emugl/shared/emugl/common/logging.h" typedef struct { logger_t coarse; diff --git a/src/anbox/graphics/emugl/RenderContext.cpp b/src/anbox/graphics/emugl/RenderContext.cpp index ef47143..2909a49 100644 --- a/src/anbox/graphics/emugl/RenderContext.cpp +++ b/src/anbox/graphics/emugl/RenderContext.cpp @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "RenderContext.h" + +#include "anbox/graphics/emugl/RenderContext.h" #include "OpenGLESDispatch/EGLDispatch.h" diff --git a/src/anbox/graphics/emugl/RenderContext.h b/src/anbox/graphics/emugl/RenderContext.h index fd2dccf..6e18a9b 100644 --- a/src/anbox/graphics/emugl/RenderContext.h +++ b/src/anbox/graphics/emugl/RenderContext.h @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef _LIBRENDER_RENDER_CONTEXT_H #define _LIBRENDER_RENDER_CONTEXT_H -#include "GLDecoderContextData.h" -#include "emugl/common/smart_ptr.h" +#include "external/android-emugl/shared/OpenglCodecCommon/GLDecoderContextData.h" #include +#include + // A class used to model a guest EGLContext. This simply wraps a host // EGLContext, associated with an GLDecoderContextData instance that is // used to store copies of guest-side arrays. @@ -60,6 +62,6 @@ class RenderContext { GLDecoderContextData mContextData; }; -typedef emugl::SmartPtr RenderContextPtr; +typedef std::shared_ptr RenderContextPtr; #endif // _LIBRENDER_RENDER_CONTEXT_H diff --git a/src/anbox/graphics/emugl/RenderControl.cpp b/src/anbox/graphics/emugl/RenderControl.cpp index b479be0..094b46c 100644 --- a/src/anbox/graphics/emugl/RenderControl.cpp +++ b/src/anbox/graphics/emugl/RenderControl.cpp @@ -13,20 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "RenderControl.h" - -#include "ChecksumCalculatorThreadInfo.h" -#include "DispatchTables.h" -#include "DisplayManager.h" -#include "RenderThreadInfo.h" -#include "Renderer.h" -#include "RendererConfig.h" - -#include "OpenGLESDispatch/EGLDispatch.h" +#include "anbox/graphics/emugl/RenderControl.h" +#include "anbox/graphics/emugl/DispatchTables.h" +#include "anbox/graphics/emugl/DisplayManager.h" +#include "anbox/graphics/emugl/RenderThreadInfo.h" +#include "anbox/graphics/emugl/Renderer.h" +#include "anbox/graphics/emugl/RendererConfig.h" #include "anbox/graphics/layer_composer.h" #include "anbox/logger.h" +#include "external/android-emugl/shared/OpenglCodecCommon/ChecksumCalculatorThreadInfo.h" +#include "external/android-emugl/host/include/OpenGLESDispatch/EGLDispatch.h" + + #include #include diff --git a/src/anbox/graphics/emugl/RenderControl.h b/src/anbox/graphics/emugl/RenderControl.h index 82f1635..5495560 100644 --- a/src/anbox/graphics/emugl/RenderControl.h +++ b/src/anbox/graphics/emugl/RenderControl.h @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef _RENDER_CONTROL_H #define _RENDER_CONTROL_H +// Generated with emugl at build time #include "renderControl_dec.h" #include diff --git a/src/anbox/graphics/emugl/RenderThread.cpp b/src/anbox/graphics/emugl/RenderThread.cpp index 9dbc569..7e6dff7 100644 --- a/src/anbox/graphics/emugl/RenderThread.cpp +++ b/src/anbox/graphics/emugl/RenderThread.cpp @@ -13,32 +13,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "RenderThread.h" - -#include "ReadBuffer.h" -#include "RenderControl.h" -#include "RenderThreadInfo.h" -#include "Renderer.h" -#include "TimeUtils.h" - -#include "../../../shared/OpenglCodecCommon/ChecksumCalculatorThreadInfo.h" -#include "OpenGLESDispatch/EGLDispatch.h" -#include "OpenGLESDispatch/GLESv1Dispatch.h" -#include "OpenGLESDispatch/GLESv2Dispatch.h" +#include "anbox/graphics/emugl/RenderThread.h" +#include "anbox/graphics/emugl/ReadBuffer.h" +#include "anbox/graphics/emugl/RenderControl.h" +#include "anbox/graphics/emugl/RenderThreadInfo.h" +#include "anbox/graphics/emugl/Renderer.h" +#include "anbox/graphics/emugl/TimeUtils.h" #include "anbox/logger.h" +#include "external/android-emugl/shared/OpenglCodecCommon/ChecksumCalculatorThreadInfo.h" +#include "external/android-emugl/host/include/OpenGLESDispatch/EGLDispatch.h" +#include "external/android-emugl/host/include/OpenGLESDispatch/GLESv1Dispatch.h" +#include "external/android-emugl/host/include/OpenGLESDispatch/GLESv2Dispatch.h" + #define STREAM_BUFFER_SIZE 4 * 1024 * 1024 -RenderThread::RenderThread(const std::shared_ptr &renderer, IOStream *stream, emugl::Mutex *lock) - : emugl::Thread(), renderer_(renderer), m_lock(lock), m_stream(stream) {} +RenderThread::RenderThread(const std::shared_ptr &renderer, IOStream *stream, std::mutex &m) + : emugl::Thread(), renderer_(renderer), m_lock(m), m_stream(stream) {} RenderThread::~RenderThread() { forceStop(); } -RenderThread *RenderThread::create(const std::shared_ptr &renderer, IOStream *stream, emugl::Mutex *lock) { - return new RenderThread(renderer, stream, lock); +RenderThread *RenderThread::create(const std::shared_ptr &renderer, IOStream *stream, std::mutex &m) { + return new RenderThread(renderer, stream, m); } void RenderThread::forceStop() { m_stream->forceStop(); } @@ -62,7 +61,8 @@ intptr_t RenderThread::main() { do { progress = false; - m_lock->lock(); + std::unique_lock l(m_lock); + size_t last = threadInfo.m_glDec.decode(readBuf.buf(), readBuf.validData(), m_stream); if (last > 0) { @@ -83,8 +83,6 @@ intptr_t RenderThread::main() { progress = true; } - m_lock->unlock(); - } while (progress); } diff --git a/src/anbox/graphics/emugl/RenderThread.h b/src/anbox/graphics/emugl/RenderThread.h index 5e6ae11..74cde6d 100644 --- a/src/anbox/graphics/emugl/RenderThread.h +++ b/src/anbox/graphics/emugl/RenderThread.h @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef _LIB_OPENGL_RENDER_RENDER_THREAD_H #define _LIB_OPENGL_RENDER_RENDER_THREAD_H -#include "IOStream.h" +#include "external/android-emugl/host/include/libOpenglRender/IOStream.h" -#include "emugl/common/mutex.h" #include "emugl/common/thread.h" #include +#include class Renderer; @@ -36,7 +37,7 @@ class RenderThread : public emugl::Thread { // decoding operations between all threads. // TODO(digit): Why is this needed here? Shouldn't this be handled // by the decoders themselves or at a lower-level? - static RenderThread* create(const std::shared_ptr& renderer, IOStream* stream, emugl::Mutex* mutex); + static RenderThread* create(const std::shared_ptr& renderer, IOStream* stream, std::mutex &m); // Destructor. virtual ~RenderThread(); @@ -51,12 +52,12 @@ class RenderThread : public emugl::Thread { private: RenderThread(); // No default constructor - RenderThread(const std::shared_ptr& renderer, IOStream* stream, emugl::Mutex* mutex); + RenderThread(const std::shared_ptr& renderer, IOStream* stream, std::mutex &m); virtual intptr_t main(); std::shared_ptr renderer_; - emugl::Mutex* m_lock; + std::mutex &m_lock; IOStream* m_stream; }; diff --git a/src/anbox/graphics/emugl/RenderThreadInfo.cpp b/src/anbox/graphics/emugl/RenderThreadInfo.cpp index 500a0b4..bc87705 100644 --- a/src/anbox/graphics/emugl/RenderThreadInfo.cpp +++ b/src/anbox/graphics/emugl/RenderThreadInfo.cpp @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "RenderThreadInfo.h" +#include "anbox/graphics/emugl/RenderThreadInfo.h" -#include "emugl/common/lazy_instance.h" -#include "emugl/common/thread_store.h" +#include "external/android-emugl/shared/emugl/common/lazy_instance.h" +#include "external/android-emugl/shared/emugl/common/thread_store.h" namespace { class ThreadInfoStore : public ::emugl::ThreadStore { diff --git a/src/anbox/graphics/emugl/RenderThreadInfo.h b/src/anbox/graphics/emugl/RenderThreadInfo.h index f246ae5..9440d61 100644 --- a/src/anbox/graphics/emugl/RenderThreadInfo.h +++ b/src/anbox/graphics/emugl/RenderThreadInfo.h @@ -13,13 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef _LIB_OPENGL_RENDER_THREAD_INFO_H #define _LIB_OPENGL_RENDER_THREAD_INFO_H -#include "GLESv1Decoder.h" -#include "GLESv2Decoder.h" -#include "RenderContext.h" -#include "WindowSurface.h" +#include "anbox/graphics/emugl/RenderContext.h" +#include "anbox/graphics/emugl/WindowSurface.h" + +#include "external/android-emugl/host/libs/GLESv1_dec/GLESv1Decoder.h" +#include "external/android-emugl/host/libs/GLESv2_dec/GLESv2Decoder.h" + +// Generated with emugl at build time #include "renderControl_dec.h" #include diff --git a/src/anbox/graphics/emugl/Renderable.cpp b/src/anbox/graphics/emugl/Renderable.cpp index e75d1a2..06e4273 100644 --- a/src/anbox/graphics/emugl/Renderable.cpp +++ b/src/anbox/graphics/emugl/Renderable.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "Renderable.h" +#include "anbox/graphics/emugl/Renderable.h" Renderable::Renderable(const std::string &name, const std::uint32_t &buffer, const anbox::graphics::Rect &screen_position, diff --git a/src/anbox/graphics/emugl/Renderer.cpp b/src/anbox/graphics/emugl/Renderer.cpp index f4e5a76..776de49 100644 --- a/src/anbox/graphics/emugl/Renderer.cpp +++ b/src/anbox/graphics/emugl/Renderer.cpp @@ -14,19 +14,18 @@ * limitations under the License. */ -#include "Renderer.h" - -#include "DispatchTables.h" -#include "RenderThreadInfo.h" -#include "TimeUtils.h" -#include "gles2_dec.h" - -#include "OpenGLESDispatch/EGLDispatch.h" - +#include "anbox/graphics/emugl/Renderer.h" +#include "anbox/graphics/emugl/DispatchTables.h" +#include "anbox/graphics/emugl/RenderThreadInfo.h" +#include "anbox/graphics/emugl/TimeUtils.h" #include "anbox/graphics/gl_extensions.h" - #include "anbox/logger.h" +#include "external/android-emugl/host/include/OpenGLESDispatch/EGLDispatch.h" + +// Generated with emugl at build time +#include "gles2_dec.h" + #include #include @@ -361,13 +360,14 @@ HandleType Renderer::genHandle() { HandleType Renderer::createColorBuffer(int p_width, int p_height, GLenum p_internalFormat) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); + HandleType ret = 0; ColorBufferPtr cb(ColorBuffer::create( getDisplay(), p_width, p_height, p_internalFormat, getCaps().has_eglimage_texture_2d, m_colorBufferHelper)); - if (cb.Ptr() != NULL) { + if (cb) { ret = genHandle(); m_colorbuffers[ret].cb = cb; m_colorbuffers[ret].refcount = 1; @@ -377,7 +377,8 @@ HandleType Renderer::createColorBuffer(int p_width, int p_height, HandleType Renderer::createRenderContext(int p_config, HandleType p_share, bool p_isGL2) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); + HandleType ret = 0; const RendererConfig *config = getConfigs()->get(p_config); @@ -394,11 +395,11 @@ HandleType Renderer::createRenderContext(int p_config, HandleType p_share, share = (*s).second; } EGLContext sharedContext = - share.Ptr() ? share->getEGLContext() : EGL_NO_CONTEXT; + share ? share->getEGLContext() : EGL_NO_CONTEXT; RenderContextPtr rctx(RenderContext::create( m_eglDisplay, config->getEglConfig(), sharedContext, p_isGL2)); - if (rctx.Ptr() != NULL) { + if (rctx) { ret = genHandle(); m_contexts[ret] = rctx; RenderThreadInfo *tinfo = RenderThreadInfo::get(); @@ -409,7 +410,7 @@ HandleType Renderer::createRenderContext(int p_config, HandleType p_share, HandleType Renderer::createWindowSurface(int p_config, int p_width, int p_height) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); HandleType ret = 0; @@ -420,7 +421,7 @@ HandleType Renderer::createWindowSurface(int p_config, int p_width, WindowSurfacePtr win(WindowSurface::create( getDisplay(), config->getEglConfig(), p_width, p_height)); - if (win.Ptr() != NULL) { + if (win) { ret = genHandle(); m_windows[ret] = std::pair(win, 0); RenderThreadInfo *tinfo = RenderThreadInfo::get(); @@ -431,7 +432,8 @@ HandleType Renderer::createWindowSurface(int p_config, int p_width, } void Renderer::drainRenderContext() { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); + RenderThreadInfo *tinfo = RenderThreadInfo::get(); if (tinfo->m_contextSet.empty()) return; for (std::set::iterator it = tinfo->m_contextSet.begin(); @@ -443,7 +445,8 @@ void Renderer::drainRenderContext() { } void Renderer::drainWindowSurface() { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); + RenderThreadInfo *tinfo = RenderThreadInfo::get(); if (tinfo->m_windowSet.empty()) return; for (std::set::iterator it = tinfo->m_windowSet.begin(); @@ -466,7 +469,8 @@ void Renderer::drainWindowSurface() { } void Renderer::DestroyRenderContext(HandleType p_context) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); + m_contexts.erase(p_context); RenderThreadInfo *tinfo = RenderThreadInfo::get(); if (tinfo->m_contextSet.empty()) return; @@ -474,7 +478,8 @@ void Renderer::DestroyRenderContext(HandleType p_context) { } void Renderer::DestroyWindowSurface(HandleType p_surface) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); + if (m_windows.find(p_surface) != m_windows.end()) { m_windows.erase(p_surface); RenderThreadInfo *tinfo = RenderThreadInfo::get(); @@ -484,7 +489,8 @@ void Renderer::DestroyWindowSurface(HandleType p_surface) { } int Renderer::openColorBuffer(HandleType p_colorbuffer) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); + ColorBufferMap::iterator c(m_colorbuffers.find(p_colorbuffer)); if (c == m_colorbuffers.end()) { // bad colorbuffer handle @@ -496,7 +502,8 @@ int Renderer::openColorBuffer(HandleType p_colorbuffer) { } void Renderer::closeColorBuffer(HandleType p_colorbuffer) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); + ColorBufferMap::iterator c(m_colorbuffers.find(p_colorbuffer)); if (c == m_colorbuffers.end()) { // This is harmless: it is normal for guest system to issue @@ -511,7 +518,7 @@ void Renderer::closeColorBuffer(HandleType p_colorbuffer) { } bool Renderer::flushWindowSurfaceColorBuffer(HandleType p_surface) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); WindowSurfaceMap::iterator w(m_windows.find(p_surface)); if (w == m_windows.end()) { @@ -521,7 +528,10 @@ bool Renderer::flushWindowSurfaceColorBuffer(HandleType p_surface) { return false; } - WindowSurface *surface = (*w).second.first.Ptr(); + auto surface = (*w).second.first; + if (!surface) + return false; + surface->flushColorBuffer(); return true; @@ -529,7 +539,7 @@ bool Renderer::flushWindowSurfaceColorBuffer(HandleType p_surface) { bool Renderer::setWindowSurfaceColorBuffer(HandleType p_surface, HandleType p_colorbuffer) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); WindowSurfaceMap::iterator w(m_windows.find(p_surface)); if (w == m_windows.end()) { @@ -553,7 +563,7 @@ bool Renderer::setWindowSurfaceColorBuffer(HandleType p_surface, void Renderer::readColorBuffer(HandleType p_colorbuffer, int x, int y, int width, int height, GLenum format, GLenum type, void *pixels) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); ColorBufferMap::iterator c(m_colorbuffers.find(p_colorbuffer)); if (c == m_colorbuffers.end()) { @@ -567,7 +577,7 @@ void Renderer::readColorBuffer(HandleType p_colorbuffer, int x, int y, bool Renderer::updateColorBuffer(HandleType p_colorbuffer, int x, int y, int width, int height, GLenum format, GLenum type, void *pixels) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); ColorBufferMap::iterator c(m_colorbuffers.find(p_colorbuffer)); if (c == m_colorbuffers.end()) { @@ -581,7 +591,7 @@ bool Renderer::updateColorBuffer(HandleType p_colorbuffer, int x, int y, } bool Renderer::bindColorBufferToTexture(HandleType p_colorbuffer) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); ColorBufferMap::iterator c(m_colorbuffers.find(p_colorbuffer)); if (c == m_colorbuffers.end()) { @@ -593,7 +603,7 @@ bool Renderer::bindColorBufferToTexture(HandleType p_colorbuffer) { } bool Renderer::bindColorBufferToRenderbuffer(HandleType p_colorbuffer) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); ColorBufferMap::iterator c(m_colorbuffers.find(p_colorbuffer)); if (c == m_colorbuffers.end()) { @@ -606,7 +616,7 @@ bool Renderer::bindColorBufferToRenderbuffer(HandleType p_colorbuffer) { bool Renderer::bindContext(HandleType p_context, HandleType p_drawSurface, HandleType p_readSurface) { - emugl::Mutex::AutoLock mutex(m_lock); + std::unique_lock l(m_lock); WindowSurfacePtr draw(NULL), read(NULL); RenderContextPtr ctx(NULL); @@ -654,7 +664,7 @@ bool Renderer::bindContext(HandleType p_context, HandleType p_drawSurface, // RenderThreadInfo *tinfo = RenderThreadInfo::get(); WindowSurfacePtr bindDraw, bindRead; - if (draw.Ptr() == NULL && read.Ptr() == NULL) { + if (!draw && !read) { // Unbind the current read and draw surfaces from the context bindDraw = tinfo->currDrawSurf; bindRead = tinfo->currReadSurf; @@ -663,8 +673,8 @@ bool Renderer::bindContext(HandleType p_context, HandleType p_drawSurface, bindRead = read; } - if (bindDraw.Ptr() != NULL && bindRead.Ptr() != NULL) { - if (bindDraw.Ptr() != bindRead.Ptr()) { + if (bindDraw && bindRead) { + if (bindDraw != bindRead) { bindDraw->bind(ctx, WindowSurface::BIND_DRAW); bindRead->bind(ctx, WindowSurface::BIND_READ); } else { diff --git a/src/anbox/graphics/emugl/Renderer.h b/src/anbox/graphics/emugl/Renderer.h index 5258639..cfcc0b2 100644 --- a/src/anbox/graphics/emugl/Renderer.h +++ b/src/anbox/graphics/emugl/Renderer.h @@ -16,14 +16,12 @@ #ifndef _LIBRENDER_FRAMEBUFFER_H #define _LIBRENDER_FRAMEBUFFER_H -#include "ColorBuffer.h" -#include "RenderContext.h" -#include "RendererConfig.h" -#include "TextureDraw.h" -#include "WindowSurface.h" -#include "emugl/common/mutex.h" - -#include "Renderable.h" +#include "anbox/graphics/emugl/ColorBuffer.h" +#include "anbox/graphics/emugl/RenderContext.h" +#include "anbox/graphics/emugl/RendererConfig.h" +#include "anbox/graphics/emugl/TextureDraw.h" +#include "anbox/graphics/emugl/WindowSurface.h" +#include "anbox/graphics/emugl/Renderable.h" #include "anbox/graphics/primitives.h" #include "anbox/graphics/program_family.h" @@ -32,6 +30,7 @@ #include #include +#include #include @@ -257,7 +256,7 @@ class Renderer : public anbox::graphics::Renderer { private: static Renderer* s_renderer; static HandleType s_nextHandle; - emugl::Mutex m_lock; + std::mutex m_lock; RendererConfigList* m_configs; RendererCaps m_caps; EGLDisplay m_eglDisplay; diff --git a/src/anbox/graphics/emugl/RendererConfig.cpp b/src/anbox/graphics/emugl/RendererConfig.cpp index 83b044f..02b6b78 100644 --- a/src/anbox/graphics/emugl/RendererConfig.cpp +++ b/src/anbox/graphics/emugl/RendererConfig.cpp @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "RendererConfig.h" +#include "anbox/graphics/emugl/RendererConfig.h" +#include "anbox/logger.h" -#include "OpenGLESDispatch/EGLDispatch.h" +#include "external/android-emugl/host/include/OpenGLESDispatch/EGLDispatch.h" #include #include -#include "anbox/logger.h" - namespace { const GLuint kConfigAttributes[] = { EGL_DEPTH_SIZE, // must be first - see getDepthSize() diff --git a/src/anbox/graphics/emugl/TextureDraw.cpp b/src/anbox/graphics/emugl/TextureDraw.cpp index bb421bd..2c052f9 100644 --- a/src/anbox/graphics/emugl/TextureDraw.cpp +++ b/src/anbox/graphics/emugl/TextureDraw.cpp @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "TextureDraw.h" - -#include "DispatchTables.h" +#include "anbox/graphics/emugl/TextureDraw.h" +#include "anbox/graphics/emugl/DispatchTables.h" +#include "anbox/logger.h" #include #include @@ -22,8 +22,6 @@ #include -#include "anbox/logger.h" - // M_PI isn't defined in C++ (when strict ISO compliance is enabled) #ifndef M_PI #define M_PI 3.14159265358979323846264338327 diff --git a/src/anbox/graphics/emugl/TextureResize.cpp b/src/anbox/graphics/emugl/TextureResize.cpp index 131be30..49407b1 100644 --- a/src/anbox/graphics/emugl/TextureResize.cpp +++ b/src/anbox/graphics/emugl/TextureResize.cpp @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "TextureResize.h" -#include "DispatchTables.h" +#include "anbox/graphics/emugl/TextureResize.h" +#include "anbox/graphics/emugl/DispatchTables.h" +#include "anbox/logger.h" #include #include #include #include -#include "anbox/logger.h" - #define MAX_FACTOR_POWER 4 static const char kCommonShaderSource[] = diff --git a/src/anbox/graphics/emugl/TextureResize.h b/src/anbox/graphics/emugl/TextureResize.h index 8024761..fece99d 100644 --- a/src/anbox/graphics/emugl/TextureResize.h +++ b/src/anbox/graphics/emugl/TextureResize.h @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef _LIBRENDER_TEXTURERESIZE_H #define _LIBRENDER_TEXTURERESIZE_H diff --git a/src/anbox/graphics/emugl/TimeUtils.cpp b/src/anbox/graphics/emugl/TimeUtils.cpp index 854bb79..8e80cd4 100644 --- a/src/anbox/graphics/emugl/TimeUtils.cpp +++ b/src/anbox/graphics/emugl/TimeUtils.cpp @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "TimeUtils.h" + +#include "anbox/graphics/emugl/TimeUtils.h" #include #include diff --git a/src/anbox/graphics/emugl/TimeUtils.h b/src/anbox/graphics/emugl/TimeUtils.h index bc4fd1c..116e37a 100644 --- a/src/anbox/graphics/emugl/TimeUtils.h +++ b/src/anbox/graphics/emugl/TimeUtils.h @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef _TIME_UTILS_H #define _TIME_UTILS_H diff --git a/src/anbox/graphics/emugl/WindowSurface.cpp b/src/anbox/graphics/emugl/WindowSurface.cpp index 669ce6d..fd60aba 100644 --- a/src/anbox/graphics/emugl/WindowSurface.cpp +++ b/src/anbox/graphics/emugl/WindowSurface.cpp @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "WindowSurface.h" -#include "RendererConfig.h" -#include "OpenGLESDispatch/EGLDispatch.h" +#include "anbox/graphics/emugl/WindowSurface.h" +#include "anbox/graphics/emugl/RendererConfig.h" +#include "anbox/logger.h" + +#include "external/android-emugl/host/include/OpenGLESDispatch/EGLDispatch.h" #include #include #include -#include "anbox/logger.h" WindowSurface::WindowSurface(EGLDisplay display, EGLConfig config) : mSurface(NULL), @@ -84,7 +85,7 @@ void WindowSurface::bind(RenderContextPtr p_ctx, BindType p_bindType) { } bool WindowSurface::flushColorBuffer() { - if (!mAttachedColorBuffer.Ptr()) { + if (!mAttachedColorBuffer) { return true; } if (!mWidth || !mHeight) { @@ -98,7 +99,7 @@ bool WindowSurface::flushColorBuffer() { return false; } - if (!mDrawContext.Ptr()) { + if (!mDrawContext) { ERROR("Draw context is NULL"); return false; } diff --git a/src/anbox/graphics/emugl/WindowSurface.h b/src/anbox/graphics/emugl/WindowSurface.h index 62c497d..4b35ddb 100644 --- a/src/anbox/graphics/emugl/WindowSurface.h +++ b/src/anbox/graphics/emugl/WindowSurface.h @@ -16,10 +16,8 @@ #ifndef _LIBRENDER_WINDOW_SURFACE_H #define _LIBRENDER_WINDOW_SURFACE_H -#include "ColorBuffer.h" -#include "RenderContext.h" - -#include "emugl/common/smart_ptr.h" +#include "anbox/graphics/emugl/ColorBuffer.h" +#include "anbox/graphics/emugl/RenderContext.h" #include #include @@ -94,6 +92,6 @@ class WindowSurface { EGLDisplay mDisplay; }; -typedef emugl::SmartPtr WindowSurfacePtr; +typedef std::shared_ptr WindowSurfacePtr; #endif // _LIBRENDER_WINDOW_SURFACE_H diff --git a/src/anbox/graphics/opengles_message_processor.cpp b/src/anbox/graphics/opengles_message_processor.cpp index bd06793..e54c205 100644 --- a/src/anbox/graphics/opengles_message_processor.cpp +++ b/src/anbox/graphics/opengles_message_processor.cpp @@ -29,7 +29,7 @@ namespace anbox { namespace graphics { -emugl::Mutex OpenGlesMessageProcessor::global_lock{}; +std::mutex OpenGlesMessageProcessor::global_lock{}; OpenGlesMessageProcessor::OpenGlesMessageProcessor( const std::shared_ptr &renderer, @@ -43,7 +43,7 @@ OpenGlesMessageProcessor::OpenGlesMessageProcessor( boost::asio::buffer(&client_flags, sizeof(unsigned int))); if (err) ERROR("%s", err.message()); - render_thread_.reset(RenderThread::create(renderer, stream_.get(), &global_lock)); + render_thread_.reset(RenderThread::create(renderer, stream_.get(), std::ref(global_lock))); if (!render_thread_->start()) BOOST_THROW_EXCEPTION( std::runtime_error("Failed to start renderer thread")); diff --git a/src/anbox/graphics/opengles_message_processor.h b/src/anbox/graphics/opengles_message_processor.h index 45f4c01..8f3bd7a 100644 --- a/src/anbox/graphics/opengles_message_processor.h +++ b/src/anbox/graphics/opengles_message_processor.h @@ -18,16 +18,15 @@ #ifndef ANBOX_GRAPHICS_OPENGLES_MESSAGE_PROCESSOR_H_ #define ANBOX_GRAPHICS_OPENGLES_MESSAGE_PROCESSOR_H_ -#include - -#include - #include "anbox/network/message_processor.h" #include "anbox/network/socket_connection.h" #include "anbox/network/socket_messenger.h" #include "anbox/runtime.h" -#include "external/android-emugl/shared/emugl/common/mutex.h" +#include + +#include +#include class IOStream; class RenderThread; @@ -45,7 +44,7 @@ class OpenGlesMessageProcessor : public network::MessageProcessor { bool process_data(const std::vector &data) override; private: - static emugl::Mutex global_lock; + static std::mutex global_lock; std::shared_ptr messenger_; std::shared_ptr stream_;