From 1045934d5e62eaf85bc280ce2d75e7558f5a5104 Mon Sep 17 00:00:00 2001 From: Roman Blum Date: Tue, 6 Dec 2016 02:16:13 +0100 Subject: [core, ios, macos] Add image accessor to MGLStyle (#7096) * [core] Add interface to get image from sprite atlas * [tests] Add tests for Map::getImage * [ios, macos] WIP: get MGLImage for name from style * [ios, macos] Fixed -imageForName: Convert from sprite images to platform images using the existing encodePNG() function, which is also used for printing. Allow -imageForName: to return nil without an assertion failure. Added a basic test. --- include/mbgl/map/map.hpp | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 10153c54e3..092cfbe291 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -171,6 +171,7 @@ public: // Add image, bound to the style void addImage(const std::string&, std::unique_ptr); void removeImage(const std::string&); + const SpriteImage* getImage(const std::string&); // Defaults std::string getStyleName() const; -- cgit v1.2.1 From a39f53df22246cc85be17933b6c99897786d2222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Wed, 7 Dec 2016 00:01:11 -0800 Subject: [ios, macos] Migrate MGLCustomStyleLayerAdditions to style layer API (#7250) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [ios, macos] Replaced custom style layer API with MGLOpenGLStyleLayer Replaced the custom style layer API on MGLMapView with an equally unsupported MGLOpenGLStyleLayer API that nonetheless is consistent with the broader runtime styling API and is compatible with macOS. Fixed an unrecognized selector crash when wrapping a layer of unrecognized type coming from mbgl. * [macos] Added lime green layer demo to macosapp Reprised the demo removed from iosapp in #5091. * [ios, macos] Rationalized MGLOpenGLStyleLayer API MGLStyle now strongly references any MGLOpenGLStyleLayer object that’s added to it, in order to prevent pointers from going stale and make it easy for layer drawing code to get more information about the map view. Replaced the MGLOpenGLStyleLayer callback blocks with overridable instance methods. Added internal documentation for each method. Subclassed MGLOpenGLStyleLayer as LimeGreenStyleLayer inside macosapp. Consolidated -addToMapView: into -addToMapView:belowLayer: to ensure that MGLRedundantLayerException gets raised even if the layer is being inserted rather than added to the bottom of the stack. * [core] Clarified that rendering happens on the main thread * [ios, macos] Fixed removing and re-adding MGLOpenGLStyleLayer Don’t allow index-based layer removal to circumvent -removeFromMapView:, which MGLOpenGLStyleLayer relies on to synchronize the style’s array of MGLOpenGLStyleLayers. When obtaining an MGLOpenGLStyleLayer, get the instance already added to the style instead of creating a new one to wrap the underlying CustomLayer. --- include/mbgl/style/layers/custom_layer.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/mbgl/style/layers/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp index 87bce06f41..1b62f82a25 100644 --- a/include/mbgl/style/layers/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -7,8 +7,8 @@ namespace style { /** * Initialize any GL state needed by the custom layer. This method is called once, from the - * rendering thread, at a point when the GL context is active but before rendering for the - * first time. + * main thread, at a point when the GL context is active but before rendering for the first + * time. * * Resources that are acquired in this method must be released in the UninitializeFunction. */ @@ -40,7 +40,7 @@ using CustomLayerRenderFunction = void (*)(void* context, const CustomLayerRende /** * Destroy any GL state needed by the custom layer, and deallocate context, if necessary. This - * method is called once, from the rendering thread, at a point when the GL context is active. + * method is called once, from the main thread, at a point when the GL context is active. * * Note that it may be called even when the InitializeFunction has not been called. */ -- cgit v1.2.1 From 18730d598d29cf876064ce6964ef88ef0351f78f Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Tue, 6 Dec 2016 17:24:32 +0100 Subject: [core] use raii to guard backend deactivation --- include/mbgl/map/backend.hpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/mbgl/map/backend.hpp b/include/mbgl/map/backend.hpp index c11d094906..0468449155 100644 --- a/include/mbgl/map/backend.hpp +++ b/include/mbgl/map/backend.hpp @@ -10,6 +10,8 @@ namespace gl { class Context; } // namespace gl +class BackendScope; + class Backend { public: Backend(); @@ -18,6 +20,14 @@ public: // Returns the backend's context which manages OpenGL state. gl::Context& getContext(); + // Called when the map needs to be rendered; the backend should call Map::render() at some point + // in the near future. (Not called for Map::renderStill() mode.) + virtual void invalidate() = 0; + + // Notifies a watcher of map x/y/scale/rotation changes. + virtual void notifyMapChange(MapChange change); + +protected: // Called when the backend's GL context needs to be made active or inactive. These are called, // as a matched pair, in four situations: // @@ -31,15 +41,24 @@ public: virtual void activate() = 0; virtual void deactivate() = 0; - // Called when the map needs to be rendered; the backend should call Map::render() at some point - // in the near future. (Not called for Map::renderStill() mode.) - virtual void invalidate() = 0; +private: + const std::unique_ptr context; - // Notifies a watcher of map x/y/scale/rotation changes. - virtual void notifyMapChange(MapChange change); + friend class BackendScope; +}; + +class BackendScope { +public: + BackendScope(Backend& backend_) : backend(backend_) { + backend.activate(); + } + + ~BackendScope() { + backend.deactivate(); + } private: - const std::unique_ptr context; + Backend& backend; }; } // namespace mbgl -- cgit v1.2.1