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

Commit 593c05ce authored by Mathias Agopian's avatar Mathias Agopian
Browse files

clean-up client management.

simplified things a lot, the biggest change is that the concept
of "ClientID" is now gone, instead we simply use references.

Change-Id: Icbc57f80865884aa5f35ad0d0a0db26f19f9f7ce
parent 66236db3
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@ LOCAL_SRC_FILES:= \
    MessageQueue.cpp \
    SurfaceFlinger.cpp \
    TextureManager.cpp \
    Tokenizer.cpp \
    Transform.cpp

LOCAL_CFLAGS:= -DLOG_TAG=\"SurfaceFlinger\"
+45 −20
Original line number Diff line number Diff line
@@ -47,9 +47,9 @@ template <typename T> inline T min(T a, T b) {

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

Layer::Layer(SurfaceFlinger* flinger, DisplayID display, 
        const sp<Client>& client, int32_t i)
    :   LayerBaseClient(flinger, display, client, i),
Layer::Layer(SurfaceFlinger* flinger,
        DisplayID display, const sp<Client>& client)
    :   LayerBaseClient(flinger, display, client),
        lcblk(NULL),
        mSecure(false),
        mNeedsBlending(true),
@@ -58,13 +58,6 @@ Layer::Layer(SurfaceFlinger* flinger, DisplayID display,
        mBufferManager(mTextureManager),
        mWidth(0), mHeight(0), mFixedSize(false)
{
    // no OpenGL operation is possible here, since we might not be
    // in the OpenGL thread.
    lcblk = new SharedBufferServer(
            client->ctrlblk, i, mBufferManager.getDefaultBufferCount(),
            getIdentity());

   mBufferManager.setActiveBufferIndex( lcblk->getFrontBuffer() );
}

Layer::~Layer()
@@ -77,13 +70,32 @@ Layer::~Layer()
    delete lcblk;
}

// TODO: get rid of this
void Layer::setToken(int32_t token)
{
    sp<Client> ourClient(client.promote());

    mToken = token;

    // no OpenGL operation is possible here, since we might not be
    // in the OpenGL thread.
    lcblk = new SharedBufferServer(
            ourClient->ctrlblk, token, mBufferManager.getDefaultBufferCount(),
            getIdentity());

   mBufferManager.setActiveBufferIndex( lcblk->getFrontBuffer() );
}

// called with SurfaceFlinger::mStateLock as soon as the layer is entered
// in the purgatory list
void Layer::onRemoved()
{
    sp<Client> ourClient(client.promote());
    if (ourClient != 0) {
        // wake up the condition
        lcblk->setStatus(NO_INIT);
    }
}

sp<LayerBaseClient::Surface> Layer::createSurface() const
{
@@ -140,7 +152,7 @@ status_t Layer::setBuffers( uint32_t w, uint32_t h,
    int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED);
    mNeedsDithering = layerRedsize > displayRedSize;

    mSurface = new SurfaceLayer(mFlinger, clientIndex(), this);
    mSurface = new SurfaceLayer(mFlinger, this);
    return NO_ERROR;
}

@@ -391,8 +403,11 @@ uint32_t Layer::doTransaction(uint32_t flags)
            // a buffer, it'll get the new size.
            setBufferSize(temp.requested_w, temp.requested_h);

            sp<Client> ourClient(client.promote());
            if (ourClient != 0) {
                // all buffers need reallocation
                lcblk->reallocateAll();
            }
        } else {
            // record the new size
            setBufferSize(temp.requested_w, temp.requested_h);
@@ -427,6 +442,13 @@ bool Layer::isFixedSize() const {

void Layer::lockPageFlip(bool& recomputeVisibleRegions)
{
    sp<Client> ourClient(client.promote());
    if (ourClient == 0) {
        // client died
        recomputeVisibleRegions = true;
        return;
    }

    ssize_t buf = lcblk->retireAndLock();
    if (buf == NOT_ENOUGH_DATA) {
        // NOTE: This is not an error, it simply means there is nothing to
@@ -538,10 +560,13 @@ void Layer::unlockPageFlip(

void Layer::finishPageFlip()
{
    sp<Client> ourClient(client.promote());
    if (ourClient != 0) {
        int buf = mBufferManager.getActiveBufferIndex();
        status_t err = lcblk->unlock( buf );
        LOGE_IF(err!=NO_ERROR, "layer %p, buffer=%d wasn't locked!", this, buf);
    }
}


void Layer::dump(String8& result, char* buffer, size_t SIZE) const
@@ -707,8 +732,8 @@ status_t Layer::BufferManager::destroyTexture(Image* tex, EGLDisplay dpy)
// ---------------------------------------------------------------------------

Layer::SurfaceLayer::SurfaceLayer(const sp<SurfaceFlinger>& flinger,
        SurfaceID id, const sp<Layer>& owner)
    : Surface(flinger, id, owner->getIdentity(), owner)
        const sp<Layer>& owner)
    : Surface(flinger, owner->getIdentity(), owner)
{
}

+8 −3
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ public:
    SharedBufferServer*     lcblk;

                 Layer(SurfaceFlinger* flinger, DisplayID display,
                         const sp<Client>& client, int32_t i);
                         const sp<Client>& client);

        virtual ~Layer();

@@ -96,8 +96,7 @@ private:

    class SurfaceLayer : public LayerBaseClient::Surface {
    public:
        SurfaceLayer(const sp<SurfaceFlinger>& flinger,
                SurfaceID id, const sp<Layer>& owner);
        SurfaceLayer(const sp<SurfaceFlinger>& flinger, const sp<Layer>& owner);
        ~SurfaceLayer();
    private:
        virtual sp<GraphicBuffer> requestBuffer(int bufferIdx,
@@ -189,6 +188,12 @@ private:
            uint32_t    mReqHeight;
            uint32_t    mReqFormat;
            bool        mFixedSize;

    // TODO: get rid of this
private:
    virtual void setToken(int32_t token);
    virtual int32_t getToken() const { return mToken; }
    int32_t mToken;
};

// ---------------------------------------------------------------------------
+10 −28
Original line number Diff line number Diff line
@@ -488,35 +488,18 @@ void LayerBase::dump(String8& result, char* buffer, size_t SIZE) const
int32_t LayerBaseClient::sIdentity = 1;

LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
        const sp<Client>& client, int32_t i)
    : LayerBase(flinger, display), client(client), mIndex(i),
        const sp<Client>& client)
    : LayerBase(flinger, display), client(client),
      mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
{
}

void LayerBaseClient::onFirstRef()
{    
    sp<Client> client(this->client.promote());
    if (client != 0) {
        client->bindLayer(this, mIndex);
    }
}

LayerBaseClient::~LayerBaseClient()
{
    sp<Client> client(this->client.promote());
    if (client != 0) {
        client->free(mIndex);
    }
}

ssize_t LayerBaseClient::serverIndex() const
{
    sp<Client> client(this->client.promote());
    if (client != 0) {
        return (client->cid<<16)|mIndex;
    sp<Client> c(client.promote());
    if (c != 0) {
        c->free(this);
    }
    return ssize_t(0xFFFF0000 | mIndex);
}

sp<LayerBaseClient::Surface> LayerBaseClient::getSurface()
@@ -533,7 +516,7 @@ sp<LayerBaseClient::Surface> LayerBaseClient::getSurface()

sp<LayerBaseClient::Surface> LayerBaseClient::createSurface() const
{
    return new Surface(mFlinger, clientIndex(), mIdentity,
    return new Surface(mFlinger, mIdentity,
            const_cast<LayerBaseClient *>(this));
}

@@ -544,10 +527,9 @@ void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
    sp<Client> client(this->client.promote());
    snprintf(buffer, SIZE,
            "      name=%s\n"
            "      id=0x%08x, client=0x%08x, identity=%u\n",
            "      client=%p, identity=%u\n",
            getName().string(),
            clientIndex(), client.get() ? client->cid : 0,
            getIdentity());
            client.get(), getIdentity());

    result.append(buffer);
}
@@ -556,9 +538,9 @@ void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const

LayerBaseClient::Surface::Surface(
        const sp<SurfaceFlinger>& flinger,
        SurfaceID id, int identity, 
        int identity,
        const sp<LayerBaseClient>& owner) 
    : mFlinger(flinger), mToken(id), mIdentity(identity), mOwner(owner)
    : mFlinger(flinger), mIdentity(identity), mOwner(owner)
{
}

+17 −21
Original line number Diff line number Diff line
@@ -101,7 +101,6 @@ public:
            void invalidate();

    virtual const char* getTypeId() const { return "LayerBase"; }
    virtual ssize_t serverIndex() const { return -1; }

    /**
     * draw - performs some global clipping optimizations
@@ -269,30 +268,24 @@ class LayerBaseClient : public LayerBase
public:
    class Surface;

    LayerBaseClient(SurfaceFlinger* flinger, DisplayID display, 
            const sp<Client>& client, int32_t i);
    virtual ~LayerBaseClient();
    virtual void onFirstRef();

    const wp<Client> client;

    inline  uint32_t    getIdentity() const { return mIdentity; }
    inline  int32_t     clientIndex() const { return mIndex; }
            LayerBaseClient(SurfaceFlinger* flinger, DisplayID display,
                        const sp<Client>& client);
    virtual ~LayerBaseClient();

            sp<Surface> getSurface();
    virtual sp<Surface> createSurface() const;
    virtual ssize_t     serverIndex() const;
    virtual const char* getTypeId() const { return "LayerBaseClient"; }

    class Surface : public BnSurface 
    {
    uint32_t getIdentity() const { return mIdentity; }

    class Surface : public BnSurface  {
    public:
        int32_t getToken() const { return mToken; }
        int32_t getIdentity() const { return mIdentity; }
        
    protected:
        Surface(const sp<SurfaceFlinger>& flinger, 
                SurfaceID id, int identity, 
        Surface(const sp<SurfaceFlinger>& flinger, int identity,
                const sp<LayerBaseClient>& owner);
        virtual ~Surface();
        virtual status_t onTransact(uint32_t code, const Parcel& data,
@@ -313,7 +306,6 @@ public:
    protected:
        friend class LayerBaseClient;
        sp<SurfaceFlinger>  mFlinger;
        int32_t             mToken;
        int32_t             mIdentity;
        wp<LayerBaseClient> mOwner;
    };
@@ -324,12 +316,16 @@ protected:
    virtual void dump(String8& result, char* scratch, size_t size) const;

private:
    int32_t         mIndex;
    mutable Mutex mLock;
    mutable wp<Surface> mClientSurface;
    // only read
    const uint32_t mIdentity;
    static int32_t sIdentity;

    // TODO: get rid of this
public:
    virtual void setToken(int32_t token) { }
    virtual int32_t getToken() const { return -1; }
};

// ---------------------------------------------------------------------------
Loading