-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conversation
@kkaefer, thanks for your PR! By analyzing this pull request, we identified @boundsj, @1ec5 and @friedbunny to be potential reviewers. |
6f60430
to
fed3eda
Compare
@kkaefer What are the implications of this feature addition on the difficulty of implementing asynchronous rendering? For instance, does it introduce synchronous tile loading callbacks that would make it difficult to move the ownership of tile data to a background thread? |
Yes, this makes sense. Since
The current design is influenced by the data source pattern in Objective-C and Swift. An arbitrary object (commonly but not necessarily the view controller) conforms to a data source protocol, registers itself as the data source, and implements those callback functions. The Objective-C data source object can have its own state, and the developer is able to assume that the object persists for the lifetime of the source. This is similar to how MGLOpenGLStyleLayer works, even as it wraps mbgl’s The SDK generally wraps each In #7375 (comment), we discussed having the SDK hang onto every source that gets added to the style. Even if we don’t take such a drastic step, I do think we should have the SDK manage the source object, just as the SDK manages the layer object for custom layers. If the source goes away behind the SDK’s back, I don’t see how the situation would be any different for custom sources than it would be for GeoJSON sources.
This would parallel the renaming I pushed for on the SDK side. (In the iOS and macOS SDKs, “shape” is used where mbgl would use “geometry”.) I think we should also consider moving away from the term “custom”, which has a tendency to get overloaded. At the SDK level, this feature is now represented by MGLComputedShapeSource, because the defining characteristic of a custom source (like a custom layer) is that it’s programmatic, computed on-demand. I hope we don’t end up having to rename runtime styling to “custom styling” for consistency. 😛 |
The current implementation calls the provided callback on the main thread. If we'd move rendering a secondary thread, we'd still retain the sources and tile management/loading on the main thread. The callback doesn't accept a callback; instead users can call the source object with tile data at any point (from the main thread). Users can either generate geometry synchronously, or use a custom or platform specific way to synthesize the geometry. The iOS/macOS bindings are using a
That's not how ownership of sources works in Core. The SDK needs to relinquish ownership to the |
fed3eda
to
6ca8886
Compare
I was referring to management in a conceptual sense, not memory ownership. I think this would work just as MGLOpenGLStyleLayer does today: MGLOpenGLStyleLayer does relinquish ownership of the mbgl::style::CustomLayer object to mbgl but keeps a non-owning pointer to it; MGLStyle strongly owns MGLOpenGLStyleLayer. MGLOpenGLStyleLayer's methods get called by lambdas that get passed into mbgl::style::CustomLayer. |
I'm anticipating that we'll want to move tile management/loading to the render thread. Discussion in #8476. |
From a user perspective, having clustering support come from the framework is very handy. If clustering was removed, i would just end up implementing the same thing in my application. |
To clarify, there are no plans to remove clustering support from GeoJSON sources (shape sources). The question is whether to extend the support for custom vector sources (computed shape sources). In #8473 (comment), the naming confused me a bit. The source type being added here is actually closer to shape sources than it is to vector sources. That’s an argument for keeping the clustering support, but either way, it’s an option, not something that would be forced on users of this source type. |
This branch is now significantly out of date with master, and will not cleanly merge. An updated version that will cleanly merge into master is at https://github.com/trailbehind/mapbox-gl-native/tree/custom-vector-source-merge-master-7-7-2017 |
→ #9983. |
This is a squashed version of #6940, with changes separated by functional units rather than development history. This makes it easier to review the soundness of this pull request.
Missing:
Needs discussion:
source->setTileData(...)
directly in the callback, theTile
object hasn't been added to the list of tiles yet, sosetTileData
does nothing.std::map
is probably low, we might be able to do better than linear search, e.g. by usingstd::equal_range
and finding allOverzoomedTileID
s that contain theCanonicalTileID
we are looking for)Source
object'scache
of abandoned tiles whensetTileData
is called.reloadRegion()
required?CustomVectorSource
object, we could provide a callback function that becomes a no-op if theSource
object goes away. This makes for a safer API.CustomVectorSource
toCustomGeometrySource
to be in line with the naming ofGeometryTile
andGeometryTileWorker
./cc @JesseCrocker @1ec5 @jonkan @frederoni @ivovandongen @incanus