From 34a09ba1efd706323a15633da5044b352988eb5f Mon Sep 17 00:00:00 2001 From: Jesse Hall Date: Sun, 29 Jul 2012 22:35:34 -0700 Subject: [PATCH] Move eglSwapBuffers out of HWComposer Commit 8630320 moved the eglSwapBuffers fallback (for devices with no HWC implementation) from DisplayHardware to HWComposer. But HWComposer only knows about the framebuffer EGL display and surface handles if there is a HWC, so it was always passing bogus handles. This change moves the eglSwapBuffers fallback up to SurfaceFlinger, which has access to the framebuffer EGL handles. Bug: 6886613 Change-Id: Iad3f5ff7c90ee48d7053999e6a4548d6794b6ebd --- .../DisplayHardware/HWComposer.cpp | 14 ++------------ .../surfaceflinger/DisplayHardware/HWComposer.h | 9 +-------- services/surfaceflinger/SurfaceFlinger.cpp | 16 +++++++--------- services/surfaceflinger/SurfaceFlinger.h | 1 + 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 0a633f01a..b8506ee70 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -39,8 +39,6 @@ #include #include -#include - #include "Layer.h" // needed only for debugging #include "LayerBase.h" #include "HWComposer.h" @@ -108,7 +106,6 @@ HWComposer::HWComposer( : mFlinger(flinger), mModule(0), mHwc(0), mList(0), mCapacity(0), mNumOVLayers(0), mNumFBLayers(0), - mDpy(EGL_NO_DISPLAY), mSur(EGL_NO_SURFACE), mCBContext(new cb_context), mEventHandler(handler), mRefreshPeriod(refreshPeriod), @@ -207,11 +204,6 @@ void HWComposer::eventControl(int event, int enabled) { } } -void HWComposer::setFrameBuffer(EGLDisplay dpy, EGLSurface sur) { - mDpy = (hwc_display_t)dpy; - mSur = (hwc_surface_t)sur; -} - status_t HWComposer::createWorkList(size_t numLayers) { if (mHwc) { if (!mList || mCapacity < numLayers) { @@ -270,15 +262,13 @@ size_t HWComposer::getLayerCount(int type) const { return 0; } -status_t HWComposer::commit() const { +status_t HWComposer::commit(void* fbDisplay, void* fbSurface) const { int err = NO_ERROR; if (mHwc) { - err = mHwc->set(mHwc, mDpy, mSur, mList); + err = mHwc->set(mHwc, fbDisplay, fbSurface, mList); if (mList) { mList->flags &= ~HWC_GEOMETRY_CHANGED; } - } else { - eglSwapBuffers(mDpy, mSur); } return (status_t)err; } diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index c2fff4fd9..ca41bd379 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -20,8 +20,6 @@ #include #include -#include - #include #include @@ -63,9 +61,6 @@ public: status_t initCheck() const; - // tells the HAL what the framebuffer is - void setFrameBuffer(EGLDisplay dpy, EGLSurface sur); - // Asks the HAL what it can do status_t prepare() const; @@ -73,7 +68,7 @@ public: status_t disable(); // commits the list - status_t commit() const; + status_t commit(void* fbDisplay, void* fbSurface) const; // release hardware resources and blank screen status_t release() const; @@ -234,8 +229,6 @@ private: size_t mCapacity; mutable size_t mNumOVLayers; mutable size_t mNumFBLayers; - EGLDisplay mDpy; - EGLSurface mSur; cb_context* mCBContext; EventHandler& mEventHandler; nsecs_t mRefreshPeriod; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 192378f3e..6cf112834 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -363,8 +363,8 @@ status_t SurfaceFlinger::readyToRun() "Initializing graphics H/W..."); // initialize EGL - EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - eglInitialize(display, NULL, NULL); + mEGLDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + eglInitialize(mEGLDisplay, NULL, NULL); // Initialize the main display // create native window to main display @@ -378,8 +378,8 @@ status_t SurfaceFlinger::readyToRun() // initialize the config and context int format; window->query(window, NATIVE_WINDOW_FORMAT, &format); - mEGLConfig = selectEGLConfig(display, format); - mEGLContext = createGLContext(display, mEGLConfig); + mEGLConfig = selectEGLConfig(mEGLDisplay, format); + mEGLContext = createGLContext(mEGLDisplay, mEGLConfig); // initialize our main display hardware DisplayHardware* const hw = new DisplayHardware(this, 0, anw, mEGLConfig); @@ -387,7 +387,7 @@ status_t SurfaceFlinger::readyToRun() // initialize OpenGL ES EGLSurface surface = hw->getEGLSurface(); - initializeGL(display, surface); + initializeGL(mEGLDisplay, surface); // start the EventThread mEventThread = new EventThread(this); @@ -397,9 +397,6 @@ status_t SurfaceFlinger::readyToRun() mHwc = new HWComposer(this, *static_cast(this), hw->getRefreshPeriod()); - if (mHwc->initCheck() == NO_ERROR) { - mHwc->setFrameBuffer(display, surface); - } // We're now ready to accept clients... mReadyToRunBarrier.open(); @@ -733,15 +730,16 @@ void SurfaceFlinger::postFramebuffer() } hw.flip(mSwapRegion); - hwc.commit(); if (hwc.initCheck() == NO_ERROR) { + hwc.commit(mEGLDisplay, hw.getEGLSurface()); HWComposer::LayerListIterator cur = hwc.begin(); const HWComposer::LayerListIterator end = hwc.end(); for (size_t i = 0; cur != end && i < numLayers; ++i, ++cur) { layers[i]->onLayerDisplayed(&*cur); } } else { + eglSwapBuffers(mEGLDisplay, hw.getEGLSurface()); for (size_t i = 0; i < numLayers; i++) { layers[i]->onLayerDisplayed(NULL); } diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index c33f1a335..a3d8538dc 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -390,6 +390,7 @@ private: GLint mMaxTextureSize; EGLContext mEGLContext; EGLConfig mEGLConfig; + EGLDisplay mEGLDisplay; // Can only accessed from the main thread, these members // don't need synchronization