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

Commit 29b4582f authored by Mathias Agopian's avatar Mathias Agopian Committed by Android (Google) Code Review
Browse files

Merge "SurfaceFlinger doesn't rely on having a custom RefBase destructor"

parents 4007fcac 47d08129
Loading
Loading
Loading
Loading
+10 −6
Original line number Original line Diff line number Diff line
@@ -65,14 +65,9 @@ Layer::Layer(SurfaceFlinger* flinger,
    glGenTextures(1, &mTextureName);
    glGenTextures(1, &mTextureName);
}
}


void Layer::destroy(RefBase const* base) {
    mFlinger->destroyLayer(static_cast<LayerBase const*>(base));
}

void Layer::onFirstRef()
void Layer::onFirstRef()
{
{
    LayerBaseClient::onFirstRef();
    LayerBaseClient::onFirstRef();
    setDestroyer(this);


    struct FrameQueuedListener : public SurfaceTexture::FrameAvailableListener {
    struct FrameQueuedListener : public SurfaceTexture::FrameAvailableListener {
        FrameQueuedListener(Layer* layer) : mLayer(layer) { }
        FrameQueuedListener(Layer* layer) : mLayer(layer) { }
@@ -93,7 +88,16 @@ void Layer::onFirstRef()


Layer::~Layer()
Layer::~Layer()
{
{
    glDeleteTextures(1, &mTextureName);
    class MessageDestroyGLState : public MessageBase {
        GLuint texture;
    public:
        MessageDestroyGLState(GLuint texture) : texture(texture) { }
        virtual bool handler() {
            glDeleteTextures(1, &texture);
            return true;
        }
    };
    mFlinger->postMessageAsync( new MessageDestroyGLState(mTextureName) );
}
}


void Layer::onFrameQueued() {
void Layer::onFrameQueued() {
+1 −2
Original line number Original line Diff line number Diff line
@@ -45,7 +45,7 @@ class GLExtensions;


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


class Layer : public LayerBaseClient, private RefBase::Destroyer
class Layer : public LayerBaseClient
{
{
public:
public:
            Layer(SurfaceFlinger* flinger, DisplayID display,
            Layer(SurfaceFlinger* flinger, DisplayID display,
@@ -78,7 +78,6 @@ public:
    inline const sp<FreezeLock>&  getFreezeLock() const { return mFreezeLock; }
    inline const sp<FreezeLock>&  getFreezeLock() const { return mFreezeLock; }


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


+0 −28
Original line number Original line Diff line number Diff line
@@ -402,9 +402,6 @@ bool SurfaceFlinger::threadLoop()
{
{
    waitForEvent();
    waitForEvent();


    // call Layer's destructor
    handleDestroyLayers();

    // check for transactions
    // check for transactions
    if (UNLIKELY(mConsoleSignals)) {
    if (UNLIKELY(mConsoleSignals)) {
        handleConsoleEvents();
        handleConsoleEvents();
@@ -597,31 +594,6 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
    commitTransaction();
    commitTransaction();
}
}


void SurfaceFlinger::destroyLayer(LayerBase const* layer)
{
    Mutex::Autolock _l(mDestroyedLayerLock);
    mDestroyedLayers.add(layer);
    signalEvent();
}

void SurfaceFlinger::handleDestroyLayers()
{
    Vector<LayerBase const *> destroyedLayers;

    { // scope for the lock
        Mutex::Autolock _l(mDestroyedLayerLock);
        destroyedLayers = mDestroyedLayers;
        mDestroyedLayers.clear();
    }

    // call destructors without a lock held
    const size_t count = destroyedLayers.size();
    for (size_t i=0 ; i<count ; i++) {
        //LOGD("destroying %s", destroyedLayers[i]->getName().string());
        delete destroyedLayers[i];
    }
}

sp<FreezeLock> SurfaceFlinger::getFreezeLock() const
sp<FreezeLock> SurfaceFlinger::getFreezeLock() const
{
{
    return new FreezeLock(const_cast<SurfaceFlinger *>(this));
    return new FreezeLock(const_cast<SurfaceFlinger *>(this));
+0 −2
Original line number Original line Diff line number Diff line
@@ -189,7 +189,6 @@ public:
    status_t addLayer(const sp<LayerBase>& layer);
    status_t addLayer(const sp<LayerBase>& layer);
    status_t invalidateLayerVisibility(const sp<LayerBase>& layer);
    status_t invalidateLayerVisibility(const sp<LayerBase>& layer);
    void invalidateHwcGeometry();
    void invalidateHwcGeometry();
    void destroyLayer(LayerBase const* layer);


    sp<Layer> getLayer(const sp<ISurface>& sur) const;
    sp<Layer> getLayer(const sp<ISurface>& sur) const;


@@ -266,7 +265,6 @@ private:
            void        handleConsoleEvents();
            void        handleConsoleEvents();
            void        handleTransaction(uint32_t transactionFlags);
            void        handleTransaction(uint32_t transactionFlags);
            void        handleTransactionLocked(uint32_t transactionFlags);
            void        handleTransactionLocked(uint32_t transactionFlags);
            void        handleDestroyLayers();


            void        computeVisibleRegions(
            void        computeVisibleRegions(
                            const LayerVector& currentLayers,
                            const LayerVector& currentLayers,