Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 86303204 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

split HWComposer out of DisplayHardware

we will only ever have a single instance of HWComposer, so
it's now an attribute of SurfaceFlinger, instead of being part
of DisplayHardware.

DisplayHardware now just represents a "display" (it should be renamed).

Change-Id: Iec191e57686868e1df6daa8b880a286c9fefde56
parent 98a121aa
Loading
Loading
Loading
Loading
+5 −61
Original line number Diff line number Diff line
@@ -106,7 +106,6 @@ DisplayHardware::DisplayHardware(
    : DisplayHardwareBase(display),
      mFlinger(flinger),
      mDisplayId(display),
      mHwc(0),
      mNativeWindow(surface),
      mFlags(0),
      mSecureLayerVisible(false)
@@ -227,12 +226,6 @@ void DisplayHardware::init(EGLConfig config)
    mFormat  = format;
    mPageFlipCount = 0;

    // initialize the H/W composer
    mHwc = new HWComposer(mFlinger, *this, mRefreshPeriod);
    if (mHwc->initCheck() == NO_ERROR) {
        mHwc->setFrameBuffer(mDisplay, mSurface);
    }

    // initialize the shared control block
    surface_flinger_cblk_t* const scblk = mFlinger->getControlBlock();
    scblk->connected |= 1 << mDisplayId;
@@ -248,53 +241,6 @@ void DisplayHardware::init(EGLConfig config)
    DisplayHardware::setOrientation(ISurfaceComposer::eOrientationDefault);
}

void DisplayHardware::setVSyncHandler(const sp<VSyncHandler>& handler) {
    Mutex::Autolock _l(mLock);
    mVSyncHandler = handler;
}

void DisplayHardware::eventControl(int event, int enabled) {
    if (event == EVENT_VSYNC) {
        mPowerHAL.vsyncHint(enabled);
    }
    mHwc->eventControl(event, enabled);
}

void DisplayHardware::onVSyncReceived(int dpy, nsecs_t timestamp) {
    sp<VSyncHandler> handler;
    { // scope for the lock
        Mutex::Autolock _l(mLock);
        mLastHwVSync = timestamp;
        if (mVSyncHandler != NULL) {
            handler = mVSyncHandler.promote();
        }
    }

    if (handler != NULL) {
        handler->onVSyncReceived(dpy, timestamp);
    }
}

HWComposer& DisplayHardware::getHwComposer() const {
    return *mHwc;
}

void DisplayHardware::releaseScreen() const
{
    DisplayHardwareBase::releaseScreen();
    if (mHwc->initCheck() == NO_ERROR) {
        mHwc->release();
    }
}

void DisplayHardware::acquireScreen() const
{
    if (mHwc->initCheck() == NO_ERROR) {
        mHwc->acquire();
    }
    DisplayHardwareBase::acquireScreen();
}

uint32_t DisplayHardware::getPageFlipCount() const {
    return mPageFlipCount;
}
@@ -319,6 +265,11 @@ status_t DisplayHardware::compositionComplete() const {
    return mFramebufferSurface->compositionComplete();
}

void DisplayHardware::onVSyncReceived(nsecs_t timestamp) {
    Mutex::Autolock _l(mLock);
    mLastHwVSync = timestamp;
}

void DisplayHardware::flip(const Region& dirty) const
{
    checkGLErrors();
@@ -342,13 +293,6 @@ void DisplayHardware::flip(const Region& dirty) const
    }
    
    mPageFlipCount++;

    if (mHwc->initCheck() == NO_ERROR) {
        mHwc->commit();
    } else {
        eglSwapBuffers(dpy, surface);
    }
    checkEGLErrors("eglSwapBuffers");
}

uint32_t DisplayHardware::getFlags() const
+9 −34
Original line number Diff line number Diff line
@@ -27,30 +27,24 @@
#include <EGL/egl.h>
#include <EGL/eglext.h>

#include <utils/Mutex.h>
#include <utils/Timers.h>

#include "Transform.h"

#include "DisplayHardware/DisplayHardwareBase.h"
#include "DisplayHardware/HWComposer.h"
#include "DisplayHardware/PowerHAL.h"

namespace android {

class FramebufferSurface;
class LayerBase;
class SurfaceFlinger;
class SurfaceTextureClient;

class DisplayHardware :
    public DisplayHardwareBase,
    public HWComposer::EventHandler
class DisplayHardware : public DisplayHardwareBase
{
public:

    class VSyncHandler : virtual public RefBase {
        friend class DisplayHardware;
        virtual void onVSyncReceived(int dpy, nsecs_t timestamp) = 0;
    protected:
        virtual ~VSyncHandler() {}
    };

    enum {
        PARTIAL_UPDATES             = 0x00020000,   // video driver feature
        SWAP_RECTANGLE              = 0x00080000,
@@ -64,13 +58,12 @@ public:

    virtual ~DisplayHardware();

    void releaseScreen() const;
    void acquireScreen() const;

    // Flip the front and back buffers if the back buffer is "dirty".  Might
    // be instantaneous, might involve copying the frame buffer around.
    void flip(const Region& dirty) const;

    void onVSyncReceived(nsecs_t timestamp);

