-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core] Replace inline SpriteAtlas updates with diffing #9010
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,10 @@ | |
|
||
namespace mbgl { | ||
|
||
template <class T> | ||
StyleDifference<T> diff(const std::vector<T>& a, const std::vector<T>& b) { | ||
template <class T, class Eq> | ||
StyleDifference<T> diff(const std::vector<T>& a, const std::vector<T>& b, const Eq& eq) { | ||
std::vector<T> lcs; | ||
|
||
auto eq = [] (const T& lhs, const T& rhs) { | ||
return std::tie(lhs->id, lhs->type) | ||
== std::tie(rhs->id, rhs->type); | ||
}; | ||
|
||
longest_common_subsequence(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(lcs), eq); | ||
|
||
auto aIt = a.begin(); | ||
|
@@ -43,14 +38,27 @@ StyleDifference<T> diff(const std::vector<T>& a, const std::vector<T>& b) { | |
return result; | ||
} | ||
|
||
ImageDifference diffImages(const std::vector<ImmutableImage>& a, | ||
const std::vector<ImmutableImage>& b) { | ||
return diff(a, b, [] (const ImmutableImage& lhs, const ImmutableImage& rhs) { | ||
return lhs->id == rhs->id; | ||
}); | ||
} | ||
|
||
SourceDifference diffSources(const std::vector<ImmutableSource>& a, | ||
const std::vector<ImmutableSource>& b) { | ||
return diff(a, b); | ||
return diff(a, b, [] (const ImmutableSource& lhs, const ImmutableSource& rhs) { | ||
return std::tie(lhs->id, lhs->type) | ||
== std::tie(rhs->id, rhs->type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, this breaks down when id/type match, but different styles use the same source name ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, what needs to happen in this situation is that the source reloads its existing tiles and clears the cache. Refactoring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, I thought we already did that, hence the comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update: after thinking about how to handle this case once we do support smart set style, I decided I want to rework the "Eliminate Style::updateBatch in favor of diffing" part of this PR significantly. I'll land just the |
||
}); | ||
} | ||
|
||
LayerDifference diffLayers(const std::vector<ImmutableLayer>& a, | ||
const std::vector<ImmutableLayer>& b) { | ||
return diff(a, b); | ||
return diff(a, b, [] (const ImmutableLayer& lhs, const ImmutableLayer& rhs) { | ||
return std::tie(lhs->id, lhs->type) | ||
== std::tie(rhs->id, rhs->type); | ||
}); | ||
} | ||
|
||
} // namespace mbgl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks down when two styles have sprites with image names that are identical, but actually refer to different images.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, the image will be added to the "changed" list, and subsequently passed to
SpriteAtlas::addImage
.#7618 is the underlying issue that should be fixed; I'm planning on working on that this week. In the meantime, I'll change the assertion to a regular conditional, mirroring this check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned this up in b2e7794 but left the assertion; I don't believe there's currently a way to trigger it.