From 62d8b4daaef84fc9aed2d7845a66a028a726a9eb Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 14 Nov 2022 11:46:58 +0800 Subject: [PATCH] Remove unused swapWindow methods. (#13356) The operation of swapping (presenting) buffers is done in gfx::Device::present. To swap multi-systemwindows, multiple gfx swapchains need be created, and relevant gfx backend will iterate each swapchain and present them. Therefore, `swap buffers` operation doesn't need to be in SystemWindow or SystemWindowManager. ```c++ void GLES3Device::present() { CC_PROFILE(GLES3DevicePresent); auto *queue = static_cast(_queue); _numDrawCalls = queue->_numDrawCalls; _numInstances = queue->_numInstances; _numTriangles = queue->_numTriangles; bool isGFXDeviceNeedsPresent = _xr ? _xr->isGFXDeviceNeedsPresent(_api) : true; for (auto *swapchain : _swapchains) { // We iterate each swapchain and do the present thing here. if (isGFXDeviceNeedsPresent) _gpuContext->present(swapchain); } if (_xr) _xr->postGFXDevicePresent(_api); // Clear queue stats queue->_numDrawCalls = 0; queue->_numInstances = 0; queue->_numTriangles = 0; } ``` Besides, `SDL_GL_SwapWindow` invocation is doing nothing on Windows & Linux platforms, it will generate an SDL an error that `The specified window isn't an OpenGL window` because GL context is not created by SDL_GL_CreateContext. We create contexts in our gfx code. https://github.com/libsdl-org/SDL/blob/main/src/video/SDL_video.c#L4192 ```c++ #define NOT_AN_OPENGL_WINDOW "The specified window isn't an OpenGL window" int SDL_GL_SwapWindowWithResult(SDL_Window * window) { CHECK_WINDOW_MAGIC(window, -1); if (!(window->flags & SDL_WINDOW_OPENGL)) { return SDL_SetError(NOT_AN_OPENGL_WINDOW); } if (SDL_GL_GetCurrentWindow() != window) { return SDL_SetError("The specified window has not been made current"); } return _this->GL_SwapWindow(_this, window); } void SDL_GL_SwapWindow(SDL_Window * window) { SDL_GL_SwapWindowWithResult(window); } ``` Also, SDL_GL_SwapWindow could not take any effect if running on gfx Vulkan backend. ```c++ void SDLHelper::swapWindow(SDL_Window *window) { SDL_GL_SwapWindow(window); } ``` --- native/cocos/platform/SDLHelper.cpp | 4 ---- native/cocos/platform/SDLHelper.h | 1 - native/cocos/platform/empty/modules/SystemWindow.cpp | 4 ---- native/cocos/platform/empty/modules/SystemWindow.h | 1 - .../cocos/platform/empty/modules/SystemWindowManager.cpp | 4 ---- .../cocos/platform/empty/modules/SystemWindowManager.h | 1 - .../platform/interfaces/modules/ISystemWindowManager.h | 5 ----- native/cocos/platform/ios/modules/SystemWindowManager.h | 1 - .../cocos/platform/java/modules/SystemWindowManager.cpp | 3 --- native/cocos/platform/java/modules/SystemWindowManager.h | 1 - native/cocos/platform/linux/LinuxPlatform.cpp | 1 - native/cocos/platform/linux/modules/SystemWindow.cpp | 4 ---- native/cocos/platform/linux/modules/SystemWindow.h | 2 -- .../cocos/platform/linux/modules/SystemWindowManager.cpp | 9 --------- .../cocos/platform/linux/modules/SystemWindowManager.h | 1 - native/cocos/platform/mac/modules/SystemWindowManager.h | 1 - native/cocos/platform/win32/WindowsPlatform.cpp | 1 - native/cocos/platform/win32/modules/SystemWindow.cpp | 4 ---- native/cocos/platform/win32/modules/SystemWindow.h | 2 -- .../cocos/platform/win32/modules/SystemWindowManager.cpp | 9 --------- .../cocos/platform/win32/modules/SystemWindowManager.h | 1 - 21 files changed, 60 deletions(-) diff --git a/native/cocos/platform/SDLHelper.cpp b/native/cocos/platform/SDLHelper.cpp index 5a0ae9d6be..d6b8fee213 100644 --- a/native/cocos/platform/SDLHelper.cpp +++ b/native/cocos/platform/SDLHelper.cpp @@ -358,10 +358,6 @@ void SDLHelper::setCursorEnabled(bool value) { SDL_SetRelativeMouseMode(value ? SDL_FALSE : SDL_TRUE); } -void SDLHelper::swapWindow(SDL_Window *window) { - SDL_GL_SwapWindow(window); -} - #if (CC_PLATFORM == CC_PLATFORM_LINUX) uintptr_t SDLHelper::getDisplay(SDL_Window *window) { SDL_SysWMinfo wmInfo; diff --git a/native/cocos/platform/SDLHelper.h b/native/cocos/platform/SDLHelper.h index 7c67d71208..062d5dd051 100644 --- a/native/cocos/platform/SDLHelper.h +++ b/native/cocos/platform/SDLHelper.h @@ -41,7 +41,6 @@ public: ~SDLHelper(); static int init(); - static void swapWindow(SDL_Window* window); static SDL_Window* createWindow(const char* title, int w, int h, int flags); diff --git a/native/cocos/platform/empty/modules/SystemWindow.cpp b/native/cocos/platform/empty/modules/SystemWindow.cpp index cd562d3c3a..3ac2003c46 100644 --- a/native/cocos/platform/empty/modules/SystemWindow.cpp +++ b/native/cocos/platform/empty/modules/SystemWindow.cpp @@ -67,10 +67,6 @@ void SystemWindow::pollEvent(bool* quit) { return; } -void SystemWindow::swapWindow() { - return; -} - SystemWindow::Size SystemWindow::getViewSize() const { return Size{static_cast(_width), static_cast(_height)}; } diff --git a/native/cocos/platform/empty/modules/SystemWindow.h b/native/cocos/platform/empty/modules/SystemWindow.h index ff387ac012..c1fb4ee3ce 100644 --- a/native/cocos/platform/empty/modules/SystemWindow.h +++ b/native/cocos/platform/empty/modules/SystemWindow.h @@ -48,7 +48,6 @@ public: int init(); void pollEvent(bool* quit); - void swapWindow(); private: int _width{0}; diff --git a/native/cocos/platform/empty/modules/SystemWindowManager.cpp b/native/cocos/platform/empty/modules/SystemWindowManager.cpp index 420ed8547f..e0b3ebf9b7 100644 --- a/native/cocos/platform/empty/modules/SystemWindowManager.cpp +++ b/native/cocos/platform/empty/modules/SystemWindowManager.cpp @@ -38,10 +38,6 @@ void SystemWindowManager::processEvent(bool* quit) { } -void SystemWindowManager::swapWindows() { - -} - ISystemWindow *SystemWindowManager::getWindow(uint32_t windowId) const { if (windowId == 0) { return nullptr; diff --git a/native/cocos/platform/empty/modules/SystemWindowManager.h b/native/cocos/platform/empty/modules/SystemWindowManager.h index 02cac6ed74..22b6c22d4c 100644 --- a/native/cocos/platform/empty/modules/SystemWindowManager.h +++ b/native/cocos/platform/empty/modules/SystemWindowManager.h @@ -39,7 +39,6 @@ public: int init() override; void processEvent(bool* quit) override; - void swapWindows() override; ISystemWindow *createWindow(const ISystemWindowInfo &info) override; ISystemWindow *getWindow(uint32_t windowId) const override; diff --git a/native/cocos/platform/interfaces/modules/ISystemWindowManager.h b/native/cocos/platform/interfaces/modules/ISystemWindowManager.h index c3e063cc64..9fd6a1cc71 100644 --- a/native/cocos/platform/interfaces/modules/ISystemWindowManager.h +++ b/native/cocos/platform/interfaces/modules/ISystemWindowManager.h @@ -58,11 +58,6 @@ public: */ virtual void processEvent(bool *quit) = 0; - /** - * Swap window back buffer - */ - virtual void swapWindows() = 0; - /** * Create an ISystemWindow object * @param info window description diff --git a/native/cocos/platform/ios/modules/SystemWindowManager.h b/native/cocos/platform/ios/modules/SystemWindowManager.h index ac2ce19b58..b6e4686684 100644 --- a/native/cocos/platform/ios/modules/SystemWindowManager.h +++ b/native/cocos/platform/ios/modules/SystemWindowManager.h @@ -40,7 +40,6 @@ public: int init() override { return 0; } void processEvent(bool *quit) override {} - void swapWindows() override {} ISystemWindow *createWindow(const ISystemWindowInfo &info) override; ISystemWindow *getWindow(uint32_t windowId) const override; diff --git a/native/cocos/platform/java/modules/SystemWindowManager.cpp b/native/cocos/platform/java/modules/SystemWindowManager.cpp index 6b1dc9b6c8..8cecfdccf0 100644 --- a/native/cocos/platform/java/modules/SystemWindowManager.cpp +++ b/native/cocos/platform/java/modules/SystemWindowManager.cpp @@ -37,9 +37,6 @@ int SystemWindowManager::init() { void SystemWindowManager::processEvent(bool *quit) { } -void SystemWindowManager::swapWindows() { -} - ISystemWindow *SystemWindowManager::createWindow(const ISystemWindowInfo &info) { if (!isExternalHandleExist(info.externalHandle)) { ISystemWindow *window = BasePlatform::getPlatform()->createNativeWindow(_nextWindowId, info.externalHandle); diff --git a/native/cocos/platform/java/modules/SystemWindowManager.h b/native/cocos/platform/java/modules/SystemWindowManager.h index 7053581e05..5c49ac1401 100644 --- a/native/cocos/platform/java/modules/SystemWindowManager.h +++ b/native/cocos/platform/java/modules/SystemWindowManager.h @@ -39,7 +39,6 @@ public: int init() override; void processEvent(bool *quit) override; - void swapWindows() override; ISystemWindow *createWindow(const ISystemWindowInfo &info) override; ISystemWindow *getWindow(uint32_t windowId) const override; const SystemWindowMap &getWindows() const override { return _windows; } diff --git a/native/cocos/platform/linux/LinuxPlatform.cpp b/native/cocos/platform/linux/LinuxPlatform.cpp index 4781fb44ba..ed53e137c3 100644 --- a/native/cocos/platform/linux/LinuxPlatform.cpp +++ b/native/cocos/platform/linux/LinuxPlatform.cpp @@ -98,7 +98,6 @@ int32_t LinuxPlatform::loop() { if (actualInterval >= desiredInterval) { lastTime = getCurrentMillSecond(); runTask(); - _windowManager->swapWindows(); } else { usleep((desiredInterval - curTime + lastTime) * 1000); } diff --git a/native/cocos/platform/linux/modules/SystemWindow.cpp b/native/cocos/platform/linux/modules/SystemWindow.cpp index 84a81997d3..0d3287a475 100644 --- a/native/cocos/platform/linux/modules/SystemWindow.cpp +++ b/native/cocos/platform/linux/modules/SystemWindow.cpp @@ -49,10 +49,6 @@ SystemWindow::~SystemWindow() { _windowId = 0; } -void SystemWindow::swapWindow() { - SDLHelper::swapWindow(_window); -} - bool SystemWindow::createWindow(const char *title, int w, int h, int flags) { _window = SDLHelper::createWindow(title, w, h, flags); diff --git a/native/cocos/platform/linux/modules/SystemWindow.h b/native/cocos/platform/linux/modules/SystemWindow.h index 95263b35c7..440a02f916 100644 --- a/native/cocos/platform/linux/modules/SystemWindow.h +++ b/native/cocos/platform/linux/modules/SystemWindow.h @@ -39,8 +39,6 @@ public: explicit SystemWindow(uint32_t windowId, void* externalHandle); ~SystemWindow() override; - void swapWindow(); - bool createWindow(const char* title, int w, int h, int flags) override; bool createWindow(const char* title, diff --git a/native/cocos/platform/linux/modules/SystemWindowManager.cpp b/native/cocos/platform/linux/modules/SystemWindowManager.cpp index e2e0f45f6e..540f3f2004 100644 --- a/native/cocos/platform/linux/modules/SystemWindowManager.cpp +++ b/native/cocos/platform/linux/modules/SystemWindowManager.cpp @@ -55,15 +55,6 @@ void SystemWindowManager::processEvent(bool *quit) { } } -void SystemWindowManager::swapWindows() { - for (const auto &pair : _windows) { - SystemWindow *window = static_cast(pair.second.get()); - if (window) { - window->swapWindow(); - } - } -} - ISystemWindow *SystemWindowManager::createWindow(const ISystemWindowInfo &info) { ISystemWindow *window = BasePlatform::getPlatform()->createNativeWindow(_nextWindowId, info.externalHandle); if (window) { diff --git a/native/cocos/platform/linux/modules/SystemWindowManager.h b/native/cocos/platform/linux/modules/SystemWindowManager.h index c19b454fe0..e30ad52143 100644 --- a/native/cocos/platform/linux/modules/SystemWindowManager.h +++ b/native/cocos/platform/linux/modules/SystemWindowManager.h @@ -40,7 +40,6 @@ public: int init() override; void processEvent(bool *quit) override; - void swapWindows() override; ISystemWindow *createWindow(const ISystemWindowInfo &info) override; ISystemWindow *getWindow(uint32_t windowId) const override; diff --git a/native/cocos/platform/mac/modules/SystemWindowManager.h b/native/cocos/platform/mac/modules/SystemWindowManager.h index 81838880dd..9456de9e18 100644 --- a/native/cocos/platform/mac/modules/SystemWindowManager.h +++ b/native/cocos/platform/mac/modules/SystemWindowManager.h @@ -41,7 +41,6 @@ public: int init() override { return 0; } void processEvent(bool *quit) override {} - void swapWindows() override {} ISystemWindow *createWindow(const ISystemWindowInfo &info) override; ISystemWindow *getWindow(uint32_t windowId) const override; diff --git a/native/cocos/platform/win32/WindowsPlatform.cpp b/native/cocos/platform/win32/WindowsPlatform.cpp index ded80cd2d2..394fb4a7a9 100644 --- a/native/cocos/platform/win32/WindowsPlatform.cpp +++ b/native/cocos/platform/win32/WindowsPlatform.cpp @@ -151,7 +151,6 @@ int32_t WindowsPlatform::loop() { if (actualInterval >= desiredInterval) { nLast.QuadPart = nNow.QuadPart; runTask(); - _windowManager->swapWindows(); } else { // The precision of timer on Windows is set to highest (1ms) by 'timeBeginPeriod' from above code, // but it's still not precise enough. For example, if the precision of timer is 1ms, diff --git a/native/cocos/platform/win32/modules/SystemWindow.cpp b/native/cocos/platform/win32/modules/SystemWindow.cpp index c95a50f5e6..f0c97c5dfa 100644 --- a/native/cocos/platform/win32/modules/SystemWindow.cpp +++ b/native/cocos/platform/win32/modules/SystemWindow.cpp @@ -45,10 +45,6 @@ SystemWindow::~SystemWindow() { _windowId = 0; } -void SystemWindow::swapWindow() { - SDLHelper::swapWindow(_window); -} - bool SystemWindow::createWindow(const char *title, int w, int h, int flags) { _window = SDLHelper::createWindow(title, w, h, flags); diff --git a/native/cocos/platform/win32/modules/SystemWindow.h b/native/cocos/platform/win32/modules/SystemWindow.h index 3bf2ce6695..3db07eefb3 100644 --- a/native/cocos/platform/win32/modules/SystemWindow.h +++ b/native/cocos/platform/win32/modules/SystemWindow.h @@ -40,8 +40,6 @@ public: explicit SystemWindow(uint32_t windowId, void* externalHandle); ~SystemWindow() override; - void swapWindow(); - bool createWindow(const char* title, int w, int h, int flags) override; bool createWindow(const char* title, diff --git a/native/cocos/platform/win32/modules/SystemWindowManager.cpp b/native/cocos/platform/win32/modules/SystemWindowManager.cpp index 6b0eb496e4..50c1cafbe2 100644 --- a/native/cocos/platform/win32/modules/SystemWindowManager.cpp +++ b/native/cocos/platform/win32/modules/SystemWindowManager.cpp @@ -55,15 +55,6 @@ void SystemWindowManager::processEvent(bool *quit) { } } -void SystemWindowManager::swapWindows() { - for (const auto &pair : _windows) { - SystemWindow *window = static_cast(pair.second.get()); - if (window) { - window->swapWindow(); - } - } -} - ISystemWindow *SystemWindowManager::createWindow(const ISystemWindowInfo &info) { ISystemWindow *window = BasePlatform::getPlatform()->createNativeWindow(_nextWindowId, info.externalHandle); if (window) { diff --git a/native/cocos/platform/win32/modules/SystemWindowManager.h b/native/cocos/platform/win32/modules/SystemWindowManager.h index e35c844b71..9a0275cb9a 100644 --- a/native/cocos/platform/win32/modules/SystemWindowManager.h +++ b/native/cocos/platform/win32/modules/SystemWindowManager.h @@ -40,7 +40,6 @@ public: int init() override; void processEvent(bool *quit) override; - void swapWindows() override; ISystemWindow *createWindow(const ISystemWindowInfo &info) override; ISystemWindow *getWindow(uint32_t windowId) const override;