Merge "emulator opengl: implement eglChooseConfig functionality."

This commit is contained in:
David Turner
2011-06-17 05:13:41 -07:00
committed by Android Code Review
7 changed files with 88 additions and 36 deletions

View File

@@ -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<nConfigs; matchedIdx++) {
if (nVerifiedCfgs >= configs_size) break; //We have enouhgt configs
int sCfgId;
s_egl.eglGetConfigAttrib(dpy, matchedConfigs[matchedIdx], EGL_CONFIG_ID, &sCfgId);
for (int fbIdx=0; fbIdx<s_numConfigs; fbIdx++) {
int dCfgId = s_fbConfigs[fbIdx]->m_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;

View File

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

View File

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

View File

@@ -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<EGLint> possibleConfigs;
for (int i=0; i<s_display.getNumConfigs(); i++)
possibleConfigs.push(i);
//Now go over the attrib_list and drop unmatching configs
while (attrib_list[0])
{
EGLInt paramAttrName = attrib_list[0];
EGLInt paramAttrVal = attrib_list[1];
attrib_list+=2;
int cIdx = 0;
while (cIdx < possibleConfigs.size()) {
EGLInt conf = possibleConfigs[cIdx];
EGLInt value;
if (s_display.getConfigAttrib((EGLConfig)conf, paramAttrName, &value) == EGL_FALSE) {
return setError(EGL_BAD_ATTRIBUTE, EGL_FALSE)
}
//if the attrib value doesn't match, the current config doesn't match
if (paramAttrValue != value)
possibleConfigs.removeAt(cIdx); //don't advance cIdx
else
cIdx++;
int attribs_size = 0;
if (attrib_list) {
const EGLint * attrib_p = attrib_list;
while (attrib_p[0] != EGL_NONE) {
attribs_size += 2;
attrib_p += 2;
}
attribs_size++; //for the terminating EGL_NONE
}
//at this point possibleConfigs holds (if any) the matching configs
cIdx=0;
for (cIdx=0 ; cIdx<possibleConfigs.size() && cIdx<config_size ; cIdx++) {
*configs++ = possibleConfigs[cIdx]
}
*num_config = cIdx;
#endif
DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE);
*num_config = rcEnc->rcChooseConfig(rcEnc, (EGLint*)attrib_list, attribs_size, (uint32_t*)configs, config_size);
return EGL_TRUE;
}

View File

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

View File

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

View File

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