From 9614b566d8e497cf8afffc3d26b004a1518baefe Mon Sep 17 00:00:00 2001 From: Stefan Karschti Date: Thu, 7 Mar 2024 16:28:33 +0200 Subject: [PATCH] Workaround for issue #2117 (#2148) --- platform/ios/CHANGELOG.md | 4 ++++ platform/ios/app/MBXAppDelegate.m | 2 +- platform/ios/benchmark/MBXBenchAppDelegate.mm | 2 +- platform/ios/src/MLNMapView.mm | 15 ++++++++------- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index a391a194f..a56260ee4 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -4,6 +4,10 @@ MapLibre welcomes participation and contributions from everyone. Please read [`C ## main +## (unreleased) + +- Temporary workaround for map display freeze / stutter when using annotation views with Metal backend. [Issue 2117](https://github.com/maplibre/maplibre-native/issues/2117) fixed by [PR 2148](https://github.com/maplibre/maplibre-native/pull/2148) + ## 6.2.0 - Add support for [multi sprites](https://github.com/maplibre/maplibre-native/pull/1858). More information on this feature can be found in the [Style Spec Documentation](https://maplibre.org/maplibre-style-spec/sprite/#multiple-sprite-sources). diff --git a/platform/ios/app/MBXAppDelegate.m b/platform/ios/app/MBXAppDelegate.m index 4766c7ad0..549eb5acd 100644 --- a/platform/ios/app/MBXAppDelegate.m +++ b/platform/ios/app/MBXAppDelegate.m @@ -11,7 +11,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { -#ifndef MLN_DISABLE_LOGGING +#ifndef MLN_LOGGING_DISABLED [MLNLoggingConfiguration sharedConfiguration].loggingLevel = MLNLoggingLevelFault; #endif [MLNSettings useWellKnownTileServer:MLNMapTiler]; diff --git a/platform/ios/benchmark/MBXBenchAppDelegate.mm b/platform/ios/benchmark/MBXBenchAppDelegate.mm index 99f9c8c6d..287d9ec49 100644 --- a/platform/ios/benchmark/MBXBenchAppDelegate.mm +++ b/platform/ios/benchmark/MBXBenchAppDelegate.mm @@ -8,7 +8,7 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { -#ifndef MLN_DISABLE_LOGGING +#ifndef MLN_LOGGING_DISABLED [MLNLoggingConfiguration sharedConfiguration].loggingLevel = MLNLoggingLevelFault; #endif diff --git a/platform/ios/src/MLNMapView.mm b/platform/ios/src/MLNMapView.mm index 930c234b3..6e4152c93 100644 --- a/platform/ios/src/MLNMapView.mm +++ b/platform/ios/src/MLNMapView.mm @@ -6974,17 +6974,14 @@ static void *windowScreenContext = &windowScreenContext; if (annotationView) { - CLLocationCoordinate2D coordinate = annotation.coordinate; + annotationView.center = MLNPointRounded([self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self]); + // Every so often (1 out of 1000 frames?) the mbgl query mechanism fails. This logic spot checks the // offscreenAnnotations values -- if they are actually still on screen then the view center is // moved and the enqueue operation is avoided. This allows us to keep the performance benefit of // using the mbgl query result. It also forces views that have just gone offscreen to be cleared // fully from view. - if (MLNCoordinateInCoordinateBounds(coordinate, coordinateBounds)) - { - annotationView.center = [self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self]; - } - else + if (!MLNCoordinateInCoordinateBounds(annotation.coordinate, coordinateBounds)) { if (annotationView.layer.animationKeys.count > 0) { continue; @@ -6995,7 +6992,11 @@ static void *windowScreenContext = &windowScreenContext; adjustedCenter.x = -CGRectGetWidth(self.frame) * 10.0; annotationView.center = adjustedCenter; - [self enqueueAnnotationViewForAnnotationContext:annotationContext]; + // Disable the offscreen annotation view recycling on Metal because of issue https://github.com/maplibre/maplibre-native/issues/2117 + // TLDR: Metal view rendering stutter / freeze +#if !MLN_RENDER_BACKEND_METAL + [self enqueueAnnotationViewForAnnotationContext:annotationContext]; +#endif } } }