Skip to content

Commit

Permalink
Create MetalSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Feb 22, 2024
1 parent 89a9090 commit 65c00c5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
4 changes: 3 additions & 1 deletion package/ios/src/AppleFilamentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
#include "FilamentView.h"
#include "FilamentMetalView.h"
#include "SurfaceProvider.h"
#include "MetalSurfaceProvider.h"

namespace margelo {

class AppleFilamentView : public FilamentView {
public:
explicit AppleFilamentView(FilamentMetalView* view): _view(view) {}
explicit AppleFilamentView(FilamentMetalView* view);

std::shared_ptr<SurfaceProvider> getSurfaceProvider() override;
private:
FilamentMetalView* _view;
std::shared_ptr<MetalSurfaceProvider> _surfaceProvider;
};

} // namespace margelo
6 changes: 5 additions & 1 deletion package/ios/src/AppleFilamentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
//

#include "AppleFilamentView.h"
#include "MetalSurfaceProvider.h"

namespace margelo {

AppleFilamentView::AppleFilamentView(FilamentMetalView* view):
_view(view), _surfaceProvider(std::make_shared<MetalSurfaceProvider>([view layer])) { }

std::shared_ptr<SurfaceProvider> AppleFilamentView::getSurfaceProvider() {
return nullptr;
return std::static_pointer_cast<SurfaceProvider>(_surfaceProvider);
}

}
2 changes: 1 addition & 1 deletion package/ios/src/FilamentViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ @interface FilamentViewManager : RCTViewManager

@implementation FilamentViewManager

RCT_EXPORT_MODULE(FilamentMetalView)
RCT_EXPORT_MODULE(FilamentView)

- (FilamentMetalView*)view {
return [[FilamentMetalView alloc] init];
Expand Down
31 changes: 31 additions & 0 deletions package/ios/src/MetalSurface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// MetalSurface.h
// Pods
//
// Created by Marc Rousavy on 22.02.24.
//

#pragma once

#include "Surface.h"
#include <Metal/Metal.h>

namespace margelo {

class MetalSurface: public Surface {
explicit MetalSurface(CAMetalLayer* layer): _layer(layer) { }

int getWidth() override {
return static_cast<int>(_layer.drawableSize.width);
}
int getHeight() override {
return static_cast<int>(_layer.drawableSize.height);
}
void* getSurface() override {
return (__bridge void*)_layer;
}
private:
CAMetalLayer* _layer;
};

} // namespace margelo
29 changes: 29 additions & 0 deletions package/ios/src/MetalSurfaceProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// MetalSurfaceProvider.h
// Pods
//
// Created by Marc Rousavy on 22.02.24.
//

#pragma once

#include "SurfaceProvider.h"
#include "MetalSurface.h"
#include <Metal/Metal.h>

namespace margelo {

class MetalSurfaceProvider : public SurfaceProvider {
explicit MetalSurfaceProvider(CAMetalLayer* layer): _surface(std::make_shared<MetalSurface>(layer)) {
onSurfaceCreated(_surface);
}

std::shared_ptr<Surface> getSurfaceOrNull() override {
return _surface;
}

private:
std::shared_ptr<MetalSurface> _surface;
};

} // namespace margelo

0 comments on commit 65c00c5

Please sign in to comment.