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

Commit 5657c010 authored by Simon Wilson's avatar Simon Wilson Committed by Android (Google) Code Review
Browse files

Merge changes I37f0f315,I8cbf6044,Ibb598931,I5262bf11 into gingerbread

* changes:
  Fix a race that could cause GL commands to be executed from the wrong thread.
  RefBase subclasses can now decide how they want to be destroyed.
  Fix a race in SurfaceFlinger that could cause layers to be leaked forever.
  Fix a race-condtion in SurfaceFlinger that could lead to a crash.
parents 8949eaba b4081bb5
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -116,6 +116,13 @@ protected:
                            RefBase();
    virtual                 ~RefBase();

    // called when the last reference goes away. this is responsible for
    // calling the destructor. The default implementation just does
    // "delete this;".
    // Make sure to never acquire a strong reference from this function. The
    // same restrictions than for destructors apply.
    virtual void            destroy() const;

    //! Flags for extendObjectLifetime()
    enum {
        OBJECT_LIFETIME_WEAK    = 0x0001,
+9 −3
Original line number Diff line number Diff line
@@ -298,6 +298,10 @@ void RefBase::incStrong(const void* id) const
    const_cast<RefBase*>(this)->onFirstRef();
}

void RefBase::destroy() const {
    delete this;
}

void RefBase::decStrong(const void* id) const
{
    weakref_impl* const refs = mRefs;
@@ -310,7 +314,7 @@ void RefBase::decStrong(const void* id) const
    if (c == 1) {
        const_cast<RefBase*>(this)->onLastStrongRef(id);
        if ((refs->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
            delete this;
            destroy();
        }
    }
    refs->removeWeakRef(id);
@@ -370,7 +374,8 @@ void RefBase::weakref_type::decWeak(const void* id)
    
    if ((impl->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
        if (impl->mStrong == INITIAL_STRONG_VALUE)
            delete impl->mBase;
            if (impl->mBase)
                impl->mBase->destroy();
        else {
//            LOGV("Freeing refs %p of old RefBase %p\n", this, impl->mBase);
            delete impl;
@@ -378,7 +383,8 @@ void RefBase::weakref_type::decWeak(const void* id)
    } else {
        impl->mBase->onLastWeakRef(id);
        if ((impl->mFlags&OBJECT_LIFETIME_FOREVER) != OBJECT_LIFETIME_FOREVER) {
            delete impl->mBase;
            if (impl->mBase)
                impl->mBase->destroy();
        }
    }
}
+4 −16
Original line number Diff line number Diff line
@@ -76,6 +76,10 @@ Layer::~Layer()
    }
}

void Layer::destroy() const {
    mFlinger->destroyLayer(this);
}

status_t Layer::setToken(const sp<UserClient>& userClient,
        SharedClient* sharedClient, int32_t token)
{
@@ -123,22 +127,6 @@ sp<LayerBaseClient::Surface> Layer::createSurface() const
    return mSurface;
}

status_t Layer::ditch()
{
    // NOTE: Called from the main UI thread

    // the layer is not on screen anymore. free as much resources as possible
    mFreezeLock.clear();

    EGLDisplay dpy(mFlinger->graphicPlane(0).getEGLDisplay());
    mBufferManager.destroy(dpy);
    mSurface.clear();

    Mutex::Autolock _l(mLock);
    mWidth = mHeight = 0;
    return NO_ERROR;
}

status_t Layer::setBuffers( uint32_t w, uint32_t h,
                            PixelFormat format, uint32_t flags)
{
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,6 @@ public:
    virtual bool needsFiltering() const;
    virtual bool isSecure() const           { return mSecure; }
    virtual sp<Surface> createSurface() const;
    virtual status_t ditch();
    virtual void onRemoved();
    virtual bool setBypass(bool enable);

@@ -95,6 +94,7 @@ public:
        return mFreezeLock; }

protected:
    virtual void destroy() const;
    virtual void dump(String8& result, char* scratch, size_t size) const;

private:
+1 −4
Original line number Diff line number Diff line
@@ -583,10 +583,7 @@ LayerBaseClient::Surface::~Surface()
     */

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

sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const {
Loading