We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4bd9453 commit 3cf200eCopy full SHA for 3cf200e
1 file changed
packages/webgpu/apple/ApplePlatformContext.mm
@@ -84,8 +84,15 @@ void checkIfUsingSimulatorWithAPIValidation() {
84
85
ImageData ApplePlatformContext::createImageBitmapFromData(
86
std::span<const uint8_t> data) {
87
- NSData *nsData = [NSData dataWithBytes:data.data()
88
- length:data.size()];
+ // This avoids a copy by assuming the UIImage/NSImage constructors
+ // decode `nsData` eagerly before the memory for the wrapped `data`
89
+ // is freed.
90
+ //
91
+ // Since we get the `CGImageRef` from `image` and then throw
92
+ // it away, that's a fairly safe assumption.
93
+ NSData *nsData = [NSData dataWithBytesNoCopy:const_cast<uint8_t *>(data.data())
94
+ length:data.size()
95
+ freeWhenDone:NO];
96
97
#if !TARGET_OS_OSX
98
UIImage *image = [UIImage imageWithData:nsData];
0 commit comments