Merge "add support for EGL_FRAMEBUFFER_TARGET_ANDROID" into jb-mr1-dev
This commit is contained in:
commit
c4a8daaa99
@ -237,10 +237,10 @@ void SurfaceFlinger::deleteTextureAsync(GLuint texture) {
|
|||||||
postMessageAsync(new MessageDestroyGLTexture(texture));
|
postMessageAsync(new MessageDestroyGLTexture(texture));
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t SurfaceFlinger::selectConfigForPixelFormat(
|
status_t SurfaceFlinger::selectConfigForAttribute(
|
||||||
EGLDisplay dpy,
|
EGLDisplay dpy,
|
||||||
EGLint const* attrs,
|
EGLint const* attrs,
|
||||||
PixelFormat format,
|
EGLint attribute, EGLint wanted,
|
||||||
EGLConfig* outConfig)
|
EGLConfig* outConfig)
|
||||||
{
|
{
|
||||||
EGLConfig config = NULL;
|
EGLConfig config = NULL;
|
||||||
@ -249,11 +249,20 @@ status_t SurfaceFlinger::selectConfigForPixelFormat(
|
|||||||
EGLConfig* const configs = new EGLConfig[numConfigs];
|
EGLConfig* const configs = new EGLConfig[numConfigs];
|
||||||
eglChooseConfig(dpy, attrs, configs, numConfigs, &n);
|
eglChooseConfig(dpy, attrs, configs, numConfigs, &n);
|
||||||
|
|
||||||
for (int i=0 ; i<n ; i++) {
|
if (n) {
|
||||||
EGLint nativeVisualId = 0;
|
if (attribute != EGL_NONE) {
|
||||||
eglGetConfigAttrib(dpy, configs[i], EGL_NATIVE_VISUAL_ID, &nativeVisualId);
|
for (int i=0 ; i<n ; i++) {
|
||||||
if (nativeVisualId>0 && format == nativeVisualId) {
|
EGLint value = 0;
|
||||||
*outConfig = configs[i];
|
eglGetConfigAttrib(dpy, configs[i], attribute, &value);
|
||||||
|
if (wanted == value) {
|
||||||
|
*outConfig = configs[i];
|
||||||
|
delete [] configs;
|
||||||
|
return NO_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// just pick the first one
|
||||||
|
*outConfig = configs[0];
|
||||||
delete [] configs;
|
delete [] configs;
|
||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
@ -262,6 +271,58 @@ status_t SurfaceFlinger::selectConfigForPixelFormat(
|
|||||||
return NAME_NOT_FOUND;
|
return NAME_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EGLAttributeVector {
|
||||||
|
struct Attribute;
|
||||||
|
class Adder;
|
||||||
|
friend class Adder;
|
||||||
|
KeyedVector<Attribute, EGLint> mList;
|
||||||
|
struct Attribute {
|
||||||
|
Attribute() {};
|
||||||
|
Attribute(EGLint v) : v(v) { }
|
||||||
|
EGLint v;
|
||||||
|
bool operator < (const Attribute& other) const {
|
||||||
|
// this places EGL_NONE at the end
|
||||||
|
EGLint lhs(v);
|
||||||
|
EGLint rhs(other.v);
|
||||||
|
if (lhs == EGL_NONE) lhs = 0x7FFFFFFF;
|
||||||
|
if (rhs == EGL_NONE) rhs = 0x7FFFFFFF;
|
||||||
|
return lhs < rhs;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
class Adder {
|
||||||
|
friend class EGLAttributeVector;
|
||||||
|
EGLAttributeVector& v;
|
||||||
|
EGLint attribute;
|
||||||
|
Adder(EGLAttributeVector& v, EGLint attribute)
|
||||||
|
: v(v), attribute(attribute) {
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
void operator = (EGLint value) {
|
||||||
|
if (attribute != EGL_NONE) {
|
||||||
|
v.mList.add(attribute, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
operator EGLint () const { return v.mList[attribute]; }
|
||||||
|
};
|
||||||
|
public:
|
||||||
|
EGLAttributeVector() {
|
||||||
|
mList.add(EGL_NONE, EGL_NONE);
|
||||||
|
}
|
||||||
|
void remove(EGLint attribute) {
|
||||||
|
if (attribute != EGL_NONE) {
|
||||||
|
mList.removeItem(attribute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Adder operator [] (EGLint attribute) {
|
||||||
|
return Adder(*this, attribute);
|
||||||
|
}
|
||||||
|
EGLint operator [] (EGLint attribute) const {
|
||||||
|
return mList[attribute];
|
||||||
|
}
|
||||||
|
// cast-operator to (EGLint const*)
|
||||||
|
operator EGLint const* () const { return &mList.keyAt(0).v; }
|
||||||
|
};
|
||||||
|
|
||||||
EGLConfig SurfaceFlinger::selectEGLConfig(EGLDisplay display, EGLint nativeVisualId) {
|
EGLConfig SurfaceFlinger::selectEGLConfig(EGLDisplay display, EGLint nativeVisualId) {
|
||||||
// select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if
|
// select our EGLConfig. It must support EGL_RECORDABLE_ANDROID if
|
||||||
// it is to be used with WIFI displays
|
// it is to be used with WIFI displays
|
||||||
@ -269,32 +330,42 @@ EGLConfig SurfaceFlinger::selectEGLConfig(EGLDisplay display, EGLint nativeVisua
|
|||||||
EGLint dummy;
|
EGLint dummy;
|
||||||
status_t err;
|
status_t err;
|
||||||
|
|
||||||
EGLint attribs[] = {
|
EGLAttributeVector attribs;
|
||||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
attribs[EGL_SURFACE_TYPE] = EGL_WINDOW_BIT;
|
||||||
// The rest of the attributes must be in this order and at the end
|
attribs[EGL_RECORDABLE_ANDROID] = EGL_TRUE;
|
||||||
// of the list; we rely on that for fallback searches below.
|
attribs[EGL_FRAMEBUFFER_TARGET_ANDROID] = EGL_TRUE;
|
||||||
EGL_RED_SIZE, 8,
|
attribs[EGL_RED_SIZE] = 8;
|
||||||
EGL_GREEN_SIZE, 8,
|
attribs[EGL_GREEN_SIZE] = 8;
|
||||||
EGL_BLUE_SIZE, 8,
|
attribs[EGL_BLUE_SIZE] = 8;
|
||||||
EGL_RECORDABLE_ANDROID, EGL_TRUE,
|
|
||||||
EGL_NONE
|
err = selectConfigForAttribute(display, attribs, EGL_NONE, EGL_NONE, &config);
|
||||||
};
|
if (!err)
|
||||||
err = selectConfigForPixelFormat(display, attribs, nativeVisualId, &config);
|
goto success;
|
||||||
|
|
||||||
|
// maybe we failed because of EGL_FRAMEBUFFER_TARGET_ANDROID
|
||||||
|
ALOGW("no suitable EGLConfig found, trying without EGL_FRAMEBUFFER_TARGET_ANDROID");
|
||||||
|
attribs.remove(EGL_FRAMEBUFFER_TARGET_ANDROID);
|
||||||
|
err = selectConfigForAttribute(display, attribs,
|
||||||
|
EGL_NATIVE_VISUAL_ID, nativeVisualId, &config);
|
||||||
if (!err)
|
if (!err)
|
||||||
goto success;
|
goto success;
|
||||||
|
|
||||||
// maybe we failed because of EGL_RECORDABLE_ANDROID
|
// maybe we failed because of EGL_RECORDABLE_ANDROID
|
||||||
ALOGW("no suitable EGLConfig found, trying without EGL_RECORDABLE_ANDROID");
|
ALOGW("no suitable EGLConfig found, trying without EGL_RECORDABLE_ANDROID");
|
||||||
attribs[NELEM(attribs) - 3] = EGL_NONE;
|
attribs.remove(EGL_RECORDABLE_ANDROID);
|
||||||
err = selectConfigForPixelFormat(display, attribs, nativeVisualId, &config);
|
err = selectConfigForAttribute(display, attribs,
|
||||||
|
EGL_NATIVE_VISUAL_ID, nativeVisualId, &config);
|
||||||
if (!err)
|
if (!err)
|
||||||
goto success;
|
goto success;
|
||||||
|
|
||||||
// allow less than 24-bit color; the non-gpu-accelerated emulator only
|
// allow less than 24-bit color; the non-gpu-accelerated emulator only
|
||||||
// supports 16-bit color
|
// supports 16-bit color
|
||||||
ALOGW("no suitable EGLConfig found, trying with 16-bit color allowed");
|
ALOGW("no suitable EGLConfig found, trying with 16-bit color allowed");
|
||||||
attribs[NELEM(attribs) - 9] = EGL_NONE;
|
attribs.remove(EGL_RED_SIZE);
|
||||||
err = selectConfigForPixelFormat(display, attribs, nativeVisualId, &config);
|
attribs.remove(EGL_GREEN_SIZE);
|
||||||
|
attribs.remove(EGL_BLUE_SIZE);
|
||||||
|
err = selectConfigForAttribute(display, attribs,
|
||||||
|
EGL_NATIVE_VISUAL_ID, nativeVisualId, &config);
|
||||||
if (!err)
|
if (!err)
|
||||||
goto success;
|
goto success;
|
||||||
|
|
||||||
|
@ -309,8 +309,8 @@ private:
|
|||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
* EGL
|
* EGL
|
||||||
*/
|
*/
|
||||||
static status_t selectConfigForPixelFormat(EGLDisplay dpy,
|
static status_t selectConfigForAttribute(EGLDisplay dpy,
|
||||||
EGLint const* attrs, PixelFormat format, EGLConfig* outConfig);
|
EGLint const* attrs, EGLint attribute, EGLint value, EGLConfig* outConfig);
|
||||||
static EGLConfig selectEGLConfig(EGLDisplay disp, EGLint visualId);
|
static EGLConfig selectEGLConfig(EGLDisplay disp, EGLint visualId);
|
||||||
static EGLContext createGLContext(EGLDisplay disp, EGLConfig config);
|
static EGLContext createGLContext(EGLDisplay disp, EGLConfig config);
|
||||||
void initializeGL(EGLDisplay display);
|
void initializeGL(EGLDisplay display);
|
||||||
|
Loading…
Reference in New Issue
Block a user