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

[core] Return source and layer ownership #7014

Merged
merged 5 commits into from
Nov 11, 2016

Conversation

boundsj
Copy link
Contributor

@boundsj boundsj commented Nov 10, 2016

When a source or layer is removed transfer ownership back to the caller so it can (optionally) take it.

ref #6959

cc @jfirebaugh

When a source or layer is removed transfer ownership back to the
caller so it can (optionally) take it.
@boundsj boundsj added Core The cross-platform C++ core, aka mbgl runtime styling labels Nov 10, 2016
@boundsj boundsj added this to the ios-v3.4.0 milestone Nov 10, 2016
@boundsj boundsj self-assigned this Nov 10, 2016
@mention-bot
Copy link

@boundsj, thanks for your PR! By analyzing the history of the files in this pull request, we identified @jfirebaugh, @brunoabinader and @kkaefer to be potential reviewers.

@boundsj
Copy link
Contributor Author

boundsj commented Nov 10, 2016

Once this is ready, I'd like to merge it to master and then cherry-pick to the iOS (and maybe Android) release branches where the returned objects can actually be used in the platform source and layer wrappers.

if (impl->style) {
impl->styleMutated = true;
impl->style->removeSource(sourceID);
return impl->style->removeSource(sourceID);
Copy link
Contributor

Choose a reason for hiding this comment

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

Trailing whitespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 8584922

}

impl->styleMutated = true;
impl->backend.activate();

impl->style->removeLayer(id);
auto removedLayer = impl->style->removeLayer(id);
impl->onUpdate(Update::Classes);

impl->backend.deactivate();
Copy link
Contributor

Choose a reason for hiding this comment

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

We will need to add special logic for CustomLayer. Currently, ~CustomLayer calls the CustomLayerDeinitializeFunction, which may make OpenGL calls. This is the reason that we call impl->backend.activate()/deactivate() -- the context needs to be active when initialization/deinitialization happens.

I think we need to preserve the behavior that removing a CustomLayer triggers deinitialization, even when returning ownership. Let's do this in Style::removeLayer, making it parallel Style::addLayer, which does initialization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -43,6 +43,11 @@ void CustomLayer::Impl::initialize() {
initializeFn(context);
}

void CustomLayer::Impl::deinitialize() {
assert(deinitializeFn);
deinitializeFn(context);
Copy link
Contributor

Choose a reason for hiding this comment

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

Also need to remove deinitialization from CustomLayer::Impl::~Impl. And from the looks of that method, it's possible that deinitializeFn may be optional? I don't remember but we should probably keep the guard.

@boundsj
Copy link
Contributor Author

boundsj commented Nov 11, 2016

@jfirebaugh can you please double check that 554abe9 looks ok to you?

@jfirebaugh
Copy link
Contributor

👍

@boundsj boundsj merged commit edf40bb into master Nov 11, 2016
@boundsj boundsj deleted the boundsj-return-source-layer-ownership branch November 11, 2016 22:40
boundsj added a commit that referenced this pull request Nov 14, 2016
When a source or layer is removed transfer ownership back to the
caller so it can (optionally) take it. Preserve the behavior that 
removing a CustomLayer triggers deinitialization.  Deinitialize all 
custom layers when a style is destroyed in case those layers are not 
explicitly removed.
ivovandongen pushed a commit that referenced this pull request Nov 14, 2016
When a source or layer is removed transfer ownership back to the
caller so it can (optionally) take it. Preserve the behavior that 
removing a CustomLayer triggers deinitialization.  Deinitialize all 
custom layers when a style is destroyed in case those layers are not 
explicitly removed.
@ivovandongen ivovandongen mentioned this pull request Nov 14, 2016
ivovandongen pushed a commit that referenced this pull request Nov 14, 2016
When a source or layer is removed transfer ownership back to the
caller so it can (optionally) take it. Preserve the behavior that 
removing a CustomLayer triggers deinitialization.  Deinitialize all 
custom layers when a style is destroyed in case those layers are not 
explicitly removed.
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 runtime styling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants