diff options
author | Jesse Bounds <jesse@rebounds.net> | 2016-10-25 15:48:29 -0700 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2016-10-25 15:48:29 -0700 |
commit | dbfa8dcc89ff55fa1f8366433d24b1a270e53a02 (patch) | |
tree | a68cd34e2197012c2b0ab9525bc747bc7c4c94e7 /platform/ios | |
parent | 1216050f9c5c472f1c8edcc32447004a40680ec7 (diff) | |
parent | a4d259c33f9bb890bba97fd89552720e3e0ec09b (diff) | |
download | qtlocation-mapboxgl-dbfa8dcc89ff55fa1f8366433d24b1a270e53a02.tar.gz |
Merge branch 'master' into boundsj-release-ios-3.4.0-merge-master
Diffstat (limited to 'platform/ios')
-rw-r--r-- | platform/ios/config.cmake | 10 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 78 |
2 files changed, 60 insertions, 28 deletions
diff --git a/platform/ios/config.cmake b/platform/ios/config.cmake index 6c83395a3e..0813d0338f 100644 --- a/platform/ios/config.cmake +++ b/platform/ios/config.cmake @@ -37,9 +37,13 @@ macro(mbgl_platform_core) PRIVATE platform/darwin/src/image.mm # Headless view - PRIVATE platform/darwin/src/headless_view_eagl.mm + PRIVATE platform/darwin/src/headless_backend_eagl.mm + PRIVATE platform/default/headless_backend.cpp PRIVATE platform/default/headless_display.cpp - PRIVATE platform/default/headless_view.cpp + PRIVATE platform/default/offscreen_view.cpp + + # Thread pool + PRIVATE platform/default/thread_pool.cpp ) target_add_mason_package(mbgl-core PUBLIC geojson) @@ -50,7 +54,7 @@ macro(mbgl_platform_core) # TODO: Remove this by converting to ARC set_source_files_properties( - platform/darwin/src/headless_view_eagl.mm + platform/darwin/src/headless_backend_eagl.mm PROPERTIES COMPILE_FLAGS -fno-objc-arc ) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index bb7e446620..c6c0920f56 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2,6 +2,7 @@ #include <mbgl/platform/log.hpp> #include <mbgl/gl/extension.hpp> +#include <mbgl/gl/context.hpp> #import <GLKit/GLKit.h> #import <OpenGLES/EAGL.h> @@ -13,10 +14,12 @@ #include <mbgl/map/mode.hpp> #include <mbgl/platform/platform.hpp> #include <mbgl/platform/darwin/reachability.h> +#include <mbgl/platform/default/thread_pool.hpp> #include <mbgl/storage/default_file_source.hpp> #include <mbgl/storage/network_status.hpp> #include <mbgl/style/transition_options.hpp> #include <mbgl/style/layers/custom_layer.hpp> +#include <mbgl/map/backend.hpp> #include <mbgl/math/wrap.hpp> #include <mbgl/util/geo.hpp> #include <mbgl/util/constants.hpp> @@ -24,7 +27,7 @@ #include <mbgl/util/projection.hpp> #include <mbgl/util/default_styles.hpp> #include <mbgl/util/chrono.hpp> -#import <mbgl/util/run_loop.hpp> +#include <mbgl/util/run_loop.hpp> #import "Mapbox.h" #import "MGLFeature_Private.h" @@ -258,6 +261,7 @@ public: { mbgl::Map *_mbglMap; MBGLView *_mbglView; + mbgl::ThreadPool *_mbglThreadPool; BOOL _opaque; @@ -387,8 +391,7 @@ public: self.clipsToBounds = YES; // setup mbgl view - const float scaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale]; - _mbglView = new MBGLView(self, scaleFactor); + _mbglView = new MBGLView(self); // Delete the pre-offline ambient cache at ~/Library/Caches/cache.db. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); @@ -396,8 +399,12 @@ public: [[NSFileManager defaultManager] removeItemAtPath:fileCachePath error:NULL]; // setup mbgl map + const std::array<uint16_t, 2> size = {{ static_cast<uint16_t>(self.bounds.size.width), + static_cast<uint16_t>(self.bounds.size.height) }}; mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource; - _mbglMap = new mbgl::Map(*_mbglView, *mbglFileSource, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default); + const float scaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale]; + _mbglThreadPool = new mbgl::ThreadPool(4); + _mbglMap = new mbgl::Map(*_mbglView, size, scaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default); [self validateTileCacheSize]; // start paused if in IB @@ -650,6 +657,12 @@ public: _mbglView = nullptr; } + if (_mbglThreadPool) + { + delete _mbglThreadPool; + _mbglThreadPool = nullptr; + } + if ([[EAGLContext currentContext] isEqual:_context]) { [EAGLContext setCurrentContext:nil]; @@ -858,7 +871,8 @@ public: { if ( ! self.dormant) { - _mbglMap->render(); + _mbglView->updateViewBinding(); + _mbglMap->render(*_mbglView); [self updateUserLocationAnnotationView]; } @@ -873,7 +887,8 @@ public: if ( ! _isTargetingInterfaceBuilder) { - _mbglMap->update(mbgl::Update::Dimensions); + _mbglMap->setSize({{ static_cast<uint16_t>(self.bounds.size.width), + static_cast<uint16_t>(self.bounds.size.height) }}); } if (self.attributionSheet.visible) @@ -4923,25 +4938,39 @@ public: return _annotationViewReuseQueueByIdentifier[identifier]; } -class MBGLView : public mbgl::View +class MBGLView : public mbgl::View, public mbgl::Backend { public: - MBGLView(MGLMapView* nativeView_, const float scaleFactor_) - : nativeView(nativeView_), scaleFactor(scaleFactor_) { - } - - float getPixelRatio() const override { - return scaleFactor; - } - - std::array<uint16_t, 2> getSize() const override { - return {{ static_cast<uint16_t>([nativeView bounds].size.width), - static_cast<uint16_t>([nativeView bounds].size.height) }}; - } - - std::array<uint16_t, 2> getFramebufferSize() const override { - return {{ static_cast<uint16_t>([[nativeView glView] drawableWidth]), - static_cast<uint16_t>([[nativeView glView] drawableHeight]) }}; + MBGLView(MGLMapView* nativeView_) + : nativeView(nativeView_) { + } + + mbgl::gl::value::Viewport::Type getViewport() const { + return { 0, 0, static_cast<uint16_t>(nativeView.glView.drawableWidth), + static_cast<uint16_t>(nativeView.glView.drawableHeight) }; + } + + /// This function is called before we start rendering, when iOS invokes our rendering method. + /// iOS already sets the correct framebuffer and viewport for us, so we need to update the + /// context state with the anticipated values. + void updateViewBinding() { + // We are using 0 as the placeholder value for the GLKView's framebuffer. + getContext().bindFramebuffer.setCurrentValue(0); + getContext().viewport.setCurrentValue(getViewport()); + } + + void bind() override { + if (getContext().bindFramebuffer != 0) { + // Something modified our state, and we need to bind the original drawable again. + // Doing this also sets the viewport to the full framebuffer. + // Note that in reality, iOS does not use the Framebuffer 0 (it's typically 1), and we + // only use this is a placeholder value. + [nativeView.glView bindDrawable]; + updateViewBinding(); + } else { + // Our framebuffer is still bound, but the viewport might have changed. + getContext().viewport = getViewport(); + } } void notifyMapChange(mbgl::MapChange change) override @@ -4966,7 +4995,6 @@ public: private: __weak MGLMapView *nativeView = nullptr; - const float scaleFactor; }; @end @@ -5180,7 +5208,7 @@ void MGLFinishCustomStyleLayer(void *context) - (void)setCustomStyleLayersNeedDisplay { - _mbglMap->update(mbgl::Update::Repaint); + [self setNeedsGLDisplay]; } - (mbgl::Map *)mbglMap { |