    float       getDpiX() const;
    float       getDpiY() const;
    float       getRefreshRate() const;
@@ -92,23 +85,11 @@ public:
    int                     getOrientation() const { return mOrientation; }
    const Transform&        getTransform() const { return mGlobalTransform; }

    void setVSyncHandler(const sp<VSyncHandler>& handler);

    enum {
        EVENT_VSYNC = HWC_EVENT_VSYNC
    };

    void eventControl(int event, int enabled);


    uint32_t getPageFlipCount() const;
    EGLDisplay getEGLDisplay() const { return mDisplay; }

    void dump(String8& res) const;

    // Hardware Composer
    HWComposer& getHwComposer() const;
    
    status_t compositionComplete() const;
    
    Rect getBounds() const {
@@ -119,15 +100,11 @@ public:
private:
    void init(EGLConfig config);

    virtual void onVSyncReceived(int dpy, nsecs_t timestamp);

    /*
     *  Constants, set during initialization
     */
    sp<SurfaceFlinger> mFlinger;
    int mDisplayId;
    HWComposer* mHwc;
    PowerHAL mPowerHAL;
    // ANativeWindow this display is rendering into
    sp<SurfaceTextureClient> mNativeWindow;
    // set if mNativeWindow is a FramebufferSurface
@@ -148,8 +125,6 @@ private:
    mutable uint32_t mPageFlipCount;

    nsecs_t         mRefreshPeriod;
    mutable nsecs_t mLastHwVSync;


    /*
     * Can only accessed from the main thread, these members
@@ -171,7 +146,7 @@ private:
     *  protected by mLock
     */
    mutable Mutex mLock;
    wp<VSyncHandler>    mVSyncHandler;
    mutable nsecs_t mLastHwVSync;
};

}; // namespace android
+8 −3
Original line number Diff line number Diff line
@@ -276,10 +276,15 @@ size_t HWComposer::getLayerCount(int type) const {
}

status_t HWComposer::commit() const {
    int err = mHwc->set(mHwc, mDpy, mSur, mList);
    int err = NO_ERROR;
    if (mHwc) {
        err = mHwc->set(mHwc, mDpy, mSur, mList);
        if (mList) {
            mList->flags &= ~HWC_GEOMETRY_CHANGED;
        }
    } else {
        eglSwapBuffers(mDpy, mSur);
    }
    return (status_t)err;
}

+5 −4
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ namespace android {
// ---------------------------------------------------------------------------

EventThread::EventThread(const sp<SurfaceFlinger>& flinger)
    : mHw(const_cast<DisplayHardware&>(flinger->getDefaultDisplayHardware())), // XXX: eventthread will need rework
    : mFlinger(flinger),
      mLastVSyncTimestamp(0),
      mVSyncTimestamp(0),
      mUseSoftwareVSync(false),
@@ -45,7 +45,6 @@ EventThread::EventThread(const sp<SurfaceFlinger>& flinger)
}

void EventThread::onFirstRef() {
    mHw.setVSyncHandler(this);
    run("EventThread", PRIORITY_URGENT_DISPLAY + PRIORITY_MORE_FAVORABLE);
}

@@ -251,13 +250,15 @@ bool EventThread::threadLoop() {
void EventThread::enableVSyncLocked() {
    if (!mUseSoftwareVSync) {
        // never enable h/w VSYNC when screen is off
        mHw.eventControl(DisplayHardware::EVENT_VSYNC, true);
        mFlinger->eventControl(SurfaceFlinger::EVENT_VSYNC, true);
        mPowerHAL.vsyncHint(true);
    }
    mDebugVsyncEnabled = true;
}

void EventThread::disableVSyncLocked() {
    mHw.eventControl(DisplayHardware::EVENT_VSYNC, false);
    mFlinger->eventControl(SurfaceFlinger::EVENT_VSYNC, false);
    mPowerHAL.vsyncHint(false);
    mDebugVsyncEnabled = false;
}

+7 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include <utils/SortedVector.h>

#include "DisplayHardware.h"
#include "DisplayHardware/PowerHAL.h"

// ---------------------------------------------------------------------------
namespace android {
@@ -38,7 +39,7 @@ class String8;

// ---------------------------------------------------------------------------

class EventThread : public Thread, public DisplayHardware::VSyncHandler {
class EventThread : public Thread {
    class Connection : public BnDisplayEventConnection {
    public:
        Connection(const sp<EventThread>& eventThread);
@@ -77,20 +78,23 @@ public:
    // called after the screen is turned on from main thread
    void onScreenAcquired();

    // called when receiving a vsync event
    void onVSyncReceived(int display, nsecs_t timestamp);

    void dump(String8& result, char* buffer, size_t SIZE) const;

private:
    virtual bool        threadLoop();
    virtual status_t    readyToRun();
    virtual void        onFirstRef();
    virtual void        onVSyncReceived(int, nsecs_t timestamp);

    void removeDisplayEventConnection(const wp<Connection>& connection);
    void enableVSyncLocked();
    void disableVSyncLocked();

    // constants
    DisplayHardware& mHw;
    sp<SurfaceFlinger> mFlinger;
    PowerHAL mPowerHAL;

    mutable Mutex mLock;
    mutable Condition mCondition;
Loading