From bcdf23028e93a8216fc6b877486a04ac5a579c58 Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Mon, 5 Mar 2018 14:16:15 -0500 Subject: [macos] Updated MGLMapView with new layer manager. --- platform/macos/macos.xcodeproj/project.pbxproj | 8 ++++++++ platform/macos/src/MGLMapView.mm | 11 ++++++++--- test/api/custom_layer.test.cpp | 10 ++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 4327670911..903b34e7dd 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -97,6 +97,8 @@ 9654C12B1FFC38E000DB6A19 /* MGLPolyline_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 9654C12A1FFC38E000DB6A19 /* MGLPolyline_Private.h */; }; 9654C12D1FFC394700DB6A19 /* MGLPolygon_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 9654C12C1FFC394700DB6A19 /* MGLPolygon_Private.h */; }; 96E027311E57C9A7004B8E66 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96E027331E57C9A7004B8E66 /* Localizable.strings */; }; + CA67C814204DCC0300C1CBB4 /* MGLStyleLayerRetentionManager_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = CA67C805204DCBE800C1CBB4 /* MGLStyleLayerRetentionManager_Private.h */; }; + CA67C815204DCC0D00C1CBB4 /* MGLStyleLayerRetentionManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = CA67C807204DCBE900C1CBB4 /* MGLStyleLayerRetentionManager.mm */; }; DA00FC8A1D5EEAC3009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; DA00FC8B1D5EEAC3009AABC8 /* MGLAttributionInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */; }; DA0CD58E1CF56F5800A5F5A5 /* MGLFeatureTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */; }; @@ -398,6 +400,8 @@ 96E027391E57C9B9004B8E66 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Localizable.strings; sourceTree = ""; }; 96E0273A1E57C9BB004B8E66 /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/Localizable.strings; sourceTree = ""; }; 96E0273B1E57C9BC004B8E66 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = ""; }; + CA67C805204DCBE800C1CBB4 /* MGLStyleLayerRetentionManager_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLStyleLayerRetentionManager_Private.h; sourceTree = ""; }; + CA67C807204DCBE900C1CBB4 /* MGLStyleLayerRetentionManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLStyleLayerRetentionManager.mm; sourceTree = ""; }; DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = ""; }; DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = ""; }; DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = ""; }; @@ -1130,6 +1134,8 @@ 92F2C3EA1F0E3A1900268EC0 /* MGLRendererFrontend.h */, DAE6C3571CC31E0400DB3429 /* MGLStyle.h */, 3537CA731D3F93A600380318 /* MGLStyle_Private.h */, + CA67C805204DCBE800C1CBB4 /* MGLStyleLayerRetentionManager_Private.h */, + CA67C807204DCBE900C1CBB4 /* MGLStyleLayerRetentionManager.mm */, DAE6C37A1CC31E2A00DB3429 /* MGLStyle.mm */, DAE6C3591CC31E0400DB3429 /* MGLTypes.h */, DAE6C37C1CC31E2A00DB3429 /* MGLTypes.m */, @@ -1207,6 +1213,7 @@ DAE6C3971CC31E2A00DB3429 /* NSBundle+MGLAdditions.h in Headers */, DAED385F1D62CED700D7640F /* NSURL+MGLAdditions.h in Headers */, DAD165741CF4CD7A001FF4B9 /* MGLShapeCollection.h in Headers */, + CA67C814204DCC0300C1CBB4 /* MGLStyleLayerRetentionManager_Private.h in Headers */, DAE6C3631CC31E0400DB3429 /* MGLPointAnnotation.h in Headers */, DAC2ABC51CC6D343006D18C4 /* MGLAnnotationImage_Private.h in Headers */, DAE6C35F1CC31E0400DB3429 /* MGLOfflinePack.h in Headers */, @@ -1543,6 +1550,7 @@ DAE6C3911CC31E2A00DB3429 /* MGLPolygon.mm in Sources */, 35C6DF851E214C0400ACA483 /* MGLDistanceFormatter.m in Sources */, DAE6C39B1CC31E2A00DB3429 /* NSProcessInfo+MGLAdditions.m in Sources */, + CA67C815204DCC0D00C1CBB4 /* MGLStyleLayerRetentionManager.mm in Sources */, DAA998FC1E9F545C002E6EA6 /* MGLFillExtrusionStyleLayer.mm in Sources */, DAE6C38F1CC31E2A00DB3429 /* MGLOfflineStorage.mm in Sources */, DAED38601D62CED700D7640F /* NSURL+MGLAdditions.m in Sources */, diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index e54b0f195d..8b9a5a982f 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -15,6 +15,7 @@ #import "MGLMultiPoint_Private.h" #import "MGLOfflineStorage_Private.h" #import "MGLStyle_Private.h" +#import "MGLStyleLayerRetentionManager_Private.h" #import "MGLShape_Private.h" #import "MGLAccountManager.h" @@ -144,6 +145,7 @@ public: @property (nonatomic, readwrite) NSView *attributionView; @property (nonatomic, readwrite) MGLStyle *style; +@property (nonatomic) MGLStyleLayerRetentionManager* styleLayerRetentionManager; /// Mapping from reusable identifiers to annotation images. @property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, MGLAnnotationImage *) *annotationImagesByIdentifier; @@ -256,6 +258,8 @@ public: - (void)commonInit { _isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent; + _styleLayerRetentionManager = [[MGLStyleLayerRetentionManager alloc] init]; + // Set up cross-platform controllers and resources. _mbglView = new MGLMapViewImpl(self); @@ -882,7 +886,7 @@ public: return; } - [self.style retainLayersUsedDuringRendering]; + [self.styleLayerRetentionManager updateRetainedLayers:self.style.managedLayers]; if ([self.delegate respondsToSelector:@selector(mapViewWillStartRenderingFrame:)]) { [self.delegate mapViewWillStartRenderingFrame:self]; @@ -898,11 +902,12 @@ public: _isChangingAnnotationLayers = NO; [self.style didChangeValueForKey:@"layers"]; } + + [self.styleLayerRetentionManager decrementLifetimes]; + if ([self.delegate respondsToSelector:@selector(mapViewDidFinishRenderingFrame:fullyRendered:)]) { [self.delegate mapViewDidFinishRenderingFrame:self fullyRendered:fullyRendered]; } - - [self.style releaseLayersUsedDuringRendering]; } - (void)mapViewWillStartRenderingMap { diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp index eb1d7e0d3a..0f6747c12e 100644 --- a/test/api/custom_layer.test.cpp +++ b/test/api/custom_layer.test.cpp @@ -96,14 +96,16 @@ TEST(CustomLayer, Basic) { map.getStyle().addLayer(std::make_unique( "custom", [] (void* context) { - reinterpret_cast(context)->initialize(); + reinterpret_cast(context)->initialize(); }, [] (void* context, const CustomLayerRenderParameters&) { - reinterpret_cast(context)->render(); + reinterpret_cast(context)->render(); }, [] (void* context) { - delete reinterpret_cast(context); - }, new TestLayer())); + delete reinterpret_cast(context); + }, + nullptr, + new TestLayer())); auto layer = std::make_unique("landcover", "mapbox"); layer->setSourceLayer("landcover"); -- cgit v1.2.1