From e0acb03cc055105243d53b8fd40eb5367843dfaa Mon Sep 17 00:00:00 2001 From: oahc09 Date: Mon, 9 Oct 2023 17:15:56 +0800 Subject: [PATCH 1/2] feat:[xr] support dispatch xr event to ts --- native/cocos/platform/interfaces/modules/XRCommon.h | 1 + native/cocos/platform/java/modules/XRInterface.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/native/cocos/platform/interfaces/modules/XRCommon.h b/native/cocos/platform/interfaces/modules/XRCommon.h index 682c448c005..d33f2115081 100644 --- a/native/cocos/platform/interfaces/modules/XRCommon.h +++ b/native/cocos/platform/interfaces/modules/XRCommon.h @@ -120,6 +120,7 @@ enum class XRConfigKey { ASYNC_LOAD_ASSETS_IMAGE_RESULTS = 56, LEFT_CONTROLLER_ACTIVE = 57, RIGHT_CONTROLLER_ACTIVE= 58, + TS_EVENT_CALLBACK = 59, MAX_COUNT }; diff --git a/native/cocos/platform/java/modules/XRInterface.cpp b/native/cocos/platform/java/modules/XRInterface.cpp index b6224a9f137..ee74e100889 100644 --- a/native/cocos/platform/java/modules/XRInterface.cpp +++ b/native/cocos/platform/java/modules/XRInterface.cpp @@ -499,6 +499,10 @@ void XRInterface::initialize(void *javaVM, void *activity) { }); } else if (key == xr::XRConfigKey::ASYNC_LOAD_ASSETS_IMAGE && value.isInt()) { _isFlipPixelY = value.getInt() == static_cast(gfx::API::GLES3); + } else if (key == xr::XRConfigKey::TS_EVENT_CALLBACK) { + se::ValueArray args; + args.emplace_back(se::Value(value.getString())); + EventDispatcher::doDispatchJsEvent("onXREvent", args); } }); #if XR_OEM_PICO From 6d3e2801f385aa21299c726fb699733153405fa2 Mon Sep 17 00:00:00 2001 From: oahc09 Date: Tue, 10 Oct 2023 10:42:27 +0800 Subject: [PATCH 2/2] improve:add se::AutoHandleScope scope; --- native/cocos/platform/java/modules/XRInterface.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/native/cocos/platform/java/modules/XRInterface.cpp b/native/cocos/platform/java/modules/XRInterface.cpp index ee74e100889..b59f0447cfb 100644 --- a/native/cocos/platform/java/modules/XRInterface.cpp +++ b/native/cocos/platform/java/modules/XRInterface.cpp @@ -500,6 +500,7 @@ void XRInterface::initialize(void *javaVM, void *activity) { } else if (key == xr::XRConfigKey::ASYNC_LOAD_ASSETS_IMAGE && value.isInt()) { _isFlipPixelY = value.getInt() == static_cast(gfx::API::GLES3); } else if (key == xr::XRConfigKey::TS_EVENT_CALLBACK) { + se::AutoHandleScope scope; se::ValueArray args; args.emplace_back(se::Value(value.getString())); EventDispatcher::doDispatchJsEvent("onXREvent", args); @@ -875,6 +876,7 @@ bool XRInterface::beginRenderEyeFrame(uint32_t eye) { #if CC_USE_XR if (IS_ENABLE_XR_LOG) CC_LOG_INFO("[XR] beginRenderEyeFrame %d", eye); if (_isEnabledEyeRenderJsCallback) { + se::AutoHandleScope scope; se::ValueArray args; args.emplace_back(se::Value(eye)); EventDispatcher::doDispatchJsEvent("onXREyeRenderBegin", args); @@ -899,6 +901,7 @@ bool XRInterface::endRenderEyeFrame(uint32_t eye) { #if CC_USE_XR if (IS_ENABLE_XR_LOG) CC_LOG_INFO("[XR] endRenderEyeFrame %d", eye); if (_isEnabledEyeRenderJsCallback) { + se::AutoHandleScope scope; se::ValueArray args; args.emplace_back(se::Value(eye)); EventDispatcher::doDispatchJsEvent("onXREyeRenderEnd", args);