diff --git a/libs/gui/IProducerListener.cpp b/libs/gui/IProducerListener.cpp index 0683087211..846eeaf8ab 100644 --- a/libs/gui/IProducerListener.cpp +++ b/libs/gui/IProducerListener.cpp @@ -25,6 +25,8 @@ enum { ON_BUFFER_RELEASED = IBinder::FIRST_CALL_TRANSACTION, NEEDS_RELEASE_NOTIFY, ON_BUFFERS_DISCARDED, + // MIUI ADD + ON_BUFFER_DETACHED, }; class BpProducerListener : public BpInterface @@ -64,6 +66,15 @@ class BpProducerListener : public BpInterface data.writeInt32Vector(discardedSlots); remote()->transact(ON_BUFFERS_DISCARDED, data, &reply, IBinder::FLAG_ONEWAY); } + + // MIUI ADD: START + virtual void onBufferDetached(int slot) { + Parcel data, reply; + data.writeInterfaceToken(IProducerListener::getInterfaceDescriptor()); + data.writeInt32(slot); + remote()->transact(ON_BUFFER_DETACHED, data, &reply, IBinder::FLAG_ONEWAY); + } + // MIUI ADD: END }; // Out-of-line virtual method definition to trigger vtable emission in this @@ -88,6 +99,12 @@ class HpProducerListener : public HpInterface< virtual void onBuffersDiscarded(const std::vector& discardedSlots) override { return mBase->onBuffersDiscarded(discardedSlots); } + + // MIUI ADD: START + virtual void onBufferDetached(int slot) { + mBase->onBufferDetached(slot); + } + // MIUI ADD: END }; IMPLEMENT_HYBRID_META_INTERFACE(ProducerListener, @@ -115,6 +132,14 @@ status_t BnProducerListener::onTransact(uint32_t code, const Parcel& data, onBuffersDiscarded(discardedSlots); return NO_ERROR; } + // MIUI ADD: START + case ON_BUFFER_DETACHED: + int slot = 0; + CHECK_INTERFACE(IProducerListener, data, reply); + data.readInt32(&slot); + onBufferDetached(slot); + return NO_ERROR; + // MIUI ADD: END } return BBinder::onTransact(code, data, reply, flags); } @@ -128,4 +153,9 @@ bool BnProducerListener::needsReleaseNotify() { void BnProducerListener::onBuffersDiscarded(const std::vector& /*discardedSlots*/) { } +// MIUI ADD: START +void BnProducerListener::onBufferDetached(int slot) { + ALOGE("BnProducerListener::onBufferDetached slot: %d",slot); +} +// MIUI ADD: END } // namespace android diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 4c8079265a..e2bbfb5d46 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1958,6 +1958,19 @@ int Surface::disconnect(int api, IGraphicBufferProducer::DisconnectMode mode) { return err; } +// MIUI ADD: START +void Surface::releaseSlot(int slot) { + Mutex::Autolock lock(mMutex); + if(mDequeuedSlots.count(slot) <= 0) { + ALOGV("Surface releaseSlot %d",slot); + if (mReportRemovedBuffers && (mSlots[slot].buffer != nullptr)) { + mRemovedBuffers.push_back(mSlots[slot].buffer); + } + mSlots[slot].buffer = nullptr; + } +} +// MIUI ADD: END + int Surface::detachNextBuffer(sp* outBuffer, sp* outFence) { ATRACE_CALL(); diff --git a/libs/gui/bufferqueue/1.0/WProducerListener.cpp b/libs/gui/bufferqueue/1.0/WProducerListener.cpp index 56b64b9ddd..c578a4fe54 100644 --- a/libs/gui/bufferqueue/1.0/WProducerListener.cpp +++ b/libs/gui/bufferqueue/1.0/WProducerListener.cpp @@ -49,4 +49,9 @@ bool LWProducerListener::needsReleaseNotify() { void LWProducerListener::onBuffersDiscarded(const std::vector& /*slots*/) { } +// MIUI ADD: START +void LWProducerListener::onBufferDetached(int /*slot*/) { +} +// MIUI ADD: END + } // namespace android diff --git a/libs/gui/bufferqueue/2.0/H2BProducerListener.cpp b/libs/gui/bufferqueue/2.0/H2BProducerListener.cpp index b2bd1172d6..e4e7df44e6 100644 --- a/libs/gui/bufferqueue/2.0/H2BProducerListener.cpp +++ b/libs/gui/bufferqueue/2.0/H2BProducerListener.cpp @@ -55,6 +55,11 @@ bool H2BProducerListener::needsReleaseNotify() { void H2BProducerListener::onBuffersDiscarded(const std::vector& /*slots*/) { } +// MIUI ADD: START +void H2BProducerListener::onBufferDetached(int /*slot*/) { +} +// MIUI ADD: END + } // namespace utils } // namespace V2_0 } // namespace bufferqueue diff --git a/libs/gui/include/gui/IProducerListener.h b/libs/gui/include/gui/IProducerListener.h index f7ffbb99ea..44b44517b3 100644 --- a/libs/gui/include/gui/IProducerListener.h +++ b/libs/gui/include/gui/IProducerListener.h @@ -49,6 +49,9 @@ class ProducerListener : public virtual RefBase // onBuffersFreed is called from IGraphicBufferConsumer::discardFreeBuffers // to notify the producer that certain free buffers are discarded by the consumer. virtual void onBuffersDiscarded(const std::vector& slots) = 0; // Asynchronous + + // MIUI ADD + virtual void onBufferDetached(int slot) = 0; }; #ifndef NO_BINDER @@ -72,6 +75,8 @@ class BnProducerListener : public BnInterface Parcel* reply, uint32_t flags = 0); virtual bool needsReleaseNotify(); virtual void onBuffersDiscarded(const std::vector& slots); + // MIUI ADD + virtual void onBufferDetached(int slot); }; #else @@ -85,6 +90,8 @@ class StubProducerListener : public BnProducerListener { virtual ~StubProducerListener(); virtual void onBufferReleased() {} virtual bool needsReleaseNotify() { return false; } + // MIUI ADD + virtual void onBufferDetached(int /**slot**/) {} }; } // namespace android diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h index 8d4e15bb40..2f4c6effde 100644 --- a/libs/gui/include/gui/Surface.h +++ b/libs/gui/include/gui/Surface.h @@ -54,6 +54,11 @@ class SurfaceListener : public virtual RefBase virtual bool needsReleaseNotify() = 0; virtual void onBuffersDiscarded(const std::vector>& buffers) = 0; + // MIUI ADD: START + virtual void onBufferDetached(int /**slot**/) { + //default do nothing + } + // MIUI ADD: END }; /* @@ -333,6 +338,8 @@ class Surface bool reportBufferRemoval); virtual int detachNextBuffer(sp* outBuffer, sp* outFence); + // MIUI ADD + virtual void releaseSlot(int slot); virtual int attachBuffer(ANativeWindowBuffer*); virtual int connect( @@ -388,6 +395,12 @@ class Surface } virtual void onBuffersDiscarded(const std::vector& slots); + + // MIUI ADD: START + virtual void onBufferDetached(int slot) { + mSurfaceListener->onBufferDetached(slot); + } + // MIUI ADD: END private: wp mParent; sp mSurfaceListener; diff --git a/libs/gui/include/gui/bufferqueue/1.0/WProducerListener.h b/libs/gui/include/gui/bufferqueue/1.0/WProducerListener.h index 197db26444..1f18b4b3be 100644 --- a/libs/gui/include/gui/bufferqueue/1.0/WProducerListener.h +++ b/libs/gui/include/gui/bufferqueue/1.0/WProducerListener.h @@ -55,6 +55,8 @@ class LWProducerListener : public BnProducerListener { void onBufferReleased() override; bool needsReleaseNotify() override; void onBuffersDiscarded(const std::vector& slots) override; + // MIUI ADD + void onBufferDetached(int slot) override; }; } // namespace android diff --git a/libs/gui/include/gui/bufferqueue/2.0/H2BProducerListener.h b/libs/gui/include/gui/bufferqueue/2.0/H2BProducerListener.h index 92650b701b..47360f69b4 100644 --- a/libs/gui/include/gui/bufferqueue/2.0/H2BProducerListener.h +++ b/libs/gui/include/gui/bufferqueue/2.0/H2BProducerListener.h @@ -47,6 +47,8 @@ class H2BProducerListener virtual void onBufferReleased() override; virtual bool needsReleaseNotify() override; virtual void onBuffersDiscarded(const std::vector& slots) override; + // MIUI ADD + virtual void onBufferDetached(int slot) override; }; } // namespace utils