-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into wcandillon-patch-8
- Loading branch information
Showing
26 changed files
with
221 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,7 @@ | |
|
||
@property NSNumber *contextId; | ||
|
||
- (void)configure; | ||
- (void)update; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#import "MetalView.h" | ||
#import "webgpu_cpp.h" | ||
|
||
#ifndef RCT_NEW_ARCH_ENABLED | ||
#import <React/RCTViewManager.h> | ||
#endif //RCT_NEW_ARCH_ENABLED | ||
|
||
@implementation MetalView { | ||
BOOL _isConfigured; | ||
} | ||
|
||
+ (Class)layerClass { | ||
return [CAMetalLayer class]; | ||
} | ||
|
||
- (void)configure | ||
{ | ||
auto size = self.frame.size; | ||
std::shared_ptr<rnwgpu::RNWebGPUManager> manager = [WebGPUModule getManager]; | ||
void *nativeSurface = (__bridge void *)self.layer; | ||
auto ®istry = rnwgpu::SurfaceRegistry::getInstance(); | ||
auto gpu = manager->_gpu; | ||
auto surface = manager->_platformContext->makeSurface( | ||
gpu, nativeSurface, size.width, size.height); | ||
registry.getSurfaceInfoOrCreate([_contextId intValue], gpu, size.width, size.height) | ||
->switchToOnscreen(nativeSurface, surface); | ||
} | ||
|
||
- (void)update | ||
{ | ||
auto size = self.frame.size; | ||
auto ®istry = rnwgpu::SurfaceRegistry::getInstance(); | ||
registry.getSurfaceInfo([_contextId intValue])->resize(size.width, size.height); | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
auto ®istry = rnwgpu::SurfaceRegistry::getInstance(); | ||
// Remove the surface info from the registry | ||
registry.removeSurfaceInfo([_contextId intValue]); | ||
} | ||
|
||
#ifndef RCT_NEW_ARCH_ENABLED | ||
// Paper only method | ||
// TODO: this method is wrong, it appears to call configureSurface instead of | ||
// updateSurface sometimes | ||
- (void)reactSetFrame:(CGRect)frame { | ||
[super reactSetFrame:frame]; | ||
if (!_isConfigured) { | ||
[self configure]; | ||
_isConfigured = YES; | ||
} else { | ||
[self update]; | ||
} | ||
} | ||
#endif //RCT_NEW_ARCH_ENABLED | ||
|
||
@end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#import "WebGPUView.h" | ||
|
||
#import <react/renderer/components/RNWgpuViewSpec/EventEmitters.h> | ||
#import <react/renderer/components/RNWgpuViewSpec/Props.h> | ||
#import <react/renderer/components/RNWgpuViewSpec/RCTComponentViewHelpers.h> | ||
#import <react/renderer/components/RNWgpuViewSpec/ComponentDescriptors.h> | ||
|
||
#import "MetalView.h" | ||
#import "RCTFabricComponentsPlugins.h" | ||
#import "Utils.h" | ||
|
||
using namespace facebook::react; | ||
|
||
@implementation WebGPUView | ||
|
||
+ (ComponentDescriptorProvider)componentDescriptorProvider { | ||
return concreteComponentDescriptorProvider<WebGPUViewComponentDescriptor>(); | ||
} | ||
|
||
- (void)prepareForRecycle { | ||
[super prepareForRecycle]; | ||
/* | ||
It's important to destroy the Metal Layer before releasing a view | ||
to the recycled pool to prevent displaying outdated content from | ||
the last usage in the new context. | ||
*/ | ||
self.contentView = nil; | ||
} | ||
|
||
- (MetalView *)getContentView | ||
{ | ||
if (!self.contentView) { | ||
self.contentView = [MetalView new]; | ||
} | ||
return (MetalView *)self.contentView; | ||
} | ||
|
||
- (void)updateProps:(const Props::Shared &)props | ||
oldProps:(const Props::Shared &)oldProps { | ||
const auto &oldViewProps = | ||
*std::static_pointer_cast<const WebGPUViewProps>(_props); | ||
const auto &newViewProps = | ||
*std::static_pointer_cast<const WebGPUViewProps>(props); | ||
|
||
if (newViewProps.contextId != oldViewProps.contextId) { | ||
/* | ||
The context is set only once during mounting the component | ||
and never changes because it isn't available for users to modify. | ||
*/ | ||
MetalView *metalView = [MetalView new]; | ||
self.contentView = metalView; | ||
[metalView setContextId:@(newViewProps.contextId)]; | ||
[metalView configure]; | ||
} | ||
|
||
[super updateProps:props oldProps:oldProps]; | ||
} | ||
|
||
- (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics | ||
oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics { | ||
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics]; | ||
[(MetalView *)self.contentView update]; | ||
} | ||
|
||
Class<RCTComponentViewProtocol> WebGPUViewCls(void) { return WebGPUView.class; } | ||
|
||
@end | ||
#endif |
4 changes: 2 additions & 2 deletions
4
packages/webgpu/ios/WebGPUViewManager.mm → packages/webgpu/apple/WebGPUViewManager.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.