Loading libs/gui/ISurfaceComposer.cpp +7 −114 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <gui/ISurfaceComposer.h> #include <gui/LayerState.h> #include <gui/SchedulingPolicy.h> #include <gui/TransactionState.h> #include <private/gui/ParcelUtils.h> #include <stdint.h> #include <sys/types.h> Loading Loading @@ -60,54 +61,12 @@ public: virtual ~BpSurfaceComposer(); status_t setTransactionState( const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state, Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, InputWindowCommands commands, int64_t desiredPresentTime, bool isAutoTimestamp, const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, const std::vector<uint64_t>& mergedTransactionIds) override { status_t setTransactionState(TransactionState&& state) override { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); SAFE_PARCEL(state.writeToParcel, &data); frameTimelineInfo.writeToParcel(&data); 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(data.writeUint32, flags); SAFE_PARCEL(data.writeStrongBinder, applyToken); SAFE_PARCEL(commands.write, data); SAFE_PARCEL(data.writeInt64, desiredPresentTime); SAFE_PARCEL(data.writeBool, isAutoTimestamp); SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(uncacheBuffers.size())); for (const client_cache_t& uncacheBuffer : uncacheBuffers) { SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote()); SAFE_PARCEL(data.writeUint64, uncacheBuffer.id); } SAFE_PARCEL(data.writeBool, hasListenerCallbacks); SAFE_PARCEL(data.writeVectorSize, listenerCallbacks); for (const auto& [listener, callbackIds] : listenerCallbacks) { SAFE_PARCEL(data.writeStrongBinder, listener); SAFE_PARCEL(data.writeParcelableVector, callbackIds); } SAFE_PARCEL(data.writeUint64, transactionId); SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(mergedTransactionIds.size())); for (auto mergedTransactionId : mergedTransactionIds) { SAFE_PARCEL(data.writeUint64, mergedTransactionId); } if (flags & ISurfaceComposer::eOneWay) { if (state.mFlags & ISurfaceComposer::eOneWay) { return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply, IBinder::FLAG_ONEWAY); } else { Loading @@ -132,75 +91,9 @@ status_t BnSurfaceComposer::onTransact( case SET_TRANSACTION_STATE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); FrameTimelineInfo frameTimelineInfo; frameTimelineInfo.readFromParcel(&data); 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); } uint32_t stateFlags = 0; SAFE_PARCEL(data.readUint32, &stateFlags); sp<IBinder> applyToken; SAFE_PARCEL(data.readStrongBinder, &applyToken); InputWindowCommands inputWindowCommands; SAFE_PARCEL(inputWindowCommands.read, data); int64_t desiredPresentTime = 0; bool isAutoTimestamp = true; SAFE_PARCEL(data.readInt64, &desiredPresentTime); SAFE_PARCEL(data.readBool, &isAutoTimestamp); SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize()); std::vector<client_cache_t> uncacheBuffers(count); sp<IBinder> tmpBinder; for (size_t i = 0; i < count; i++) { SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder); uncacheBuffers[i].token = tmpBinder; SAFE_PARCEL(data.readUint64, &uncacheBuffers[i].id); } bool hasListenerCallbacks = false; SAFE_PARCEL(data.readBool, &hasListenerCallbacks); std::vector<ListenerCallbacks> listenerCallbacks; int32_t listenersSize = 0; SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize()); for (int32_t i = 0; i < listenersSize; i++) { SAFE_PARCEL(data.readStrongBinder, &tmpBinder); std::vector<CallbackId> callbackIds; SAFE_PARCEL(data.readParcelableVector, &callbackIds); listenerCallbacks.emplace_back(tmpBinder, callbackIds); } uint64_t transactionId = -1; SAFE_PARCEL(data.readUint64, &transactionId); SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize()); std::vector<uint64_t> mergedTransactions(count); for (size_t i = 0; i < count; i++) { SAFE_PARCEL(data.readUint64, &mergedTransactions[i]); } return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken, std::move(inputWindowCommands), desiredPresentTime, isAutoTimestamp, uncacheBuffers, hasListenerCallbacks, listenerCallbacks, transactionId, mergedTransactions); TransactionState state; SAFE_PARCEL(state.readFromParcel, &data); return setTransactionState(std::move(state)); } case GET_SCHEDULING_POLICY: { gui::SchedulingPolicy policy; Loading libs/gui/SurfaceComposerClient.cpp +55 −275 File changed.Preview size limit exceeded, changes collapsed. Show changes libs/gui/include/gui/ISurfaceComposer.h +2 −7 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ struct DisplayState; struct InputWindowCommands; class HdrCapabilities; class Rect; class TransactionState; using gui::FrameTimelineInfo; using gui::IDisplayEventConnection; Loading Loading @@ -105,13 +106,7 @@ public: }; /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */ virtual status_t setTransactionState( const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state, Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, bool isAutoTimestamp, const std::vector<client_cache_t>& uncacheBuffer, bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, const std::vector<uint64_t>& mergedTransactionIds) = 0; virtual status_t setTransactionState(TransactionState&& state) = 0; }; // ---------------------------------------------------------------------------- Loading libs/gui/include/gui/SurfaceComposerClient.h +8 −47 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ #include <gui/ITransactionCompletedListener.h> #include <gui/LayerState.h> #include <gui/SurfaceControl.h> #include <gui/TransactionState.h> #include <gui/WindowInfosListenerReporter.h> #include <math/vec3.h> Loading Loading @@ -447,56 +448,11 @@ public: static sp<IBinder> sApplyToken; static std::mutex sApplyTokenMutex; void releaseBufferIfOverwriting(const layer_state_t& state); static void mergeFrameTimelineInfo(FrameTimelineInfo& t, const FrameTimelineInfo& other); // Tracks registered callbacks sp<TransactionCompletedListener> mTransactionCompletedListener = nullptr; // Prints debug logs when enabled. bool mLogCallPoints = false; protected: Vector<ComposerState> mComposerStates; Vector<DisplayState> mDisplayStates; std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> mListenerCallbacks; std::vector<client_cache_t> mUncacheBuffers; // We keep track of the last MAX_MERGE_HISTORY_LENGTH merged transaction ids. // Ordered most recently merged to least recently merged. static const size_t MAX_MERGE_HISTORY_LENGTH = 10u; std::vector<uint64_t> mMergedTransactionIds; uint64_t mId; uint32_t mFlags = 0; // Indicates that the Transaction may contain buffers that should be cached. The reason this // is only a guess is that buffers can be removed before cache is called. This is only a // hint that at some point a buffer was added to this transaction before apply was called. bool mMayContainBuffer = false; // mDesiredPresentTime is the time in nanoseconds that the client would like the transaction // to be presented. When it is not possible to present at exactly that time, it will be // presented after the time has passed. // // If the client didn't pass a desired presentation time, mDesiredPresentTime will be // populated to the time setBuffer was called, and mIsAutoTimestamp will be set to true. // // Desired present times that are more than 1 second in the future may be ignored. // When a desired present time has already passed, the transaction will be presented as soon // as possible. // // Transactions from the same process are presented in the same order that they are applied. // The desired present time does not affect this ordering. int64_t mDesiredPresentTime = 0; bool mIsAutoTimestamp = true; // The vsync id provided by Choreographer.getVsyncId and the input event id FrameTimelineInfo mFrameTimelineInfo; // If not null, transactions will be queued up using this token otherwise a common token // per process will be used. sp<IBinder> mApplyToken = nullptr; TransactionState mState; InputWindowCommands mInputWindowCommands; int mStatus = NO_ERROR; layer_state_t* getLayerState(const sp<SurfaceControl>& sc); Loading @@ -506,6 +462,11 @@ public: void registerSurfaceControlForCallback(const sp<SurfaceControl>& sc); void setReleaseBufferCallback(BufferData*, ReleaseBufferCallback); protected: // Accessed in tests. std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> mListenerCallbacks; public: Transaction(); virtual ~Transaction() = default; Loading @@ -522,7 +483,7 @@ public: // Returns the current id of the transaction. // The id is updated every time the transaction is applied. uint64_t getId(); uint64_t getId() const; std::vector<uint64_t> getMergedTransactionIds(); Loading libs/gui/tests/Surface_test.cpp +1 −10 Original line number Diff line number Diff line Loading @@ -648,16 +648,7 @@ public: mSupportsPresent = supportsPresent; } status_t setTransactionState( const FrameTimelineInfo& /*frameTimelineInfo*/, Vector<ComposerState>& /*state*/, Vector<DisplayState>& /*displays*/, uint32_t /*flags*/, const sp<IBinder>& /*applyToken*/, InputWindowCommands /*inputWindowCommands*/, int64_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/, const std::vector<client_cache_t>& /*cachedBuffer*/, bool /*hasListenerCallbacks*/, const std::vector<ListenerCallbacks>& /*listenerCallbacks*/, uint64_t /*transactionId*/, const std::vector<uint64_t>& /*mergedTransactionIds*/) override { return NO_ERROR; } status_t setTransactionState(TransactionState&&) override { return NO_ERROR; } protected: IBinder* onAsBinder() override { return nullptr; } Loading Loading
libs/gui/ISurfaceComposer.cpp +7 −114 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <gui/ISurfaceComposer.h> #include <gui/LayerState.h> #include <gui/SchedulingPolicy.h> #include <gui/TransactionState.h> #include <private/gui/ParcelUtils.h> #include <stdint.h> #include <sys/types.h> Loading Loading @@ -60,54 +61,12 @@ public: virtual ~BpSurfaceComposer(); status_t setTransactionState( const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state, Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, InputWindowCommands commands, int64_t desiredPresentTime, bool isAutoTimestamp, const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, const std::vector<uint64_t>& mergedTransactionIds) override { status_t setTransactionState(TransactionState&& state) override { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); SAFE_PARCEL(state.writeToParcel, &data); frameTimelineInfo.writeToParcel(&data); 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(data.writeUint32, flags); SAFE_PARCEL(data.writeStrongBinder, applyToken); SAFE_PARCEL(commands.write, data); SAFE_PARCEL(data.writeInt64, desiredPresentTime); SAFE_PARCEL(data.writeBool, isAutoTimestamp); SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(uncacheBuffers.size())); for (const client_cache_t& uncacheBuffer : uncacheBuffers) { SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote()); SAFE_PARCEL(data.writeUint64, uncacheBuffer.id); } SAFE_PARCEL(data.writeBool, hasListenerCallbacks); SAFE_PARCEL(data.writeVectorSize, listenerCallbacks); for (const auto& [listener, callbackIds] : listenerCallbacks) { SAFE_PARCEL(data.writeStrongBinder, listener); SAFE_PARCEL(data.writeParcelableVector, callbackIds); } SAFE_PARCEL(data.writeUint64, transactionId); SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(mergedTransactionIds.size())); for (auto mergedTransactionId : mergedTransactionIds) { SAFE_PARCEL(data.writeUint64, mergedTransactionId); } if (flags & ISurfaceComposer::eOneWay) { if (state.mFlags & ISurfaceComposer::eOneWay) { return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE, data, &reply, IBinder::FLAG_ONEWAY); } else { Loading @@ -132,75 +91,9 @@ status_t BnSurfaceComposer::onTransact( case SET_TRANSACTION_STATE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); FrameTimelineInfo frameTimelineInfo; frameTimelineInfo.readFromParcel(&data); 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); } uint32_t stateFlags = 0; SAFE_PARCEL(data.readUint32, &stateFlags); sp<IBinder> applyToken; SAFE_PARCEL(data.readStrongBinder, &applyToken); InputWindowCommands inputWindowCommands; SAFE_PARCEL(inputWindowCommands.read, data); int64_t desiredPresentTime = 0; bool isAutoTimestamp = true; SAFE_PARCEL(data.readInt64, &desiredPresentTime); SAFE_PARCEL(data.readBool, &isAutoTimestamp); SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize()); std::vector<client_cache_t> uncacheBuffers(count); sp<IBinder> tmpBinder; for (size_t i = 0; i < count; i++) { SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder); uncacheBuffers[i].token = tmpBinder; SAFE_PARCEL(data.readUint64, &uncacheBuffers[i].id); } bool hasListenerCallbacks = false; SAFE_PARCEL(data.readBool, &hasListenerCallbacks); std::vector<ListenerCallbacks> listenerCallbacks; int32_t listenersSize = 0; SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize()); for (int32_t i = 0; i < listenersSize; i++) { SAFE_PARCEL(data.readStrongBinder, &tmpBinder); std::vector<CallbackId> callbackIds; SAFE_PARCEL(data.readParcelableVector, &callbackIds); listenerCallbacks.emplace_back(tmpBinder, callbackIds); } uint64_t transactionId = -1; SAFE_PARCEL(data.readUint64, &transactionId); SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize()); std::vector<uint64_t> mergedTransactions(count); for (size_t i = 0; i < count; i++) { SAFE_PARCEL(data.readUint64, &mergedTransactions[i]); } return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken, std::move(inputWindowCommands), desiredPresentTime, isAutoTimestamp, uncacheBuffers, hasListenerCallbacks, listenerCallbacks, transactionId, mergedTransactions); TransactionState state; SAFE_PARCEL(state.readFromParcel, &data); return setTransactionState(std::move(state)); } case GET_SCHEDULING_POLICY: { gui::SchedulingPolicy policy; Loading
libs/gui/SurfaceComposerClient.cpp +55 −275 File changed.Preview size limit exceeded, changes collapsed. Show changes
libs/gui/include/gui/ISurfaceComposer.h +2 −7 Original line number Diff line number Diff line Loading @@ -65,6 +65,7 @@ struct DisplayState; struct InputWindowCommands; class HdrCapabilities; class Rect; class TransactionState; using gui::FrameTimelineInfo; using gui::IDisplayEventConnection; Loading Loading @@ -105,13 +106,7 @@ public: }; /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */ virtual status_t setTransactionState( const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state, Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, InputWindowCommands inputWindowCommands, int64_t desiredPresentTime, bool isAutoTimestamp, const std::vector<client_cache_t>& uncacheBuffer, bool hasListenerCallbacks, const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId, const std::vector<uint64_t>& mergedTransactionIds) = 0; virtual status_t setTransactionState(TransactionState&& state) = 0; }; // ---------------------------------------------------------------------------- Loading
libs/gui/include/gui/SurfaceComposerClient.h +8 −47 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ #include <gui/ITransactionCompletedListener.h> #include <gui/LayerState.h> #include <gui/SurfaceControl.h> #include <gui/TransactionState.h> #include <gui/WindowInfosListenerReporter.h> #include <math/vec3.h> Loading Loading @@ -447,56 +448,11 @@ public: static sp<IBinder> sApplyToken; static std::mutex sApplyTokenMutex; void releaseBufferIfOverwriting(const layer_state_t& state); static void mergeFrameTimelineInfo(FrameTimelineInfo& t, const FrameTimelineInfo& other); // Tracks registered callbacks sp<TransactionCompletedListener> mTransactionCompletedListener = nullptr; // Prints debug logs when enabled. bool mLogCallPoints = false; protected: Vector<ComposerState> mComposerStates; Vector<DisplayState> mDisplayStates; std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> mListenerCallbacks; std::vector<client_cache_t> mUncacheBuffers; // We keep track of the last MAX_MERGE_HISTORY_LENGTH merged transaction ids. // Ordered most recently merged to least recently merged. static const size_t MAX_MERGE_HISTORY_LENGTH = 10u; std::vector<uint64_t> mMergedTransactionIds; uint64_t mId; uint32_t mFlags = 0; // Indicates that the Transaction may contain buffers that should be cached. The reason this // is only a guess is that buffers can be removed before cache is called. This is only a // hint that at some point a buffer was added to this transaction before apply was called. bool mMayContainBuffer = false; // mDesiredPresentTime is the time in nanoseconds that the client would like the transaction // to be presented. When it is not possible to present at exactly that time, it will be // presented after the time has passed. // // If the client didn't pass a desired presentation time, mDesiredPresentTime will be // populated to the time setBuffer was called, and mIsAutoTimestamp will be set to true. // // Desired present times that are more than 1 second in the future may be ignored. // When a desired present time has already passed, the transaction will be presented as soon // as possible. // // Transactions from the same process are presented in the same order that they are applied. // The desired present time does not affect this ordering. int64_t mDesiredPresentTime = 0; bool mIsAutoTimestamp = true; // The vsync id provided by Choreographer.getVsyncId and the input event id FrameTimelineInfo mFrameTimelineInfo; // If not null, transactions will be queued up using this token otherwise a common token // per process will be used. sp<IBinder> mApplyToken = nullptr; TransactionState mState; InputWindowCommands mInputWindowCommands; int mStatus = NO_ERROR; layer_state_t* getLayerState(const sp<SurfaceControl>& sc); Loading @@ -506,6 +462,11 @@ public: void registerSurfaceControlForCallback(const sp<SurfaceControl>& sc); void setReleaseBufferCallback(BufferData*, ReleaseBufferCallback); protected: // Accessed in tests. std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> mListenerCallbacks; public: Transaction(); virtual ~Transaction() = default; Loading @@ -522,7 +483,7 @@ public: // Returns the current id of the transaction. // The id is updated every time the transaction is applied. uint64_t getId(); uint64_t getId() const; std::vector<uint64_t> getMergedTransactionIds(); Loading
libs/gui/tests/Surface_test.cpp +1 −10 Original line number Diff line number Diff line Loading @@ -648,16 +648,7 @@ public: mSupportsPresent = supportsPresent; } status_t setTransactionState( const FrameTimelineInfo& /*frameTimelineInfo*/, Vector<ComposerState>& /*state*/, Vector<DisplayState>& /*displays*/, uint32_t /*flags*/, const sp<IBinder>& /*applyToken*/, InputWindowCommands /*inputWindowCommands*/, int64_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/, const std::vector<client_cache_t>& /*cachedBuffer*/, bool /*hasListenerCallbacks*/, const std::vector<ListenerCallbacks>& /*listenerCallbacks*/, uint64_t /*transactionId*/, const std::vector<uint64_t>& /*mergedTransactionIds*/) override { return NO_ERROR; } status_t setTransactionState(TransactionState&&) override { return NO_ERROR; } protected: IBinder* onAsBinder() override { return nullptr; } Loading