From 9b3d5272e78a3b6e8d6539d242519df3b7792acb Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Fri, 23 Mar 2018 16:12:34 -0400 Subject: Updates to macos and tests for previous changes. --- include/mbgl/style/layers/custom_layer.hpp | 2 +- platform/darwin/src/MGLOpenGLStyleLayer.mm | 9 ++++++--- platform/macos/macos.xcodeproj/project.pbxproj | 8 -------- platform/macos/src/MGLMapView.mm | 8 -------- src/mbgl/style/layers/custom_layer.cpp | 4 ++-- test/api/custom_layer.test.cpp | 26 ++++++++++++-------------- 6 files changed, 21 insertions(+), 36 deletions(-) diff --git a/include/mbgl/style/layers/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp index 3c6d015392..60c42e2d5a 100644 --- a/include/mbgl/style/layers/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -69,7 +69,7 @@ class CustomLayerContext { virtual void initialize() = 0; virtual void render(const CustomLayerRenderParameters&) = 0; - virtual void deinitialize() = 0; + virtual void deinitialize() {}; virtual void lost() {}; diff --git a/platform/darwin/src/MGLOpenGLStyleLayer.mm b/platform/darwin/src/MGLOpenGLStyleLayer.mm index 2641369fd1..7b0200c56f 100644 --- a/platform/darwin/src/MGLOpenGLStyleLayer.mm +++ b/platform/darwin/src/MGLOpenGLStyleLayer.mm @@ -193,7 +193,9 @@ public: // We need to ensure that this layer is retained, so that any references from layer impl's // e.g. contexts) are still valid -// [style addToManagedLayers:self]; + +// [style addToManagedLayers:self]; // This is currently handled by the Custom layer, when the style +// sets itself to be the layer's observer [super addToStyle:style belowLayer:otherLayer]; } @@ -201,8 +203,9 @@ public: - (void)removeFromStyle:(MGLStyle *)style { [super removeFromStyle:style]; - // We need to ensure that this layer is now released (however, if this layer is about to be - // used by the renderer then it will released once rendering is complete) + // We need to ensure that this layer is now released (not necessarily freed) + // This is currently handled by the Custom layer, when the style + // unsets itself as the layer's observer // [style removeFromManagedLayers:self]; self.style = nil; diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 903b34e7dd..4327670911 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -97,8 +97,6 @@ 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 */; }; @@ -400,8 +398,6 @@ 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 = ""; }; @@ -1134,8 +1130,6 @@ 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 */, @@ -1213,7 +1207,6 @@ 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 */, @@ -1550,7 +1543,6 @@ 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 8b9a5a982f..4cbf2b9fba 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -15,7 +15,6 @@ #import "MGLMultiPoint_Private.h" #import "MGLOfflineStorage_Private.h" #import "MGLStyle_Private.h" -#import "MGLStyleLayerRetentionManager_Private.h" #import "MGLShape_Private.h" #import "MGLAccountManager.h" @@ -145,7 +144,6 @@ 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; @@ -258,8 +256,6 @@ public: - (void)commonInit { _isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent; - _styleLayerRetentionManager = [[MGLStyleLayerRetentionManager alloc] init]; - // Set up cross-platform controllers and resources. _mbglView = new MGLMapViewImpl(self); @@ -886,8 +882,6 @@ public: return; } - [self.styleLayerRetentionManager updateRetainedLayers:self.style.managedLayers]; - if ([self.delegate respondsToSelector:@selector(mapViewWillStartRenderingFrame:)]) { [self.delegate mapViewWillStartRenderingFrame:self]; } @@ -903,8 +897,6 @@ public: [self.style didChangeValueForKey:@"layers"]; } - [self.styleLayerRetentionManager decrementLifetimes]; - if ([self.delegate respondsToSelector:@selector(mapViewDidFinishRenderingFrame:fullyRendered:)]) { [self.delegate mapViewDidFinishRenderingFrame:self fullyRendered:fullyRendered]; } diff --git a/src/mbgl/style/layers/custom_layer.cpp b/src/mbgl/style/layers/custom_layer.cpp index 4f69ce8b52..eeb7dd384d 100644 --- a/src/mbgl/style/layers/custom_layer.cpp +++ b/src/mbgl/style/layers/custom_layer.cpp @@ -10,7 +10,8 @@ CustomLayer::~CustomLayer() printf("~CustomLayer destructor %p\n", this); // Need to set rawLayer to nil in the obj-c layer. - onDestruction(); + if (onDestruction) + onDestruction(); } CustomLayer::CustomLayer(const std::string& layerID, @@ -18,7 +19,6 @@ CustomLayer::CustomLayer(const std::string& layerID, Layer(makeMutable(layerID, std::move(context))) { printf("CustomLayer::CustomLayer %p\n", this); - } const CustomLayer::Impl& CustomLayer::impl() const { diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp index 0f6747c12e..0d29aacba8 100644 --- a/test/api/custom_layer.test.cpp +++ b/test/api/custom_layer.test.cpp @@ -34,7 +34,7 @@ void main() { // layer implementation because it is intended to reflect how someone using custom layers // might actually write their own implementation. -class TestLayer { +class TestLayer: public CustomLayerContext { public: ~TestLayer() { if (program) { @@ -67,6 +67,11 @@ public: MBGL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(GLfloat), triangle, GL_STATIC_DRAW)); } + void render(const CustomLayerRenderParameters& params) { + (void)params; + render(); + } + void render() { MBGL_CHECK_ERROR(glUseProgram(program)); MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, buffer)); @@ -93,19 +98,12 @@ TEST(CustomLayer, Basic) { threadPool, MapMode::Static); map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json")); map.setLatLngZoom({ 37.8, -122.5 }, 10); - map.getStyle().addLayer(std::make_unique( - "custom", - [] (void* context) { - reinterpret_cast(context)->initialize(); - }, - [] (void* context, const CustomLayerRenderParameters&) { - reinterpret_cast(context)->render(); - }, - [] (void* context) { - delete reinterpret_cast(context); - }, - nullptr, - new TestLayer())); + + + auto testLayer = std::make_unique(); + auto customLayer = std::make_unique("custom", std::move(testLayer)); + map.getStyle().addLayer(std::move(customLayer)); + auto layer = std::make_unique("landcover", "mapbox"); layer->setSourceLayer("landcover"); -- cgit v1.2.1