Repository navigation
Core support for source-driven attribution - #6431
Conversation
|
@1ec5, thanks for your PR! By analyzing this pull request, we identified @jfirebaugh, @tmpsantos and @ansis to be potential reviewers. |
tmpsantos
left a comment
There was a problem hiding this comment.
Thanks a lot for this!
| virtual ~SourceObserver() = default; | ||
|
|
||
| virtual void onSourceLoaded(Source&) {} | ||
| virtual void onSourceAttributionChanged(Source&, std::string) {} |
| static_assert(mbgl::underlying_type(QMapboxGL::MapChangeWillStartRenderingMap) == mbgl::underlying_type(mbgl::MapChangeWillStartRenderingMap), "error"); | ||
| static_assert(mbgl::underlying_type(QMapboxGL::MapChangeDidFinishRenderingMap) == mbgl::underlying_type(mbgl::MapChangeDidFinishRenderingMap), "error"); | ||
| static_assert(mbgl::underlying_type(QMapboxGL::MapChangeDidFinishRenderingMapFullyRendered) == mbgl::underlying_type(mbgl::MapChangeDidFinishRenderingMapFullyRendered), "error"); | ||
| static_assert(mbgl::underlying_type(QMapboxGL::MapChangeSourceAttributionDidChange) == mbgl::underlying_type(mbgl::MapChangeSourceAttributionDidChange), "error"); |
There was a problem hiding this comment.
This static_assert will fail because we did not add yet MapChangeDidFinishLoadingStyle on Qt. Can you add that one too?
There was a problem hiding this comment.
I added it here, since MapChangeDidFinishRenderingMapFullyRendered was also defined there. Do I need to add it anywhere else?
There was a problem hiding this comment.
Do I need to add it anywhere else?
That is not it, this code won't compile on Qt because we are missing the MapChangeDidFinishLoadingStyle signal on the API that must be declared before MapChangeSourceAttributionDidChange otherwise the enum won't fully match the counterpart which is exactly what the static_assert is asserting.
| style::TileSourceImpl* tileSource = static_cast<style::TileSourceImpl*>(source->baseImpl.get()); | ||
| auto attribution = tileSource->getAttribution(); | ||
| if (!attribution.empty()) { | ||
| result.push_back(attribution); |
| observer->onUpdate(Update::Repaint); | ||
| } | ||
|
|
||
| void Style::onSourceAttributionChanged(Source& source, std::string attribution) { |
| if (sourceLoaded) sourceLoaded(source); | ||
| } | ||
|
|
||
| void onSourceAttributionChanged(Source& source, std::string attribution) override { |
5a26cd4 to
147cd9d
Compare
jfirebaugh
left a comment
There was a problem hiding this comment.
Instead of adding Map::getAttributions() and Style::getAttributions(), can we add Source::getAttribution()? That leverages the existing runtime source API better.
That would make a lot of sense, though it means we’ll need more infrastructure for bubbling source-related changes up to the SDK level. The macOS implementation of MGLMapView, for instance, would need to register itself as a source observer as sources are added and removed in order to accomplish the dynamically updating attribution control in #5999. (Presumably the Qt SDK would have to do likewise, since an on-demand attribution control is only an option for mobile UIs.) How will this fit into the |
| MapChangeDidFinishRenderingMap, | ||
| MapChangeDidFinishRenderingMapFullyRendered | ||
| MapChangeDidFinishRenderingMapFullyRendered, | ||
| MapChangeSourceAttributionDidChange |
There was a problem hiding this comment.
This code will fail on the static_assert because we don't have MapChangeDidFinishLoadingStyle before MapChangeSourceAttributionDidChange.
This function can be called from different threads and was depending on a global `std::string protocol` which can do heap allocations. The first thread to use it would initialized it which is not exactly safe, so this patch moves it to a `char *` that is just a pointer to the data segment, so no races. Valgrind detected it on #6431. ``` ==9874== Conditional jump or move depends on uninitialised value(s) ==9874== at 0x4C307C2: __memcmp_sse4_1 (in /home/travis/build/mapbox/mapbox-gl-native/mason_packages/linux-x86_64/valgrind/latest/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==9874== by 0x79896E: mbgl::util::mapbox::isMapboxURL(std::string const&) (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test) ==9874== by 0x6DC756: mbgl::style::TileSourceImpl::parseTileJSON(std::string const&, std::string const&, mbgl::SourceType, unsigned short) (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test) ==9874== by 0x6DDA6A: std::_Function_handler<void (mbgl::Response), mbgl::style::TileSourceImpl::loadDescription(mbgl::FileSource&)::{lambda(mbgl::Response)#1}>::_M_invoke(std::_Any_data const&, mbgl::Response&&) (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test) ==9874== by 0x50BE80: std::_Function_handler<void (), mbgl::StubFileSource::StubFileSource()::{lambda()#1}>::_M_invoke(std::_Any_data const&) (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test) ==9874== by 0x70972A5: QMetaObject::activate(QObject*, int, int, void**) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1) ==9874== by 0x70A3621: QTimer::timerEvent(QTimerEvent*) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1) ==9874== by 0x7098053: QObject::event(QEvent*) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1) ==9874== by 0x60CCC8B: QApplicationPrivate::notify_helper(QObject*, QEvent*) (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1) ==9874== by 0x60D1E55: QApplication::notify(QObject*, QEvent*) (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1) ==9874== by 0x706FC2C: QCoreApplication::notifyInternal(QObject*, QEvent*) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1) ==9874== by 0x70BC1AC: QTimerInfoList::activateTimers() (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1) ==9874== ```
This function can be called from different threads and was depending on a global `std::string protocol` which can do heap allocations. The first thread to use it would initialized it which is not exactly safe, so this patch moves it to a `char *` that is just a pointer to the data segment, so no races. Valgrind detected it on #6431. ``` ==9874== Conditional jump or move depends on uninitialised value(s) ==9874== at 0x4C307C2: __memcmp_sse4_1 (in /home/travis/build/mapbox/mapbox-gl-native/mason_packages/linux-x86_64/valgrind/latest/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==9874== by 0x79896E: mbgl::util::mapbox::isMapboxURL(std::string const&) (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test) ==9874== by 0x6DC756: mbgl::style::TileSourceImpl::parseTileJSON(std::string const&, std::string const&, mbgl::SourceType, unsigned short) (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test) ==9874== by 0x6DDA6A: std::_Function_handler<void (mbgl::Response), mbgl::style::TileSourceImpl::loadDescription(mbgl::FileSource&)::{lambda(mbgl::Response)#1}>::_M_invoke(std::_Any_data const&, mbgl::Response&&) (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test) ==9874== by 0x50BE80: std::_Function_handler<void (), mbgl::StubFileSource::StubFileSource()::{lambda()#1}>::_M_invoke(std::_Any_data const&) (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test) ==9874== by 0x70972A5: QMetaObject::activate(QObject*, int, int, void**) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1) ==9874== by 0x70A3621: QTimer::timerEvent(QTimerEvent*) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1) ==9874== by 0x7098053: QObject::event(QEvent*) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1) ==9874== by 0x60CCC8B: QApplicationPrivate::notify_helper(QObject*, QEvent*) (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1) ==9874== by 0x60D1E55: QApplication::notify(QObject*, QEvent*) (in /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.2.1) ==9874== by 0x706FC2C: QCoreApplication::notifyInternal(QObject*, QEvent*) (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1) ==9874== by 0x70BC1AC: QTimerInfoList::activateTimers() (in /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.2.1) ==9874== ```
Fix landed, bots should be 🍏 if you rebase. |
Implemented observer callbacks so the style knows when the source’s attribution changes and the map knows when the style’s attribution changes. Also implemented a getter for a tile source’s attribution. Fixes #2723.
c1ef372 to
6433cc7
Compare
|
Hmm, I guess I should have disapproved the PR. I don't want to commit the core API to |
Implemented observer callbacks so the style knows when the source’s attribution changes and the map knows when the style’s attribution changes. Also implemented a getter for a tile source’s attribution.
Working towards #2723. Blocks #5999.
/cc @tmpsantos