Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions platform/macos/src/MLNMapView+Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class MLNMapViewImpl : public mbgl::MapObserver {

virtual CGLContextObj getCGLContextObj() { return nullptr; }

virtual void backingPropertiesChanged() {}

#if MLN_RENDER_BACKEND_METAL
// Returns the backend resource for Metal rendering in custom layers
virtual MLNBackendResource* getObject() { return nullptr; }
Expand Down
2 changes: 2 additions & 0 deletions platform/macos/src/MLNMapView+Metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class MLNMapViewMetalImpl final : public MLNMapViewImpl,
mbgl::PremultipliedImage readStillImage() override;
MLNBackendResource* getObject() override;

void backingPropertiesChanged() override;

private:
bool presentsWithTransaction = false;
};
12 changes: 12 additions & 0 deletions platform/macos/src/MLNMapView+Metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ void swap() override {
[mapView addSubview:resource.mtlView positioned:NSWindowBelow relativeTo:nil];
}

void MLNMapViewMetalImpl::backingPropertiesChanged() {
auto& resource = getResource<MLNMapViewMetalRenderableResource>();
const CGFloat scale = mapView.window.backingScaleFactor;
if (!resource.mtlView || scale <= 0) {
return;
}
resource.mtlView.layer.contentsScale = scale;
const CGSize bounds = resource.mtlView.bounds.size;
resource.mtlView.drawableSize =
CGSizeMake(std::round(bounds.width * scale), std::round(bounds.height * scale));
}

MLNMapViewMetalImpl::~MLNMapViewMetalImpl() = default;

void MLNMapViewMetalImpl::activate() {
Expand Down
11 changes: 11 additions & 0 deletions platform/macos/src/MLNMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,10 @@ - (void)viewDidMoveToWindow {
self.dormant = NO;
}

if (window && _mbglView) {
_mbglView->backingPropertiesChanged();
}

if (window && _mbglMap->getMapOptions().constrainMode() == mbgl::ConstrainMode::None) {
_mbglMap->setConstrainMode(mbgl::ConstrainMode::HeightOnly);
}
Expand All @@ -821,6 +825,13 @@ - (void)viewDidMoveToWindow {
context:NULL];
}

- (void)viewDidChangeBackingProperties {
[super viewDidChangeBackingProperties];
if (_mbglView) {
_mbglView->backingPropertiesChanged();
}
}

- (BOOL)wantsLayer {
return YES;
}
Expand Down