diff options
author | 2019-01-25 17:46:06 -0800 | |
---|---|---|
committer | 2019-02-05 23:33:39 +0000 | |
commit | ef876c9c6bb5118c457c9146964d76de854c11fc (patch) | |
tree | 5704e98cea15fb2204408c0932eb0e911b8652d8 /libs/gui/LayerMetadata.cpp | |
parent | c0f4a2edd57ec26335ac52efd4584552cea19f2c (diff) |
Merge metadata from transaction instead of replace
This was replacing metadata when set in transactions rather
than merging. To fix this, merge has been augmented to also
report if a change occurred and to erase empty entries (as
a mechanism to "unset" metadata)
Bug: 122925737
Test: Added more unittests
Change-Id: Ia854cbcc1ddd334f18ffacea667cbb98778ec210
Diffstat (limited to 'libs/gui/LayerMetadata.cpp')
-rw-r--r-- | libs/gui/LayerMetadata.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/libs/gui/LayerMetadata.cpp b/libs/gui/LayerMetadata.cpp index 745433a605..04d2871c77 100644 --- a/libs/gui/LayerMetadata.cpp +++ b/libs/gui/LayerMetadata.cpp @@ -31,10 +31,23 @@ LayerMetadata::LayerMetadata(const LayerMetadata& other) = default; LayerMetadata::LayerMetadata(LayerMetadata&& other) = default; -void LayerMetadata::merge(const LayerMetadata& other) { +bool LayerMetadata::merge(const LayerMetadata& other, bool eraseEmpty) { + bool changed = false; for (const auto& entry : other.mMap) { - mMap[entry.first] = entry.second; + auto it = mMap.find(entry.first); + if (it != mMap.cend() && it->second != entry.second) { + if (eraseEmpty && entry.second.empty()) { + mMap.erase(it); + } else { + it->second = entry.second; + } + changed = true; + } else if (it == mMap.cend() && !entry.second.empty()) { + mMap[entry.first] = entry.second; + changed = true; + } } + return changed; } status_t LayerMetadata::writeToParcel(Parcel* parcel) const { |