summaryrefslogtreecommitdiff
path: root/platform/ios
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-05-31 16:10:47 +0300
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-06-05 00:03:13 -0700
commit0ba0b8c04069718e476457d39fd7dc0f085ab734 (patch)
tree3d55ddad6376babb03a57aad288d9c5f8dcb9111 /platform/ios
parent012e3931bf1060df89923404ea9324f170139797 (diff)
downloadqtlocation-mapboxgl-0ba0b8c04069718e476457d39fd7dc0f085ab734.tar.gz
[ios] Calculate size of a MGLMapViewOpenGLImpl renderable from MGLMapView bounds
Fixes: #14807
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/src/MGLMapView+Impl.h3
-rw-r--r--platform/ios/src/MGLMapView+OpenGL.h1
-rw-r--r--platform/ios/src/MGLMapView+OpenGL.mm19
-rw-r--r--platform/ios/src/MGLMapView.mm4
4 files changed, 23 insertions, 4 deletions
diff --git a/platform/ios/src/MGLMapView+Impl.h b/platform/ios/src/MGLMapView+Impl.h
index f9368b7f85..3a7488b443 100644
--- a/platform/ios/src/MGLMapView+Impl.h
+++ b/platform/ios/src/MGLMapView+Impl.h
@@ -48,6 +48,9 @@ public:
// the rendering context and reduce memory while in the background.
virtual UIImage* snapshot() = 0;
+ // Called when UIView's layout has changed.
+ virtual void layoutChanged() {};
+
// Called by the view delegate when it's time to render.
void render();
diff --git a/platform/ios/src/MGLMapView+OpenGL.h b/platform/ios/src/MGLMapView+OpenGL.h
index 12edb13113..b1c13724cb 100644
--- a/platform/ios/src/MGLMapView+OpenGL.h
+++ b/platform/ios/src/MGLMapView+OpenGL.h
@@ -55,5 +55,6 @@ public:
UIView* getView() override;
void deleteView() override;
UIImage* snapshot() override;
+ void layoutChanged() override;
// End implementation of MGLMapViewImpl
};
diff --git a/platform/ios/src/MGLMapView+OpenGL.mm b/platform/ios/src/MGLMapView+OpenGL.mm
index cd9489d96f..e599024e26 100644
--- a/platform/ios/src/MGLMapView+OpenGL.mm
+++ b/platform/ios/src/MGLMapView+OpenGL.mm
@@ -28,6 +28,14 @@
@end
+namespace {
+CGFloat contentScaleFactor() {
+ return [UIScreen instancesRespondToSelector:@selector(nativeScale)]
+ ? [[UIScreen mainScreen] nativeScale]
+ : [[UIScreen mainScreen] scale];
+}
+} // namespace
+
class MGLMapViewOpenGLRenderableResource final : public mbgl::gl::RenderableResource {
public:
MGLMapViewOpenGLRenderableResource(MGLMapViewOpenGLImpl& backend_)
@@ -124,9 +132,7 @@ void MGLMapViewOpenGLImpl::createView() {
resource.glView = [[GLKView alloc] initWithFrame:mapView.bounds context:resource.context];
resource.glView.delegate = resource.delegate;
resource.glView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- resource.glView.contentScaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)]
- ? [[UIScreen mainScreen] nativeScale]
- : [[UIScreen mainScreen] scale];
+ resource.glView.contentScaleFactor = contentScaleFactor();
resource.glView.contentMode = UIViewContentModeCenter;
resource.glView.drawableStencilFormat = GLKViewDrawableStencilFormat8;
resource.glView.drawableDepthFormat = GLKViewDrawableDepthFormat16;
@@ -137,7 +143,6 @@ void MGLMapViewOpenGLImpl::createView() {
eaglLayer.presentsWithTransaction = NO;
[mapView insertSubview:resource.glView atIndex:0];
- size = resource.framebufferSize();
}
UIView* MGLMapViewOpenGLImpl::getView() {
@@ -247,6 +252,12 @@ UIImage* MGLMapViewOpenGLImpl::snapshot() {
return resource.glView.snapshot;
}
+void MGLMapViewOpenGLImpl::layoutChanged() {
+ const auto scaleFactor = contentScaleFactor();
+ size = { static_cast<uint32_t>(mapView.bounds.size.width * scaleFactor),
+ static_cast<uint32_t>(mapView.bounds.size.height * scaleFactor) };
+}
+
EAGLContext* MGLMapViewOpenGLImpl::getEAGLContext() {
auto& resource = getResource<MGLMapViewOpenGLRenderableResource>();
return resource.context;
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 077729d448..5074b783ba 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -946,6 +946,10 @@ public:
[self adjustContentInset];
+ if (_mbglView) {
+ _mbglView->layoutChanged();
+ }
+
if (_mbglMap) {
self.mbglMap.setSize([self size]);
}