Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Core support for source-driven attribution #6431

Merged
merged 1 commit into from
Sep 26, 2016

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented Sep 22, 2016

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

@1ec5 1ec5 added feature GL JS parity For feature parity with Mapbox GL JS Core The cross-platform C++ core, aka mbgl labels Sep 22, 2016
@1ec5 1ec5 self-assigned this Sep 22, 2016
@mention-bot
Copy link

@1ec5, thanks for your PR! By analyzing this pull request, we identified @jfirebaugh, @tmpsantos and @ansis to be potential reviewers.

@1ec5 1ec5 mentioned this pull request Sep 22, 2016
9 tasks
Copy link
Contributor

@tmpsantos tmpsantos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this!

@@ -17,6 +17,7 @@ class SourceObserver {
virtual ~SourceObserver() = default;

virtual void onSourceLoaded(Source&) {}
virtual void onSourceAttributionChanged(Source&, std::string) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string&

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -76,6 +76,7 @@ static_assert(mbgl::underlying_type(QMapboxGL::MapChangeDidFinishRenderingFrameF
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This static_assert will fail because we did not add yet MapChangeDidFinishLoadingStyle on Qt. Can you add that one too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it here, since MapChangeDidFinishRenderingMapFullyRendered was also defined there. Do I need to add it anywhere else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I understand. Done in c1ef372. (Something similar is still missing from the iOS and macOS SDKs: #6412.)

style::TileSourceImpl* tileSource = static_cast<style::TileSourceImpl*>(source->baseImpl.get());
auto attribution = tileSource->getAttribution();
if (!attribution.empty()) {
result.push_back(attribution);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::move(attribution)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -465,6 +489,10 @@ void Style::onSourceLoaded(Source& source) {
observer->onUpdate(Update::Repaint);
}

void Style::onSourceAttributionChanged(Source& source, std::string attribution) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string&

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -30,6 +30,10 @@ class StubStyleObserver : public style::Observer {
if (sourceLoaded) sourceLoaded(source);
}

void onSourceAttributionChanged(Source& source, std::string attribution) override {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string&

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@1ec5 1ec5 force-pushed the 1ec5-attribution-callback-core-5999 branch from 5a26cd4 to 147cd9d Compare September 22, 2016 16:50
Copy link
Contributor

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding Map::getAttributions() and Style::getAttributions(), can we add Source::getAttribution()? That leverages the existing runtime source API better.

@1ec5
Copy link
Contributor Author

1ec5 commented Sep 22, 2016

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 MapChange revamp proposed in #6383?

@@ -111,7 +111,8 @@ class Q_DECL_EXPORT QMapboxGL : public QObject
MapChangeDidFinishRenderingFrameFullyRendered,
MapChangeWillStartRenderingMap,
MapChangeDidFinishRenderingMap,
MapChangeDidFinishRenderingMapFullyRendered
MapChangeDidFinishRenderingMapFullyRendered,
MapChangeSourceAttributionDidChange
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will fail on the static_assert because we don't have MapChangeDidFinishLoadingStyle before MapChangeSourceAttributionDidChange.

tmpsantos added a commit that referenced this pull request Sep 26, 2016
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==
```
@tmpsantos
Copy link
Contributor

@1ec5 seems like valgrind found an issue (not exactly related to this PR). I have a fix on #6455.

tmpsantos added a commit that referenced this pull request Sep 26, 2016
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==
```
@tmpsantos
Copy link
Contributor

I have a fix on #6455.

Fix landed, bots should be 🍏 if you rebase.

@1ec5 1ec5 added the Qt Mapbox Maps SDK for Qt, aka Qt Location Mapbox GL label Sep 26, 2016
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.
@1ec5 1ec5 force-pushed the 1ec5-attribution-callback-core-5999 branch from c1ef372 to 6433cc7 Compare September 26, 2016 18:09
@1ec5 1ec5 merged commit f307652 into master Sep 26, 2016
@1ec5 1ec5 deleted the 1ec5-attribution-callback-core-5999 branch September 26, 2016 18:37
@jfirebaugh
Copy link
Contributor

Hmm, I guess I should have disapproved the PR. I don't want to commit the core API to Map::getAttributions().

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl feature GL JS parity For feature parity with Mapbox GL JS Qt Mapbox Maps SDK for Qt, aka Qt Location Mapbox GL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants