From a7b7e95b039f51123ebcb6fd5ff05e7967f4f50e Mon Sep 17 00:00:00 2001 From: Stas Gurtovoy Date: Wed, 4 May 2011 08:53:51 +0300 Subject: [PATCH] emulator opengl: implement eglChooseConfig functionality. Added new RenderControl command to request the host to execute the ChooseConfig functionality. Change-Id: Ib92be313a6df740de69d671c6994ec6cae17ea13 --- .../host/libs/libOpenglRender/FBConfig.cpp | 52 +++++++++++++++++-- .../host/libs/libOpenglRender/FBConfig.h | 1 + .../libs/libOpenglRender/RenderControl.cpp | 11 ++++ tools/emulator/opengl/system/egl/egl.cpp | 44 ++++------------ .../opengl/system/renderControl_enc/README | 9 ++++ .../renderControl_enc/renderControl.attrib | 6 +++ .../system/renderControl_enc/renderControl.in | 1 + 7 files changed, 88 insertions(+), 36 deletions(-) diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/FBConfig.cpp b/tools/emulator/opengl/host/libs/libOpenglRender/FBConfig.cpp index 14e84b931..81ba067ce 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/FBConfig.cpp +++ b/tools/emulator/opengl/host/libs/libOpenglRender/FBConfig.cpp @@ -24,15 +24,15 @@ int FBConfig::s_numConfigs = 0; const GLuint FBConfig::s_configAttribs[] = { EGL_DEPTH_SIZE, // must be first - see getDepthSize() EGL_STENCIL_SIZE, // must be second - see getStencilSize() - EGL_RENDERABLE_TYPE, // must be third - see getRenderableType() - EGL_SURFACE_TYPE, // must be fourth - see getSurfaceType() + EGL_RENDERABLE_TYPE,// must be third - see getRenderableType() + EGL_SURFACE_TYPE, // must be fourth - see getSurfaceType() + EGL_CONFIG_ID, // must be fifth - see chooseConfig() EGL_BUFFER_SIZE, EGL_ALPHA_SIZE, EGL_BLUE_SIZE, EGL_GREEN_SIZE, EGL_RED_SIZE, EGL_CONFIG_CAVEAT, - EGL_CONFIG_ID, EGL_LEVEL, EGL_MAX_PBUFFER_HEIGHT, EGL_MAX_PBUFFER_PIXELS, @@ -201,6 +201,52 @@ void FBConfig::packConfigsInfo(GLuint *buffer) } } +int FBConfig::chooseConfig(FrameBuffer *fb, EGLint * attribs, uint32_t * configs, uint32_t configs_size) +{ + EGLDisplay dpy = fb->getDisplay(); + int ret = 0; + + if (dpy == EGL_NO_DISPLAY) { + fprintf(stderr,"Could not get EGL Display\n"); + return ret; + } + // + // Query the num of configs in the EGL backend + // + EGLint nConfigs; + if (!s_egl.eglGetConfigs(dpy, NULL, 0, &nConfigs)) { + fprintf(stderr, "Could not get number of available configs\n"); + return ret; + } + // + // Query the max matching configs in the backend + // + EGLConfig *matchedConfigs = new EGLConfig[nConfigs]; + s_egl.eglChooseConfig(dpy, attribs, matchedConfigs, nConfigs, &nConfigs); + + // + // From all matchedConfigs we need only config_size FBConfigs, so we intersect both lists compating the CONFIG_ID attribute + // + uint32_t nVerifiedCfgs = 0; + for (int matchedIdx=0; matchedIdx= configs_size) break; //We have enouhgt configs + int sCfgId; + s_egl.eglGetConfigAttrib(dpy, matchedConfigs[matchedIdx], EGL_CONFIG_ID, &sCfgId); + for (int fbIdx=0; fbIdxm_attribValues[4]; //CONFIG_ID + if (sCfgId == dCfgId) { + //This config matches the requested attributes and filtered into fbConfigs, so we're happy with it + configs[nVerifiedCfgs++] = fbIdx; + break; + } + } + } + + delete matchedConfigs; + + return nVerifiedCfgs; +} + FBConfig::FBConfig(EGLDisplay p_eglDpy, EGLConfig p_eglCfg) { m_eglConfig = p_eglCfg; diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/FBConfig.h b/tools/emulator/opengl/host/libs/libOpenglRender/FBConfig.h index b898b378b..8e0356a88 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/FBConfig.h +++ b/tools/emulator/opengl/host/libs/libOpenglRender/FBConfig.h @@ -35,6 +35,7 @@ public: static int getNumConfigs(); static int getNumAttribs() { return s_numConfigAttribs; } static void packConfigsInfo(GLuint *buffer); + static int chooseConfig(FrameBuffer *fb, EGLint * attribs, uint32_t * configs, uint32_t configs_size); ~FBConfig(); EGLConfig getEGLConfig() const { return m_eglConfig; } diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/RenderControl.cpp b/tools/emulator/opengl/host/libs/libOpenglRender/RenderControl.cpp index 504d79289..891c89b28 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/RenderControl.cpp +++ b/tools/emulator/opengl/host/libs/libOpenglRender/RenderControl.cpp @@ -78,6 +78,16 @@ static EGLint rcGetConfigs(uint32_t bufSize, GLuint* buffer) return nConfigs; } +static EGLint rcChooseConfig(EGLint *attribs, uint32_t attribs_size, uint32_t *configs, uint32_t configs_size) +{ + FrameBuffer *fb = FrameBuffer::getFB(); + if (!fb) { + return 0; + } + + return FBConfig::chooseConfig(fb, attribs, configs, configs_size); +} + static EGLint rcGetFBParam(EGLint param) { FrameBuffer *fb = FrameBuffer::getFB(); @@ -252,6 +262,7 @@ void initRenderControlContext(renderControl_decoder_context_t *dec) dec->set_rcQueryEGLString(rcQueryEGLString); dec->set_rcGetNumConfigs(rcGetNumConfigs); dec->set_rcGetConfigs(rcGetConfigs); + dec->set_rcChooseConfig(rcChooseConfig); dec->set_rcGetFBParam(rcGetFBParam); dec->set_rcCreateContext(rcCreateContext); dec->set_rcDestroyContext(rcDestroyContext); diff --git a/tools/emulator/opengl/system/egl/egl.cpp b/tools/emulator/opengl/system/egl/egl.cpp index 8f1cca093..54273637b 100644 --- a/tools/emulator/opengl/system/egl/egl.cpp +++ b/tools/emulator/opengl/system/egl/egl.cpp @@ -461,43 +461,21 @@ EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config) { -#if 0 - VALIDATE_DISPLAY_INIT(dpy, NULL); + VALIDATE_DISPLAY_INIT(dpy, EGL_FALSE); - //First construct a vector of all configs - Vector possibleConfigs; - for (int i=0; ircChooseConfig(rcEnc, (EGLint*)attrib_list, attribs_size, (uint32_t*)configs, config_size); + return EGL_TRUE; } diff --git a/tools/emulator/opengl/system/renderControl_enc/README b/tools/emulator/opengl/system/renderControl_enc/README index 41bb66969..b8ffc4981 100644 --- a/tools/emulator/opengl/system/renderControl_enc/README +++ b/tools/emulator/opengl/system/renderControl_enc/README @@ -39,6 +39,15 @@ EGLint rcGetConfigs(uint32_t bufSize, GLuint* buffer); holding the attribute values for that config, the values are specified in the same order as the attribute vector. +EGLint rcChooseConfig(EGLint *attribs, uint32_t attribs_size, uint32_t *configs, uint32_t configs_size) + This function triggers an eglChooseConfig on the host, to get a list of + configs matching the given attribs values. + attribs - a list of attribute names followed by the desired values, terminated by EGL_NONE + attribs_size - the size of the list + configs - the returned matching configuration names (same names as familiar to the client in rcGetConfigs) + configs_size - the size of the configs buffers + returns - the actual number of matching configurations (<= configs_size) + EGLint rcGetFBParam(EGLint param); queries the host for framebuffer parameter, see renderControl_types.h for possible values of 'param'. diff --git a/tools/emulator/opengl/system/renderControl_enc/renderControl.attrib b/tools/emulator/opengl/system/renderControl_enc/renderControl.attrib index 310d3d065..a77d21fcc 100644 --- a/tools/emulator/opengl/system/renderControl_enc/renderControl.attrib +++ b/tools/emulator/opengl/system/renderControl_enc/renderControl.attrib @@ -20,6 +20,12 @@ rcGetConfigs dir buffer out len buffer bufSize +rcChooseConfig + dir attribs in + len attribs attribs_size + dir configs out + len configs configs_size + rcReadColorBuffer dir pixels out len pixels (((glUtilsPixelBitSize(format, type) * width) >> 3) * height) diff --git a/tools/emulator/opengl/system/renderControl_enc/renderControl.in b/tools/emulator/opengl/system/renderControl_enc/renderControl.in index db23c5b48..c91a662a6 100644 --- a/tools/emulator/opengl/system/renderControl_enc/renderControl.in +++ b/tools/emulator/opengl/system/renderControl_enc/renderControl.in @@ -3,6 +3,7 @@ GL_ENTRY(EGLint, rcGetEGLVersion, EGLint *major, EGLint *minor) GL_ENTRY(EGLint, rcQueryEGLString, EGLenum name, void *buffer, EGLint bufferSize) GL_ENTRY(EGLint, rcGetNumConfigs, uint32_t *numAttribs) GL_ENTRY(EGLint, rcGetConfigs, uint32_t bufSize, GLuint *buffer) +GL_ENTRY(EGLint, rcChooseConfig, EGLint *attribs, uint32_t attribs_size, uint32_t *configs, uint32_t configs_size) GL_ENTRY(EGLint, rcGetFBParam, EGLint param) GL_ENTRY(uint32_t, rcCreateContext, uint32_t config, uint32_t share, uint32_t glVersion) GL_ENTRY(void, rcDestroyContext, uint32_t context)