Fixed memory usage high in some cases (#2442)

This commit is contained in:
Alex Cristici
2024-05-29 12:17:31 +03:00
committed by GitHub
parent 8dc8462a61
commit 9c6ba6914b
4 changed files with 12 additions and 44 deletions

View File

@@ -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;

View File

@@ -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;
};

View File

@@ -80,18 +80,14 @@ public:
void swap() override {
id<CAMetalDrawable> 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 <MTLCommandBuffer> commandBuffer;
id <MTLCommandQueue> 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<MLNMapViewMetalRenderableResource>();
resource.presentsWithTransaction = value;
if (@available(iOS 13.0, *)) {
auto& resource = getResource<MLNMapViewMetalRenderableResource>();
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];

View File

@@ -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<MLNAnnotation> 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