summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/style/layers/custom_layer.hpp2
-rw-r--r--platform/darwin/src/MGLOpenGLStyleLayer.mm9
-rw-r--r--platform/macos/macos.xcodeproj/project.pbxproj8
-rw-r--r--platform/macos/src/MGLMapView.mm8
-rw-r--r--src/mbgl/style/layers/custom_layer.cpp4
-rw-r--r--test/api/custom_layer.test.cpp26
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 = "<group>"; };
96E0273A1E57C9BB004B8E66 /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/Localizable.strings; sourceTree = "<group>"; };
96E0273B1E57C9BC004B8E66 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; };
- CA67C805204DCBE800C1CBB4 /* MGLStyleLayerRetentionManager_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLStyleLayerRetentionManager_Private.h; sourceTree = "<group>"; };
- CA67C807204DCBE900C1CBB4 /* MGLStyleLayerRetentionManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLStyleLayerRetentionManager.mm; sourceTree = "<group>"; };
DA00FC881D5EEAC3009AABC8 /* MGLAttributionInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLAttributionInfo.h; sourceTree = "<group>"; };
DA00FC891D5EEAC3009AABC8 /* MGLAttributionInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLAttributionInfo.mm; sourceTree = "<group>"; };
DA0CD58D1CF56F5800A5F5A5 /* MGLFeatureTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLFeatureTests.mm; path = ../../darwin/test/MGLFeatureTests.mm; sourceTree = "<group>"; };
@@ -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<Impl>(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<CustomLayer>(
- "custom",
- [] (void* context) {
- reinterpret_cast<TestLayer*>(context)->initialize();
- },
- [] (void* context, const CustomLayerRenderParameters&) {
- reinterpret_cast<TestLayer*>(context)->render();
- },
- [] (void* context) {
- delete reinterpret_cast<TestLayer*>(context);
- },
- nullptr,
- new TestLayer()));
+
+
+ auto testLayer = std::make_unique<TestLayer>();
+ auto customLayer = std::make_unique<CustomLayer>("custom", std::move(testLayer));
+ map.getStyle().addLayer(std::move(customLayer));
+
auto layer = std::make_unique<FillLayer>("landcover", "mapbox");
layer->setSourceLayer("landcover");