diff --git a/platform/ios/src/MLNMapView+Impl.h b/platform/ios/src/MLNMapView+Impl.h index 717818bbf..04a991977 100644 --- a/platform/ios/src/MLNMapView+Impl.h +++ b/platform/ios/src/MLNMapView+Impl.h @@ -57,10 +57,6 @@ public: void render(); virtual MLNBackendResource getObject() = 0; - - virtual void setSynchronous(bool value) {}; - virtual bool getSynchronous() const { return false; }; - // mbgl::MapObserver implementation void onCameraWillChange(mbgl::MapObserver::CameraChangeMode) override; diff --git a/platform/ios/src/MLNMapView+Metal.h b/platform/ios/src/MLNMapView+Metal.h index 5c43fe853..f83d66413 100644 --- a/platform/ios/src/MLNMapView+Metal.h +++ b/platform/ios/src/MLNMapView+Metal.h @@ -49,10 +49,4 @@ public: void layoutChanged() override; MLNBackendResource getObject() override; // End implementation of MLNMapViewImpl - - void setSynchronous(bool value) override { synchronousFrame = value; }; - bool getSynchronous() const override { return synchronousFrame; }; -private: - bool presentsWithTransaction = false; - bool synchronousFrame = false; }; diff --git a/platform/ios/src/MLNMapView+Metal.mm b/platform/ios/src/MLNMapView+Metal.mm index 99deb858a..54c530c83 100644 --- a/platform/ios/src/MLNMapView+Metal.mm +++ b/platform/ios/src/MLNMapView+Metal.mm @@ -80,18 +80,14 @@ public: void swap() override { id currentDrawable = [mtlView currentDrawable]; if (currentDrawable) { - [commandBuffer presentDrawable:currentDrawable]; - } - [commandBuffer commit]; - - // Synchronous rendering can help troubleshoot rendering problems, - // particularly those related to resource tracking and multiple queued buffers. - // The conditional logic for synchronous rendering is commanded from MLNMapView.updateAnnotationViews: - // `_mbglView->setSynchronous(haveVisibleAnnotationViews);` - // and fixes the desynchronization of UIView annotation when the map is rendered on the Metal backend - // Issue: https://github.com/maplibre/maplibre-native/issues/2053 - if (backend.getSynchronous()) { - [commandBuffer waitUntilCompleted]; + if (presentsWithTransaction) { + [commandBuffer commit]; + [commandBuffer waitUntilCompleted]; + [currentDrawable present]; + } else { + [commandBuffer presentDrawable:currentDrawable]; + [commandBuffer commit]; + } } commandBuffer = nil; @@ -116,6 +112,7 @@ public: MTKView *mtlView = nil; id commandBuffer; id commandQueue; + bool presentsWithTransaction = false; // We count how often the context was activated/deactivated so that we can truly deactivate it // after the activation count drops to 0. @@ -137,10 +134,10 @@ void MLNMapViewMetalImpl::setOpaque(const bool opaque) { } void MLNMapViewMetalImpl::setPresentsWithTransaction(const bool value) { - presentsWithTransaction = value; + auto& resource = getResource(); + resource.presentsWithTransaction = value; if (@available(iOS 13.0, *)) { - auto& resource = getResource(); if (CAMetalLayer* metalLayer = MLN_OBJC_DYNAMIC_CAST(resource.mtlView.layer, CAMetalLayer)) { metalLayer.presentsWithTransaction = value; } @@ -180,7 +177,7 @@ void MLNMapViewMetalImpl::createView() { resource.mtlView.enableSetNeedsDisplay = YES; if (@available(iOS 13.0, *)) { CAMetalLayer* metalLayer = MLN_OBJC_DYNAMIC_CAST(resource.mtlView.layer, CAMetalLayer); - metalLayer.presentsWithTransaction = presentsWithTransaction; + metalLayer.presentsWithTransaction = resource.presentsWithTransaction; } [mapView insertSubview:resource.mtlView atIndex:0]; diff --git a/platform/ios/src/MLNMapView.mm b/platform/ios/src/MLNMapView.mm index a1eb98c00..6e4152c93 100644 --- a/platform/ios/src/MLNMapView.mm +++ b/platform/ios/src/MLNMapView.mm @@ -6917,9 +6917,6 @@ static void *windowScreenContext = &windowScreenContext; NSMutableArray *offscreenAnnotations = [self.annotations mutableCopy]; [offscreenAnnotations removeObjectsInArray:visibleAnnotations]; - // Dynamic flag used to drive the backend's synchronous frame rendering (see comment below) - bool haveVisibleAnnotationViews = false; - // Update the center of visible annotation views for (id annotation in visibleAnnotations) { @@ -6955,15 +6952,7 @@ static void *windowScreenContext = &windowScreenContext; if (annotationView) { - // Reset the center to zero in order to force the annotation view to redraw even when is not moving. - // This will force somehow the map view to display the rendered drawable for older devices. - // This is a fix for the following issues: - // https://github.com/maplibre/maplibre-native/issues/2337 - // https://github.com/maplibre/maplibre-native/issues/2380 - annotationView.center = CGPointZero; - annotationView.center = MLNPointRounded([self convertCoordinate:annotationContext.annotation.coordinate toPointToView:self]); - haveVisibleAnnotationViews = true; } } @@ -7011,14 +7000,6 @@ static void *windowScreenContext = &windowScreenContext; } } } - - // Switch synchronous frame rendering on if we have visible annotation views. - // Only implemented on Metal, just a stub on OpenGL. - // This logic is needed to fix the desynchronization of UIView annotations when the map is rendered on the Metal backend with asynchronous frames. - // Root cause: the Map transform is updated immediately and the annotations are positioned on the screen using it, - // while the map rendered surface catches up when the frame is complete. - // Issue: https://github.com/maplibre/maplibre-native/issues/2053 - _mbglView->setSynchronous(haveVisibleAnnotationViews); } - (BOOL)hasAnAnchoredAnnotationCalloutView