[ios] Calculate size of a MGLMapViewOpenGLImpl renderable from MGLMapView bounds

Fixes: #14807
This commit is contained in:
Alexander Shalamov
2019-05-31 16:10:47 +03:00
parent 012e3931bf
commit 0ba0b8c040
4 changed files with 23 additions and 4 deletions

View File

@@ -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();

View File

@@ -55,5 +55,6 @@ public:
UIView* getView() override;
void deleteView() override;
UIImage* snapshot() override;
void layoutChanged() override;
// End implementation of MGLMapViewImpl
};

View File

@@ -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;

View File

@@ -946,6 +946,10 @@ public:
[self adjustContentInset];
if (_mbglView) {
_mbglView->layoutChanged();
}
if (_mbglMap) {
self.mbglMap.setSize([self size]);
}