diff --git a/.github/jobs/linux.yml b/.github/jobs/linux.yml index 076370352..7edf8d613 100644 --- a/.github/jobs/linux.yml +++ b/.github/jobs/linux.yml @@ -22,11 +22,11 @@ jobs: - script: | sudo apt-get update - sudo apt-get install libjavascriptcoregtk-4.0-dev libgl1-mesa-dev libcurl4-openssl-dev libwayland-dev + sudo apt-get install libjavascriptcoregtk-4.1-dev libgl1-mesa-dev libcurl4-openssl-dev libwayland-dev displayName: 'Install packages' - script: | - cmake -G Ninja -B build -D JAVASCRIPTCORE_LIBRARY=/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.0.so -D NAPI_JAVASCRIPT_ENGINE=${{ parameters.JSEngine }} -D CMAKE_BUILD_TYPE=RelWithDebInfo -D BX_CONFIG_DEBUG=ON -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D OpenGL_GL_PREFERENCE=GLVND -D BABYLON_DEBUG_TRACE=ON + cmake -G Ninja -B build -D JAVASCRIPTCORE_LIBRARY=/usr/lib/x86_64-linux-gnu/libjavascriptcoregtk-4.1.so -D NAPI_JAVASCRIPT_ENGINE=${{ parameters.JSEngine }} -D CMAKE_BUILD_TYPE=RelWithDebInfo -D BX_CONFIG_DEBUG=ON -D CMAKE_UNITY_BUILD=$(UNITY_BUILD) -D OpenGL_GL_PREFERENCE=GLVND -D BABYLON_DEBUG_TRACE=ON ninja -C build displayName: 'Build X11' diff --git a/Apps/package-lock.json b/Apps/package-lock.json index 0748d60bd..eefa9d484 100644 --- a/Apps/package-lock.json +++ b/Apps/package-lock.json @@ -8,11 +8,11 @@ "name": "BabylonNative", "version": "0.0.1", "dependencies": { - "babylonjs": "^8.0.0", - "babylonjs-gltf2interface": "^8.0.0", - "babylonjs-gui": "^8.0.0", - "babylonjs-loaders": "^8.0.0", - "babylonjs-materials": "^8.0.0", + "babylonjs": "^8.3.1", + "babylonjs-gltf2interface": "^8.3.1", + "babylonjs-gui": "^8.3.1", + "babylonjs-loaders": "^8.3.1", + "babylonjs-materials": "^8.3.1", "chai": "^4.3.4", "jsc-android": "^241213.1.0", "mocha": "^9.2.2", @@ -87,44 +87,39 @@ } }, "node_modules/babylonjs": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/babylonjs/-/babylonjs-8.0.0.tgz", - "integrity": "sha512-jCXdPH9ruqSIwFZoQo3qT+cmfTeNtl3Y8/rjCNaWNvnnRZdDKN+BgbKEZTB3GQlmEoQXLJMwKNNL/LQgxnxmLw==", - "hasInstallScript": true, - "license": "Apache-2.0" + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/babylonjs/-/babylonjs-8.3.1.tgz", + "integrity": "sha512-vrBJpt6AMcyXltN6t5UhnusTyWB2gugxEHPs0c6ef6sdLFZHRI9BE9njyppAItl3sgI0gKW5R1CALH0NFEdtrQ==", + "hasInstallScript": true }, "node_modules/babylonjs-gltf2interface": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/babylonjs-gltf2interface/-/babylonjs-gltf2interface-8.0.0.tgz", - "integrity": "sha512-BenZ6S2L0ftHqOz0ow9SSfPlAppmILmvwlJcwh6bZ9PzU+vFExsjpUSnE4zGfGKvx9VH98eD4AGwoXhExPrNjQ==", - "license": "Apache-2.0" + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/babylonjs-gltf2interface/-/babylonjs-gltf2interface-8.3.1.tgz", + "integrity": "sha512-ymnDfjRpQEoxmsiSQZKLAn2QFRSMz3HBJTZXmlIqghPeGA1H1vioeUq7/BM0eRaZAC0TdhtznainfOmdcg8DMQ==" }, "node_modules/babylonjs-gui": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/babylonjs-gui/-/babylonjs-gui-8.0.0.tgz", - "integrity": "sha512-Bhb9cWZFAXvzPhBZLayF73pAcWQInPugR57+mZ3pKgBPABntJEnwaEF/ahb6xr0irUgmko9gWJVtBrw+J5u+QQ==", - "license": "Apache-2.0", + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/babylonjs-gui/-/babylonjs-gui-8.3.1.tgz", + "integrity": "sha512-7XwlqKqdjiZLC/X1wYRusp0GwbqRRueypZF6HYsP/UpXfP0bVEU+KC8pOHFijqTROiIPJ1BWeQFIQQhp7Ba2wQ==", "dependencies": { - "babylonjs": "^8.0.0" + "babylonjs": "^8.3.1" } }, "node_modules/babylonjs-loaders": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/babylonjs-loaders/-/babylonjs-loaders-8.0.0.tgz", - "integrity": "sha512-LL4vRbuvZzYuflW+Zm6WI+0bxfaGX1lwNZ8JJ2+CYWTaiWmN7LxQII+geVG8kB8jCoIX9ptVI1FJ06xSqzcPpw==", - "license": "Apache-2.0", + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/babylonjs-loaders/-/babylonjs-loaders-8.3.1.tgz", + "integrity": "sha512-18PXsv7dr2nehs0yvRukDMYHg7+DTailjW/vp3D+QYqJROI1cBSrWl9nOjSu8L34FbCJCDCBQpxwEAsSaxx5Ow==", "dependencies": { - "babylonjs": "^8.0.0", - "babylonjs-gltf2interface": "^8.0.0" + "babylonjs": "^8.3.1", + "babylonjs-gltf2interface": "^8.3.1" } }, "node_modules/babylonjs-materials": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/babylonjs-materials/-/babylonjs-materials-8.0.0.tgz", - "integrity": "sha512-Gi0e5hOx82i78xCE3Xxso7h3ocjhq8/8MHhkX1qdh7LkuB3Ec0ZZIRbeX56TSEG1IK21y/pBExCBv1YPIqZwRA==", - "license": "Apache-2.0", + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/babylonjs-materials/-/babylonjs-materials-8.3.1.tgz", + "integrity": "sha512-Jj+t9hHCqlgdz+g89vGOyx0NH/D1Ub2YIvhOVoPwBm1HZ8QlU1T6z0r9mv2YiiNyp6mSYXB7iqMPiBSJN6N7zg==", "dependencies": { - "babylonjs": "^8.0.0" + "babylonjs": "^8.3.1" } }, "node_modules/balanced-match": { diff --git a/Apps/package.json b/Apps/package.json index 2f4fe77cd..8d40a0e71 100644 --- a/Apps/package.json +++ b/Apps/package.json @@ -6,11 +6,11 @@ "getNightly": "node scripts/getNightly.js" }, "dependencies": { - "babylonjs": "^8.0.0", - "babylonjs-gltf2interface": "^8.0.0", - "babylonjs-gui": "^8.0.0", - "babylonjs-loaders": "^8.0.0", - "babylonjs-materials": "^8.0.0", + "babylonjs": "^8.3.1", + "babylonjs-gltf2interface": "^8.3.1", + "babylonjs-gui": "^8.3.1", + "babylonjs-loaders": "^8.3.1", + "babylonjs-materials": "^8.3.1", "chai": "^4.3.4", "jsc-android": "^241213.1.0", "mocha": "^9.2.2", diff --git a/CMakeLists.txt b/CMakeLists.txt index 202c9b8aa..3f4f2f0b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ FetchContent_Declare(ios-cmake GIT_TAG 4.5.0) FetchContent_Declare(JsRuntimeHost GIT_REPOSITORY https://github.com/BabylonJS/JsRuntimeHost.git - GIT_TAG 27f17e531c6521b9210cfa651b43251a7c860ac6) + GIT_TAG c64c8a8cfc95b187e9547b165f02633909568c22) FetchContent_Declare(OpenXR-MixedReality GIT_REPOSITORY https://github.com/microsoft/OpenXR-MixedReality.git GIT_TAG 67424511525b96a36847f2a96d689d99e5879503) diff --git a/Plugins/NativeCamera/Source/MediaDevices.cpp b/Plugins/NativeCamera/Source/MediaDevices.cpp index 7469061b5..eabcc1030 100644 --- a/Plugins/NativeCamera/Source/MediaDevices.cpp +++ b/Plugins/NativeCamera/Source/MediaDevices.cpp @@ -49,7 +49,7 @@ namespace Babylon::Plugins::Internal deferred.Resolve(result.value()); }); - return std::move(promise); + return promise; } static Napi::Value EnumerateDevices(const Napi::CallbackInfo& info) @@ -76,7 +76,7 @@ namespace Babylon::Plugins::Internal deferred.Resolve(devices); - return std::move(promise); + return promise; } }; } diff --git a/Plugins/NativeCamera/Source/MediaStream.cpp b/Plugins/NativeCamera/Source/MediaStream.cpp index 583a1ce8d..209a1f302 100644 --- a/Plugins/NativeCamera/Source/MediaStream.cpp +++ b/Plugins/NativeCamera/Source/MediaStream.cpp @@ -73,7 +73,7 @@ namespace Babylon::Plugins // ObjectWrap fullfills the MediaStream and MediaStreamTrack interfaces auto tracks = Napi::Array::New(info.Env(), 1); tracks.Set(uint32_t{0}, info.This()); - return std::move(tracks); + return tracks; } Napi::Value MediaStream::GetAudioTracks(const Napi::CallbackInfo& info) @@ -149,7 +149,7 @@ namespace Babylon::Plugins capability->AddAsCapability(capabilities); } - return std::move(capabilities); + return capabilities; } Napi::Value MediaStream::GetSettings(const Napi::CallbackInfo& info) @@ -169,7 +169,7 @@ namespace Babylon::Plugins capability->AddAsSetting(settings); } - return std::move(settings); + return settings; } Napi::Value MediaStream::GetConstraints(const Napi::CallbackInfo& info) diff --git a/Plugins/NativeEngine/Source/NativeEngine.cpp b/Plugins/NativeEngine/Source/NativeEngine.cpp index 329176b8d..b342a0afb 100644 --- a/Plugins/NativeEngine/Source/NativeEngine.cpp +++ b/Plugins/NativeEngine/Source/NativeEngine.cpp @@ -418,7 +418,7 @@ namespace Babylon JS_CLASS_NAME, { // This must match the version in nativeEngine.ts - StaticValue("PROTOCOL_VERSION", Napi::Number::From(env, 8)), + StaticValue("PROTOCOL_VERSION", Napi::Number::From(env, 9)), StaticValue("CAPS_LIMITS_MAX_TEXTURE_SIZE", Napi::Number::From(env, limits.maxTextureSize)), StaticValue("CAPS_LIMITS_MAX_TEXTURE_LAYERS", Napi::Number::From(env, limits.maxTextureLayers)), @@ -653,6 +653,7 @@ namespace Babylon StaticValue("COMMAND_SETSTENCIL", Napi::FunctionPointer::Create(env, &NativeEngine::SetStencil)), StaticValue("COMMAND_SETVIEWPORT", Napi::FunctionPointer::Create(env, &NativeEngine::SetViewPort)), StaticValue("COMMAND_SETSCISSOR", Napi::FunctionPointer::Create(env, &NativeEngine::SetScissor)), + StaticValue("COMMAND_COPYTEXTURE", Napi::FunctionPointer::Create(env, &NativeEngine::CopyTexture)), InstanceMethod("dispose", &NativeEngine::Dispose), @@ -682,7 +683,6 @@ namespace Babylon InstanceMethod("loadCubeTextureWithMips", &NativeEngine::LoadCubeTextureWithMips), InstanceMethod("getTextureWidth", &NativeEngine::GetTextureWidth), InstanceMethod("getTextureHeight", &NativeEngine::GetTextureHeight), - InstanceMethod("copyTexture", &NativeEngine::CopyTexture), InstanceMethod("deleteTexture", &NativeEngine::DeleteTexture), InstanceMethod("readTexture", &NativeEngine::ReadTexture), @@ -1103,7 +1103,7 @@ namespace Babylon uniforms[index] = info.Env().Null(); } - return std::move(uniforms); + return uniforms; } Napi::Value NativeEngine::GetAttributes(const Napi::CallbackInfo& info) @@ -1123,7 +1123,7 @@ namespace Babylon attributes[index] = Napi::Value::From(info.Env(), location); } - return std::move(attributes); + return attributes; } void NativeEngine::SetProgram(NativeDataStream::Reader& data) @@ -1427,22 +1427,14 @@ namespace Babylon }); } - void NativeEngine::CopyTexture(const Napi::CallbackInfo& info) + void NativeEngine::CopyTexture(NativeDataStream::Reader& data) { - const auto textureDestination = info[0].As>().Get(); - const auto textureSource = info[1].As>().Get(); + bgfx::Encoder* encoder = GetUpdateToken().GetEncoder(); - arcana::make_task(m_update.Scheduler(), *m_cancellationSource, [this, textureDestination, textureSource, cancellationSource = m_cancellationSource]() { - return arcana::make_task(m_runtimeScheduler, *m_cancellationSource, [this, textureDestination, textureSource, updateToken = m_update.GetUpdateToken(), cancellationSource = m_cancellationSource]() { - bgfx::Encoder* encoder = m_update.GetUpdateToken().GetEncoder(); - GetBoundFrameBuffer(*encoder).Blit(*encoder, textureDestination->Handle(), 0, 0, textureSource->Handle()); - }).then(arcana::inline_scheduler, *m_cancellationSource, [this, cancellationSource{m_cancellationSource}](const arcana::expected& result) { - if (!cancellationSource->cancelled() && result.has_error()) - { - Napi::Error::New(Env(), result.error()).ThrowAsJavaScriptException(); - } - }); - }); + const auto textureSource = data.ReadPointer(); + const auto textureDestination = data.ReadPointer(); + + GetBoundFrameBuffer(*encoder).Blit(*encoder, textureDestination->Handle(), 0, 0, textureSource->Handle()); } void NativeEngine::LoadRawTexture(const Napi::CallbackInfo& info) @@ -2111,7 +2103,7 @@ namespace Babylon bimg::imageFree(image); } - return std::move(imageBitmap); + return imageBitmap; } Napi::Value NativeEngine::ResizeImageBitmap(const Napi::CallbackInfo& info) diff --git a/Plugins/NativeEngine/Source/NativeEngine.h b/Plugins/NativeEngine/Source/NativeEngine.h index b9cac9232..6b7690149 100644 --- a/Plugins/NativeEngine/Source/NativeEngine.h +++ b/Plugins/NativeEngine/Source/NativeEngine.h @@ -184,7 +184,7 @@ namespace Babylon Napi::Value CreateTexture(const Napi::CallbackInfo& info); void InitializeTexture(const Napi::CallbackInfo& info); void LoadTexture(const Napi::CallbackInfo& info); - void CopyTexture(const Napi::CallbackInfo& info); + void CopyTexture(NativeDataStream::Reader& data); void LoadRawTexture(const Napi::CallbackInfo& info); void LoadRawTexture2DArray(const Napi::CallbackInfo& info); void LoadCubeTexture(const Napi::CallbackInfo& info); diff --git a/Plugins/NativeXr/Source/XRFrame.cpp b/Plugins/NativeXr/Source/XRFrame.cpp index 4a103877f..d51e2d17d 100644 --- a/Plugins/NativeXr/Source/XRFrame.cpp +++ b/Plugins/NativeXr/Source/XRFrame.cpp @@ -275,7 +275,7 @@ namespace Babylon results[i++] = currentResult; } - return std::move(results); + return results; } Napi::Value XRFrame::CreateAnchor(const Napi::CallbackInfo& info) @@ -295,7 +295,7 @@ namespace Babylon anchorSet.Get("add").As().Call(anchorSet, { napiAnchorRef.Value() }); } - return std::move(anchorSet); + return anchorSet; } void XRFrame::UpdateAnchors() @@ -349,7 +349,7 @@ namespace Babylon worldInformationObj.Set("detectedMeshes", m_meshSet.Value()); } - return std::move(worldInformationObj); + return worldInformationObj; } Napi::Value XRFrame::GetFeaturePointCloud(const Napi::CallbackInfo& info) @@ -368,7 +368,7 @@ namespace Babylon featurePointArray.Set(pointIndex + 4, Napi::Value::From(info.Env(), featurePoint.ID)); } - return std::move(featurePointArray); + return featurePointArray; } void XRFrame::UpdateSceneObjects(const Napi::Env& env) diff --git a/Plugins/NativeXr/Source/XRHitTestResult.h b/Plugins/NativeXr/Source/XRHitTestResult.h index 9705c5a7e..2a18018a5 100644 --- a/Plugins/NativeXr/Source/XRHitTestResult.h +++ b/Plugins/NativeXr/Source/XRHitTestResult.h @@ -61,7 +61,7 @@ namespace Babylon XRPose* pose = XRPose::Unwrap(napiPose); pose->Update(info, m_hitResult.Pose); - return std::move(napiPose); + return napiPose; } Napi::Value CreateAnchor(const Napi::CallbackInfo& info) diff --git a/Plugins/NativeXr/Source/XRPlane.h b/Plugins/NativeXr/Source/XRPlane.h index 1d803872d..0c9053edc 100644 --- a/Plugins/NativeXr/Source/XRPlane.h +++ b/Plugins/NativeXr/Source/XRPlane.h @@ -87,7 +87,7 @@ namespace Babylon polygonArray.Set((int)i, polygonPoint); } - return std::move(polygonArray); + return polygonArray; } Napi::Value GetLastChangedTime(const Napi::CallbackInfo& info) diff --git a/Plugins/NativeXr/Source/XRSession.cpp b/Plugins/NativeXr/Source/XRSession.cpp index ac8b3c3fb..ac67583e8 100644 --- a/Plugins/NativeXr/Source/XRSession.cpp +++ b/Plugins/NativeXr/Source/XRSession.cpp @@ -759,7 +759,7 @@ namespace Babylon results.Set(index++, Napi::Value::From(info.Env(), scoreString)); } - return std::move(results); + return results; } } // Plugins } // Babylon \ No newline at end of file diff --git a/Polyfills/Canvas/Source/Canvas.cpp b/Polyfills/Canvas/Source/Canvas.cpp index d81c00063..f7248a1aa 100644 --- a/Polyfills/Canvas/Source/Canvas.cpp +++ b/Polyfills/Canvas/Source/Canvas.cpp @@ -80,11 +80,17 @@ namespace Babylon::Polyfills::Internal Napi::Value NativeCanvas::GetContext(const Napi::CallbackInfo& info) { - if (m_contextObject.IsEmpty()) + auto thisObj = info.This().ToObject(); + const auto contextPropertyName = Napi::Value::From(Env(), "_context"); + + auto context = thisObj.Get(contextPropertyName); + if (context.IsUndefined()) { - m_contextObject = Napi::Persistent(Context::CreateInstance(info.Env(), info.This()).As()); + context = Context::CreateInstance(info.Env(), info.This()); + thisObj.Set(contextPropertyName, context); } - return m_contextObject.Value(); + + return context; } Napi::Value NativeCanvas::GetWidth(const Napi::CallbackInfo&) diff --git a/Polyfills/Canvas/Source/Canvas.h b/Polyfills/Canvas/Source/Canvas.h index 2edb3914b..b8c29972b 100644 --- a/Polyfills/Canvas/Source/Canvas.h +++ b/Polyfills/Canvas/Source/Canvas.h @@ -66,7 +66,6 @@ namespace Babylon::Polyfills::Internal static inline std::map> fontsInfos; - // returns true if frameBuffer size has changed bool UpdateRenderTarget(); Babylon::Graphics::FrameBuffer& GetFrameBuffer() { return *m_frameBuffer; } FrameBufferPool m_frameBufferPool; diff --git a/Polyfills/Canvas/Source/Context.cpp b/Polyfills/Canvas/Source/Context.cpp index 8f4f612dd..64042b2f9 100644 --- a/Polyfills/Canvas/Source/Context.cpp +++ b/Polyfills/Canvas/Source/Context.cpp @@ -77,6 +77,7 @@ namespace Babylon::Polyfills::Internal InstanceMethod("setTransform", &Context::SetTransform), InstanceMethod("transform", &Context::Transform), InstanceMethod("dispose", &Context::Dispose), + InstanceMethod("flush", &Context::Flush), InstanceAccessor("lineCap", &Context::GetLineCap, &Context::SetLineCap), InstanceAccessor("lineJoin", &Context::GetLineJoin, &Context::SetLineJoin), InstanceAccessor("miterLimit", &Context::GetMiterLimit, &Context::SetMiterLimit), @@ -98,8 +99,6 @@ namespace Babylon::Polyfills::Internal Napi::Value Context::CreateInstance(Napi::Env env, Napi::Value canvas) { - Napi::HandleScope scope{env}; - auto func = JsRuntime::NativeObject::GetFromJavaScript(env).Get(JS_CONTEXT_CONSTRUCTOR_NAME).As(); return func.New({canvas}); } @@ -204,7 +203,6 @@ namespace Babylon::Polyfills::Internal SetFilterStack(); nvgFill(*m_nvg); - SetDirty(); } Napi::Value Context::GetFillStyle(const Napi::CallbackInfo&) @@ -233,7 +231,6 @@ namespace Babylon::Polyfills::Internal CanvasGradient* canvasGradient = CanvasGradient::Unwrap(info[0].As()); m_fillStyle = canvasGradient; } - SetDirty(); } Napi::Value Context::GetStrokeStyle(const Napi::CallbackInfo&) @@ -246,7 +243,6 @@ namespace Babylon::Polyfills::Internal m_strokeStyle = value.As().Utf8Value(); auto color = StringToColor(info.Env(), m_strokeStyle); nvgStrokeColor(*m_nvg, color); - SetDirty(); } Napi::Value Context::GetLineWidth(const Napi::CallbackInfo&) @@ -258,7 +254,6 @@ namespace Babylon::Polyfills::Internal { m_lineWidth = value.As().FloatValue(); nvgStrokeWidth(*m_nvg, m_lineWidth); - SetDirty(); } void Context::Fill(const Napi::CallbackInfo& info) @@ -274,23 +269,19 @@ namespace Babylon::Polyfills::Internal if (path != nullptr) { PlayPath2D(path); - SetDirty(); } nvgFill(*m_nvg); - SetDirty(); } void Context::Save(const Napi::CallbackInfo&) { nvgSave(*m_nvg); - SetDirty(); } void Context::Restore(const Napi::CallbackInfo&) { nvgRestore(*m_nvg); - SetDirty(); m_isClipped = false; } @@ -319,7 +310,6 @@ namespace Babylon::Polyfills::Internal nvgFillColor(*m_nvg, TRANSPARENT_BLACK); nvgFill(*m_nvg); nvgRestore(*m_nvg); - SetDirty(); } void Context::Translate(const Napi::CallbackInfo& info) @@ -327,14 +317,12 @@ namespace Babylon::Polyfills::Internal const auto x = info[0].As().FloatValue(); const auto y = info[1].As().FloatValue(); nvgTranslate(*m_nvg, x, y); - SetDirty(); } void Context::Rotate(const Napi::CallbackInfo& info) { const auto angle = info[0].As().FloatValue(); nvgRotate(*m_nvg, angle); - SetDirty(); } void Context::Scale(const Napi::CallbackInfo& info) @@ -342,19 +330,16 @@ namespace Babylon::Polyfills::Internal const auto x = info[0].As().FloatValue(); const auto y = info[1].As().FloatValue(); nvgScale(*m_nvg, x, y); - SetDirty(); } void Context::BeginPath(const Napi::CallbackInfo&) { nvgBeginPath(*m_nvg); - SetDirty(); } void Context::ClosePath(const Napi::CallbackInfo&) { nvgClosePath(*m_nvg); - SetDirty(); } void Context::Rect(const Napi::CallbackInfo& info) @@ -366,7 +351,6 @@ namespace Babylon::Polyfills::Internal nvgRect(*m_nvg, left, top, width, height); m_rectangleClipping = {left, top, width, height}; - SetDirty(); } void Context::RoundRect(const Napi::CallbackInfo& info) @@ -422,16 +406,15 @@ namespace Babylon::Polyfills::Internal } m_rectangleClipping = {x, y, width, height}; - SetDirty(); } void Context::Clip(const Napi::CallbackInfo& /*info*/) { m_isClipped = true; - //By default m_rectangleClipping is not set, in this case we use the default render target width and height. - auto w = m_rectangleClipping.width != 0 ? m_rectangleClipping.width : m_canvas->GetFrameBuffer().Width(); - auto h = m_rectangleClipping.height != 0 ? m_rectangleClipping.height : m_canvas->GetFrameBuffer().Height(); + //By default m_rectangleClipping is not set, in this case we use the canvas width and height. + auto w = m_rectangleClipping.width != 0 ? m_rectangleClipping.width : m_canvas->GetWidth(); + auto h = m_rectangleClipping.height != 0 ? m_rectangleClipping.height : m_canvas->GetHeight(); // expand clipping 1pix in each direction because nanovg AA gets cut a bit short. nvgScissor(*m_nvg, m_rectangleClipping.left - 1, m_rectangleClipping.top - 1, w + 1, h + 1); @@ -447,7 +430,6 @@ namespace Babylon::Polyfills::Internal nvgRect(*m_nvg, left, top, width, height); SetFilterStack(); nvgStroke(*m_nvg); - SetDirty(); } void Context::PlayPath2D(const NativeCanvasPath2D* path) @@ -456,7 +438,6 @@ namespace Babylon::Polyfills::Internal for (const auto& command : *path) { const auto args = command.args; - bool setDirty = true; switch (command.type) { case P2D_CLOSE: @@ -525,12 +506,10 @@ namespace Babylon::Polyfills::Internal if (path != nullptr) { PlayPath2D(path); - SetDirty(); } SetFilterStack(); nvgStroke(*m_nvg); - SetDirty(); } void Context::MoveTo(const Napi::CallbackInfo& info) @@ -539,7 +518,6 @@ namespace Babylon::Polyfills::Internal const auto y = info[1].As().FloatValue(); nvgMoveTo(*m_nvg, x, y); - SetDirty(); } void Context::LineTo(const Napi::CallbackInfo& info) @@ -548,7 +526,6 @@ namespace Babylon::Polyfills::Internal const auto y = info[1].As().FloatValue(); nvgLineTo(*m_nvg, x, y); - SetDirty(); } void Context::QuadraticCurveTo(const Napi::CallbackInfo& info) @@ -559,7 +536,6 @@ namespace Babylon::Polyfills::Internal const auto y = info[3].As().FloatValue(); nvgBezierTo(*m_nvg, cx, cy, cx, cy, x, y); - SetDirty(); } Napi::Value Context::MeasureText(const Napi::CallbackInfo& info) @@ -608,76 +584,54 @@ namespace Babylon::Polyfills::Internal } nvgText(*m_nvg, x, y, text.c_str(), nullptr); - SetDirty(); } } - void Context::SetDirty() + void Context::Flush(const Napi::CallbackInfo&) { - if (!m_dirty) + bool needClear = m_canvas->UpdateRenderTarget(); + + Graphics::FrameBuffer& frameBuffer = m_canvas->GetFrameBuffer(); + + auto updateToken{m_update.GetUpdateToken()}; + bgfx::Encoder* encoder = updateToken.GetEncoder(); + frameBuffer.Bind(*encoder); + if (needClear) { - m_dirty = true; - DeferredFlushFrame(); + frameBuffer.Clear(*encoder, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH | BGFX_CLEAR_STENCIL, 0, 1.f, 0); } - } + frameBuffer.SetViewPort(*encoder, 0.f, 0.f, 1.f, 1.f); + const auto width = m_canvas->GetWidth(); + const auto height = m_canvas->GetHeight(); - void Context::DeferredFlushFrame() - { - // on some systems (Ubuntu), the framebuffer contains garbage. - // Unlike other systems where it's cleared. - bool needClear = m_canvas->UpdateRenderTarget(); + for (auto& buffer : m_canvas->m_frameBufferPool.GetPoolBuffers()) + { + // sanity check no buffers should have been acquired yet + assert(buffer.isAvailable == true); + } + std::function acquire = [this, encoder]() -> Babylon::Graphics::FrameBuffer* { + Babylon::Graphics::FrameBuffer *frameBuffer = this->m_canvas->m_frameBufferPool.Acquire(); + frameBuffer->Bind(*encoder); + return frameBuffer; + }; + std::function release = [this, encoder](Babylon::Graphics::FrameBuffer* frameBuffer) -> void { + // clear framebuffer when released + frameBuffer->Clear(*encoder, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH | BGFX_CLEAR_STENCIL, 0, 1.f, 0); + this->m_canvas->m_frameBufferPool.Release(frameBuffer); + frameBuffer->Unbind(*encoder); + }; - arcana::make_task(m_update.Scheduler(), *m_cancellationSource, [this, needClear, cancellationSource{m_cancellationSource}]() { - return arcana::make_task(m_runtimeScheduler, *m_cancellationSource, [this, needClear, updateToken{m_update.GetUpdateToken()}, cancellationSource{m_cancellationSource}]() { - // JS Thread - Graphics::FrameBuffer& frameBuffer = m_canvas->GetFrameBuffer(); - bgfx::Encoder* encoder = m_update.GetUpdateToken().GetEncoder(); - frameBuffer.Bind(*encoder); - if (needClear) - { - frameBuffer.Clear(*encoder, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH | BGFX_CLEAR_STENCIL, 0, 1.f, 0); - } - frameBuffer.SetViewPort(*encoder, 0.f, 0.f, 1.f, 1.f); - const auto width = m_canvas->GetWidth(); - const auto height = m_canvas->GetHeight(); - - for (auto& buffer : m_canvas->m_frameBufferPool.GetPoolBuffers()) - { - // sanity check no buffers should have been acquired yet - assert(buffer.isAvailable == true); - } - std::function acquire = [this, encoder]() -> Babylon::Graphics::FrameBuffer* { - Babylon::Graphics::FrameBuffer *frameBuffer = this->m_canvas->m_frameBufferPool.Acquire(); - frameBuffer->Bind(*encoder); - return frameBuffer; - }; - std::function release = [this, encoder](Babylon::Graphics::FrameBuffer* frameBuffer) -> void { - // clear framebuffer when released - frameBuffer->Clear(*encoder, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH | BGFX_CLEAR_STENCIL, 0, 1.f, 0); - this->m_canvas->m_frameBufferPool.Release(frameBuffer); - frameBuffer->Unbind(*encoder); - }; - - nvgBeginFrame(*m_nvg, float(width), float(height), 1.0f); - nvgSetFrameBufferAndEncoder(*m_nvg, frameBuffer, encoder); - nvgSetFrameBufferPool(*m_nvg, { acquire, release }); - nvgEndFrame(*m_nvg); - frameBuffer.Unbind(*encoder); - - for (auto& buffer : m_canvas->m_frameBufferPool.GetPoolBuffers()) - { - // sanity check no unreleased buffers - assert(buffer.isAvailable == true); - } - - m_dirty = false; - }).then(arcana::inline_scheduler, *m_cancellationSource, [this, cancellationSource{m_cancellationSource}](const arcana::expected& result) { - if (!cancellationSource->cancelled() && result.has_error()) - { - Napi::Error::New(Env(), result.error()).ThrowAsJavaScriptException(); - } - }); - }); + nvgBeginFrame(*m_nvg, float(width), float(height), 1.0f); + nvgSetFrameBufferAndEncoder(*m_nvg, frameBuffer, encoder); + nvgSetFrameBufferPool(*m_nvg, { acquire, release }); + nvgEndFrame(*m_nvg); + frameBuffer.Unbind(*encoder); + + for (auto& buffer : m_canvas->m_frameBufferPool.GetPoolBuffers()) + { + // sanity check no unreleased buffers + assert(buffer.isAvailable == true); + } } void Context::PutImageData(const Napi::CallbackInfo&) @@ -694,7 +648,6 @@ namespace Babylon::Polyfills::Internal const auto endAngle = static_cast(info[4].As().DoubleValue()); const NVGwinding winding = (info.Length() == 6 && info[5].As()) ? NVGwinding::NVG_CCW : NVGwinding::NVG_CW; nvgArc(*m_nvg, x, y, radius, startAngle, endAngle, winding); - SetDirty(); } void Context::DrawImage(const Napi::CallbackInfo& info) @@ -732,7 +685,6 @@ namespace Babylon::Polyfills::Internal nvgFillPaint(*m_nvg, imagePaint); SetFilterStack(); nvgFill(*m_nvg); - SetDirty(); } else if (info.Length() == 5) { @@ -752,7 +704,6 @@ namespace Babylon::Polyfills::Internal nvgFillPaint(*m_nvg, imagePaint); SetFilterStack(); nvgFill(*m_nvg); - SetDirty(); } else if (info.Length() == 9) { @@ -778,7 +729,6 @@ namespace Babylon::Polyfills::Internal nvgFillPaint(*m_nvg, imagePaint); SetFilterStack(); nvgFill(*m_nvg); - SetDirty(); } else { @@ -816,7 +766,6 @@ namespace Babylon::Polyfills::Internal if (SetFontFaceId()) { nvgStrokeText(*m_nvg, x, y, text.c_str(), nullptr); - SetDirty(); } } @@ -888,7 +837,6 @@ namespace Babylon::Polyfills::Internal const auto f = info[5].As().FloatValue(); nvgResetTransform(*m_nvg); nvgTransform(*m_nvg, a, b, c, d, e, f); - SetDirty(); } void Context::Transform(const Napi::CallbackInfo& info) @@ -900,7 +848,6 @@ namespace Babylon::Polyfills::Internal const auto e = info[4].As().FloatValue(); const auto f = info[5].As().FloatValue(); nvgTransform(*m_nvg, a, b, c, d, e, f); - SetDirty(); } Napi::Value Context::GetLineCap(const Napi::CallbackInfo& info) @@ -913,7 +860,6 @@ namespace Babylon::Polyfills::Internal m_lineCap = value.As().Utf8Value(); const auto lineCap = StringToLineCap(info.Env(), m_lineCap); nvgLineCap(*m_nvg, lineCap); - SetDirty(); } Napi::Value Context::GetLineJoin(const Napi::CallbackInfo& info) @@ -926,7 +872,6 @@ namespace Babylon::Polyfills::Internal m_lineJoin = value.As().Utf8Value(); const auto lineJoin = StringToLineJoin(info.Env(), m_lineJoin); nvgLineJoin(*m_nvg, lineJoin); - SetDirty(); } Napi::Value Context::GetMiterLimit(const Napi::CallbackInfo& info) @@ -938,7 +883,6 @@ namespace Babylon::Polyfills::Internal { m_miterLimit = value.As().FloatValue(); nvgMiterLimit(*m_nvg, m_miterLimit); - SetDirty(); } Napi::Value Context::GetFilter(const Napi::CallbackInfo& info) diff --git a/Polyfills/Canvas/Source/Context.h b/Polyfills/Canvas/Source/Context.h index 89e9a0a42..e4472964e 100644 --- a/Polyfills/Canvas/Source/Context.h +++ b/Polyfills/Canvas/Source/Context.h @@ -88,9 +88,8 @@ namespace Babylon::Polyfills::Internal void SetShadowOffsetY(const Napi::CallbackInfo&, const Napi::Value& value); void Dispose(const Napi::CallbackInfo&); void Dispose(); - void SetDirty(); - void DeferredFlushFrame(); bool SetFontFaceId(); + void Flush(const Napi::CallbackInfo&); NativeCanvas* m_canvas; std::shared_ptr m_nvg; @@ -113,7 +112,6 @@ namespace Babylon::Polyfills::Internal Graphics::DeviceContext& m_graphicsContext; Graphics::Update m_update; - bool m_dirty{}; bool m_isClipped{false}; struct RectangleClipping diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c09b2661c..67b1695f5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,32 +6,32 @@ pr: variables: - name: CMAKE_VERSION - value: 3.26.3 + value: 3.31.6 - name: NDK_VERSION value: 25.2.9519653 - name: UNITY_BUILD value: true - name: XCODE_VERSION - value: 15.4 + value: 16.2 jobs: # Apple - template: .github/jobs/macos.yml parameters: - name: MacOS_Xcode153 - vmImage: 'macOS-14' + name: MacOS + vmImage: 'macOS-latest' - template: .github/jobs/ios.yml parameters: - name: iOS_Xcode153_iOS162 - vmImage: 'macOS-14' - deploymentTarget: 16.2 + name: iOS_iOS180 + vmImage: 'macOS-latest' + deploymentTarget: 18.0 - template: .github/jobs/ios.yml parameters: - name: iOS_Xcode153_iOS172 - vmImage: 'macOS-14' - deploymentTarget: 17.2 + name: iOS_iOS175 + vmImage: 'macOS-latest' + deploymentTarget: 17.5 # WIN32 - template: .github/jobs/win32.yml