diff --git a/native/cocos/bindings/event/EventDispatcher.cpp b/native/cocos/bindings/event/EventDispatcher.cpp index 670830e976..307b8b7ee5 100644 --- a/native/cocos/bindings/event/EventDispatcher.cpp +++ b/native/cocos/bindings/event/EventDispatcher.cpp @@ -405,8 +405,7 @@ void EventDispatcher::dispatchCloseEvent() { void EventDispatcher::dispatchDestroyWindowEvent() { #if CC_PLATFORM == CC_PLATFORM_WINDOWS - EventDispatcher::dispatchCustomEvent(EVENT_DESTROY_WINDOW, 1, - reinterpret_cast(CC_GET_MAIN_SYSTEM_WINDOW()->getWindowHandle())); + EventDispatcher::dispatchCustomEvent(EVENT_DESTROY_WINDOW, 1, ISystemWindow::mainWindowId); #else EventDispatcher::dispatchCustomEvent(EVENT_DESTROY_WINDOW, 0); #endif @@ -414,7 +413,7 @@ void EventDispatcher::dispatchDestroyWindowEvent() { void EventDispatcher::dispatchDestroyWindowEvent(cc::ISystemWindow *window) { #if CC_PLATFORM == CC_PLATFORM_WINDOWS - EventDispatcher::dispatchCustomEvent(EVENT_DESTROY_WINDOW, 1, reinterpret_cast(window->getWindowHandle())); + EventDispatcher::dispatchCustomEvent(EVENT_DESTROY_WINDOW, 1, window->getWindowId()); #else CC_UNUSED_PARAM(window); EventDispatcher::dispatchCustomEvent(EVENT_DESTROY_WINDOW, 0); @@ -423,8 +422,7 @@ void EventDispatcher::dispatchDestroyWindowEvent(cc::ISystemWindow *window) { void EventDispatcher::dispatchRecreateWindowEvent() { #if CC_PLATFORM == CC_PLATFORM_WINDOWS - EventDispatcher::dispatchCustomEvent(EVENT_RECREATE_WINDOW, 1, - reinterpret_cast(CC_GET_MAIN_SYSTEM_WINDOW()->getWindowHandle())); + EventDispatcher::dispatchCustomEvent(EVENT_RECREATE_WINDOW, 1, ISystemWindow::mainWindowId); #else EventDispatcher::dispatchCustomEvent(EVENT_RECREATE_WINDOW, 0); #endif @@ -432,8 +430,7 @@ void EventDispatcher::dispatchRecreateWindowEvent() { void EventDispatcher::dispatchRecreateWindowEvent(cc::ISystemWindow *window) { #if CC_PLATFORM == CC_PLATFORM_WINDOWS - auto windowId = static_cast(window->getWindowId()); - EventDispatcher::dispatchCustomEvent(EVENT_RECREATE_WINDOW, 1, reinterpret_cast(windowId)); + EventDispatcher::dispatchCustomEvent(EVENT_RECREATE_WINDOW, 1, window->getWindowId()); #else CC_UNUSED_PARAM(window); EventDispatcher::dispatchCustomEvent(EVENT_RECREATE_WINDOW, 0); diff --git a/native/cocos/engine/Engine.cpp b/native/cocos/engine/Engine.cpp index e47d6eec9c..1e8a21167d 100644 --- a/native/cocos/engine/Engine.cpp +++ b/native/cocos/engine/Engine.cpp @@ -60,6 +60,7 @@ #include "core/assets/FreeTypeFont.h" #include "network/HttpClient.h" #include "platform/UniversalPlatform.h" +#include "platform/interfaces/modules/IScreen.h" #include "platform/interfaces/modules/ISystemWindow.h" #include "platform/interfaces/modules/ISystemWindowManager.h" #if CC_USE_DEBUG_RENDERER @@ -75,11 +76,12 @@ bool setCanvasCallback(se::Object * /*global*/) { auto *window = CC_GET_MAIN_SYSTEM_WINDOW(); auto handler = window->getWindowHandle(); auto viewSize = window->getViewSize(); - + auto dpr = cc::BasePlatform::getPlatform()->getInterface()->getDevicePixelRatio(); + std::stringstream ss; { - ss << "window.innerWidth = " << static_cast(viewSize.x) << ";"; - ss << "window.innerHeight = " << static_cast(viewSize.y) << ";"; + ss << "window.innerWidth = " << static_cast(viewSize.x / dpr) << ";"; + ss << "window.innerHeight = " << static_cast(viewSize.y / dpr) << ";"; ss << "window.windowHandler = "; if (sizeof(handler) == 8) { // use bigint ss << static_cast(handler) << "n;"; diff --git a/native/cocos/platform/android/AndroidPlatform.cpp b/native/cocos/platform/android/AndroidPlatform.cpp index 1a7482535f..6eaadefee0 100644 --- a/native/cocos/platform/android/AndroidPlatform.cpp +++ b/native/cocos/platform/android/AndroidPlatform.cpp @@ -343,7 +343,7 @@ public: cc::CustomEvent event; event.name = EVENT_RECREATE_WINDOW; - event.args->ptrVal = reinterpret_cast(ISystemWindow::mainWindowId); + event.args[0].intVal = ISystemWindow::mainWindowId; _androidPlatform->dispatchEvent(event); } break; @@ -358,7 +358,7 @@ public: } cc::CustomEvent event; event.name = EVENT_DESTROY_WINDOW; - event.args->ptrVal = reinterpret_cast(_androidPlatform->_app->window); + event.args[0].intVal = ISystemWindow::mainWindowId; _androidPlatform->dispatchEvent(event); break; } diff --git a/native/cocos/platform/android/jni/JniCocosSurfaceView.cpp b/native/cocos/platform/android/jni/JniCocosSurfaceView.cpp index b12ce6ea52..58c22c0d63 100644 --- a/native/cocos/platform/android/jni/JniCocosSurfaceView.cpp +++ b/native/cocos/platform/android/jni/JniCocosSurfaceView.cpp @@ -121,7 +121,7 @@ JNIEXPORT void JNICALL Java_com_cocos_lib_CocosSurfaceView_onSurfaceCreatedNativ auto func = [sysWindow]() -> void { cc::CustomEvent event; event.name = EVENT_RECREATE_WINDOW; - event.args->ptrVal = reinterpret_cast(sysWindow->getWindowId()); + event.args[0].intVal = sysWindow->getWindowId(); auto *platform = static_cast(cc::BasePlatform::getPlatform()); platform->dispatchEvent(event); }; @@ -159,7 +159,7 @@ JNIEXPORT void JNICALL Java_com_cocos_lib_CocosSurfaceView_onSurfaceChangedNativ auto func = [sysWindow]() -> void { cc::CustomEvent event; event.name = EVENT_RECREATE_WINDOW; - event.args->ptrVal = reinterpret_cast(sysWindow->getWindowId()); + event.args[0].intVal = sysWindow->getWindowId(); auto *platform = static_cast(cc::BasePlatform::getPlatform()); platform->dispatchEvent(event); }; @@ -179,9 +179,12 @@ JNIEXPORT void JNICALL Java_com_cocos_lib_CocosSurfaceView_onSurfaceDestroyedNat // todo: destroy gfx surface auto func = [nativeWindow]() -> void { auto *platform = static_cast(cc::BasePlatform::getPlatform()); + auto *windowMgr = platform->getInterface(); + cc::ISystemWindow *window = windowMgr->getWindowFromANativeWindow(nativeWindow); + cc::CustomEvent event; event.name = EVENT_DESTROY_WINDOW; - event.args->ptrVal = reinterpret_cast(nativeWindow); + event.args[0].intVal = window->getWindowId(); platform->dispatchEvent(event); }; CC_CURRENT_ENGINE()->getScheduler()->performFunctionInCocosThread(func); diff --git a/native/cocos/platform/java/modules/SystemWindowManager.cpp b/native/cocos/platform/java/modules/SystemWindowManager.cpp index 023a1b35f0..85bf910166 100644 --- a/native/cocos/platform/java/modules/SystemWindowManager.cpp +++ b/native/cocos/platform/java/modules/SystemWindowManager.cpp @@ -42,7 +42,7 @@ void SystemWindowManager::swapWindows() { } ISystemWindow *SystemWindowManager::createWindow(const ISystemWindowInfo &info) { - if (!info.externalHandle || !isExternalHandleExist(info.externalHandle)) { + if (!isExternalHandleExist(info.externalHandle)) { ISystemWindow *window = BasePlatform::getPlatform()->createNativeWindow(_nextWindowId, info.externalHandle); if (window) { if (!info.externalHandle) { diff --git a/native/cocos/renderer/GFXDeviceManager.h b/native/cocos/renderer/GFXDeviceManager.h index 63bbf95074..f5965557eb 100644 --- a/native/cocos/renderer/GFXDeviceManager.h +++ b/native/cocos/renderer/GFXDeviceManager.h @@ -137,11 +137,11 @@ private: static void addSurfaceEventListener() { Device *device = Device::instance; EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [device](const CustomEvent &e) -> void { - device->destroySurface(e.args->ptrVal); + device->destroySurface(e.args[0].intVal); }); EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [device](const CustomEvent &e) -> void { - device->createSurface(e.args->ptrVal); + device->createSurface(e.args[0].intVal); }); } diff --git a/native/cocos/renderer/gfx-base/GFXDevice.cpp b/native/cocos/renderer/gfx-base/GFXDevice.cpp index d56ae888bc..032f86827c 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.cpp +++ b/native/cocos/renderer/gfx-base/GFXDevice.cpp @@ -98,17 +98,16 @@ void Device::destroy() { CC_SAFE_DELETE(_onAcquire); } -void Device::destroySurface(void *windowHandle) { +void Device::destroySurface(uint32_t windowId) { for (const auto &swapchain : _swapchains) { - if (swapchain->getWindowHandle() == windowHandle) { + if (swapchain->getWindowId() == windowId) { swapchain->destroySurface(); break; } } } -void Device::createSurface(void *windowHandle) { - auto windowId = static_cast(reinterpret_cast(windowHandle)); +void Device::createSurface(uint32_t windowId) { for (const auto &swapchain : _swapchains) { if (swapchain->getWindowId() == windowId) { auto *windowMgr = BasePlatform::getPlatform()->getInterface(); diff --git a/native/cocos/renderer/gfx-base/GFXDevice.h b/native/cocos/renderer/gfx-base/GFXDevice.h index 7cb0892666..0f24f17333 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.h +++ b/native/cocos/renderer/gfx-base/GFXDevice.h @@ -132,8 +132,8 @@ protected: Device(); - void destroySurface(void *windowHandle); - void createSurface(void *windowHandle); + void destroySurface(uint32_t windowId); + void createSurface(uint32_t windowId); virtual bool doInit(const DeviceInfo &info) = 0; virtual void doDestroy() = 0;