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
9 changes: 0 additions & 9 deletions packages/webgpu/apple/MetalLayerColorSpace.mm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#import <CoreGraphics/CoreGraphics.h>
#import <Foundation/Foundation.h>
#import <QuartzCore/CAMetalLayer.h>
#import <QuartzCore/CATransaction.h>

#include "webgpu/webgpu_cpp.h"

Expand Down Expand Up @@ -31,14 +30,6 @@ void applyCAMetalLayerColorSpace(void *nativeSurface,
// 8-bit format.
metalLayer.colorspace = nil;
}
// The change must be set synchronously so the first present already sees
// it, and it must reach the render server. On a non-main thread (RN JS or
// worklet runtime) the property lands in that thread's implicit
// CATransaction, which may never commit on threads without a spinning
// runloop, so flush it now. On the main thread the runloop commits it.
if (!NSThread.isMainThread) {
[CATransaction flush];
}
}

} // namespace rnwgpu
10 changes: 9 additions & 1 deletion packages/webgpu/cpp/rnwgpu/RNWebGPUManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,19 @@ void RNWebGPUManager::installWebGPUWorkletHelpers(jsi::Runtime &runtime) {

void RNWebGPUManager::flushPendingSurfaceTransition(
std::shared_ptr<SurfaceInfo> info) {
if (info == nullptr || _jsCallInvoker == nullptr) {
if (info == nullptr) {
return;
}
#ifdef __APPLE__
RunOnMainThreadAsync(
[info = std::move(info)] { info->applyPendingAttach(); });
#else
if (_jsCallInvoker == nullptr) {
return;
}
_jsCallInvoker->invokeAsync(
[info = std::move(info)] { info->applyPendingAttach(); });
#endif
}

RNWebGPUManager::~RNWebGPUManager() {
Expand Down
7 changes: 3 additions & 4 deletions packages/webgpu/cpp/rnwgpu/RNWebGPUManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ class RNWebGPUManager {

/**
* Applies a surface attach latched by the platform UI thread (see
* SurfaceInfo::applyPendingAttach) from the JS thread. Surface attaches are
* normally adopted at the next frame boundary by whichever thread renders;
* this flush covers contexts that are not actively rendering (static
* content), so the last offscreen frame still makes it on screen.
* SurfaceInfo::applyPendingAttach). Apple runs the transition on main;
* other platforms use the JS CallInvoker. This covers contexts that are not
* actively rendering, so the last offscreen frame still reaches the screen.
*/
void flushPendingSurfaceTransition(std::shared_ptr<SurfaceInfo> info);

Expand Down
Loading
Loading