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

Commit 6cf0db22 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

more Surface lifetime management

Surfaces are now destroyed once all references from the clients are gone, but they go through a partial destruction as soon as the window manager requests it.
This last part is still buggy. see comments in SurfaceFlinger::destroySurface()
parent 2b1927f6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -179,6 +179,7 @@ bool BootAnimation::threadLoop() {
    eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    eglDestroyContext(mDisplay, mContext);
    eglDestroySurface(mDisplay, mSurface);
    mFlingerSurface.clear();
    mFlingerSurfaceControl.clear();
    return r;
}
+14 −3
Original line number Diff line number Diff line
@@ -87,6 +87,12 @@ sp<LayerBaseClient::Surface> Layer::createSurface() const
    return mSurface;
}

status_t Layer::ditch()
{
    mSurface.clear();
    return NO_ERROR;
}

status_t Layer::setBuffers( Client* client,
                            uint32_t w, uint32_t h,
                            PixelFormat format, uint32_t flags)
@@ -119,7 +125,7 @@ status_t Layer::setBuffers( Client* client,
            return err;
        }
    }
    mSurface = new SurfaceLayer(clientIndex(), this);
    mSurface = new SurfaceLayer(mFlinger, clientIndex(), this);
    return NO_ERROR;
}

@@ -626,8 +632,13 @@ void Layer::finishPageFlip()

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

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

Layer::SurfaceLayer::~SurfaceLayer()
{
}

+4 −1
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ public:
    virtual bool needsBlending() const      { return mNeedsBlending; }
    virtual bool isSecure() const           { return mSecure; }
    virtual sp<Surface> createSurface() const;
    virtual status_t ditch();

    const LayerBitmap& getBuffer(int i) const { return mBuffers[i]; }
          LayerBitmap& getBuffer(int i)       { return mBuffers[i]; }
@@ -108,7 +109,9 @@ private:
    class SurfaceLayer : public LayerBaseClient::Surface
    {
    public:
                SurfaceLayer(SurfaceID id, const sp<Layer>& owner);
                SurfaceLayer(const sp<SurfaceFlinger>& flinger,
                        SurfaceID id, const sp<Layer>& owner);
                ~SurfaceLayer();

    private:
        virtual sp<SurfaceBuffer> getBuffer();
+17 −10
Original line number Diff line number Diff line
@@ -681,25 +681,32 @@ sp<LayerBaseClient::Surface> LayerBaseClient::getSurface()

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

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

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


LayerBaseClient::Surface::~Surface() {
    // TODO: We now have a point here were we can clean-up the
    // client's mess.
    // This is also where surface id should be recycled.
    //LOGD("Surface %d, heaps={%p, %p} destroyed",
    //        mId, mHeap[0].get(), mHeap[1].get());
LayerBaseClient::Surface::~Surface() 
{
    /*
     * This is a good place to clean-up all client resources 
     */

    // destroy client resources
    sp<LayerBaseClient> layer = getOwner();
    if (layer != 0) {
        mFlinger->destroySurface(layer);
    }
}

sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const {
+16 −8
Original line number Diff line number Diff line
@@ -203,10 +203,15 @@ public:

    /**
     * isSecure - true if this surface is secure, that is if it prevents
     * screenshots or vns servers.
     * screenshots or VNC servers.
     */
    virtual bool isSecure() const       { return false; }

    /** signal this layer that it's not needed any longer */
    virtual status_t ditch() { return NO_ERROR; }

    
    
    enum { // flags for doTransaction()
        eVisibleRegion      = 0x00000002,
        eRestartTransaction = 0x00000008
@@ -244,7 +249,7 @@ protected:
                  GLint textureName, const GGLSurface& t,
                  GLuint& textureWidth, GLuint& textureHeight) const;

                SurfaceFlinger* mFlinger;
                sp<SurfaceFlinger> mFlinger;
                uint32_t        mFlags;

                // cached during validateVisibility()
@@ -316,7 +321,9 @@ public:
                ISurfaceFlingerClient::surface_data_t* params) const;

    protected:
        Surface(SurfaceID id, int identity, const sp<LayerBaseClient>& owner);
        Surface(const sp<SurfaceFlinger>& flinger, 
                SurfaceID id, int identity, 
                const sp<LayerBaseClient>& owner);
        virtual ~Surface();
        virtual status_t onTransact(uint32_t code, const Parcel& data,
                Parcel* reply, uint32_t flags);
@@ -330,8 +337,9 @@ public:
        virtual sp<OverlayRef> createOverlay(uint32_t w, uint32_t h,
                int32_t format);

    private:
    protected:
        friend class LayerBaseClient;
        sp<SurfaceFlinger>  mFlinger;
        int32_t             mToken;
        int32_t             mIdentity;
        wp<LayerBaseClient> mOwner;
Loading