Skip to content

Commit

Permalink
Fix build issues from merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bghgary committed May 4, 2023
1 parent bdaf1b9 commit 0ae6cf4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
11 changes: 9 additions & 2 deletions Core/Graphics/Source/DeviceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,16 @@ namespace Babylon::Graphics
return m_afterRenderDispatcher.scheduler();
}

void DeviceImpl::RequestScreenShot(std::function<void(std::vector<uint8_t>)> callback)
arcana::task<std::vector<uint8_t>, std::exception_ptr> DeviceImpl::RequestScreenShotAsync()
{
m_screenShotCallbacks.push(std::move(callback));
arcana::task_completion_source<std::vector<uint8_t>, std::exception_ptr> taskCompletionSource{};

m_screenShotCallbacks.push([taskCompletionSource](std::vector<uint8_t> bytes) mutable
{
taskCompletionSource.complete(std::move(bytes));
});

return taskCompletionSource.as_task();
}

arcana::task<void, std::exception_ptr> DeviceImpl::ReadTextureAsync(bgfx::TextureHandle handle, gsl::span<uint8_t> data, uint8_t mipLevel)
Expand Down
2 changes: 0 additions & 2 deletions Core/Graphics/Source/DeviceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ namespace Babylon::Graphics
continuation_scheduler<>& BeforeRenderScheduler();
continuation_scheduler<>& AfterRenderScheduler();

Update GetUpdate(const char* updateName);

arcana::task<std::vector<uint8_t>, std::exception_ptr> RequestScreenShotAsync();

arcana::task<void, std::exception_ptr> ReadTextureAsync(bgfx::TextureHandle handle, gsl::span<uint8_t> data, uint8_t mipLevel);
Expand Down
2 changes: 1 addition & 1 deletion Dependencies/arcana.cpp
24 changes: 14 additions & 10 deletions Plugins/NativeCamera/Source/MediaStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Babylon::Plugins
auto mediaStreamObject{Napi::Persistent(GetConstructor(env).New({}))};
auto mediaStream{MediaStream::Unwrap(mediaStreamObject.Value())};

return mediaStream->ApplyInitialConstraintsAsync(constraints).then(mediaStream->m_runtimeScheduler, arcana::cancellation::none(), [mediaStreamObject{std::move(mediaStreamObject)}]() {
return mediaStream->ApplyInitialConstraintsAsync(constraints).then(arcana::inline_scheduler, arcana::cancellation::none(), [mediaStreamObject{std::move(mediaStreamObject)}]() {
return mediaStreamObject.Value();
});
}
Expand Down Expand Up @@ -58,14 +58,18 @@ namespace Babylon::Plugins

MediaStream::~MediaStream()
{
// TODO: Is this still necessary?
// if (m_cameraDevice != nullptr)
// {
// // The cameraDevice should be destroyed on the JS thread as it may need to access main thread resources
// // move ownership of the cameraDevice to a lambda and dispatch it with the runtimeScheduler so the destructor
// // is called from that thread.
// m_runtimeScheduler.Get()([cameraDevice = std::move(m_cameraDevice)]() {});
// }
m_cancellationSource.cancel();

// HACK: This is a hack to make sure the camera device is destroyed on the JS thread.
// The napi-jsi adapter currently calls the destructors of JS objects possibly on the wrong thread.
// Once this is fixed, this hack will no longer be needed.
if (m_cameraDevice != nullptr)
{
// The cameraDevice should be destroyed on the JS thread as it may need to access main thread resources
// move ownership of the cameraDevice to a lambda and dispatch it with the runtimeScheduler so the destructor
// is called from that thread.
m_runtimeScheduler.Get()([cameraDevice = std::move(m_cameraDevice)]() {});
}

// Wait for async operations to complete.
m_runtimeScheduler.Rundown();
Expand Down Expand Up @@ -124,7 +128,7 @@ namespace Babylon::Plugins
// Create a persistent ref to the constraints object so it isn't destructed during our async work
auto constraintsRef{Napi::Persistent(constraints)};

return m_cameraDevice->OpenAsync(bestCamera.value().second).then(m_runtimeScheduler.Get(), arcana::cancellation::none(), [this, constraintsRef{std::move(constraintsRef)}](CameraDevice::CameraDimensions cameraDimensions) {
return m_cameraDevice->OpenAsync(bestCamera.value().second).then(m_runtimeScheduler.Get(), m_cancellationSource, [this, constraintsRef{std::move(constraintsRef)}](CameraDevice::CameraDimensions cameraDimensions) {
this->Width = cameraDimensions.width;
this->Height = cameraDimensions.height;

Expand Down
1 change: 1 addition & 0 deletions Plugins/NativeCamera/Source/MediaStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace Babylon::Plugins
// Capture CameraDevice in a shared_ptr because the iOS implementation relies on the `shared_from_this` syntax for async work
std::shared_ptr<CameraDevice> m_cameraDevice{};
JsRuntimeScheduler m_runtimeScheduler;
arcana::cancellation_source m_cancellationSource;

Napi::ObjectReference m_currentConstraints{};
};
Expand Down

0 comments on commit 0ae6cf4

Please sign in to comment.