[ios] Calculate size of a MGLMapViewOpenGLImpl renderable from MGLMapView bounds
Fixes: #14807
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -55,5 +55,6 @@ public:
|
||||
UIView* getView() override;
|
||||
void deleteView() override;
|
||||
UIImage* snapshot() override;
|
||||
void layoutChanged() override;
|
||||
// End implementation of MGLMapViewImpl
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -946,6 +946,10 @@ public:
|
||||
|
||||
[self adjustContentInset];
|
||||
|
||||
if (_mbglView) {
|
||||
_mbglView->layoutChanged();
|
||||
}
|
||||
|
||||
if (_mbglMap) {
|
||||
self.mbglMap.setSize([self size]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user