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

Commit 6a647865 authored by Rob Carr's avatar Rob Carr Committed by Android (Google) Code Review
Browse files

Merge "SurfaceControl: C++ Binding Lifetime refactoring"

parents a8f091ec 0e328f6a
Loading
Loading
Loading
Loading
+2 −17
Original line number Diff line number Diff line
@@ -526,21 +526,6 @@ void SurfaceComposerClient::Transaction::clear() {
    mDesiredPresentTime = -1;
}

void SurfaceComposerClient::doDropReferenceTransaction(const sp<IBinder>& handle) {
    sp<ISurfaceComposer> sf(ComposerService::getComposerService());
    Vector<ComposerState> composerStates;
    Vector<DisplayState> displayStates;

    ComposerState s;
    s.state.surface = handle;
    s.state.what |= layer_state_t::eReparent;
    s.state.parentHandleForChild = nullptr;

    composerStates.add(s);
    sp<IBinder> applyToken = IInterface::asBinder(TransactionCompletedListener::getIInstance());
    sf->setTransactionState(composerStates, displayStates, 0, applyToken, {}, -1, {}, false, {});
}

void SurfaceComposerClient::doUncacheBufferTransaction(uint64_t cacheId) {
    sp<ISurfaceComposer> sf(ComposerService::getComposerService());

@@ -1558,7 +1543,7 @@ sp<SurfaceControl> SurfaceComposerClient::createWithSurfaceParent(const String8&
        }
        ALOGE_IF(err, "SurfaceComposerClient::createWithSurfaceParent error %s", strerror(-err));
        if (err == NO_ERROR) {
            return new SurfaceControl(this, handle, gbp, true /* owned */, transformHint);
            return new SurfaceControl(this, handle, gbp, transformHint);
        }
    }
    return nullptr;
@@ -1589,7 +1574,7 @@ status_t SurfaceComposerClient::createSurfaceChecked(const String8& name, uint32
        }
        ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err));
        if (err == NO_ERROR) {
            *outSurface = new SurfaceControl(this, handle, gbp, true /* owned */, transformHint);
            *outSurface = new SurfaceControl(this, handle, gbp, transformHint);
        }
    }
    return err;
+2 −15
Original line number Diff line number Diff line
@@ -46,33 +46,21 @@ namespace android {
// ============================================================================

SurfaceControl::SurfaceControl(const sp<SurfaceComposerClient>& client, const sp<IBinder>& handle,
                               const sp<IGraphicBufferProducer>& gbp, bool owned,
                               const sp<IGraphicBufferProducer>& gbp,
                               uint32_t transform)
      : mClient(client),
        mHandle(handle),
        mGraphicBufferProducer(gbp),
        mOwned(owned),
        mTransformHint(transform) {}

SurfaceControl::SurfaceControl(const sp<SurfaceControl>& other) {
    mClient = other->mClient;
    mHandle = other->mHandle;
    mGraphicBufferProducer = other->mGraphicBufferProducer;
    mOwned = false;
    mTransformHint = other->mTransformHint;
}

SurfaceControl::~SurfaceControl()
{
    // Avoid reparenting the server-side surface to null if we are not the owner of it,
    // meaning that we retrieved it from another process.
    if (mHandle != nullptr && mOwned) {
        SurfaceComposerClient::doDropReferenceTransaction(mHandle);
    }
    release();
}

void SurfaceControl::release()
{
    // Trigger an IPC now, to make sure things
    // happen without delay, since these resources are quite heavy.
@@ -157,7 +145,6 @@ sp<Surface> SurfaceControl::createSurface() const

sp<IBinder> SurfaceControl::getHandle() const
{
    Mutex::Autolock lock(mLock);
    return mHandle;
}

@@ -206,7 +193,7 @@ sp<SurfaceControl> SurfaceControl::readFromParcel(const Parcel* parcel) {
    return new SurfaceControl(new SurfaceComposerClient(
                                      interface_cast<ISurfaceComposerClient>(client)),
                              handle.get(), interface_cast<IGraphicBufferProducer>(gbp),
                              false /* owned */, transformHint);
                               transformHint);
}

// ----------------------------------------------------------------------------
+0 −6
Original line number Diff line number Diff line
@@ -183,12 +183,6 @@ public:
     */
    static bool getProtectedContentSupport();

    /**
     * Called from SurfaceControl d'tor to 'destroy' the surface (or rather, reparent it
     * to null), but without needing an sp<SurfaceControl> to avoid infinite ressurection.
     */
    static void doDropReferenceTransaction(const sp<IBinder>& handle);

    /**
     * Uncaches a buffer in ISurfaceComposer. It must be uncached via a transaction so that it is
     * in order with other transactions that use buffers.
+1 −6
Original line number Diff line number Diff line
@@ -58,10 +58,6 @@ public:
    static bool isSameSurface(
            const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);

    // Release the handles assosciated with the SurfaceControl, without reparenting
    // them off-screen. At the moment if this isn't executed before ~SurfaceControl
    // is called then the destructor will reparent the layer off-screen for you.
    void        release();
    // Reparent off-screen and release. This is invoked by the destructor.
    void destroy();

@@ -89,7 +85,7 @@ public:
    explicit SurfaceControl(const sp<SurfaceControl>& other);

    SurfaceControl(const sp<SurfaceComposerClient>& client, const sp<IBinder>& handle,
                   const sp<IGraphicBufferProducer>& gbp, bool owned, uint32_t transformHint = 0);
                   const sp<IGraphicBufferProducer>& gbp, uint32_t transformHint = 0);

private:
    // can't be copied
@@ -109,7 +105,6 @@ private:
    sp<IGraphicBufferProducer>  mGraphicBufferProducer;
    mutable Mutex               mLock;
    mutable sp<Surface>         mSurfaceData;
    bool                        mOwned;
    uint32_t mTransformHint;
};

+2 −1
Original line number Diff line number Diff line
@@ -92,7 +92,8 @@ TEST_P(LayerTypeAndRenderTypeTransactionTest, SetRelativeZBug64572777) {
            .setRelativeLayer(layerG, layerR->getHandle(), 1)
            .apply();

    layerG.clear();
    Transaction().reparent(layerG, nullptr).apply();

    // layerG should have been removed
    getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED);
}
Loading