am 288b94b4: am f2e4fcd9: Merge changes I34935d21,If423cd29 into klp-dev

* commit '288b94b4abb42c534def97e955c6ae77e79afe6c':
  handle several vsync signal correctly
  only use format compatible with CPU consumers
This commit is contained in:
Mathias Agopian 2013-08-26 15:17:19 -07:00 committed by Android Git Automerger
commit d3cf96416e
3 changed files with 46 additions and 23 deletions

View File

@ -386,8 +386,6 @@ static int modifyFormatColorspace(int fmt, EGLint colorspace) {
switch (fmt) { switch (fmt) {
case HAL_PIXEL_FORMAT_RGBA_8888: return HAL_PIXEL_FORMAT_sRGB_A_8888; 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; 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; return fmt;
@ -410,24 +408,39 @@ EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config,
return setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); 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 // 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 // of our native format. So if sRGB gamma is requested, we have to
// modify the EGLconfig's format before setting the native window's // modify the EGLconfig's format before setting the native window's
// format. // format.
EGLint format;
if (!cnx->egl.eglGetConfigAttrib(iDpy, config, EGL_NATIVE_VISUAL_ID, // by default, just pick RGBA_8888
&format)) { EGLint format = HAL_PIXEL_FORMAT_RGBA_8888;
ALOGE("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID) failed: %#x",
eglGetError()); EGLint a = 0;
format = 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) { // now select a corresponding sRGB format if needed
if (*attr == EGL_GL_COLORSPACE_KHR && if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) {
dp->haveExtension("EGL_KHR_gl_colorspace")) { for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) {
format = modifyFormatColorspace(format, *(attr+1)); if (*attr == EGL_GL_COLORSPACE_KHR) {
format = modifyFormatColorspace(format, attr[1]);
} }
} }
} }

View File

@ -87,12 +87,17 @@ HWComposer::HWComposer(
mFbDev(0), mHwc(0), mNumDisplays(1), mFbDev(0), mHwc(0), mNumDisplays(1),
mCBContext(new cb_context), mCBContext(new cb_context),
mEventHandler(handler), mEventHandler(handler),
mVSyncCount(0), mDebugForceFakeVSync(false) mDebugForceFakeVSync(false)
{ {
for (size_t i =0 ; i<MAX_HWC_DISPLAYS ; i++) { for (size_t i =0 ; i<MAX_HWC_DISPLAYS ; i++) {
mLists[i] = 0; mLists[i] = 0;
} }
for (size_t i=0 ; i<HWC_NUM_PHYSICAL_DISPLAY_TYPES ; i++) {
mLastHwVSync[i] = 0;
mVSyncCounts[i] = 0;
}
char value[PROPERTY_VALUE_MAX]; char value[PROPERTY_VALUE_MAX];
property_get("debug.sf.no_hw_vsync", value, "0"); property_get("debug.sf.no_hw_vsync", value, "0");
mDebugForceFakeVSync = atoi(value); mDebugForceFakeVSync = atoi(value);
@ -278,10 +283,15 @@ void HWComposer::invalidate() {
} }
void HWComposer::vsync(int disp, int64_t timestamp) { void HWComposer::vsync(int disp, int64_t timestamp) {
ATRACE_INT("VSYNC", ++mVSyncCount&1); if (uint32_t(disp) < HWC_NUM_PHYSICAL_DISPLAY_TYPES) {
char tag[16];
snprintf(tag, sizeof(tag), "VSYNC_%1u", disp);
ATRACE_INT(tag, ++mVSyncCounts[disp] & 1);
mEventHandler.onVSyncReceived(disp, timestamp); mEventHandler.onVSyncReceived(disp, timestamp);
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
mLastHwVSync = timestamp; mLastHwVSync[disp] = timestamp;
}
} }
void HWComposer::hotplug(int disp, int connected) { void HWComposer::hotplug(int disp, int connected) {
@ -415,7 +425,7 @@ nsecs_t HWComposer::getRefreshTimestamp(int disp) const {
// the refresh period and whatever closest timestamp we have. // the refresh period and whatever closest timestamp we have.
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
nsecs_t now = systemTime(CLOCK_MONOTONIC); nsecs_t now = systemTime(CLOCK_MONOTONIC);
return now - ((now - mLastHwVSync) % mDisplayData[disp].refresh); return now - ((now - mLastHwVSync[disp]) % mDisplayData[disp].refresh);
} }
sp<Fence> HWComposer::getDisplayFence(int disp) const { sp<Fence> HWComposer::getDisplayFence(int disp) const {

View File

@ -342,14 +342,14 @@ private:
cb_context* mCBContext; cb_context* mCBContext;
EventHandler& mEventHandler; EventHandler& mEventHandler;
size_t mVSyncCount; size_t mVSyncCounts[HWC_NUM_PHYSICAL_DISPLAY_TYPES];
sp<VSyncThread> mVSyncThread; sp<VSyncThread> mVSyncThread;
bool mDebugForceFakeVSync; bool mDebugForceFakeVSync;
BitSet32 mAllocatedDisplayIDs; BitSet32 mAllocatedDisplayIDs;
// protected by mLock // protected by mLock
mutable Mutex mLock; mutable Mutex mLock;
mutable nsecs_t mLastHwVSync; mutable nsecs_t mLastHwVSync[HWC_NUM_PHYSICAL_DISPLAY_TYPES];
// thread-safe // thread-safe
mutable Mutex mEventControlLock; mutable Mutex mEventControlLock;