MCPcopy Create free account
hub / github.com/cocos/cocos-engine / initialize

Method initialize

native/cocos/platform/java/modules/XRInterface.cpp:459–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

457}
458
459void XRInterface::initialize(void *javaVM, void *activity) {
460#if CC_USE_XR
461 CC_LOG_INFO("[XR] initialize vm.%p,aty.%p | %d", javaVM, activity, (int)gettid());
462 _isXrEntryInstanceValid = true;
463 xr::XrEntry::getInstance()->initPlatformData(javaVM, activity);
464 xr::XrEntry::getInstance()->setGamepadCallback(std::bind(&XRInterface::dispatchGamepadEventInternal, this, std::placeholders::_1));
465 xr::XrEntry::getInstance()->setHandleCallback(std::bind(&XRInterface::dispatchHandleEventInternal, this, std::placeholders::_1));
466 xr::XrEntry::getInstance()->setHMDCallback(std::bind(&XRInterface::dispatchHMDEventInternal, this, std::placeholders::_1));
467 xr::XrEntry::getInstance()->setXRConfig(xr::XRConfigKey::LOGIC_THREAD_ID, static_cast<int>(gettid()));
468 xr::XrEntry::getInstance()->setXRConfig(xr::XRConfigKey::ENGINE_VERSION, COCOS_VERSION);
469 xr::XrEntry::getInstance()->setXRConfigCallback([this](xr::XRConfigKey key, xr::XRConfigValue value) {
470 if (IS_ENABLE_XR_LOG) CC_LOG_INFO("XRConfigCallback.%d", key);
471 if (key == xr::XRConfigKey::RENDER_EYE_FRAME_LEFT || key == xr::XRConfigKey::RENDER_EYE_FRAME_RIGHT) {
472 if (value.getInt() == 0) {
473 this->beginRenderEyeFrame(key == xr::XRConfigKey::RENDER_EYE_FRAME_LEFT ? 0 : 1);
474 }
475
476 if (value.getInt() == 1) {
477 this->endRenderEyeFrame(key == xr::XRConfigKey::RENDER_EYE_FRAME_LEFT ? 0 : 1);
478 }
479 } else if (key == xr::XRConfigKey::IMAGE_TRACKING_CANDIDATEIMAGE && value.isString()) {
480 if (!_gThreadPool) {
481 _gThreadPool = LegacyThreadPool::newSingleThreadPool();
482 }
483
484 std::string imageInfo = value.getString();
485 _gThreadPool->pushTask([imageInfo, this](int /*tid*/) {
486 this->loadImageTrackingData(imageInfo);
487 });
488 } else if (key == xr::XRConfigKey::ASYNC_LOAD_ASSETS_IMAGE && value.isString()) {
489 std::string imagePath = value.getString();
490 if (imagePath.length() == 0) {
491 return;
492 }
493
494 if (!_gThreadPool) {
495 _gThreadPool = LegacyThreadPool::newSingleThreadPool();
496 }
497 _gThreadPool->pushTask([imagePath, this](int /*tid*/) {
498 this->asyncLoadAssetsImage(imagePath);
499 });
500 } else if (key == xr::XRConfigKey::ASYNC_LOAD_ASSETS_IMAGE && value.isInt()) {
501 _isFlipPixelY = value.getInt() == static_cast<int>(gfx::API::GLES3);
502 } else if (key == xr::XRConfigKey::TS_EVENT_CALLBACK) {
503 se::AutoHandleScope scope;
504 se::ValueArray args;
505 args.emplace_back(se::Value(value.getString()));
506 EventDispatcher::doDispatchJsEvent("onXREvent", args);
507 }
508 });
509 #if XR_OEM_PICO
510 std::string graphicsApiName = GraphicsApiOpenglES;
511 #if CC_USE_VULKAN
512 graphicsApiName = GraphicsApiVulkan_1_1;
513 #endif
514 xr::XrEntry::getInstance()->createXrInstance(graphicsApiName.c_str());
515 #endif
516

Callers

nothing calls this directly

Calls 13

beginRenderEyeFrameMethod · 0.95
endRenderEyeFrameMethod · 0.95
loadImageTrackingDataMethod · 0.95
asyncLoadAssetsImageMethod · 0.95
setXRConfigMethod · 0.80
pushTaskMethod · 0.80
isIntMethod · 0.80
bindFunction · 0.50
ValueClass · 0.50
getIntMethod · 0.45
isStringMethod · 0.45
getStringMethod · 0.45

Tested by

no test coverage detected