diff options
-rw-r--r-- | libs/rs/driver/rsdGL.cpp | 80 | ||||
-rw-r--r-- | libs/ui/EGLUtils.cpp | 58 | ||||
-rw-r--r-- | services/surfaceflinger/DisplayHardware/DisplayHardware.cpp | 45 |
3 files changed, 145 insertions, 38 deletions
diff --git a/libs/rs/driver/rsdGL.cpp b/libs/rs/driver/rsdGL.cpp index 1f7bb0f..04446ad 100644 --- a/libs/rs/driver/rsdGL.cpp +++ b/libs/rs/driver/rsdGL.cpp @@ -99,9 +99,8 @@ static void printEGLConfiguration(EGLDisplay dpy, EGLConfig config) { for (size_t j = 0; j < sizeof(names) / sizeof(names[0]); j++) { EGLint value = -1; - EGLint returnVal = eglGetConfigAttrib(dpy, config, names[j].attribute, &value); - EGLint error = eglGetError(); - if (returnVal && error == EGL_SUCCESS) { + EGLBoolean returnVal = eglGetConfigAttrib(dpy, config, names[j].attribute, &value); + if (returnVal) { LOGV(" %s: %d (0x%x)", names[j].name, value, value); } } @@ -169,6 +168,24 @@ bool rsdGLInit(const Context *rsc) { configAttribsPtr[1] = EGL_OPENGL_ES2_BIT; configAttribsPtr += 2; + configAttribsPtr[0] = EGL_RED_SIZE; + configAttribsPtr[1] = 8; + configAttribsPtr += 2; + + configAttribsPtr[0] = EGL_GREEN_SIZE; + configAttribsPtr[1] = 8; + configAttribsPtr += 2; + + configAttribsPtr[0] = EGL_BLUE_SIZE; + configAttribsPtr[1] = 8; + configAttribsPtr += 2; + + if (rsc->mUserSurfaceConfig.alphaMin > 0) { + configAttribsPtr[0] = EGL_ALPHA_SIZE; + configAttribsPtr[1] = rsc->mUserSurfaceConfig.alphaMin; + configAttribsPtr += 2; + } + if (rsc->mUserSurfaceConfig.depthMin > 0) { configAttribsPtr[0] = EGL_DEPTH_SIZE; configAttribsPtr[1] = rsc->mUserSurfaceConfig.depthMin; @@ -191,16 +208,53 @@ bool rsdGLInit(const Context *rsc) { eglInitialize(dc->gl.egl.display, &dc->gl.egl.majorVersion, &dc->gl.egl.minorVersion); checkEglError("eglInitialize"); - PixelFormat pf = PIXEL_FORMAT_RGBA_8888; - if (rsc->mUserSurfaceConfig.alphaMin == 0) { - pf = PIXEL_FORMAT_RGBX_8888; - } + EGLBoolean ret; - status_t err = EGLUtils::selectConfigForPixelFormat(dc->gl.egl.display, configAttribs, - pf, &dc->gl.egl.config); - if (err) { - LOGE("%p, couldn't find an EGLConfig matching the screen format\n", rsc); + EGLint numConfigs = -1, n = 0; + ret = eglChooseConfig(dc->gl.egl.display, configAttribs, 0, 0, &numConfigs); + checkEglError("eglGetConfigs", ret); + + if (numConfigs) { + EGLConfig* const configs = new EGLConfig[numConfigs]; + + ret = eglChooseConfig(dc->gl.egl.display, + configAttribs, configs, numConfigs, &n); + if (!ret || !n) { + checkEglError("eglChooseConfig", ret); + LOGE("%p, couldn't find an EGLConfig matching the screen format\n", rsc); + } + + // The first config is guaranteed to over-satisfy the constraints + dc->gl.egl.config = configs[0]; + + // go through the list and skip configs that over-satisfy our needs + for (int i=0 ; i<n ; i++) { + if (rsc->mUserSurfaceConfig.alphaMin <= 0) { + EGLint alphaSize; + eglGetConfigAttrib(dc->gl.egl.display, + configs[i], EGL_ALPHA_SIZE, &alphaSize); + if (alphaSize > 0) { + continue; + } + } + + if (rsc->mUserSurfaceConfig.depthMin <= 0) { + EGLint depthSize; + eglGetConfigAttrib(dc->gl.egl.display, + configs[i], EGL_DEPTH_SIZE, &depthSize); + if (depthSize > 0) { + continue; + } + } + + // Found one! + dc->gl.egl.config = configs[i]; + break; + } + + delete [] configs; } + //if (props.mLogVisual) { if (0) { printEGLConfiguration(dc->gl.egl.display, dc->gl.egl.config); @@ -227,8 +281,8 @@ bool rsdGLInit(const Context *rsc) { return false; } - EGLBoolean ret = eglMakeCurrent(dc->gl.egl.display, dc->gl.egl.surfaceDefault, - dc->gl.egl.surfaceDefault, dc->gl.egl.context); + ret = eglMakeCurrent(dc->gl.egl.display, dc->gl.egl.surfaceDefault, + dc->gl.egl.surfaceDefault, dc->gl.egl.context); if (ret == EGL_FALSE) { LOGE("eglMakeCurrent returned EGL_FALSE"); checkEglError("eglMakeCurrent", ret); diff --git a/libs/ui/EGLUtils.cpp b/libs/ui/EGLUtils.cpp index f24a71d..020646b 100644 --- a/libs/ui/EGLUtils.cpp +++ b/libs/ui/EGLUtils.cpp @@ -24,6 +24,8 @@ #include <EGL/egl.h> +#include <system/graphics.h> + #include <private/ui/android_natives_priv.h> // ---------------------------------------------------------------------------- @@ -67,31 +69,49 @@ status_t EGLUtils::selectConfigForPixelFormat( return BAD_VALUE; // Get all the "potential match" configs... - if (eglGetConfigs(dpy, NULL, 0, &numConfigs) == EGL_FALSE) + if (eglChooseConfig(dpy, attrs, 0, 0, &numConfigs) == EGL_FALSE) return BAD_VALUE; - EGLConfig* const configs = (EGLConfig*)malloc(sizeof(EGLConfig)*numConfigs); - if (eglChooseConfig(dpy, attrs, configs, numConfigs, &n) == EGL_FALSE) { - free(configs); - return BAD_VALUE; - } - - int i; - EGLConfig config = NULL; - for (i=0 ; i<n ; i++) { - EGLint nativeVisualId = 0; - eglGetConfigAttrib(dpy, configs[i], EGL_NATIVE_VISUAL_ID, &nativeVisualId); - if (nativeVisualId>0 && format == nativeVisualId) { + if (numConfigs) { + EGLConfig* const configs = new EGLConfig[numConfigs]; + if (eglChooseConfig(dpy, attrs, configs, numConfigs, &n) == EGL_FALSE) { + delete [] configs; + return BAD_VALUE; + } + + bool hasAlpha = false; + switch (format) { + case HAL_PIXEL_FORMAT_RGBA_8888: + case HAL_PIXEL_FORMAT_BGRA_8888: + case HAL_PIXEL_FORMAT_RGBA_5551: + case HAL_PIXEL_FORMAT_RGBA_4444: + hasAlpha = true; + break; + } + + // The first config is guaranteed to over-satisfy the constraints + EGLConfig config = configs[0]; + + // go through the list and skip configs that over-satisfy our needs + int i; + for (i=0 ; i<n ; i++) { + if (!hasAlpha) { + EGLint alphaSize; + eglGetConfigAttrib(dpy, configs[i], EGL_ALPHA_SIZE, &alphaSize); + if (alphaSize > 0) { + continue; + } + } config = configs[i]; break; } - } - free(configs); - - if (i<n) { - *outConfig = config; - return NO_ERROR; + delete [] configs; + + if (i<n) { + *outConfig = config; + return NO_ERROR; + } } return NAME_NOT_FOUND; diff --git a/services/surfaceflinger/DisplayHardware/DisplayHardware.cpp b/services/surfaceflinger/DisplayHardware/DisplayHardware.cpp index 33125c4..7bf3e0a 100644 --- a/services/surfaceflinger/DisplayHardware/DisplayHardware.cpp +++ b/services/surfaceflinger/DisplayHardware/DisplayHardware.cpp @@ -99,6 +99,31 @@ uint32_t DisplayHardware::getMaxViewportDims() const { mMaxViewportDims[0] : mMaxViewportDims[1]; } +static status_t selectConfigForPixelFormat( + EGLDisplay dpy, + EGLint const* attrs, + PixelFormat format, + EGLConfig* outConfig) +{ + EGLConfig config = NULL; + EGLint numConfigs = -1, n=0; + eglGetConfigs(dpy, NULL, 0, &numConfigs); + EGLConfig* const configs = new EGLConfig[numConfigs]; + eglChooseConfig(dpy, attrs, configs, numConfigs, &n); + for (int i=0 ; i<n ; i++) { + EGLint nativeVisualId = 0; + eglGetConfigAttrib(dpy, configs[i], EGL_NATIVE_VISUAL_ID, &nativeVisualId); + if (nativeVisualId>0 && format == nativeVisualId) { + *outConfig = configs[i]; + delete [] configs; + return NO_ERROR; + } + } + delete [] configs; + return NAME_NOT_FOUND; +} + + void DisplayHardware::init(uint32_t dpy) { mNativeWindow = new FramebufferNativeWindow(); @@ -108,6 +133,9 @@ void DisplayHardware::init(uint32_t dpy) exit(0); } + int format; + ANativeWindow const * const window = mNativeWindow.get(); + window->query(window, NATIVE_WINDOW_FORMAT, &format); mDpiX = mNativeWindow->xdpi; mDpiY = mNativeWindow->ydpi; mRefreshRate = fbDev->fps; @@ -116,11 +144,13 @@ void DisplayHardware::init(uint32_t dpy) EGLint numConfigs=0; EGLSurface surface; EGLContext context; + EGLBoolean result; + status_t err; // initialize EGL EGLint attribs[] = { - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_NONE, 0, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_NONE, 0, EGL_NONE }; @@ -141,9 +171,8 @@ void DisplayHardware::init(uint32_t dpy) eglInitialize(display, NULL, NULL); eglGetConfigs(display, NULL, 0, &numConfigs); - EGLConfig config; - status_t err = EGLUtils::selectConfigForNativeWindow( - display, attribs, mNativeWindow.get(), &config); + EGLConfig config = NULL; + err = selectConfigForPixelFormat(display, attribs, format, &config); LOGE_IF(err, "couldn't find an EGLConfig matching the screen format"); EGLint r,g,b,a; @@ -224,7 +253,11 @@ void DisplayHardware::init(uint32_t dpy) * Gather OpenGL ES extensions */ - eglMakeCurrent(display, surface, surface, context); + result = eglMakeCurrent(display, surface, surface, context); + if (!result) { + LOGE("Couldn't create a working GLES context. check logs. exiting..."); + exit(0); + } GLExtensions& extensions(GLExtensions::getInstance()); extensions.initWithGLStrings( |