From fdcba322fe6fb12ee69425d1670b036f0cc9401a Mon Sep 17 00:00:00 2001 From: Stas Gurtovoy Date: Mon, 6 Jun 2011 13:42:06 +0300 Subject: [PATCH 1/5] opengles emulator: Fixed upside-down gl image This fix performs a flip software copy to match our coords with those expected by the flinger. We may think of a better implementation in the future. Change-Id: Ic09a5d0e22f7e209b33c07c993a3d56e328dd3ed --- .../host/libs/libOpenglRender/ColorBuffer.cpp | 8 ++++---- .../libs/libOpenglRender/WindowSurface.cpp | 19 +++++++++++++++++++ .../host/libs/libOpenglRender/WindowSurface.h | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.cpp b/tools/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.cpp index 0a794ed97..099eeea74 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.cpp +++ b/tools/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.cpp @@ -231,10 +231,10 @@ void ColorBuffer::drawTexQuad() +1.0f, -1.0f, 0.0f, +1.0f, +1.0f, 0.0f }; - GLfloat tcoords[] = { 0.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 0.0f, - 1.0f, 1.0f }; + GLfloat tcoords[] = { 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 1.0f, + 1.0f, 0.0f }; s_gl.glClientActiveTexture(GL_TEXTURE0); s_gl.glEnableClientState(GL_TEXTURE_COORD_ARRAY); diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.cpp b/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.cpp index 21b92e286..0b12604be 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.cpp +++ b/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.cpp @@ -227,8 +227,27 @@ void WindowSurface::copyToColorBuffer() GL_RGBA, GL_UNSIGNED_BYTE, data); } +#define FLIP_BUFFER 1 +#if FLIP_BUFFER + //We need to flip the pixels + int bpp = 4; + void *tmpBuf = m_xUpdateBuf.alloc(m_width * m_height * bpp); + + int dst_line_len = m_width * bpp; + int src_line_len = m_width * bpp; + char *src = (char *)data; + char *dst = (char*)tmpBuf + (m_height-1)*dst_line_len; + for (uint32_t y=0; yupdate(GL_RGBA, GL_UNSIGNED_BYTE, tmpBuf); +#else // update the attached color buffer with the readback pixels m_attachedColorBuffer->update(GL_RGBA, GL_UNSIGNED_BYTE, data); +#endif // restore current context/surface s_egl.eglMakeCurrent(fb->getDisplay(), prevDrawSurf, diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.h b/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.h index 2a496df53..73ef86b92 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.h +++ b/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.h @@ -58,6 +58,7 @@ private: bool m_useEGLImage; bool m_useBindToTexture; FixedBuffer m_xferBuffer; + FixedBuffer m_xUpdateBuf; }; typedef SmartPtr WindowSurfacePtr; From 128f401e4f6eee67690cb7ec77616f7503af5971 Mon Sep 17 00:00:00 2001 From: Stas Gurtovoy Date: Thu, 9 Jun 2011 07:28:13 +0300 Subject: [PATCH 2/5] emulator opengles: Fixed a bug in eglChooseConfig implementation. The config_size argument in rcChooseConfig should match the number of requested configs and not the size in bytes to store it. Moved the configs array size computation into rendeerControl.attrib. Change-Id: I9e797024522965a656764c20252b25ff5ae657f5 --- tools/emulator/opengl/system/egl/egl.cpp | 2 +- .../opengl/system/renderControl_enc/renderControl.attrib | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/emulator/opengl/system/egl/egl.cpp b/tools/emulator/opengl/system/egl/egl.cpp index d8ef8aa03..698aa842c 100644 --- a/tools/emulator/opengl/system/egl/egl.cpp +++ b/tools/emulator/opengl/system/egl/egl.cpp @@ -634,7 +634,7 @@ EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig } DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE); - *num_config = rcEnc->rcChooseConfig(rcEnc, (EGLint*)attrib_list, attribs_size * sizeof(EGLint), (uint32_t*)configs, config_size*sizeof(EGLint)); + *num_config = rcEnc->rcChooseConfig(rcEnc, (EGLint*)attrib_list, attribs_size * sizeof(EGLint), (uint32_t*)configs, config_size); return EGL_TRUE; } diff --git a/tools/emulator/opengl/system/renderControl_enc/renderControl.attrib b/tools/emulator/opengl/system/renderControl_enc/renderControl.attrib index 4197d64ef..7baaf0752 100644 --- a/tools/emulator/opengl/system/renderControl_enc/renderControl.attrib +++ b/tools/emulator/opengl/system/renderControl_enc/renderControl.attrib @@ -28,7 +28,7 @@ rcChooseConfig dir attribs in len attribs attribs_size dir configs out - len configs configs_size + len configs configs_size*sizeof(uint32_t) rcReadColorBuffer dir pixels out From 88ad268dd9301c4845302d59063e016971135ce3 Mon Sep 17 00:00:00 2001 From: Stas Gurtovoy Date: Thu, 9 Jun 2011 08:50:32 +0300 Subject: [PATCH 3/5] emulator opengles: Fixed bug in gralloc unregister_buffer Reset the ashmemBase & mappedPid on unregister_buffer Change-Id: Ia209f88a15eb51edb39b1a799500d835b944bc87 --- tools/emulator/opengl/system/gralloc/gralloc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/emulator/opengl/system/gralloc/gralloc.cpp b/tools/emulator/opengl/system/gralloc/gralloc.cpp index 774d7b669..5c11ee367 100644 --- a/tools/emulator/opengl/system/gralloc/gralloc.cpp +++ b/tools/emulator/opengl/system/gralloc/gralloc.cpp @@ -441,6 +441,8 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module, if (err) { return -EINVAL; } + cb->ashmemBase = NULL; + cb->mappedPid = 0; } return 0; From 4ef1f3474e12f1c78af44947c44a22c99d8c2557 Mon Sep 17 00:00:00 2001 From: Guy Zadikario Date: Sun, 12 Jun 2011 15:19:30 +0300 Subject: [PATCH 4/5] emulator opengl: initialize new colorbuffers Initialize new allocated color buffers with zeros. Change-Id: I64a63c2eda83fdec1926c387e171324fb07ebe83 --- .../opengl/host/libs/libOpenglRender/ColorBuffer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.cpp b/tools/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.cpp index 099eeea74..adc84d27a 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.cpp +++ b/tools/emulator/opengl/host/libs/libOpenglRender/ColorBuffer.cpp @@ -56,10 +56,16 @@ ColorBuffer *ColorBuffer::create(int p_width, int p_height, s_gl.glGenTextures(1, &cb->m_tex); s_gl.glBindTexture(GL_TEXTURE_2D, cb->m_tex); + int nComp = (texInternalFormat == GL_RGB ? 3 : 4); + char *zBuff = new char[nComp*p_width*p_height]; + if (zBuff) { + memset(zBuff, 0, nComp*p_width*p_height); + } s_gl.glTexImage2D(GL_TEXTURE_2D, 0, texInternalFormat, p_width, p_height, 0, texInternalFormat, - GL_UNSIGNED_BYTE, NULL); + GL_UNSIGNED_BYTE, zBuff); + delete [] zBuff; s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); From 0536060b40190ccd5484ec9761d1f3eb2957d39c Mon Sep 17 00:00:00 2001 From: Guy Zadikario Date: Mon, 13 Jun 2011 09:51:26 +0300 Subject: [PATCH 5/5] emulator opengl: guest/host rendering syncronization. Added a return value for rcFlushWindowColorBuffer and rcUpdateColorBuffer in order to make those calls to block with a round-trip to the host. This is to make sure that the color buffer is up-to-date before the flinger use it for rendering. Also added a call to the native windows's lock function after EGL is attached and bound to render on the window. This call was missed before. This syncronization can be optimized by removing the round-trip and insert sync primitive to the stream at every draw command that reads from a color buffer to make the sync happen on the host before rendering the color buffer and remove the need for the guest to wait for that update. Change-Id: I1c2d8bc407b69663e992a68d5aa755f19bbe0ec3 --- .../opengl/host/libs/libOpenglRender/RenderControl.cpp | 10 ++++++---- tools/emulator/opengl/system/egl/egl.cpp | 7 +++++++ .../opengl/system/renderControl_enc/renderControl.in | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/RenderControl.cpp b/tools/emulator/opengl/host/libs/libOpenglRender/RenderControl.cpp index 9c973e9f6..c5097a4ab 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/RenderControl.cpp +++ b/tools/emulator/opengl/host/libs/libOpenglRender/RenderControl.cpp @@ -224,13 +224,14 @@ static void rcDestroyColorBuffer(uint32_t colorbuffer) fb->DestroyColorBuffer( colorbuffer ); } -static void rcFlushWindowColorBuffer(uint32_t windowSurface) +static int rcFlushWindowColorBuffer(uint32_t windowSurface) { FrameBuffer *fb = FrameBuffer::getFB(); if (!fb) { - return; + return -1; } fb->flushWindowSurfaceColorBuffer(windowSurface); + return 0; } static void rcSetWindowColorBuffer(uint32_t windowSurface, @@ -296,17 +297,18 @@ static void rcReadColorBuffer(uint32_t colorBuffer, // XXX: TBD - should be implemented } -static void rcUpdateColorBuffer(uint32_t colorBuffer, +static int rcUpdateColorBuffer(uint32_t colorBuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void* pixels) { FrameBuffer *fb = FrameBuffer::getFB(); if (!fb) { - return; + return -1; } fb->updateColorBuffer(colorBuffer, x, y, width, height, format, type, pixels); + return 0; } void initRenderControlContext(renderControl_decoder_context_t *dec) diff --git a/tools/emulator/opengl/system/egl/egl.cpp b/tools/emulator/opengl/system/egl/egl.cpp index 698aa842c..50fb2c56b 100644 --- a/tools/emulator/opengl/system/egl/egl.cpp +++ b/tools/emulator/opengl/system/egl/egl.cpp @@ -325,8 +325,12 @@ EGLBoolean egl_window_surface_t::connect() if (nativeWindow->dequeueBuffer(nativeWindow, &buffer) != NO_ERROR) { setErrorReturn(EGL_BAD_ALLOC, EGL_FALSE); } + buffer->common.incRef(&buffer->common); + // lock the buffer + nativeWindow->lockBuffer(nativeWindow, buffer); + DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE); rcEnc->rcSetWindowColorBuffer(rcEnc, rcSurface, ((cb_handle_t *)(buffer->handle))->hostHandle); @@ -360,6 +364,9 @@ EGLBoolean egl_window_surface_t::swapBuffers() setErrorReturn(EGL_BAD_ALLOC, EGL_FALSE); } + // lock the buffer + nativeWindow->lockBuffer(nativeWindow, buffer); + rcEnc->rcSetWindowColorBuffer(rcEnc, rcSurface, ((cb_handle_t *)(buffer->handle))->hostHandle); return EGL_TRUE; diff --git a/tools/emulator/opengl/system/renderControl_enc/renderControl.in b/tools/emulator/opengl/system/renderControl_enc/renderControl.in index 37a8e9013..9ee3d3f1e 100644 --- a/tools/emulator/opengl/system/renderControl_enc/renderControl.in +++ b/tools/emulator/opengl/system/renderControl_enc/renderControl.in @@ -13,11 +13,11 @@ GL_ENTRY(void, rcDestroyWindowSurface, uint32_t windowSurface) GL_ENTRY(uint32_t, rcCreateColorBuffer, uint32_t width, uint32_t height, GLenum internalFormat) GL_ENTRY(void, rcDestroyColorBuffer, uint32_t colorbuffer) GL_ENTRY(void, rcSetWindowColorBuffer, uint32_t windowSurface, uint32_t colorBuffer) -GL_ENTRY(void, rcFlushWindowColorBuffer, uint32_t windowSurface) +GL_ENTRY(int, rcFlushWindowColorBuffer, uint32_t windowSurface) GL_ENTRY(EGLint, rcMakeCurrent, uint32_t context, uint32_t drawSurf, uint32_t readSurf) GL_ENTRY(void, rcFBPost, uint32_t colorBuffer) GL_ENTRY(void, rcFBSetSwapInterval, EGLint interval) GL_ENTRY(void, rcBindTexture, uint32_t colorBuffer) GL_ENTRY(EGLint, rcColorBufferCacheFlush, uint32_t colorbuffer, EGLint postCount,int forRead) GL_ENTRY(void, rcReadColorBuffer, uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void *pixels) -GL_ENTRY(void, rcUpdateColorBuffer, uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void *pixels) +GL_ENTRY(int, rcUpdateColorBuffer, uint32_t colorbuffer, GLint x, GLint y, GLint width, GLint height, GLenum format, GLenum type, void *pixels)