Metal backend resource for MacOS fixes (#4020)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Miloš Marković
2025-12-31 15:11:42 +01:00
committed by GitHub
parent 4862c8193c
commit 2d3271403b
5 changed files with 39 additions and 2 deletions

View File

@@ -2,6 +2,8 @@
#import <mbgl/map/map_observer.hpp>
#import <mbgl/util/image.hpp>
#import "MLNBackendResource.h"
@class MLNMapView;
typedef struct _CGLContextObject* CGLContextObj;
@@ -20,6 +22,11 @@ class MLNMapViewImpl : public mbgl::MapObserver {
virtual CGLContextObj getCGLContextObj() { return nullptr; }
#if MLN_RENDER_BACKEND_METAL
// Returns the backend resource for Metal rendering in custom layers
virtual MLNBackendResource* getObject() { return nullptr; }
#endif
// Called by the view delegate when it's time to render.
void render();

View File

@@ -36,6 +36,7 @@ class MLNMapViewMetalImpl final : public MLNMapViewImpl,
mbgl::gfx::RendererBackend& getRendererBackend() override { return *this; }
mbgl::PremultipliedImage readStillImage() override;
MLNBackendResource* getObject() override;
private:
bool presentsWithTransaction = false;

View File

@@ -44,8 +44,10 @@ public:
commandQueue = [mtlView.device newCommandQueue];
}
commandBuffer = [commandQueue commandBuffer];
commandBufferPtr = NS::RetainPtr((__bridge MTL::CommandBuffer*)commandBuffer);
if (!commandBuffer) {
commandBuffer = [commandQueue commandBuffer];
commandBufferPtr = NS::RetainPtr((__bridge MTL::CommandBuffer*)commandBuffer);
}
}
const mbgl::mtl::RendererBackend& getBackend() const override { return backend; }
@@ -158,3 +160,12 @@ mbgl::PremultipliedImage MLNMapViewMetalImpl::readStillImage() {
// return readFramebuffer(mapView.framebufferSize); // TODO: RendererBackend::readFramebuffer
return {};
}
MLNBackendResource* MLNMapViewMetalImpl::getObject() {
auto& resource = getResource<MLNMapViewMetalRenderableResource>();
return [[MLNBackendResource alloc] initWithMTKView:resource.mtlView
device:resource.mtlView.device
renderPassDescriptor:resource.mtlView.currentRenderPassDescriptor
commandBuffer:resource.commandBuffer];
}

View File

@@ -2,6 +2,7 @@
#import <CoreLocation/CoreLocation.h>
#import <QuartzCore/QuartzCore.h>
#import "MLNBackendResource.h"
#import "MLNFoundation.h"
#import "MLNGeometry.h"
#import "MLNMapOptions.h"
@@ -1336,6 +1337,16 @@ around the returned camera object if it were set as the receiver’s camera.
*/
- (void)clearActionJournalLog;
#if MLN_RENDER_BACKEND_METAL
/**
Returns the Metal backend resource for use in custom style layers.
This property provides access to the Metal device, command buffer, and other
resources needed for custom Metal rendering in MLNCustomStyleLayer subclasses.
*/
- (MLNBackendResource *)backendResource;
#endif
@end
NS_ASSUME_NONNULL_END

View File

@@ -48,6 +48,7 @@
#import <unordered_set>
#import "MLNMapView+Impl.h"
#import "MLNBackendResource.h"
#import "NSBundle+MLNAdditions.h"
#import "NSDate+MLNAdditions.h"
#import "NSProcessInfo+MLNAdditions.h"
@@ -3314,4 +3315,10 @@ public:
actionJournal->clearLog();
}
#if MLN_RENDER_BACKEND_METAL
- (MLNBackendResource *)backendResource {
return _mbglView->getObject();
}
#endif
@end