Loading libs/gui/LayerState.cpp +86 −24 Original line number Diff line number Diff line Loading @@ -55,6 +55,28 @@ namespace android { using gui::FocusRequest; using gui::WindowInfoHandle; namespace { bool isSameWindowHandle(const sp<WindowInfoHandle>& lhs, const sp<WindowInfoHandle>& rhs) { if (lhs == rhs) { return true; } if (!lhs || !rhs) { return false; } return *lhs->getInfo() == *rhs->getInfo(); }; bool isSameSurfaceControl(const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs) { if (lhs == rhs) { return true; } return SurfaceControl::isSameSurface(lhs, rhs); }; } // namespace layer_state_t::layer_state_t() : surface(nullptr), layerId(-1), Loading @@ -73,7 +95,6 @@ layer_state_t::layer_state_t() transformToDisplayInverse(false), crop({0, 0, -1, -1}), dataspace(ui::Dataspace::UNKNOWN), surfaceDamageRegion(), api(-1), colorTransform(mat4()), bgColor(0), Loading Loading @@ -117,19 +138,21 @@ status_t layer_state_t::write(Parcel& output) const SAFE_PARCEL(output.writeFloat, crop.left); SAFE_PARCEL(output.writeFloat, crop.bottom); SAFE_PARCEL(output.writeFloat, crop.right); SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl); SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild); SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, mNotDefCmpState.relativeLayerSurfaceControl); SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, mNotDefCmpState.parentSurfaceControlForChild); SAFE_PARCEL(output.writeFloat, color.r); SAFE_PARCEL(output.writeFloat, color.g); SAFE_PARCEL(output.writeFloat, color.b); SAFE_PARCEL(output.writeFloat, color.a); SAFE_PARCEL(windowInfoHandle->writeToParcel, &output); SAFE_PARCEL(output.write, transparentRegion); SAFE_PARCEL(mNotDefCmpState.windowInfoHandle->writeToParcel, &output); SAFE_PARCEL(output.write, mNotDefCmpState.transparentRegion); SAFE_PARCEL(output.writeUint32, bufferTransform); SAFE_PARCEL(output.writeBool, transformToDisplayInverse); SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace)); SAFE_PARCEL(output.write, hdrMetadata); SAFE_PARCEL(output.write, surfaceDamageRegion); SAFE_PARCEL(output.write, mNotDefCmpState.surfaceDamageRegion); SAFE_PARCEL(output.writeInt32, api); if (sidebandStream) { Loading Loading @@ -241,8 +264,10 @@ status_t layer_state_t::read(const Parcel& input) SAFE_PARCEL(input.readFloat, &crop.bottom); SAFE_PARCEL(input.readFloat, &crop.right); SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl); SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild); SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &mNotDefCmpState.relativeLayerSurfaceControl); SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &mNotDefCmpState.parentSurfaceControlForChild); float tmpFloat = 0; SAFE_PARCEL(input.readFloat, &tmpFloat); Loading @@ -254,9 +279,9 @@ status_t layer_state_t::read(const Parcel& input) SAFE_PARCEL(input.readFloat, &tmpFloat); color.a = tmpFloat; SAFE_PARCEL(windowInfoHandle->readFromParcel, &input); SAFE_PARCEL(mNotDefCmpState.windowInfoHandle->readFromParcel, &input); SAFE_PARCEL(input.read, transparentRegion); SAFE_PARCEL(input.read, mNotDefCmpState.transparentRegion); SAFE_PARCEL(input.readUint32, &bufferTransform); SAFE_PARCEL(input.readBool, &transformToDisplayInverse); Loading @@ -265,7 +290,7 @@ status_t layer_state_t::read(const Parcel& input) dataspace = static_cast<ui::Dataspace>(tmpUint32); SAFE_PARCEL(input.read, hdrMetadata); SAFE_PARCEL(input.read, surfaceDamageRegion); SAFE_PARCEL(input.read, mNotDefCmpState.surfaceDamageRegion); SAFE_PARCEL(input.readInt32, &api); bool tmpBool = false; Loading Loading @@ -583,7 +608,7 @@ void layer_state_t::merge(const layer_state_t& other) { } if (other.what & eTransparentRegionChanged) { what |= eTransparentRegionChanged; transparentRegion = other.transparentRegion; mNotDefCmpState.transparentRegion = other.mNotDefCmpState.transparentRegion; } if (other.what & eFlagsChanged) { what |= eFlagsChanged; Loading Loading @@ -615,11 +640,13 @@ void layer_state_t::merge(const layer_state_t& other) { what |= eRelativeLayerChanged; what &= ~eLayerChanged; z = other.z; relativeLayerSurfaceControl = other.relativeLayerSurfaceControl; mNotDefCmpState.relativeLayerSurfaceControl = other.mNotDefCmpState.relativeLayerSurfaceControl; } if (other.what & eReparent) { what |= eReparent; parentSurfaceControlForChild = other.parentSurfaceControlForChild; mNotDefCmpState.parentSurfaceControlForChild = other.mNotDefCmpState.parentSurfaceControlForChild; } if (other.what & eBufferTransformChanged) { what |= eBufferTransformChanged; Loading Loading @@ -665,7 +692,7 @@ void layer_state_t::merge(const layer_state_t& other) { } if (other.what & eSurfaceDamageRegionChanged) { what |= eSurfaceDamageRegionChanged; surfaceDamageRegion = other.surfaceDamageRegion; mNotDefCmpState.surfaceDamageRegion = other.mNotDefCmpState.surfaceDamageRegion; } if (other.what & eApiChanged) { what |= eApiChanged; Loading @@ -684,7 +711,8 @@ void layer_state_t::merge(const layer_state_t& other) { } if (other.what & eInputInfoChanged) { what |= eInputInfoChanged; windowInfoHandle = sp<WindowInfoHandle>::make(*other.windowInfoHandle); mNotDefCmpState.windowInfoHandle = sp<WindowInfoHandle>::make(*other.mNotDefCmpState.windowInfoHandle); } if (other.what & eBackgroundColorChanged) { what |= eBackgroundColorChanged; Loading Loading @@ -807,7 +835,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const { CHECK_DIFF(diff, eAlphaChanged, other, color.a); CHECK_DIFF(diff, eMatrixChanged, other, matrix); if (other.what & eTransparentRegionChanged && (!transparentRegion.hasSameRects(other.transparentRegion))) { (!mNotDefCmpState.transparentRegion.hasSameRects( other.mNotDefCmpState.transparentRegion))) { diff |= eTransparentRegionChanged; } if (other.what & eFlagsChanged) { Loading @@ -824,8 +853,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const { diff &= ~eLayerChanged; } if (other.what & eReparent && !SurfaceControl::isSameSurface(parentSurfaceControlForChild, other.parentSurfaceControlForChild)) { !SurfaceControl::isSameSurface(mNotDefCmpState.parentSurfaceControlForChild, other.mNotDefCmpState.parentSurfaceControlForChild)) { diff |= eReparent; } CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform); Loading @@ -839,7 +868,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const { CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint); CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata); if (other.what & eSurfaceDamageRegionChanged && (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) { (!mNotDefCmpState.surfaceDamageRegion.hasSameRects( other.mNotDefCmpState.surfaceDamageRegion))) { diff |= eSurfaceDamageRegionChanged; } CHECK_DIFF(diff, eApiChanged, other, api); Loading Loading @@ -901,6 +931,38 @@ status_t layer_state_t::matrix22_t::read(const Parcel& input) { SAFE_PARCEL(input.readFloat, &dsdy); return NO_ERROR; } void layer_state_t::updateTransparentRegion(const Region& transparentRegion) { what |= eTransparentRegionChanged; mNotDefCmpState.transparentRegion = transparentRegion; } void layer_state_t::updateSurfaceDamageRegion(const Region& surfaceDamageRegion) { what |= eSurfaceDamageRegionChanged; mNotDefCmpState.surfaceDamageRegion = surfaceDamageRegion; } void layer_state_t::updateRelativeLayer(const sp<SurfaceControl>& relativeTo, int32_t z) { what |= layer_state_t::eRelativeLayerChanged; what &= ~layer_state_t::eLayerChanged; mNotDefCmpState.relativeLayerSurfaceControl = relativeTo; this->z = z; } void layer_state_t::updateParentLayer(const sp<SurfaceControl>& newParent) { what |= layer_state_t::eReparent; mNotDefCmpState.parentSurfaceControlForChild = newParent ? newParent->getParentingLayer() : nullptr; } void layer_state_t::updateInputWindowInfo(sp<gui::WindowInfoHandle>&& info) { what |= eInputInfoChanged; mNotDefCmpState.windowInfoHandle = std::move(info); } bool layer_state_t::NotDefaultComparableState::operator==( const NotDefaultComparableState& rhs) const { return transparentRegion.hasSameRects(rhs.transparentRegion) && surfaceDamageRegion.hasSameRects(rhs.surfaceDamageRegion) && isSameWindowHandle(windowInfoHandle, rhs.windowInfoHandle) && isSameSurfaceControl(relativeLayerSurfaceControl, rhs.relativeLayerSurfaceControl) && isSameSurfaceControl(parentSurfaceControlForChild, rhs.parentSurfaceControlForChild); } // ------------------------------- InputWindowCommands ---------------------------------------- Loading Loading @@ -1034,8 +1096,8 @@ status_t BufferData::readFromParcel(const Parcel* input) { } status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const { SAFE_PARCEL(parcel->writeStrongBinder, callbackInterface); SAFE_PARCEL(parcel->writeInt32, callbackId); SAFE_PARCEL(parcel->writeStrongBinder, mState.callbackInterface); SAFE_PARCEL(parcel->writeInt32, mState.callbackId); return NO_ERROR; } Loading @@ -1043,9 +1105,9 @@ status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) { sp<IBinder> tmpBinder = nullptr; SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder); if (tmpBinder) { callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder); mState.callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder); } SAFE_PARCEL(parcel->readInt32, &callbackId); SAFE_PARCEL(parcel->readInt32, &mState.callbackId); return NO_ERROR; } Loading libs/gui/SurfaceComposerClient.cpp +11 −22 Original line number Diff line number Diff line Loading @@ -1523,11 +1523,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelat mStatus = BAD_INDEX; return *this; } s->what |= layer_state_t::eRelativeLayerChanged; s->what &= ~layer_state_t::eLayerChanged; s->relativeLayerSurfaceControl = relativeTo; s->z = z; s->updateRelativeLayer(relativeTo, z); registerSurfaceControlForCallback(sc); return *this; } Loading Loading @@ -1557,9 +1553,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTrans mStatus = BAD_INDEX; return *this; } s->what |= layer_state_t::eTransparentRegionChanged; s->transparentRegion = transparentRegion; s->updateTransparentRegion(transparentRegion); registerSurfaceControlForCallback(sc); return *this; } Loading Loading @@ -1721,9 +1715,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent if (SurfaceControl::isSameSurface(sc, newParent)) { return *this; } s->what |= layer_state_t::eReparent; s->parentSurfaceControlForChild = newParent ? newParent->getParentingLayer() : nullptr; s->updateParentLayer(newParent); registerSurfaceControlForCallback(sc); return *this; } Loading Loading @@ -2009,9 +2001,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSurfa mStatus = BAD_INDEX; return *this; } s->what |= layer_state_t::eSurfaceDamageRegionChanged; s->surfaceDamageRegion = surfaceDamageRegion; s->updateSurfaceDamageRegion(surfaceDamageRegion); registerSurfaceControlForCallback(sc); return *this; } Loading Loading @@ -2130,21 +2120,20 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInput mStatus = BAD_INDEX; return *this; } s->windowInfoHandle = std::move(info); s->what |= layer_state_t::eInputInfoChanged; s->updateInputWindowInfo(std::move(info)); return *this; } SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFocusedWindow( const FocusRequest& request) { mInputWindowCommands.focusRequests.push_back(request); mInputWindowCommands.addFocusRequest(request); return *this; } SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::addWindowInfosReportedListener( sp<gui::IWindowInfosReportedListener> windowInfosReportedListener) { mInputWindowCommands.windowInfosReportedListeners.insert(windowInfosReportedListener); mInputWindowCommands.addWindowInfosReportedListener(windowInfosReportedListener); return *this; } Loading Loading @@ -2568,8 +2557,9 @@ SurfaceComposerClient::Transaction::setTrustedPresentationCallback( } s->what |= layer_state_t::eTrustedPresentationInfoChanged; s->trustedPresentationThresholds = thresholds; s->trustedPresentationListener.callbackInterface = TransactionCompletedListener::getIInstance(); s->trustedPresentationListener.callbackId = sc->getLayerId(); s->trustedPresentationListener.configure( {.callbackInterface = TransactionCompletedListener::getIInstance(), .callbackId = sc->getLayerId()}); return *this; } Loading @@ -2585,8 +2575,7 @@ SurfaceComposerClient::Transaction::clearTrustedPresentationCallback(const sp<Su } s->what |= layer_state_t::eTrustedPresentationInfoChanged; s->trustedPresentationThresholds = TrustedPresentationThresholds(); s->trustedPresentationListener.callbackInterface = nullptr; s->trustedPresentationListener.callbackId = -1; s->trustedPresentationListener.clear(); return *this; } Loading libs/gui/include/gui/LayerMetadata.h +4 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,10 @@ struct LayerMetadata : public Parcelable { LayerMetadata& operator=(const LayerMetadata& other); LayerMetadata& operator=(LayerMetadata&& other); // Note: `default` is not feasible because Parcelable does not provide ==. bool operator==(const LayerMetadata& rhs) const { return mMap == rhs.mMap; } bool operator!=(const LayerMetadata&) const = default; // Merges other into this LayerMetadata. If eraseEmpty is true, any entries in // in this whose keys are paired with empty values in other will be erased. bool merge(const LayerMetadata& other, bool eraseEmpty = false); Loading libs/gui/include/gui/LayerState.h +83 −17 Original line number Diff line number Diff line Loading @@ -17,9 +17,9 @@ #ifndef ANDROID_SF_LAYER_STATE_H #define ANDROID_SF_LAYER_STATE_H #include <stdint.h> #include <sys/types.h> #include <span> #include <android/gui/DisplayCaptureArgs.h> #include <android/gui/IWindowInfosReportedListener.h> Loading Loading @@ -69,21 +69,39 @@ struct client_cache_t { uint64_t id; bool operator==(const client_cache_t& other) const { return id == other.id; } bool operator!=(const client_cache_t&) const = default; bool isValid() const { return token != nullptr; } }; class TrustedPresentationListener : public Parcelable { public: struct State { sp<ITransactionCompletedListener> callbackInterface; int callbackId = -1; bool operator==(const State&) const = default; bool operator!=(const State&) const = default; }; void invoke(bool presentedWithinThresholds) { callbackInterface->onTrustedPresentationChanged(callbackId, presentedWithinThresholds); mState.callbackInterface->onTrustedPresentationChanged(mState.callbackId, presentedWithinThresholds); } void configure(State&& state) { mState = std::move(state); } const sp<ITransactionCompletedListener>& getCallback() { return mState.callbackInterface; } void clear() { mState.callbackInterface = nullptr; mState.callbackId = -1; } status_t writeToParcel(Parcel* parcel) const; status_t readFromParcel(const Parcel* parcel); bool operator==(const TrustedPresentationListener& rhs) const { return mState == rhs.mState; } bool operator!=(const TrustedPresentationListener&) const = default; private: State mState; }; class BufferData : public Parcelable { Loading Loading @@ -309,6 +327,32 @@ struct layer_state_t { bool hasValidBuffer() const; void sanitize(int32_t permissions); void updateTransparentRegion(const Region& transparentRegion); const Region& getTransparentRegion() const { return mNotDefCmpState.transparentRegion; } void updateSurfaceDamageRegion(const Region& surfaceDamageRegion); const Region& getSurfaceDamageRegion() const { return mNotDefCmpState.surfaceDamageRegion; } // Do not update state flags. Used to set up test state. void setSurfaceDamageRegion(Region&& surfaceDamageRegion) { mNotDefCmpState.surfaceDamageRegion = std::move(surfaceDamageRegion); } void updateRelativeLayer(const sp<SurfaceControl>& relativeTo, int32_t z); void updateParentLayer(const sp<SurfaceControl>& newParent); void updateInputWindowInfo(sp<gui::WindowInfoHandle>&& info); const gui::WindowInfo& getWindowInfo() const { return *mNotDefCmpState.windowInfoHandle->getInfo(); } gui::WindowInfo* editWindowInfo() { return mNotDefCmpState.windowInfoHandle->editInfo(); } const sp<SurfaceControl>& getParentSurfaceControlForChild() const { return mNotDefCmpState.parentSurfaceControlForChild; } const sp<SurfaceControl>& getRelativeLayerSurfaceControl() const { return mNotDefCmpState.relativeLayerSurfaceControl; } bool operator==(const layer_state_t&) const = default; bool operator!=(const layer_state_t&) const = default; struct matrix22_t { float dsdx{0}; float dtdx{0}; Loading Loading @@ -337,28 +381,20 @@ struct layer_state_t { float clientDrawnCornerRadius; uint32_t backgroundBlurRadius; sp<SurfaceControl> relativeLayerSurfaceControl; sp<SurfaceControl> parentSurfaceControlForChild; half4 color; // non POD must be last. see write/read Region transparentRegion; uint32_t bufferTransform; bool transformToDisplayInverse; FloatRect crop; std::shared_ptr<BufferData> bufferData = nullptr; ui::Dataspace dataspace; HdrMetadata hdrMetadata; Region surfaceDamageRegion; int32_t api; sp<NativeHandle> sidebandStream; mat4 colorTransform; std::vector<BlurRegion> blurRegions; sp<gui::WindowInfoHandle> windowInfoHandle = sp<gui::WindowInfoHandle>::make(); LayerMetadata metadata; // The following refer to the alpha, and dataspace, respectively of Loading Loading @@ -444,6 +480,18 @@ struct layer_state_t { std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> bufferReleaseChannel; std::shared_ptr<gui::DisplayLuts> luts; protected: struct NotDefaultComparableState { Region transparentRegion; Region surfaceDamageRegion; sp<gui::WindowInfoHandle> windowInfoHandle = sp<gui::WindowInfoHandle>::make(); sp<SurfaceControl> relativeLayerSurfaceControl; sp<SurfaceControl> parentSurfaceControlForChild; bool operator==(const NotDefaultComparableState& rhs) const; bool operator!=(const NotDefaultComparableState& rhs) const = default; } mNotDefCmpState; }; class ComposerState { Loading @@ -451,6 +499,9 @@ public: layer_state_t state; status_t write(Parcel& output) const; status_t read(const Parcel& input); bool operator==(const ComposerState&) const = default; bool operator!=(const ComposerState&) const = default; }; struct DisplayState { Loading Loading @@ -516,20 +567,35 @@ struct DisplayState { status_t write(Parcel& output) const; status_t read(const Parcel& input); bool operator==(const DisplayState&) const = default; bool operator!=(const DisplayState&) const = default; }; struct InputWindowCommands { std::vector<gui::FocusRequest> focusRequests; std::unordered_set<sp<gui::IWindowInfosReportedListener>, SpHash<gui::IWindowInfosReportedListener>> windowInfosReportedListeners; using Listener = gui::IWindowInfosReportedListener; using ListenerSet = std::unordered_set<sp<Listener>, SpHash<Listener>>; // Merges the passed in commands and returns true if there were any changes. bool merge(const InputWindowCommands& other); bool empty() const; void clear(); void addFocusRequest(const gui::FocusRequest& request) { focusRequests.push_back(request); } void addWindowInfosReportedListener(const sp<Listener>& listener) { windowInfosReportedListeners.insert(listener); } ListenerSet&& releaseListeners() { return std::move(windowInfosReportedListeners); } status_t write(Parcel& output) const; status_t read(const Parcel& input); std::span<const gui::FocusRequest> getFocusRequests() const { return focusRequests; } const ListenerSet& getListeners() const { return windowInfosReportedListeners; } bool operator==(const InputWindowCommands&) const = default; bool operator!=(const InputWindowCommands&) const = default; private: std::vector<gui::FocusRequest> focusRequests; ListenerSet windowInfosReportedListeners; }; static inline int compare_type(const ComposerState& lhs, const ComposerState& rhs) { Loading libs/gui/include/gui/WindowInfo.h +4 −0 Original line number Diff line number Diff line Loading @@ -268,6 +268,7 @@ struct WindowInfo : public Parcelable { bool overlaps(const WindowInfo* other) const; bool operator==(const WindowInfo& inputChannel) const; bool operator!=(const WindowInfo&) const = default; status_t writeToParcel(android::Parcel* parcel) const override; Loading Loading @@ -319,6 +320,9 @@ public: status_t readFromParcel(const android::Parcel* parcel); status_t writeToParcel(android::Parcel* parcel) const; bool operator==(const WindowInfoHandle& rhs) const { return mInfo == rhs.mInfo; } bool operator!=(const WindowInfoHandle&) const = default; protected: virtual ~WindowInfoHandle(); Loading Loading
libs/gui/LayerState.cpp +86 −24 Original line number Diff line number Diff line Loading @@ -55,6 +55,28 @@ namespace android { using gui::FocusRequest; using gui::WindowInfoHandle; namespace { bool isSameWindowHandle(const sp<WindowInfoHandle>& lhs, const sp<WindowInfoHandle>& rhs) { if (lhs == rhs) { return true; } if (!lhs || !rhs) { return false; } return *lhs->getInfo() == *rhs->getInfo(); }; bool isSameSurfaceControl(const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs) { if (lhs == rhs) { return true; } return SurfaceControl::isSameSurface(lhs, rhs); }; } // namespace layer_state_t::layer_state_t() : surface(nullptr), layerId(-1), Loading @@ -73,7 +95,6 @@ layer_state_t::layer_state_t() transformToDisplayInverse(false), crop({0, 0, -1, -1}), dataspace(ui::Dataspace::UNKNOWN), surfaceDamageRegion(), api(-1), colorTransform(mat4()), bgColor(0), Loading Loading @@ -117,19 +138,21 @@ status_t layer_state_t::write(Parcel& output) const SAFE_PARCEL(output.writeFloat, crop.left); SAFE_PARCEL(output.writeFloat, crop.bottom); SAFE_PARCEL(output.writeFloat, crop.right); SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl); SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild); SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, mNotDefCmpState.relativeLayerSurfaceControl); SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, mNotDefCmpState.parentSurfaceControlForChild); SAFE_PARCEL(output.writeFloat, color.r); SAFE_PARCEL(output.writeFloat, color.g); SAFE_PARCEL(output.writeFloat, color.b); SAFE_PARCEL(output.writeFloat, color.a); SAFE_PARCEL(windowInfoHandle->writeToParcel, &output); SAFE_PARCEL(output.write, transparentRegion); SAFE_PARCEL(mNotDefCmpState.windowInfoHandle->writeToParcel, &output); SAFE_PARCEL(output.write, mNotDefCmpState.transparentRegion); SAFE_PARCEL(output.writeUint32, bufferTransform); SAFE_PARCEL(output.writeBool, transformToDisplayInverse); SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace)); SAFE_PARCEL(output.write, hdrMetadata); SAFE_PARCEL(output.write, surfaceDamageRegion); SAFE_PARCEL(output.write, mNotDefCmpState.surfaceDamageRegion); SAFE_PARCEL(output.writeInt32, api); if (sidebandStream) { Loading Loading @@ -241,8 +264,10 @@ status_t layer_state_t::read(const Parcel& input) SAFE_PARCEL(input.readFloat, &crop.bottom); SAFE_PARCEL(input.readFloat, &crop.right); SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl); SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild); SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &mNotDefCmpState.relativeLayerSurfaceControl); SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &mNotDefCmpState.parentSurfaceControlForChild); float tmpFloat = 0; SAFE_PARCEL(input.readFloat, &tmpFloat); Loading @@ -254,9 +279,9 @@ status_t layer_state_t::read(const Parcel& input) SAFE_PARCEL(input.readFloat, &tmpFloat); color.a = tmpFloat; SAFE_PARCEL(windowInfoHandle->readFromParcel, &input); SAFE_PARCEL(mNotDefCmpState.windowInfoHandle->readFromParcel, &input); SAFE_PARCEL(input.read, transparentRegion); SAFE_PARCEL(input.read, mNotDefCmpState.transparentRegion); SAFE_PARCEL(input.readUint32, &bufferTransform); SAFE_PARCEL(input.readBool, &transformToDisplayInverse); Loading @@ -265,7 +290,7 @@ status_t layer_state_t::read(const Parcel& input) dataspace = static_cast<ui::Dataspace>(tmpUint32); SAFE_PARCEL(input.read, hdrMetadata); SAFE_PARCEL(input.read, surfaceDamageRegion); SAFE_PARCEL(input.read, mNotDefCmpState.surfaceDamageRegion); SAFE_PARCEL(input.readInt32, &api); bool tmpBool = false; Loading Loading @@ -583,7 +608,7 @@ void layer_state_t::merge(const layer_state_t& other) { } if (other.what & eTransparentRegionChanged) { what |= eTransparentRegionChanged; transparentRegion = other.transparentRegion; mNotDefCmpState.transparentRegion = other.mNotDefCmpState.transparentRegion; } if (other.what & eFlagsChanged) { what |= eFlagsChanged; Loading Loading @@ -615,11 +640,13 @@ void layer_state_t::merge(const layer_state_t& other) { what |= eRelativeLayerChanged; what &= ~eLayerChanged; z = other.z; relativeLayerSurfaceControl = other.relativeLayerSurfaceControl; mNotDefCmpState.relativeLayerSurfaceControl = other.mNotDefCmpState.relativeLayerSurfaceControl; } if (other.what & eReparent) { what |= eReparent; parentSurfaceControlForChild = other.parentSurfaceControlForChild; mNotDefCmpState.parentSurfaceControlForChild = other.mNotDefCmpState.parentSurfaceControlForChild; } if (other.what & eBufferTransformChanged) { what |= eBufferTransformChanged; Loading Loading @@ -665,7 +692,7 @@ void layer_state_t::merge(const layer_state_t& other) { } if (other.what & eSurfaceDamageRegionChanged) { what |= eSurfaceDamageRegionChanged; surfaceDamageRegion = other.surfaceDamageRegion; mNotDefCmpState.surfaceDamageRegion = other.mNotDefCmpState.surfaceDamageRegion; } if (other.what & eApiChanged) { what |= eApiChanged; Loading @@ -684,7 +711,8 @@ void layer_state_t::merge(const layer_state_t& other) { } if (other.what & eInputInfoChanged) { what |= eInputInfoChanged; windowInfoHandle = sp<WindowInfoHandle>::make(*other.windowInfoHandle); mNotDefCmpState.windowInfoHandle = sp<WindowInfoHandle>::make(*other.mNotDefCmpState.windowInfoHandle); } if (other.what & eBackgroundColorChanged) { what |= eBackgroundColorChanged; Loading Loading @@ -807,7 +835,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const { CHECK_DIFF(diff, eAlphaChanged, other, color.a); CHECK_DIFF(diff, eMatrixChanged, other, matrix); if (other.what & eTransparentRegionChanged && (!transparentRegion.hasSameRects(other.transparentRegion))) { (!mNotDefCmpState.transparentRegion.hasSameRects( other.mNotDefCmpState.transparentRegion))) { diff |= eTransparentRegionChanged; } if (other.what & eFlagsChanged) { Loading @@ -824,8 +853,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const { diff &= ~eLayerChanged; } if (other.what & eReparent && !SurfaceControl::isSameSurface(parentSurfaceControlForChild, other.parentSurfaceControlForChild)) { !SurfaceControl::isSameSurface(mNotDefCmpState.parentSurfaceControlForChild, other.mNotDefCmpState.parentSurfaceControlForChild)) { diff |= eReparent; } CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform); Loading @@ -839,7 +868,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const { CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint); CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata); if (other.what & eSurfaceDamageRegionChanged && (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) { (!mNotDefCmpState.surfaceDamageRegion.hasSameRects( other.mNotDefCmpState.surfaceDamageRegion))) { diff |= eSurfaceDamageRegionChanged; } CHECK_DIFF(diff, eApiChanged, other, api); Loading Loading @@ -901,6 +931,38 @@ status_t layer_state_t::matrix22_t::read(const Parcel& input) { SAFE_PARCEL(input.readFloat, &dsdy); return NO_ERROR; } void layer_state_t::updateTransparentRegion(const Region& transparentRegion) { what |= eTransparentRegionChanged; mNotDefCmpState.transparentRegion = transparentRegion; } void layer_state_t::updateSurfaceDamageRegion(const Region& surfaceDamageRegion) { what |= eSurfaceDamageRegionChanged; mNotDefCmpState.surfaceDamageRegion = surfaceDamageRegion; } void layer_state_t::updateRelativeLayer(const sp<SurfaceControl>& relativeTo, int32_t z) { what |= layer_state_t::eRelativeLayerChanged; what &= ~layer_state_t::eLayerChanged; mNotDefCmpState.relativeLayerSurfaceControl = relativeTo; this->z = z; } void layer_state_t::updateParentLayer(const sp<SurfaceControl>& newParent) { what |= layer_state_t::eReparent; mNotDefCmpState.parentSurfaceControlForChild = newParent ? newParent->getParentingLayer() : nullptr; } void layer_state_t::updateInputWindowInfo(sp<gui::WindowInfoHandle>&& info) { what |= eInputInfoChanged; mNotDefCmpState.windowInfoHandle = std::move(info); } bool layer_state_t::NotDefaultComparableState::operator==( const NotDefaultComparableState& rhs) const { return transparentRegion.hasSameRects(rhs.transparentRegion) && surfaceDamageRegion.hasSameRects(rhs.surfaceDamageRegion) && isSameWindowHandle(windowInfoHandle, rhs.windowInfoHandle) && isSameSurfaceControl(relativeLayerSurfaceControl, rhs.relativeLayerSurfaceControl) && isSameSurfaceControl(parentSurfaceControlForChild, rhs.parentSurfaceControlForChild); } // ------------------------------- InputWindowCommands ---------------------------------------- Loading Loading @@ -1034,8 +1096,8 @@ status_t BufferData::readFromParcel(const Parcel* input) { } status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const { SAFE_PARCEL(parcel->writeStrongBinder, callbackInterface); SAFE_PARCEL(parcel->writeInt32, callbackId); SAFE_PARCEL(parcel->writeStrongBinder, mState.callbackInterface); SAFE_PARCEL(parcel->writeInt32, mState.callbackId); return NO_ERROR; } Loading @@ -1043,9 +1105,9 @@ status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) { sp<IBinder> tmpBinder = nullptr; SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder); if (tmpBinder) { callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder); mState.callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder); } SAFE_PARCEL(parcel->readInt32, &callbackId); SAFE_PARCEL(parcel->readInt32, &mState.callbackId); return NO_ERROR; } Loading
libs/gui/SurfaceComposerClient.cpp +11 −22 Original line number Diff line number Diff line Loading @@ -1523,11 +1523,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelat mStatus = BAD_INDEX; return *this; } s->what |= layer_state_t::eRelativeLayerChanged; s->what &= ~layer_state_t::eLayerChanged; s->relativeLayerSurfaceControl = relativeTo; s->z = z; s->updateRelativeLayer(relativeTo, z); registerSurfaceControlForCallback(sc); return *this; } Loading Loading @@ -1557,9 +1553,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTrans mStatus = BAD_INDEX; return *this; } s->what |= layer_state_t::eTransparentRegionChanged; s->transparentRegion = transparentRegion; s->updateTransparentRegion(transparentRegion); registerSurfaceControlForCallback(sc); return *this; } Loading Loading @@ -1721,9 +1715,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent if (SurfaceControl::isSameSurface(sc, newParent)) { return *this; } s->what |= layer_state_t::eReparent; s->parentSurfaceControlForChild = newParent ? newParent->getParentingLayer() : nullptr; s->updateParentLayer(newParent); registerSurfaceControlForCallback(sc); return *this; } Loading Loading @@ -2009,9 +2001,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSurfa mStatus = BAD_INDEX; return *this; } s->what |= layer_state_t::eSurfaceDamageRegionChanged; s->surfaceDamageRegion = surfaceDamageRegion; s->updateSurfaceDamageRegion(surfaceDamageRegion); registerSurfaceControlForCallback(sc); return *this; } Loading Loading @@ -2130,21 +2120,20 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInput mStatus = BAD_INDEX; return *this; } s->windowInfoHandle = std::move(info); s->what |= layer_state_t::eInputInfoChanged; s->updateInputWindowInfo(std::move(info)); return *this; } SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFocusedWindow( const FocusRequest& request) { mInputWindowCommands.focusRequests.push_back(request); mInputWindowCommands.addFocusRequest(request); return *this; } SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::addWindowInfosReportedListener( sp<gui::IWindowInfosReportedListener> windowInfosReportedListener) { mInputWindowCommands.windowInfosReportedListeners.insert(windowInfosReportedListener); mInputWindowCommands.addWindowInfosReportedListener(windowInfosReportedListener); return *this; } Loading Loading @@ -2568,8 +2557,9 @@ SurfaceComposerClient::Transaction::setTrustedPresentationCallback( } s->what |= layer_state_t::eTrustedPresentationInfoChanged; s->trustedPresentationThresholds = thresholds; s->trustedPresentationListener.callbackInterface = TransactionCompletedListener::getIInstance(); s->trustedPresentationListener.callbackId = sc->getLayerId(); s->trustedPresentationListener.configure( {.callbackInterface = TransactionCompletedListener::getIInstance(), .callbackId = sc->getLayerId()}); return *this; } Loading @@ -2585,8 +2575,7 @@ SurfaceComposerClient::Transaction::clearTrustedPresentationCallback(const sp<Su } s->what |= layer_state_t::eTrustedPresentationInfoChanged; s->trustedPresentationThresholds = TrustedPresentationThresholds(); s->trustedPresentationListener.callbackInterface = nullptr; s->trustedPresentationListener.callbackId = -1; s->trustedPresentationListener.clear(); return *this; } Loading
libs/gui/include/gui/LayerMetadata.h +4 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,10 @@ struct LayerMetadata : public Parcelable { LayerMetadata& operator=(const LayerMetadata& other); LayerMetadata& operator=(LayerMetadata&& other); // Note: `default` is not feasible because Parcelable does not provide ==. bool operator==(const LayerMetadata& rhs) const { return mMap == rhs.mMap; } bool operator!=(const LayerMetadata&) const = default; // Merges other into this LayerMetadata. If eraseEmpty is true, any entries in // in this whose keys are paired with empty values in other will be erased. bool merge(const LayerMetadata& other, bool eraseEmpty = false); Loading
libs/gui/include/gui/LayerState.h +83 −17 Original line number Diff line number Diff line Loading @@ -17,9 +17,9 @@ #ifndef ANDROID_SF_LAYER_STATE_H #define ANDROID_SF_LAYER_STATE_H #include <stdint.h> #include <sys/types.h> #include <span> #include <android/gui/DisplayCaptureArgs.h> #include <android/gui/IWindowInfosReportedListener.h> Loading Loading @@ -69,21 +69,39 @@ struct client_cache_t { uint64_t id; bool operator==(const client_cache_t& other) const { return id == other.id; } bool operator!=(const client_cache_t&) const = default; bool isValid() const { return token != nullptr; } }; class TrustedPresentationListener : public Parcelable { public: struct State { sp<ITransactionCompletedListener> callbackInterface; int callbackId = -1; bool operator==(const State&) const = default; bool operator!=(const State&) const = default; }; void invoke(bool presentedWithinThresholds) { callbackInterface->onTrustedPresentationChanged(callbackId, presentedWithinThresholds); mState.callbackInterface->onTrustedPresentationChanged(mState.callbackId, presentedWithinThresholds); } void configure(State&& state) { mState = std::move(state); } const sp<ITransactionCompletedListener>& getCallback() { return mState.callbackInterface; } void clear() { mState.callbackInterface = nullptr; mState.callbackId = -1; } status_t writeToParcel(Parcel* parcel) const; status_t readFromParcel(const Parcel* parcel); bool operator==(const TrustedPresentationListener& rhs) const { return mState == rhs.mState; } bool operator!=(const TrustedPresentationListener&) const = default; private: State mState; }; class BufferData : public Parcelable { Loading Loading @@ -309,6 +327,32 @@ struct layer_state_t { bool hasValidBuffer() const; void sanitize(int32_t permissions); void updateTransparentRegion(const Region& transparentRegion); const Region& getTransparentRegion() const { return mNotDefCmpState.transparentRegion; } void updateSurfaceDamageRegion(const Region& surfaceDamageRegion); const Region& getSurfaceDamageRegion() const { return mNotDefCmpState.surfaceDamageRegion; } // Do not update state flags. Used to set up test state. void setSurfaceDamageRegion(Region&& surfaceDamageRegion) { mNotDefCmpState.surfaceDamageRegion = std::move(surfaceDamageRegion); } void updateRelativeLayer(const sp<SurfaceControl>& relativeTo, int32_t z); void updateParentLayer(const sp<SurfaceControl>& newParent); void updateInputWindowInfo(sp<gui::WindowInfoHandle>&& info); const gui::WindowInfo& getWindowInfo() const { return *mNotDefCmpState.windowInfoHandle->getInfo(); } gui::WindowInfo* editWindowInfo() { return mNotDefCmpState.windowInfoHandle->editInfo(); } const sp<SurfaceControl>& getParentSurfaceControlForChild() const { return mNotDefCmpState.parentSurfaceControlForChild; } const sp<SurfaceControl>& getRelativeLayerSurfaceControl() const { return mNotDefCmpState.relativeLayerSurfaceControl; } bool operator==(const layer_state_t&) const = default; bool operator!=(const layer_state_t&) const = default; struct matrix22_t { float dsdx{0}; float dtdx{0}; Loading Loading @@ -337,28 +381,20 @@ struct layer_state_t { float clientDrawnCornerRadius; uint32_t backgroundBlurRadius; sp<SurfaceControl> relativeLayerSurfaceControl; sp<SurfaceControl> parentSurfaceControlForChild; half4 color; // non POD must be last. see write/read Region transparentRegion; uint32_t bufferTransform; bool transformToDisplayInverse; FloatRect crop; std::shared_ptr<BufferData> bufferData = nullptr; ui::Dataspace dataspace; HdrMetadata hdrMetadata; Region surfaceDamageRegion; int32_t api; sp<NativeHandle> sidebandStream; mat4 colorTransform; std::vector<BlurRegion> blurRegions; sp<gui::WindowInfoHandle> windowInfoHandle = sp<gui::WindowInfoHandle>::make(); LayerMetadata metadata; // The following refer to the alpha, and dataspace, respectively of Loading Loading @@ -444,6 +480,18 @@ struct layer_state_t { std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> bufferReleaseChannel; std::shared_ptr<gui::DisplayLuts> luts; protected: struct NotDefaultComparableState { Region transparentRegion; Region surfaceDamageRegion; sp<gui::WindowInfoHandle> windowInfoHandle = sp<gui::WindowInfoHandle>::make(); sp<SurfaceControl> relativeLayerSurfaceControl; sp<SurfaceControl> parentSurfaceControlForChild; bool operator==(const NotDefaultComparableState& rhs) const; bool operator!=(const NotDefaultComparableState& rhs) const = default; } mNotDefCmpState; }; class ComposerState { Loading @@ -451,6 +499,9 @@ public: layer_state_t state; status_t write(Parcel& output) const; status_t read(const Parcel& input); bool operator==(const ComposerState&) const = default; bool operator!=(const ComposerState&) const = default; }; struct DisplayState { Loading Loading @@ -516,20 +567,35 @@ struct DisplayState { status_t write(Parcel& output) const; status_t read(const Parcel& input); bool operator==(const DisplayState&) const = default; bool operator!=(const DisplayState&) const = default; }; struct InputWindowCommands { std::vector<gui::FocusRequest> focusRequests; std::unordered_set<sp<gui::IWindowInfosReportedListener>, SpHash<gui::IWindowInfosReportedListener>> windowInfosReportedListeners; using Listener = gui::IWindowInfosReportedListener; using ListenerSet = std::unordered_set<sp<Listener>, SpHash<Listener>>; // Merges the passed in commands and returns true if there were any changes. bool merge(const InputWindowCommands& other); bool empty() const; void clear(); void addFocusRequest(const gui::FocusRequest& request) { focusRequests.push_back(request); } void addWindowInfosReportedListener(const sp<Listener>& listener) { windowInfosReportedListeners.insert(listener); } ListenerSet&& releaseListeners() { return std::move(windowInfosReportedListeners); } status_t write(Parcel& output) const; status_t read(const Parcel& input); std::span<const gui::FocusRequest> getFocusRequests() const { return focusRequests; } const ListenerSet& getListeners() const { return windowInfosReportedListeners; } bool operator==(const InputWindowCommands&) const = default; bool operator!=(const InputWindowCommands&) const = default; private: std::vector<gui::FocusRequest> focusRequests; ListenerSet windowInfosReportedListeners; }; static inline int compare_type(const ComposerState& lhs, const ComposerState& rhs) { Loading
libs/gui/include/gui/WindowInfo.h +4 −0 Original line number Diff line number Diff line Loading @@ -268,6 +268,7 @@ struct WindowInfo : public Parcelable { bool overlaps(const WindowInfo* other) const; bool operator==(const WindowInfo& inputChannel) const; bool operator!=(const WindowInfo&) const = default; status_t writeToParcel(android::Parcel* parcel) const override; Loading Loading @@ -319,6 +320,9 @@ public: status_t readFromParcel(const android::Parcel* parcel); status_t writeToParcel(android::Parcel* parcel) const; bool operator==(const WindowInfoHandle& rhs) const { return mInfo == rhs.mInfo; } bool operator!=(const WindowInfoHandle&) const = default; protected: virtual ~WindowInfoHandle(); Loading