From 0f288fcc9c1b2d23b1cff2f5c59689aef76b77ae Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 21 Aug 2013 16:36:34 -0700 Subject: [PATCH 1/2] only use format compatible with CPU consumers EGL now picks the buffer format out of a small set of formats compatible with CPU consumers instead of using the EGL_NATIVE_VISUAL_ID. Bug: 10194508 Change-Id: If423cd29601b7a3ace8670f4c73004132cfc4b31 --- opengl/libs/EGL/eglApi.cpp | 43 +++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp index a81c45027..7410c12e2 100644 --- a/opengl/libs/EGL/eglApi.cpp +++ b/opengl/libs/EGL/eglApi.cpp @@ -386,8 +386,6 @@ static int modifyFormatColorspace(int fmt, EGLint colorspace) { switch (fmt) { case HAL_PIXEL_FORMAT_RGBA_8888: return HAL_PIXEL_FORMAT_sRGB_A_8888; case HAL_PIXEL_FORMAT_RGBX_8888: return HAL_PIXEL_FORMAT_sRGB_X_8888; - // TODO: this should go away once drivers stop using BGRA EGLConfigs - case HAL_PIXEL_FORMAT_BGRA_8888: return HAL_PIXEL_FORMAT_sRGB_A_8888; } } return fmt; @@ -410,24 +408,39 @@ EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); } - // Set the native window's buffers format to match this config. + // Set the native window's buffers format to match what this config requests. // Whether to use sRGB gamma is not part of the EGLconfig, but is part // of our native format. So if sRGB gamma is requested, we have to // modify the EGLconfig's format before setting the native window's // format. - EGLint format; - if (!cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_NATIVE_VISUAL_ID, - &format)) { - ALOGE("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID) failed: %#x", - eglGetError()); - format = 0; + + // by default, just pick RGBA_8888 + EGLint format = HAL_PIXEL_FORMAT_RGBA_8888; + + EGLint a = 0; + cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_ALPHA_SIZE, &a); + if (a > 0) { + // alpha-channel requested, there's really only one suitable format + format = HAL_PIXEL_FORMAT_RGBA_8888; + } else { + EGLint r, g, b; + r = g = b = 0; + cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_RED_SIZE, &r); + cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_GREEN_SIZE, &g); + cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_BLUE_SIZE, &b); + EGLint colorDepth = r + g + b; + if (colorDepth <= 16) { + format = HAL_PIXEL_FORMAT_RGB_565; + } else { + format = HAL_PIXEL_FORMAT_RGBX_8888; + } } - if (attrib_list) { - for (const EGLint* attr = attrib_list; *attr != EGL_NONE; - attr += 2) { - if (*attr == EGL_GL_COLORSPACE_KHR && - dp->haveExtension("EGL_KHR_gl_colorspace")) { - format = modifyFormatColorspace(format, *(attr+1)); + + // now select a corresponding sRGB format if needed + if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) { + for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) { + if (*attr == EGL_GL_COLORSPACE_KHR) { + format = modifyFormatColorspace(format, attr[1]); } } } From bef42c50ebda2d63400f92611e1dd857c03bb38c Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 21 Aug 2013 17:45:46 -0700 Subject: [PATCH 2/2] handle several vsync signal correctly Change-Id: I34935d2197ce8e914fef2f110896e47b44225ad2 --- .../DisplayHardware/HWComposer.cpp | 22 ++++++++++++++----- .../DisplayHardware/HWComposer.h | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index e7d0d239c..32c55fd1f 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -87,12 +87,17 @@ HWComposer::HWComposer( mFbDev(0), mHwc(0), mNumDisplays(1), mCBContext(new cb_context), mEventHandler(handler), - mVSyncCount(0), mDebugForceFakeVSync(false) + mDebugForceFakeVSync(false) { for (size_t i =0 ; i HWComposer::getDisplayFence(int disp) const { diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index d901c621e..9f961139b 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -342,14 +342,14 @@ private: cb_context* mCBContext; EventHandler& mEventHandler; - size_t mVSyncCount; + size_t mVSyncCounts[HWC_NUM_PHYSICAL_DISPLAY_TYPES]; sp mVSyncThread; bool mDebugForceFakeVSync; BitSet32 mAllocatedDisplayIDs; // protected by mLock mutable Mutex mLock; - mutable nsecs_t mLastHwVSync; + mutable nsecs_t mLastHwVSync[HWC_NUM_PHYSICAL_DISPLAY_TYPES]; // thread-safe mutable Mutex mEventControlLock;