[ios, macos] Refcount view activations (#7208)

This adds a ref count to guard against calling activate after it has
already been called. This can happen when a layer is added during
certain map lifecycle methods like MapChangeWillStartRenderingFrame
that also triggers activation. This also protects against issues
related to a deactivation of the context happening in an inner scope
while an outer scope is still expecting to be able to use the context.
This commit is contained in:
Jesse Bounds
2016-11-29 08:56:59 -08:00
committed by GitHub
parent 83e134eb9f
commit d830c48e4a
2 changed files with 23 additions and 0 deletions

View File

@@ -5093,16 +5093,28 @@ public:
void activate() override
{
if (activationCount++)
{
return;
}
[EAGLContext setCurrentContext:nativeView.context];
}
void deactivate() override
{
if (--activationCount)
{
return;
}
[EAGLContext setCurrentContext:nil];
}
private:
__weak MGLMapView *nativeView = nullptr;
NSUInteger activationCount = 0;
};
@end

View File

@@ -2611,11 +2611,19 @@ public:
}
void activate() override {
if (activationCount++) {
return;
}
MGLOpenGLLayer *layer = (MGLOpenGLLayer *)nativeView.layer;
[layer.openGLContext makeCurrentContext];
}
void deactivate() override {
if (--activationCount) {
return;
}
[NSOpenGLContext clearCurrentContext];
}
@@ -2661,6 +2669,9 @@ private:
/// The current framebuffer of the NSOpenGLLayer we are painting to.
GLint fbo = 0;
/// The reference counted count of activation calls
NSUInteger activationCount = 0;
};
@end