Loading libs/gui/ISurfaceComposer.cpp +5 −31 Original line number Diff line number Diff line Loading @@ -60,21 +60,12 @@ public: status_t setTransactionState(const SimpleTransactionState simpleState, const ComplexTransactionState& complexState, Vector<ComposerState>& state, Vector<DisplayState>& displays, MutableTransactionState& mutableState, const sp<IBinder>& applyToken) override { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size())); for (const auto& s : state) { SAFE_PARCEL(s.write, data); } SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size())); for (const auto& d : displays) { SAFE_PARCEL(d.write, data); } SAFE_PARCEL(mutableState.writeToParcel, &data); SAFE_PARCEL(simpleState.writeToParcel, &data); SAFE_PARCEL(complexState.writeToParcel, &data); SAFE_PARCEL(data.writeStrongBinder, applyToken); Loading Loading @@ -102,25 +93,8 @@ status_t BnSurfaceComposer::onTransact(uint32_t code, const Parcel& data, Parcel case SET_TRANSACTION_STATE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); uint32_t count = 0; SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize()); Vector<ComposerState> state; state.setCapacity(count); for (size_t i = 0; i < count; i++) { ComposerState s; SAFE_PARCEL(s.read, data); state.add(s); } SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize()); DisplayState d; Vector<DisplayState> displays; displays.setCapacity(count); for (size_t i = 0; i < count; i++) { SAFE_PARCEL(d.read, data); displays.add(d); } MutableTransactionState mutableState; SAFE_PARCEL(mutableState.readFromParcel, &data); SimpleTransactionState simpleState; SAFE_PARCEL(simpleState.readFromParcel, &data); ComplexTransactionState complexState; Loading @@ -129,7 +103,7 @@ status_t BnSurfaceComposer::onTransact(uint32_t code, const Parcel& data, Parcel sp<IBinder> applyToken; SAFE_PARCEL(data.readStrongBinder, &applyToken); return setTransactionState(simpleState, complexState, state, displays, applyToken); return setTransactionState(simpleState, complexState, mutableState, applyToken); } case GET_SCHEDULING_POLICY: { gui::SchedulingPolicy policy; Loading libs/gui/SurfaceComposerClient.cpp +16 −105 Original line number Diff line number Diff line Loading @@ -831,17 +831,16 @@ SurfaceComposerClient::Transaction::Transaction() { SurfaceComposerClient::Transaction::Transaction(const Transaction& other) : mSimpleState(other.mSimpleState), mComplexState(other.mComplexState), mMutableState(other.mMutableState), mMayContainBuffer(other.mMayContainBuffer), mApplyToken(other.mApplyToken) { mDisplayStates = other.mDisplayStates; mComposerStates = other.mComposerStates; mListenerCallbacks = other.mListenerCallbacks; mTransactionCompletedListener = TransactionCompletedListener::getInstance(); } void SurfaceComposerClient::Transaction::sanitize(int pid, int uid) { uint32_t permissions = LayerStatePermissions::getTransactionPermissions(pid, uid); for (auto& composerState : mComposerStates) { for (auto& composerState : mMutableState.mComposerStates) { composerState.state.sanitize(permissions); } if (!mComplexState.mInputWindowCommands.empty() && Loading @@ -865,6 +864,8 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel SAFE_PARCEL(simpleState.readFromParcel, parcel); ComplexTransactionState complexState; SAFE_PARCEL(complexState.readFromParcel, parcel); MutableTransactionState mutableState; SAFE_PARCEL(mutableState.readFromParcel, parcel); const bool logCallPoints = parcel->readBool(); sp<IBinder> applyToken; Loading @@ -873,20 +874,6 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel if (count > parcel->dataSize()) { return BAD_VALUE; } Vector<DisplayState> displayStates; displayStates.setCapacity(count); for (size_t i = 0; i < count; i++) { DisplayState displayState; if (displayState.read(*parcel) == BAD_VALUE) { return BAD_VALUE; } displayStates.add(displayState); } count = static_cast<size_t>(parcel->readUint32()); if (count > parcel->dataSize()) { return BAD_VALUE; } std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> listenerCallbacks; listenerCallbacks.reserve(count); for (size_t i = 0; i < count; i++) { Loading @@ -912,26 +899,11 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel } } count = static_cast<size_t>(parcel->readUint32()); if (count > parcel->dataSize()) { return BAD_VALUE; } Vector<ComposerState> composerStates; composerStates.setCapacity(count); for (size_t i = 0; i < count; i++) { ComposerState composerState; if (composerState.read(*parcel) == BAD_VALUE) { return BAD_VALUE; } composerStates.add(composerState); } // Parsing was successful. Update the object. mSimpleState = std::move(simpleState); mComplexState = std::move(complexState); mDisplayStates = std::move(displayStates); mMutableState = std::move(mutableState); mListenerCallbacks = listenerCallbacks; mComposerStates = std::move(composerStates); mApplyToken = applyToken; return NO_ERROR; } Loading @@ -952,12 +924,9 @@ status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const SAFE_PARCEL(mSimpleState.writeToParcel, parcel); SAFE_PARCEL(mComplexState.writeToParcel, parcel); SAFE_PARCEL(mMutableState.writeToParcel, parcel); parcel->writeBool(mLogCallPoints); parcel->writeStrongBinder(mApplyToken); parcel->writeUint32(static_cast<uint32_t>(mDisplayStates.size())); for (auto const& displayState : mDisplayStates) { displayState.write(*parcel); } parcel->writeUint32(static_cast<uint32_t>(mListenerCallbacks.size())); for (auto const& [listener, callbackInfo] : mListenerCallbacks) { Loading @@ -972,11 +941,6 @@ status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const } } parcel->writeUint32(static_cast<uint32_t>(mComposerStates.size())); for (auto const& composerState : mComposerStates) { composerState.write(*parcel); } return NO_ERROR; } Loading @@ -1001,34 +965,6 @@ void SurfaceComposerClient::Transaction::releaseBufferIfOverwriting(const layer_ } SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Transaction&& other) { for (auto const& otherState : other.mComposerStates) { if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(), [&otherState](const auto& composerState) { return composerState.state.surface == otherState.state.surface; }); it != mComposerStates.end()) { if (otherState.state.what & layer_state_t::eBufferChanged) { releaseBufferIfOverwriting(it->state); } it->state.merge(otherState.state); } else { mComposerStates.add(otherState); } } for (auto const& state : other.mDisplayStates) { if (auto it = std::find_if(mDisplayStates.begin(), mDisplayStates.end(), [&state](const auto& displayState) { return displayState.token == state.token; }); it != mDisplayStates.end()) { it->merge(state); } else { mDisplayStates.add(state); } } for (const auto& [listener, callbackInfo] : other.mListenerCallbacks) { auto& [callbackIds, surfaceControls] = callbackInfo; mListenerCallbacks[listener].callbackIds.insert(std::make_move_iterator( Loading Loading @@ -1056,6 +992,8 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr mComplexState.merge(other.mComplexState); mComplexState.mMergedTransactionIds.insert(mComplexState.mMergedTransactionIds.begin(), other.mSimpleState.mId); mMutableState.merge(other.mMutableState, [this](const auto& state) { releaseBufferIfOverwriting(state); }); mMayContainBuffer |= other.mMayContainBuffer; mApplyToken = other.mApplyToken; Loading @@ -1074,8 +1012,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr void SurfaceComposerClient::Transaction::clear() { mSimpleState.clear(); mComplexState.clear(); mComposerStates.clear(); mDisplayStates.clear(); mMutableState.clear(); mListenerCallbacks.clear(); mMayContainBuffer = false; mApplyToken = nullptr; Loading @@ -1098,12 +1035,11 @@ void SurfaceComposerClient::doUncacheBufferTransaction(uint64_t cacheId) { uncacheBuffer.token = BufferCache::getInstance().getToken(); uncacheBuffer.id = cacheId; complexState.mUncacheBuffers.emplace_back(std::move(uncacheBuffer)); Vector<ComposerState> composerStates; Vector<DisplayState> displayStates; MutableTransactionState mutableState; status_t status = sf->setTransactionState(SimpleTransactionState(generateId(), ISurfaceComposer::eOneWay, systemTime(), true), complexState, composerStates, displayStates, complexState, mutableState, Transaction::getDefaultApplyToken()); if (status != NO_ERROR) { ALOGE_AND_TRACE("SurfaceComposerClient::doUncacheBufferTransaction - %s", Loading @@ -1117,7 +1053,7 @@ void SurfaceComposerClient::Transaction::cacheBuffers() { } size_t count = 0; for (auto& cs : mComposerStates) { for (auto& cs : mMutableState.mComposerStates) { layer_state_t* s = &cs.state; if (!(s->what & layer_state_t::eBufferChanged)) { continue; Loading Loading @@ -1264,8 +1200,8 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay sp<IBinder> applyToken = mApplyToken ? mApplyToken : getDefaultApplyToken(); sp<ISurfaceComposer> sf(ComposerService::getComposerService()); status_t binderStatus = sf->setTransactionState(mSimpleState, mComplexState, mComposerStates, mDisplayStates, applyToken); status_t binderStatus = sf->setTransactionState(mSimpleState, mComplexState, mMutableState, applyToken); mSimpleState.mId = generateId(); // Clear the current states and flags Loading Loading @@ -1386,22 +1322,7 @@ void SurfaceComposerClient::Transaction::setEarlyWakeupEnd(gui::EarlyWakeupInfo } layer_state_t* SurfaceComposerClient::Transaction::getLayerState(const sp<SurfaceControl>& sc) { auto handle = sc->getLayerStateHandle(); if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(), [&handle](const auto& composerState) { return composerState.state.surface == handle; }); it != mComposerStates.end()) { return &it->state; } // we don't have it, add an initialized layer_state to our list ComposerState s; s.state.surface = handle; s.state.layerId = sc->getLayerId(); mComposerStates.add(s); return &mComposerStates.editItemAt(mComposerStates.size() - 1).state; return mMutableState.getLayerState(sc); } void SurfaceComposerClient::Transaction::registerSurfaceControlForCallback( Loading Loading @@ -2446,17 +2367,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setConte // --------------------------------------------------------------------------- DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) { if (auto it = std::find_if(mDisplayStates.begin(), mDisplayStates.end(), [token](const auto& display) { return display.token == token; }); it != mDisplayStates.end()) { return *it; } // If display state doesn't exist, add a new one. DisplayState s; s.token = token; mDisplayStates.add(s); return mDisplayStates.editItemAt(mDisplayStates.size() - 1); return mMutableState.getDisplayState(token); } status_t SurfaceComposerClient::Transaction::setDisplaySurface( Loading libs/gui/TransactionState.cpp +105 −0 Original line number Diff line number Diff line Loading @@ -136,6 +136,41 @@ status_t ComplexTransactionState::readFromParcel(const Parcel* parcel) { return NO_ERROR; } status_t MutableTransactionState::writeToParcel(Parcel* parcel) const { SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mComposerStates.size())); for (const auto& s : mComposerStates) { SAFE_PARCEL(s.write, *parcel); } SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mDisplayStates.size())); for (const auto& d : mDisplayStates) { SAFE_PARCEL(d.write, *parcel); } return NO_ERROR; } status_t MutableTransactionState::readFromParcel(const Parcel* parcel) { uint32_t count = 0; SAFE_PARCEL_READ_SIZE(parcel->readUint32, &count, parcel->dataSize()); mComposerStates.setCapacity(count); for (size_t i = 0; i < count; i++) { ComposerState s; SAFE_PARCEL(s.read, *parcel); mComposerStates.add(s); } SAFE_PARCEL_READ_SIZE(parcel->readUint32, &count, parcel->dataSize()); DisplayState d; mDisplayStates.setCapacity(count); for (size_t i = 0; i < count; i++) { SAFE_PARCEL(d.read, *parcel); mDisplayStates.add(d); } return NO_ERROR; } status_t TransactionState::writeToParcel(Parcel* parcel) const { SAFE_PARCEL(mSimpleState.writeToParcel, parcel); SAFE_PARCEL(mComplexState.writeToParcel, parcel); Loading Loading @@ -217,6 +252,38 @@ void ComplexTransactionState::merge(ComplexTransactionState& other) { } } void MutableTransactionState::merge( const MutableTransactionState& other, const std::function<void(const layer_state_t&)>& onBufferOverwrite) { for (auto const& otherState : other.mComposerStates) { if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(), [&otherState](const auto& composerState) { return composerState.state.surface == otherState.state.surface; }); it != mComposerStates.end()) { if (otherState.state.what & layer_state_t::eBufferChanged) { onBufferOverwrite(it->state); } it->state.merge(otherState.state); } else { mComposerStates.add(otherState); } } for (auto const& state : other.mDisplayStates) { if (auto it = std::find_if(mDisplayStates.begin(), mDisplayStates.end(), [&state](const auto& displayState) { return displayState.token == state.token; }); it != mDisplayStates.end()) { it->merge(state); } else { mDisplayStates.add(state); } } } void TransactionState::merge(TransactionState&& other, const std::function<void(layer_state_t&)>& onBufferOverwrite) { mSimpleState.merge(other.mSimpleState); Loading Loading @@ -282,6 +349,11 @@ void ComplexTransactionState::clear() { mEarlyWakeupInfos.clear(); } void MutableTransactionState::clear() { mComposerStates.clear(); mDisplayStates.clear(); } void TransactionState::clear() { mSimpleState.clear(); mComplexState.clear(); Loading @@ -292,6 +364,25 @@ void TransactionState::clear() { mLogCallPoints = false; } layer_state_t* MutableTransactionState::getLayerState(const sp<SurfaceControl>& sc) { auto handle = sc->getLayerStateHandle(); if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(), [&handle](const auto& composerState) { return composerState.state.surface == handle; }); it != mComposerStates.end()) { return &it->state; } // we don't have it, add an initialized layer_state to our list ComposerState s; s.state.surface = handle; s.state.layerId = sc->getLayerId(); mComposerStates.add(s); return &mComposerStates.editItemAt(mComposerStates.size() - 1).state; } layer_state_t* TransactionState::getLayerState(const sp<SurfaceControl>& sc) { auto handle = sc->getLayerStateHandle(); if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(), Loading @@ -311,6 +402,20 @@ layer_state_t* TransactionState::getLayerState(const sp<SurfaceControl>& sc) { return &mComposerStates.back().state; } DisplayState& MutableTransactionState::getDisplayState(const sp<IBinder>& token) { if (auto it = std::find_if(mDisplayStates.begin(), mDisplayStates.end(), [token](const auto& display) { return display.token == token; }); it != mDisplayStates.end()) { return *it; } // If display state doesn't exist, add a new one. DisplayState s; s.token = token; mDisplayStates.add(s); return mDisplayStates.editItemAt(mDisplayStates.size() - 1); } DisplayState& TransactionState::getDisplayState(const sp<IBinder>& token) { if (auto it = std::find_if(mDisplayStates.begin(), mDisplayStates.end(), [token](const auto& display) { return display.token == token; }); Loading libs/gui/include/gui/ISurfaceComposer.h +2 −2 Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ class HdrCapabilities; class Rect; struct SimpleTransactionState; struct ComplexTransactionState; struct MutableTransactionState; using gui::FrameTimelineInfo; using gui::IDisplayEventConnection; Loading Loading @@ -110,8 +111,7 @@ public: /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */ virtual status_t setTransactionState(SimpleTransactionState simpleState, const ComplexTransactionState& complexState, Vector<ComposerState>& state, Vector<DisplayState>& displays, MutableTransactionState& mutableState, const sp<IBinder>& applyToken) = 0; }; Loading libs/gui/include/gui/SurfaceComposerClient.h +1 −2 Original line number Diff line number Diff line Loading @@ -474,8 +474,7 @@ public: bool mLogCallPoints = false; protected: Vector<ComposerState> mComposerStates; Vector<DisplayState> mDisplayStates; MutableTransactionState mMutableState; std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> mListenerCallbacks; Loading Loading
libs/gui/ISurfaceComposer.cpp +5 −31 Original line number Diff line number Diff line Loading @@ -60,21 +60,12 @@ public: status_t setTransactionState(const SimpleTransactionState simpleState, const ComplexTransactionState& complexState, Vector<ComposerState>& state, Vector<DisplayState>& displays, MutableTransactionState& mutableState, const sp<IBinder>& applyToken) override { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size())); for (const auto& s : state) { SAFE_PARCEL(s.write, data); } SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size())); for (const auto& d : displays) { SAFE_PARCEL(d.write, data); } SAFE_PARCEL(mutableState.writeToParcel, &data); SAFE_PARCEL(simpleState.writeToParcel, &data); SAFE_PARCEL(complexState.writeToParcel, &data); SAFE_PARCEL(data.writeStrongBinder, applyToken); Loading Loading @@ -102,25 +93,8 @@ status_t BnSurfaceComposer::onTransact(uint32_t code, const Parcel& data, Parcel case SET_TRANSACTION_STATE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); uint32_t count = 0; SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize()); Vector<ComposerState> state; state.setCapacity(count); for (size_t i = 0; i < count; i++) { ComposerState s; SAFE_PARCEL(s.read, data); state.add(s); } SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize()); DisplayState d; Vector<DisplayState> displays; displays.setCapacity(count); for (size_t i = 0; i < count; i++) { SAFE_PARCEL(d.read, data); displays.add(d); } MutableTransactionState mutableState; SAFE_PARCEL(mutableState.readFromParcel, &data); SimpleTransactionState simpleState; SAFE_PARCEL(simpleState.readFromParcel, &data); ComplexTransactionState complexState; Loading @@ -129,7 +103,7 @@ status_t BnSurfaceComposer::onTransact(uint32_t code, const Parcel& data, Parcel sp<IBinder> applyToken; SAFE_PARCEL(data.readStrongBinder, &applyToken); return setTransactionState(simpleState, complexState, state, displays, applyToken); return setTransactionState(simpleState, complexState, mutableState, applyToken); } case GET_SCHEDULING_POLICY: { gui::SchedulingPolicy policy; Loading
libs/gui/SurfaceComposerClient.cpp +16 −105 Original line number Diff line number Diff line Loading @@ -831,17 +831,16 @@ SurfaceComposerClient::Transaction::Transaction() { SurfaceComposerClient::Transaction::Transaction(const Transaction& other) : mSimpleState(other.mSimpleState), mComplexState(other.mComplexState), mMutableState(other.mMutableState), mMayContainBuffer(other.mMayContainBuffer), mApplyToken(other.mApplyToken) { mDisplayStates = other.mDisplayStates; mComposerStates = other.mComposerStates; mListenerCallbacks = other.mListenerCallbacks; mTransactionCompletedListener = TransactionCompletedListener::getInstance(); } void SurfaceComposerClient::Transaction::sanitize(int pid, int uid) { uint32_t permissions = LayerStatePermissions::getTransactionPermissions(pid, uid); for (auto& composerState : mComposerStates) { for (auto& composerState : mMutableState.mComposerStates) { composerState.state.sanitize(permissions); } if (!mComplexState.mInputWindowCommands.empty() && Loading @@ -865,6 +864,8 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel SAFE_PARCEL(simpleState.readFromParcel, parcel); ComplexTransactionState complexState; SAFE_PARCEL(complexState.readFromParcel, parcel); MutableTransactionState mutableState; SAFE_PARCEL(mutableState.readFromParcel, parcel); const bool logCallPoints = parcel->readBool(); sp<IBinder> applyToken; Loading @@ -873,20 +874,6 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel if (count > parcel->dataSize()) { return BAD_VALUE; } Vector<DisplayState> displayStates; displayStates.setCapacity(count); for (size_t i = 0; i < count; i++) { DisplayState displayState; if (displayState.read(*parcel) == BAD_VALUE) { return BAD_VALUE; } displayStates.add(displayState); } count = static_cast<size_t>(parcel->readUint32()); if (count > parcel->dataSize()) { return BAD_VALUE; } std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> listenerCallbacks; listenerCallbacks.reserve(count); for (size_t i = 0; i < count; i++) { Loading @@ -912,26 +899,11 @@ status_t SurfaceComposerClient::Transaction::readFromParcel(const Parcel* parcel } } count = static_cast<size_t>(parcel->readUint32()); if (count > parcel->dataSize()) { return BAD_VALUE; } Vector<ComposerState> composerStates; composerStates.setCapacity(count); for (size_t i = 0; i < count; i++) { ComposerState composerState; if (composerState.read(*parcel) == BAD_VALUE) { return BAD_VALUE; } composerStates.add(composerState); } // Parsing was successful. Update the object. mSimpleState = std::move(simpleState); mComplexState = std::move(complexState); mDisplayStates = std::move(displayStates); mMutableState = std::move(mutableState); mListenerCallbacks = listenerCallbacks; mComposerStates = std::move(composerStates); mApplyToken = applyToken; return NO_ERROR; } Loading @@ -952,12 +924,9 @@ status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const SAFE_PARCEL(mSimpleState.writeToParcel, parcel); SAFE_PARCEL(mComplexState.writeToParcel, parcel); SAFE_PARCEL(mMutableState.writeToParcel, parcel); parcel->writeBool(mLogCallPoints); parcel->writeStrongBinder(mApplyToken); parcel->writeUint32(static_cast<uint32_t>(mDisplayStates.size())); for (auto const& displayState : mDisplayStates) { displayState.write(*parcel); } parcel->writeUint32(static_cast<uint32_t>(mListenerCallbacks.size())); for (auto const& [listener, callbackInfo] : mListenerCallbacks) { Loading @@ -972,11 +941,6 @@ status_t SurfaceComposerClient::Transaction::writeToParcel(Parcel* parcel) const } } parcel->writeUint32(static_cast<uint32_t>(mComposerStates.size())); for (auto const& composerState : mComposerStates) { composerState.write(*parcel); } return NO_ERROR; } Loading @@ -1001,34 +965,6 @@ void SurfaceComposerClient::Transaction::releaseBufferIfOverwriting(const layer_ } SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Transaction&& other) { for (auto const& otherState : other.mComposerStates) { if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(), [&otherState](const auto& composerState) { return composerState.state.surface == otherState.state.surface; }); it != mComposerStates.end()) { if (otherState.state.what & layer_state_t::eBufferChanged) { releaseBufferIfOverwriting(it->state); } it->state.merge(otherState.state); } else { mComposerStates.add(otherState); } } for (auto const& state : other.mDisplayStates) { if (auto it = std::find_if(mDisplayStates.begin(), mDisplayStates.end(), [&state](const auto& displayState) { return displayState.token == state.token; }); it != mDisplayStates.end()) { it->merge(state); } else { mDisplayStates.add(state); } } for (const auto& [listener, callbackInfo] : other.mListenerCallbacks) { auto& [callbackIds, surfaceControls] = callbackInfo; mListenerCallbacks[listener].callbackIds.insert(std::make_move_iterator( Loading Loading @@ -1056,6 +992,8 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr mComplexState.merge(other.mComplexState); mComplexState.mMergedTransactionIds.insert(mComplexState.mMergedTransactionIds.begin(), other.mSimpleState.mId); mMutableState.merge(other.mMutableState, [this](const auto& state) { releaseBufferIfOverwriting(state); }); mMayContainBuffer |= other.mMayContainBuffer; mApplyToken = other.mApplyToken; Loading @@ -1074,8 +1012,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::merge(Tr void SurfaceComposerClient::Transaction::clear() { mSimpleState.clear(); mComplexState.clear(); mComposerStates.clear(); mDisplayStates.clear(); mMutableState.clear(); mListenerCallbacks.clear(); mMayContainBuffer = false; mApplyToken = nullptr; Loading @@ -1098,12 +1035,11 @@ void SurfaceComposerClient::doUncacheBufferTransaction(uint64_t cacheId) { uncacheBuffer.token = BufferCache::getInstance().getToken(); uncacheBuffer.id = cacheId; complexState.mUncacheBuffers.emplace_back(std::move(uncacheBuffer)); Vector<ComposerState> composerStates; Vector<DisplayState> displayStates; MutableTransactionState mutableState; status_t status = sf->setTransactionState(SimpleTransactionState(generateId(), ISurfaceComposer::eOneWay, systemTime(), true), complexState, composerStates, displayStates, complexState, mutableState, Transaction::getDefaultApplyToken()); if (status != NO_ERROR) { ALOGE_AND_TRACE("SurfaceComposerClient::doUncacheBufferTransaction - %s", Loading @@ -1117,7 +1053,7 @@ void SurfaceComposerClient::Transaction::cacheBuffers() { } size_t count = 0; for (auto& cs : mComposerStates) { for (auto& cs : mMutableState.mComposerStates) { layer_state_t* s = &cs.state; if (!(s->what & layer_state_t::eBufferChanged)) { continue; Loading Loading @@ -1264,8 +1200,8 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous, bool oneWay sp<IBinder> applyToken = mApplyToken ? mApplyToken : getDefaultApplyToken(); sp<ISurfaceComposer> sf(ComposerService::getComposerService()); status_t binderStatus = sf->setTransactionState(mSimpleState, mComplexState, mComposerStates, mDisplayStates, applyToken); status_t binderStatus = sf->setTransactionState(mSimpleState, mComplexState, mMutableState, applyToken); mSimpleState.mId = generateId(); // Clear the current states and flags Loading Loading @@ -1386,22 +1322,7 @@ void SurfaceComposerClient::Transaction::setEarlyWakeupEnd(gui::EarlyWakeupInfo } layer_state_t* SurfaceComposerClient::Transaction::getLayerState(const sp<SurfaceControl>& sc) { auto handle = sc->getLayerStateHandle(); if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(), [&handle](const auto& composerState) { return composerState.state.surface == handle; }); it != mComposerStates.end()) { return &it->state; } // we don't have it, add an initialized layer_state to our list ComposerState s; s.state.surface = handle; s.state.layerId = sc->getLayerId(); mComposerStates.add(s); return &mComposerStates.editItemAt(mComposerStates.size() - 1).state; return mMutableState.getLayerState(sc); } void SurfaceComposerClient::Transaction::registerSurfaceControlForCallback( Loading Loading @@ -2446,17 +2367,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setConte // --------------------------------------------------------------------------- DisplayState& SurfaceComposerClient::Transaction::getDisplayState(const sp<IBinder>& token) { if (auto it = std::find_if(mDisplayStates.begin(), mDisplayStates.end(), [token](const auto& display) { return display.token == token; }); it != mDisplayStates.end()) { return *it; } // If display state doesn't exist, add a new one. DisplayState s; s.token = token; mDisplayStates.add(s); return mDisplayStates.editItemAt(mDisplayStates.size() - 1); return mMutableState.getDisplayState(token); } status_t SurfaceComposerClient::Transaction::setDisplaySurface( Loading
libs/gui/TransactionState.cpp +105 −0 Original line number Diff line number Diff line Loading @@ -136,6 +136,41 @@ status_t ComplexTransactionState::readFromParcel(const Parcel* parcel) { return NO_ERROR; } status_t MutableTransactionState::writeToParcel(Parcel* parcel) const { SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mComposerStates.size())); for (const auto& s : mComposerStates) { SAFE_PARCEL(s.write, *parcel); } SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(mDisplayStates.size())); for (const auto& d : mDisplayStates) { SAFE_PARCEL(d.write, *parcel); } return NO_ERROR; } status_t MutableTransactionState::readFromParcel(const Parcel* parcel) { uint32_t count = 0; SAFE_PARCEL_READ_SIZE(parcel->readUint32, &count, parcel->dataSize()); mComposerStates.setCapacity(count); for (size_t i = 0; i < count; i++) { ComposerState s; SAFE_PARCEL(s.read, *parcel); mComposerStates.add(s); } SAFE_PARCEL_READ_SIZE(parcel->readUint32, &count, parcel->dataSize()); DisplayState d; mDisplayStates.setCapacity(count); for (size_t i = 0; i < count; i++) { SAFE_PARCEL(d.read, *parcel); mDisplayStates.add(d); } return NO_ERROR; } status_t TransactionState::writeToParcel(Parcel* parcel) const { SAFE_PARCEL(mSimpleState.writeToParcel, parcel); SAFE_PARCEL(mComplexState.writeToParcel, parcel); Loading Loading @@ -217,6 +252,38 @@ void ComplexTransactionState::merge(ComplexTransactionState& other) { } } void MutableTransactionState::merge( const MutableTransactionState& other, const std::function<void(const layer_state_t&)>& onBufferOverwrite) { for (auto const& otherState : other.mComposerStates) { if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(), [&otherState](const auto& composerState) { return composerState.state.surface == otherState.state.surface; }); it != mComposerStates.end()) { if (otherState.state.what & layer_state_t::eBufferChanged) { onBufferOverwrite(it->state); } it->state.merge(otherState.state); } else { mComposerStates.add(otherState); } } for (auto const& state : other.mDisplayStates) { if (auto it = std::find_if(mDisplayStates.begin(), mDisplayStates.end(), [&state](const auto& displayState) { return displayState.token == state.token; }); it != mDisplayStates.end()) { it->merge(state); } else { mDisplayStates.add(state); } } } void TransactionState::merge(TransactionState&& other, const std::function<void(layer_state_t&)>& onBufferOverwrite) { mSimpleState.merge(other.mSimpleState); Loading Loading @@ -282,6 +349,11 @@ void ComplexTransactionState::clear() { mEarlyWakeupInfos.clear(); } void MutableTransactionState::clear() { mComposerStates.clear(); mDisplayStates.clear(); } void TransactionState::clear() { mSimpleState.clear(); mComplexState.clear(); Loading @@ -292,6 +364,25 @@ void TransactionState::clear() { mLogCallPoints = false; } layer_state_t* MutableTransactionState::getLayerState(const sp<SurfaceControl>& sc) { auto handle = sc->getLayerStateHandle(); if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(), [&handle](const auto& composerState) { return composerState.state.surface == handle; }); it != mComposerStates.end()) { return &it->state; } // we don't have it, add an initialized layer_state to our list ComposerState s; s.state.surface = handle; s.state.layerId = sc->getLayerId(); mComposerStates.add(s); return &mComposerStates.editItemAt(mComposerStates.size() - 1).state; } layer_state_t* TransactionState::getLayerState(const sp<SurfaceControl>& sc) { auto handle = sc->getLayerStateHandle(); if (auto it = std::find_if(mComposerStates.begin(), mComposerStates.end(), Loading @@ -311,6 +402,20 @@ layer_state_t* TransactionState::getLayerState(const sp<SurfaceControl>& sc) { return &mComposerStates.back().state; } DisplayState& MutableTransactionState::getDisplayState(const sp<IBinder>& token) { if (auto it = std::find_if(mDisplayStates.begin(), mDisplayStates.end(), [token](const auto& display) { return display.token == token; }); it != mDisplayStates.end()) { return *it; } // If display state doesn't exist, add a new one. DisplayState s; s.token = token; mDisplayStates.add(s); return mDisplayStates.editItemAt(mDisplayStates.size() - 1); } DisplayState& TransactionState::getDisplayState(const sp<IBinder>& token) { if (auto it = std::find_if(mDisplayStates.begin(), mDisplayStates.end(), [token](const auto& display) { return display.token == token; }); Loading
libs/gui/include/gui/ISurfaceComposer.h +2 −2 Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ class HdrCapabilities; class Rect; struct SimpleTransactionState; struct ComplexTransactionState; struct MutableTransactionState; using gui::FrameTimelineInfo; using gui::IDisplayEventConnection; Loading Loading @@ -110,8 +111,7 @@ public: /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */ virtual status_t setTransactionState(SimpleTransactionState simpleState, const ComplexTransactionState& complexState, Vector<ComposerState>& state, Vector<DisplayState>& displays, MutableTransactionState& mutableState, const sp<IBinder>& applyToken) = 0; }; Loading
libs/gui/include/gui/SurfaceComposerClient.h +1 −2 Original line number Diff line number Diff line Loading @@ -474,8 +474,7 @@ public: bool mLogCallPoints = false; protected: Vector<ComposerState> mComposerStates; Vector<DisplayState> mDisplayStates; MutableTransactionState mMutableState; std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> mListenerCallbacks; Loading