diff --git a/native/cocos/bindings/manual/jsb_gfx_manual.cpp b/native/cocos/bindings/manual/jsb_gfx_manual.cpp index f0225c7b60..ac1b41457f 100644 --- a/native/cocos/bindings/manual/jsb_gfx_manual.cpp +++ b/native/cocos/bindings/manual/jsb_gfx_manual.cpp @@ -32,8 +32,8 @@ #include #include -bool js_gfx_Device_copyBuffersToTexture(se::State &s) { - cc::gfx::Device *cobj = (cc::gfx::Device *)s.nativeThisObject(); +bool js_gfx_Device_copyBuffersToTexture(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) + auto *cobj = static_cast(s.nativeThisObject()); SE_PRECONDITION2(cobj, false, "js_gfx_Device_copyBuffersToTexture : Invalid Native Object"); const auto & args = s.args(); @@ -69,7 +69,7 @@ bool js_gfx_Device_copyBuffersToTexture(se::State &s) { } else { unsigned long address = 0; seval_to_ulong(value, &address); - ptr = (uint8_t *)address; + ptr = reinterpret_cast(address); } arg0[i] = ptr; @@ -88,8 +88,8 @@ bool js_gfx_Device_copyBuffersToTexture(se::State &s) { } SE_BIND_FUNC(js_gfx_Device_copyBuffersToTexture) -bool js_gfx_Device_copyTexImagesToTexture(se::State &s) { - cc::gfx::Device *cobj = (cc::gfx::Device *)s.nativeThisObject(); +bool js_gfx_Device_copyTexImagesToTexture(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) + auto *cobj = static_cast(s.nativeThisObject()); SE_PRECONDITION2(cobj, false, "js_gfx_Device_copyBuffersToTexture : Invalid Native Object"); const auto & args = s.args(); @@ -117,7 +117,7 @@ bool js_gfx_Device_copyTexImagesToTexture(se::State &s) { } else { unsigned long dataPtr = 0; seval_to_ulong(value, &dataPtr); - arg0[i] = (uint8_t *)dataPtr; + arg0[i] = reinterpret_cast(dataPtr); } } } @@ -135,8 +135,8 @@ bool js_gfx_Device_copyTexImagesToTexture(se::State &s) { } SE_BIND_FUNC(js_gfx_Device_copyTexImagesToTexture) -static bool js_gfx_Device_createBuffer(se::State &s) { - cc::gfx::Device *cobj = (cc::gfx::Device *)s.nativeThisObject(); +static bool js_gfx_Device_createBuffer(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) + auto *cobj = static_cast(s.nativeThisObject()); SE_PRECONDITION2(cobj, false, "js_gfx_Device_createBuffer : Invalid Native Object"); const auto &args = s.args(); size_t argc = args.size(); @@ -168,8 +168,8 @@ static bool js_gfx_Device_createBuffer(se::State &s) { } SE_BIND_FUNC(js_gfx_Device_createBuffer) -static bool js_gfx_Device_createTexture(se::State &s) { - cc::gfx::Device *cobj = (cc::gfx::Device *)s.nativeThisObject(); +static bool js_gfx_Device_createTexture(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) + auto *cobj = static_cast(s.nativeThisObject()); SE_PRECONDITION2(cobj, false, "js_gfx_Device_createTexture : Invalid Native Object"); const auto &args = s.args(); size_t argc = args.size(); @@ -179,8 +179,8 @@ static bool js_gfx_Device_createTexture(se::State &s) { bool createTextureView = false; seval_to_boolean(args[1], &createTextureView); if (createTextureView) { - auto textureViewInfo = (cc::gfx::TextureViewInfo *)(args[0].toObject()->getPrivateData()); - texture = cobj->createTexture(*textureViewInfo); + auto *textureViewInfo = static_cast(args[0].toObject()->getPrivateData()); + texture = cobj->createTexture(*textureViewInfo); } else { cc::gfx::TextureInfo textureInfo; sevalue_to_native(args[0], &textureInfo, s.thisObject()); @@ -198,9 +198,9 @@ static bool js_gfx_Device_createTexture(se::State &s) { } SE_BIND_FUNC(js_gfx_Device_createTexture) -static bool js_gfx_Buffer_initialize(se::State &s) { - CC_UNUSED bool ok = true; - cc::gfx::Buffer *cobj = (cc::gfx::Buffer *)s.nativeThisObject(); +static bool js_gfx_Buffer_initialize(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) + CC_UNUSED bool ok = true; + auto * cobj = static_cast(s.nativeThisObject()); SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_initialize : Invalid Native Object"); const auto &args = s.args(); size_t argc = args.size(); @@ -210,10 +210,10 @@ static bool js_gfx_Buffer_initialize(se::State &s) { seval_to_boolean(args[1], &initWithBufferViewInfo); if (initWithBufferViewInfo) { - auto bufferViewInfo = (cc::gfx::BufferViewInfo *)(args[0].toObject()->getPrivateData()); + auto *bufferViewInfo = static_cast(args[0].toObject()->getPrivateData()); cobj->initialize(*bufferViewInfo); } else { - auto bufferInfo = (cc::gfx::BufferInfo *)(args[0].toObject()->getPrivateData()); + auto *bufferInfo = static_cast(args[0].toObject()->getPrivateData()); cobj->initialize(*bufferInfo); } @@ -227,9 +227,9 @@ static bool js_gfx_Buffer_initialize(se::State &s) { } SE_BIND_FUNC(js_gfx_Buffer_initialize) -static bool js_gfx_Texture_initialize(se::State &s) { - CC_UNUSED bool ok = true; - cc::gfx::Texture *cobj = (cc::gfx::Texture *)s.nativeThisObject(); +static bool js_gfx_Texture_initialize(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) + CC_UNUSED bool ok = true; + auto * cobj = static_cast(s.nativeThisObject()); SE_PRECONDITION2(cobj, false, "js_gfx_Texture_initialize : Invalid Native Object"); const auto &args = s.args(); size_t argc = args.size(); @@ -239,10 +239,10 @@ static bool js_gfx_Texture_initialize(se::State &s) { seval_to_boolean(args[1], &initWithTextureViewInfo); if (initWithTextureViewInfo) { - auto textureViewInfo = (cc::gfx::TextureViewInfo *)(args[0].toObject()->getPrivateData()); + auto *textureViewInfo = static_cast(args[0].toObject()->getPrivateData()); cobj->initialize(*textureViewInfo); } else { - auto textureInfo = (cc::gfx::TextureInfo *)(args[0].toObject()->getPrivateData()); + auto *textureInfo = static_cast(args[0].toObject()->getPrivateData()); cobj->initialize(*textureInfo); } @@ -256,8 +256,8 @@ static bool js_gfx_Texture_initialize(se::State &s) { } SE_BIND_FUNC(js_gfx_Texture_initialize) -static bool js_gfx_GFXBuffer_update(se::State &s) { - cc::gfx::Buffer *cobj = (cc::gfx::Buffer *)s.nativeThisObject(); +static bool js_gfx_GFXBuffer_update(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) + auto *cobj = static_cast(s.nativeThisObject()); SE_PRECONDITION2(cobj, false, "js_gfx_GFXBuffer_update : Invalid Native Object"); const auto & args = s.args(); size_t argc = args.size(); @@ -283,7 +283,7 @@ static bool js_gfx_GFXBuffer_update(se::State &s) { } if (argc == 2) { unsigned int arg1 = 0; - ok &= seval_to_uint32(args[1], (uint32_t *)&arg1); + ok &= seval_to_uint32(args[1], &arg1); SE_PRECONDITION2(ok, false, "js_gfx_GFXBuffer_update : Error processing arguments"); cobj->update(arg0, arg1); return true; @@ -293,8 +293,8 @@ static bool js_gfx_GFXBuffer_update(se::State &s) { } SE_BIND_FUNC(js_gfx_GFXBuffer_update) -static bool js_gfx_CommandBuffer_execute(se::State &s) { - cc::gfx::CommandBuffer *cobj = (cc::gfx::CommandBuffer *)s.nativeThisObject(); +static bool js_gfx_CommandBuffer_execute(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) + auto *cobj = static_cast(s.nativeThisObject()); SE_PRECONDITION2(cobj, false, "js_gfx_CommandBuffer_execute : Invalid Native Object"); const auto & args = s.args(); size_t argc = args.size(); @@ -302,7 +302,7 @@ static bool js_gfx_CommandBuffer_execute(se::State &s) { if (argc == 2) { cc::gfx::CommandBufferList cmdBufs; unsigned int count = 0; - ok &= seval_to_uint32(args[1], (uint32_t *)&count); + ok &= seval_to_uint32(args[1], &count); se::Object *jsarr = args[0].toObject(); assert(jsarr->isArray()); @@ -322,8 +322,8 @@ static bool js_gfx_CommandBuffer_execute(se::State &s) { break; } - cc::gfx::CommandBuffer *cmdBuf = (cc::gfx::CommandBuffer *)tmp.toObject()->getPrivateData(); - cmdBufs[i] = cmdBuf; + auto *cmdBuf = static_cast(tmp.toObject()->getPrivateData()); + cmdBufs[i] = cmdBuf; } } @@ -336,8 +336,8 @@ static bool js_gfx_CommandBuffer_execute(se::State &s) { } SE_BIND_FUNC(js_gfx_CommandBuffer_execute) -static bool js_gfx_CommandBuffer_updateBuffer(se::State &s) { - cc::gfx::CommandBuffer *cobj = (cc::gfx::CommandBuffer *)s.nativeThisObject(); +static bool js_gfx_CommandBuffer_updateBuffer(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) + auto *cobj = static_cast(s.nativeThisObject()); SE_PRECONDITION2(cobj, false, "js_gfx_CommandBuffer_updateBuffer : Invalid Native Object"); const auto & args = s.args(); @@ -346,7 +346,7 @@ static bool js_gfx_CommandBuffer_updateBuffer(se::State &s) { cc::gfx::Buffer *arg0 = nullptr; SE_PRECONDITION2(args[0].isObject(), false, "js_gfx_CommandBuffer_updateBuffer : Invalid Native Object"); - arg0 = (cc::gfx::Buffer *)args[0].toObject()->getPrivateData(); + arg0 = static_cast(args[0].toObject()->getPrivateData()); uint8_t * arg1 = nullptr; CC_UNUSED size_t dataLength = 0; @@ -372,8 +372,8 @@ static bool js_gfx_CommandBuffer_updateBuffer(se::State &s) { } SE_BIND_FUNC(js_gfx_CommandBuffer_updateBuffer) -static bool js_gfx_CommandBuffer_copyBuffersToTexture(se::State &s) { - cc::gfx::CommandBuffer *cobj = (cc::gfx::CommandBuffer *)s.nativeThisObject(); +static bool js_gfx_CommandBuffer_copyBuffersToTexture(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) + auto *cobj = static_cast(s.nativeThisObject()); SE_PRECONDITION2(cobj, false, "js_gfx_CommandBuffer_copyBuffersToTexture : Invalid Native Object"); const auto & args = s.args(); @@ -420,8 +420,8 @@ static bool js_gfx_CommandBuffer_copyBuffersToTexture(se::State &s) { } SE_BIND_FUNC(js_gfx_CommandBuffer_copyBuffersToTexture) -static bool js_gfx_InputAssembler_extractDrawInfo(se::State &s) { - cc::gfx::InputAssembler *cobj = (cc::gfx::InputAssembler *)s.nativeThisObject(); +static bool js_gfx_InputAssembler_extractDrawInfo(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) + auto *cobj = static_cast(s.nativeThisObject()); SE_PRECONDITION2(cobj, false, "js_gfx_InputAssembler_extractDrawInfo : Invalid Native Object"); const auto &args = s.args(); size_t argc = args.size(); @@ -458,7 +458,7 @@ static bool js_gfx_InputAssembler_extractDrawInfo(se::State &s) { } SE_BIND_FUNC(js_gfx_InputAssembler_extractDrawInfo) -bool js_gfx_get_deviceInstance(se::State &s) { +bool js_gfx_get_deviceInstance(se::State &s) { // NOLINT(readability-identifier-naming, google-runtime-references) nativevalue_to_se(cc::gfx::Device::getInstance(), s.rval(), nullptr); return true; } @@ -491,12 +491,5 @@ bool register_all_gfx_manual(se::Object *obj) { } se::Object *ns = nsVal.toObject(); - { - se::Value jsret; - nativevalue_to_se(cc::gfx::Device::getInstance(), jsret, nullptr); - ns->setProperty("deviceInstance", jsret); - // ns->defineProperty("deviceInstance", _SE(js_gfx_get_deviceInstance), nullptr); - } - return true; } diff --git a/native/cocos/bindings/manual/jsb_gfx_manual.h b/native/cocos/bindings/manual/jsb_gfx_manual.h index bae3d9ab63..cbee35c69e 100644 --- a/native/cocos/bindings/manual/jsb_gfx_manual.h +++ b/native/cocos/bindings/manual/jsb_gfx_manual.h @@ -28,4 +28,4 @@ namespace se { class Object; } -bool register_all_gfx_manual(se::Object *obj); +bool register_all_gfx_manual(se::Object *obj); // NOLINT(readability-identifier-naming) diff --git a/native/cocos/platform/android/Application-android.cpp b/native/cocos/platform/android/Application-android.cpp index 180b09ba9a..0226e78adc 100644 --- a/native/cocos/platform/android/Application-android.cpp +++ b/native/cocos/platform/android/Application-android.cpp @@ -66,16 +66,6 @@ bool setCanvasCallback(se::Object * /*global*/) { reinterpret_cast(cc::cocosApp.window)); se->evalString(commandBuf); - gfx::DeviceInfo deviceInfo; - deviceInfo.windowHandle = reinterpret_cast(cc::cocosApp.window); - deviceInfo.width = static_cast(viewLogicalSize.x); - deviceInfo.height = static_cast(viewLogicalSize.y); - deviceInfo.nativeWidth = static_cast(viewLogicalSize.x); - deviceInfo.nativeHeight = static_cast(viewLogicalSize.y); - deviceInfo.bindingMappingInfo = pipeline::bindingMappingInfo; - - gfx::DeviceManager::create(deviceInfo); - return true; } diff --git a/native/cocos/platform/ios/Application-ios.mm b/native/cocos/platform/ios/Application-ios.mm index b1bbdd4815..b88297de83 100644 --- a/native/cocos/platform/ios/Application-ios.mm +++ b/native/cocos/platform/ios/Application-ios.mm @@ -113,16 +113,6 @@ namespace { se::ScriptEngine *se = se::ScriptEngine::getInstance(); se->evalString(commandBuf.str().c_str()); - gfx::DeviceInfo deviceInfo; - deviceInfo.windowHandle = windowHandle; - deviceInfo.width = viewLogicalSize.x; - deviceInfo.height = viewLogicalSize.y; - deviceInfo.nativeWidth = nativeWidth; - deviceInfo.nativeHeight = nativeHeight; - deviceInfo.bindingMappingInfo = pipeline::bindingMappingInfo; - - gfx::DeviceManager::create(deviceInfo); - return true; } diff --git a/native/cocos/platform/mac/Application-mac.mm b/native/cocos/platform/mac/Application-mac.mm index 578b711490..8cbf02e0a7 100644 --- a/native/cocos/platform/mac/Application-mac.mm +++ b/native/cocos/platform/mac/Application-mac.mm @@ -107,16 +107,6 @@ bool setCanvasCallback(se::Object *global) { << "; window.windowHandler = " << reinterpret_cast(view) << ";"; se->evalString(commandBuf.str().c_str()); - gfx::DeviceInfo deviceInfo; - deviceInfo.windowHandle = (uintptr_t)view; - deviceInfo.width = viewLogicalSize.x; - deviceInfo.height = viewLogicalSize.y; - deviceInfo.nativeWidth = viewLogicalSize.x * Device::getDevicePixelRatio(); - deviceInfo.nativeHeight = viewLogicalSize.y * Device::getDevicePixelRatio(); - deviceInfo.bindingMappingInfo = pipeline::bindingMappingInfo; - - gfx::DeviceManager::create(deviceInfo); - return true; } diff --git a/native/cocos/platform/ohos/Application-ohos.cpp b/native/cocos/platform/ohos/Application-ohos.cpp index 654bd14129..04af914933 100644 --- a/native/cocos/platform/ohos/Application-ohos.cpp +++ b/native/cocos/platform/ohos/Application-ohos.cpp @@ -57,16 +57,6 @@ bool setCanvasCallback(se::Object *global) { //NOLINT << "window.windowHandler = " << cc::cocosApp.pendingWindow << ";"; se->evalString(ss.str().c_str()); - cc::gfx::DeviceInfo deviceInfo; - deviceInfo.windowHandle = reinterpret_cast(view); - deviceInfo.width = viewLogicalSize.x; - deviceInfo.height = viewLogicalSize.y; - deviceInfo.nativeWidth = viewLogicalSize.x * cc::Device::getDevicePixelRatio(); - deviceInfo.nativeHeight = viewLogicalSize.y * cc::Device::getDevicePixelRatio(); - deviceInfo.bindingMappingInfo = cc::pipeline::bindingMappingInfo; - - cc::gfx::DeviceManager::create(deviceInfo); - return true; } } // namespace diff --git a/native/cocos/platform/win32/Application-win32.cpp b/native/cocos/platform/win32/Application-win32.cpp index 86740ae012..95c382e61b 100644 --- a/native/cocos/platform/win32/Application-win32.cpp +++ b/native/cocos/platform/win32/Application-win32.cpp @@ -88,16 +88,6 @@ bool Application::init() { auto view = cc_get_application_view(); auto viewSize = view->getViewSize(); - gfx::DeviceInfo deviceInfo; - deviceInfo.windowHandle = reinterpret_cast(view->getWindowHandler()); - deviceInfo.width = viewSize[0]; - deviceInfo.height = viewSize[1]; - deviceInfo.nativeWidth = viewSize[0]; - deviceInfo.nativeHeight = viewSize[1]; - deviceInfo.bindingMappingInfo = pipeline::bindingMappingInfo; - - gfx::DeviceManager::create(deviceInfo); - return true; } diff --git a/native/cocos/renderer/gfx-base/GFXContext.h b/native/cocos/renderer/gfx-base/GFXContext.h index e29e476b50..66f3a0da83 100644 --- a/native/cocos/renderer/gfx-base/GFXContext.h +++ b/native/cocos/renderer/gfx-base/GFXContext.h @@ -33,7 +33,7 @@ namespace gfx { class CC_DLL Context : public Object { public: Context(); - virtual ~Context(); + ~Context() override; bool initialize(const ContextInfo &info); void destroy(); diff --git a/native/cocos/renderer/gfx-gles2/GLES2Context.cpp b/native/cocos/renderer/gfx-gles2/GLES2Context.cpp index f146e9be8f..af36aa9b87 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Context.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Context.cpp @@ -31,8 +31,6 @@ #if (CC_PLATFORM == CC_PLATFORM_ANDROID) #include "android/native_window.h" - #include "cocos/bindings/event/CustomEventTypes.h" - #include "cocos/bindings/event/EventDispatcher.h" #endif #define FORCE_DISABLE_VALIDATION 1 @@ -100,6 +98,7 @@ GLES2Context::~GLES2Context() = default; bool GLES2Context::doInit(const ContextInfo &info) { _vsyncMode = info.vsyncMode; _windowHandle = info.windowHandle; + auto *window = reinterpret_cast(_windowHandle); // NOLINT(performance-no-int-to-ptr) ////////////////////////////////////////////////////////////////////////// @@ -112,7 +111,7 @@ bool GLES2Context::doInit(const ContextInfo &info) { _windowHandle = info.windowHandle; #if (CC_PLATFORM == CC_PLATFORM_WINDOWS) - _nativeDisplay = GetDC(reinterpret_cast(_windowHandle)); + _nativeDisplay = GetDC(window); if (!_nativeDisplay) { return false; } @@ -190,11 +189,11 @@ bool GLES2Context::doInit(const ContextInfo &info) { EGLint depth{0}; EGLint stencil{0}; - const uint8_t attrNums = 8; - int params[attrNums] = {0}; - bool matched = false; - const bool performancePreferred = info.performance == Performance::HIGH_QUALITY; - uint64_t lastScore = performancePreferred ? std::numeric_limits::min() : std::numeric_limits::max(); + const uint8_t attrNums = 8; + EGLint params[attrNums] = {0}; + bool matched = false; + const bool qualityPreferred = info.performance == Performance::HIGH_QUALITY; + uint64_t lastScore = qualityPreferred ? std::numeric_limits::min() : std::numeric_limits::max(); for (int i = 0; i < numConfig; i++) { int depthValue{0}; @@ -213,23 +212,20 @@ bool GLES2Context::doInit(const ContextInfo &info) { /*------------------------------------------ANGLE's priority-----------------------------------------------*/ // Favor EGLConfigLists by RGB, then Depth, then Non-linear Depth, then Stencil, then Alpha uint64_t currScore{0}; - currScore |= (static_cast(std::min(std::max(params[6], 0), 15))) << 29; - currScore |= (static_cast(std::min(std::max(params[7], 0), 31))) << 24; - currScore |= std::min(std::abs(params[0] - redSize) + - std::abs(params[1] - greenSize) + - std::abs(params[2] - blueSize), - 127) - << 17; - currScore |= std::min(std::abs(params[4] - depthSize), 63) << 11; - currScore |= std::min(std::abs(1 - bNonLinearDepth), 1) << 10; - currScore |= std::min(std::abs(params[5] - stencilSize), 31) << 6; - currScore |= std::min(std::abs(params[3] - alphaSize), 31) << 0; + EGLint colorScore = std::abs(params[0] - redSize) + std::abs(params[1] - greenSize) + std::abs(params[2] - blueSize); + currScore |= static_cast(std::min(std::max(params[6], 0), 15)) << 29; + currScore |= static_cast(std::min(std::max(params[7], 0), 31)) << 24; + currScore |= static_cast(std::min(colorScore, 127)) << 17; + currScore |= static_cast(std::min(std::abs(params[4] - depthSize), 63)) << 11; + currScore |= static_cast(std::min(std::abs(1 - bNonLinearDepth), 1)) << 10; + currScore |= static_cast(std::min(std::abs(params[5] - stencilSize), 31)) << 6; + currScore |= static_cast(std::min(std::abs(params[3] - alphaSize), 31)) << 0; /*------------------------------------------ANGLE's priority-----------------------------------------------*/ // if msaaEnabled, sampleBuffers and sampleCount should be greater than 0, until iterate to the last one(can't find). bool msaaLimit = (msaaEnabled ? (params[6] > 0 && params[7] > 0) : (params[6] == 0 && params[7] == 0)); // performancePreferred ? [>=] : [<] , egl configurations store in "ascending order" - bool filter = (currScore < lastScore) ^ performancePreferred; + bool filter = (currScore < lastScore) ^ qualityPreferred; if ((filter && msaaLimit) || (!matched && i == numConfig - 1)) { _eglConfig = _vecEGLConfig[i]; depth = params[4]; @@ -281,7 +277,8 @@ bool GLES2Context::doInit(const ContextInfo &info) { */ #if (CC_PLATFORM == CC_PLATFORM_ANDROID) - EGLint nFmt; + EGLint nFmt = 0; + if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { CC_LOG_ERROR("Getting configuration attributes failed."); return false; @@ -289,19 +286,16 @@ bool GLES2Context::doInit(const ContextInfo &info) { auto width = static_cast(GLES2Device::getInstance()->getWidth()); auto height = static_cast(GLES2Device::getInstance()->getHeight()); - ANativeWindow_setBuffersGeometry(reinterpret_cast(_windowHandle), width, height, nFmt); //NOLINT + + ANativeWindow_setBuffersGeometry(window, width, height, nFmt); #endif - //NOLINTNEXTLINE - EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast(_windowHandle), nullptr)); + EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, window, nullptr)); if (_eglSurface == EGL_NO_SURFACE) { CC_LOG_ERROR("Window surface created failed."); return false; } - //String eglVendor = eglQueryString(_eglDisplay, EGL_VENDOR); - //String eglVersion = eglQueryString(_eglDisplay, EGL_VERSION); - EGL_CHECK(_extensions = StringUtil::split(eglQueryString(_eglDisplay, EGL_EXTENSIONS), " ")); _majorVersion = 2; @@ -435,28 +429,31 @@ void GLES2Context::releaseSurface(uintptr_t /*windowHandle*/) { void GLES2Context::acquireSurface(uintptr_t windowHandle) { #if (CC_PLATFORM == CC_PLATFORM_ANDROID) - _windowHandle = windowHandle; + { + _windowHandle = windowHandle; + auto *window = reinterpret_cast(_windowHandle); // NOLINT(performance-no-int-to-ptr) - EGLint nFmt = 0; - if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { - CC_LOG_ERROR("Getting configuration attributes failed."); - return; + EGLint nFmt = 0; + if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { + CC_LOG_ERROR("Getting configuration attributes failed."); + return; + } + + // Device's size will be updated after recreate window (in resize event) and is incorrect for now. + int32_t width = ANativeWindow_getWidth(window); + int32_t height = ANativeWindow_getHeight(window); + ANativeWindow_setBuffersGeometry(window, width, height, nFmt); + GLES2Device::getInstance()->resize(width, height); + + EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, window, nullptr)); + if (_eglSurface == EGL_NO_SURFACE) { + CC_LOG_ERROR("Recreate window surface failed."); + return; + } + + static_cast(GLES2Device::getInstance()->getContext())->makeCurrent(); + GLES2Device::getInstance()->stateCache()->reset(); } - // Device's size will be updated after recreate window (in resize event) and is incorrect for now. - auto *window = reinterpret_cast(_windowHandle); - uint width = ANativeWindow_getWidth(window); - uint height = ANativeWindow_getHeight(window); - ANativeWindow_setBuffersGeometry(window, width, height, nFmt); - GLES2Device::getInstance()->resize(width, height); - - EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast(_windowHandle), nullptr)); - if (_eglSurface == EGL_NO_SURFACE) { - CC_LOG_ERROR("Recreate window surface failed."); - return; - } - - static_cast(GLES2Device::getInstance()->getContext())->makeCurrent(); - GLES2Device::getInstance()->stateCache()->reset(); #endif } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.h b/native/cocos/renderer/gfx-gles3/GLES3Commands.h index 989506d7b3..4dd7da636e 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.h @@ -132,7 +132,7 @@ public: GLES3GPUTexture * gpuTexture = nullptr; const BufferTextureCopy *regions = nullptr; uint count = 0U; - const uint8_t *const * buffers; + const uint8_t *const * buffers = nullptr; GLES3CmdCopyBufferToTexture() : GLESCmd(GLESCmdType::COPY_BUFFER_TO_TEXTURE) {} diff --git a/native/cocos/renderer/gfx-gles3/GLES3Context.cpp b/native/cocos/renderer/gfx-gles3/GLES3Context.cpp index 2184644c4c..f588ef1f8c 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Context.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Context.cpp @@ -35,10 +35,6 @@ #include #include #endif -#if CC_PLATFORM == CC_PLATFORM_OHOS || CC_PLATFORM == CC_PLATFORM_ANDROID - #include "cocos/bindings/event/CustomEventTypes.h" - #include "cocos/bindings/event/EventDispatcher.h" -#endif #define FORCE_DISABLE_VALIDATION 1 @@ -102,6 +98,7 @@ GLES3Context::~GLES3Context() = default; bool GLES3Context::doInit(const ContextInfo &info) { _vsyncMode = info.vsyncMode; _windowHandle = info.windowHandle; + auto *window = reinterpret_cast(_windowHandle); // NOLINT(performance-no-int-to-ptr) ////////////////////////////////////////////////////////////////////////// @@ -114,7 +111,7 @@ bool GLES3Context::doInit(const ContextInfo &info) { _windowHandle = info.windowHandle; #if (CC_PLATFORM == CC_PLATFORM_WINDOWS) - _nativeDisplay = GetDC(reinterpret_cast(_windowHandle)); + _nativeDisplay = GetDC(window); if (!_nativeDisplay) { return false; } @@ -195,11 +192,11 @@ bool GLES3Context::doInit(const ContextInfo &info) { EGLint depth{0}; EGLint stencil{0}; - const uint8_t attrNums = 8; - int params[attrNums] = {0}; - bool matched = false; - const bool performancePreferred = info.performance == Performance::HIGH_QUALITY; - uint64_t lastScore = performancePreferred ? std::numeric_limits::min() : std::numeric_limits::max(); + const uint8_t attrNums = 8; + int params[attrNums] = {0}; + bool matched = false; + const bool qualityPreferred = info.performance == Performance::HIGH_QUALITY; + uint64_t lastScore = qualityPreferred ? std::numeric_limits::min() : std::numeric_limits::max(); for (int i = 0; i < numConfig; i++) { int depthValue{0}; @@ -218,23 +215,20 @@ bool GLES3Context::doInit(const ContextInfo &info) { /*------------------------------------------ANGLE's priority-----------------------------------------------*/ // Favor EGLConfigLists by RGB, then Depth, then Non-linear Depth, then Stencil, then Alpha uint64_t currScore{0}; - currScore |= (static_cast(std::min(std::max(params[6], 0), 15))) << 29; - currScore |= (static_cast(std::min(std::max(params[7], 0), 31))) << 24; - currScore |= std::min(std::abs(params[0] - redSize) + - std::abs(params[1] - greenSize) + - std::abs(params[2] - blueSize), - 127) - << 17; - currScore |= std::min(std::abs(params[4] - depthSize), 63) << 11; - currScore |= std::min(std::abs(1 - bNonLinearDepth), 1) << 10; - currScore |= std::min(std::abs(params[5] - stencilSize), 31) << 6; - currScore |= std::min(std::abs(params[3] - alphaSize), 31) << 0; + EGLint colorScore = std::abs(params[0] - redSize) + std::abs(params[1] - greenSize) + std::abs(params[2] - blueSize); + currScore |= static_cast(std::min(std::max(params[6], 0), 15)) << 29; + currScore |= static_cast(std::min(std::max(params[7], 0), 31)) << 24; + currScore |= static_cast(std::min(colorScore, 127)) << 17; + currScore |= static_cast(std::min(std::abs(params[4] - depthSize), 63)) << 11; + currScore |= static_cast(std::min(std::abs(1 - bNonLinearDepth), 1)) << 10; + currScore |= static_cast(std::min(std::abs(params[5] - stencilSize), 31)) << 6; + currScore |= static_cast(std::min(std::abs(params[3] - alphaSize), 31)) << 0; /*------------------------------------------ANGLE's priority-----------------------------------------------*/ // if msaaEnabled, sampleBuffers and sampleCount should be greater than 0, until iterate to the last one(can't find). bool msaaLimit = (msaaEnabled ? (params[6] > 0 && params[7] > 0) : (params[6] == 0 && params[7] == 0)); // performancePreferred ? [>=] : [<] , egl configurations store in "ascending order" - bool filter = (currScore < lastScore) ^ performancePreferred; + bool filter = (currScore < lastScore) ^ qualityPreferred; if ((filter && msaaLimit) || (!matched && i == numConfig - 1)) { _eglConfig = _vecEGLConfig[i]; depth = params[4]; @@ -283,28 +277,25 @@ bool GLES3Context::doInit(const ContextInfo &info) { * As soon as we picked a EGLConfig, we can safely reconfigure the * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ - #if (CC_PLATFORM == CC_PLATFORM_ANDROID) + #if (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_OHOS) + EGLint nFmt; if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { CC_LOG_ERROR("Getting configuration attributes failed."); return false; } - uint width = GLES3Device::getInstance()->getWidth(); - uint height = GLES3Device::getInstance()->getHeight(); - ANativeWindow_setBuffersGeometry(reinterpret_cast(_windowHandle), width, height, nFmt); - #elif CC_PLATFORM == CC_PLATFORM_OHOS - EGLint nFmt; - if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { - CC_LOG_ERROR("Getting configuration attributes failed."); - return false; - } - uint width = GLES3Device::getInstance()->getWidth(); - uint height = GLES3Device::getInstance()->getHeight(); - NativeLayerHandle(reinterpret_cast(_windowHandle), NativeLayerOps::SET_WIDTH_AND_HEIGHT, width, height); - NativeLayerHandle(reinterpret_cast(_windowHandle), NativeLayerOps::SET_FORMAT, nFmt); + auto width = static_cast(GLES3Device::getInstance()->getWidth()); + auto height = static_cast(GLES3Device::getInstance()->getHeight()); + + #if CC_PLATFORM == CC_PLATFORM_ANDROID + ANativeWindow_setBuffersGeometry(window, width, height, nFmt); + #elif CC_PLATFORM == CC_PLATFORM_OHOS + NativeLayerHandle(window, NativeLayerOps::SET_WIDTH_AND_HEIGHT, width, height); + NativeLayerHandle(window, NativeLayerOps::SET_FORMAT, nFmt); + #endif #endif - EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast(_windowHandle), nullptr)); + EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, window, nullptr)); if (_eglSurface == EGL_NO_SURFACE) { auto err = eglGetError(); CC_LOG_ERROR("Window surface created failed. code %d", err); @@ -459,35 +450,36 @@ void GLES3Context::releaseSurface(uintptr_t /*windowHandle*/) { void GLES3Context::acquireSurface(uintptr_t windowHandle) { #if (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_OHOS) - _windowHandle = windowHandle; + { + _windowHandle = windowHandle; + auto *window = reinterpret_cast(_windowHandle); // NOLINT(performance-no-int-to-ptr) + + EGLint nFmt = 0; + if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { + CC_LOG_ERROR("Getting configuration attributes failed."); + return; + } - EGLint nFmt; - if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { - CC_LOG_ERROR("Getting configuration attributes failed."); - return; - } // Device's size will be updated after recreate window (in resize event) and is incorrect for now. #if CC_PLATFORM == CC_PLATFORM_ANDROID - auto *window = reinterpret_cast(_windowHandle); - uint width = ANativeWindow_getWidth(window); - uint height = ANativeWindow_getHeight(window); - ANativeWindow_setBuffersGeometry(window, width, height, nFmt); - GLES3Device::getInstance()->resize(width, height); + int32_t width = ANativeWindow_getWidth(window); + int32_t height = ANativeWindow_getHeight(window); + ANativeWindow_setBuffersGeometry(window, width, height, nFmt); #elif CC_PLATFORM == CC_PLATFORM_OHOS - auto *window = reinterpret_cast(_windowHandle); - uint width = GLES3Device::getInstance()->getWidth(); - uint height = GLES3Device::getInstance()->getHeight(); - NativeLayerHandle(window, NativeLayerOps::SET_WIDTH_AND_HEIGHT, width, height); + int32_t width = NativeLayerHandle(window, NativeLayerOps::GET_WIDTH); + int32_t height = NativeLayerHandle(window, NativeLayerOps::GET_HEIGHT); #endif + GLES3Device::getInstance()->resize(width, height); - EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, reinterpret_cast(_windowHandle), nullptr)); - if (_eglSurface == EGL_NO_SURFACE) { - CC_LOG_ERROR("Recreate window surface failed."); - return; + EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, window, nullptr)); + if (_eglSurface == EGL_NO_SURFACE) { + CC_LOG_ERROR("Recreate window surface failed."); + return; + } + + static_cast(GLES3Device::getInstance()->getContext())->makeCurrent(); + GLES3Device::getInstance()->stateCache()->reset(); } - - static_cast(GLES3Device::getInstance()->getContext())->makeCurrent(); - GLES3Device::getInstance()->stateCache()->reset(); #endif } diff --git a/native/cocos/renderer/gfx-vulkan/VKContext.cpp b/native/cocos/renderer/gfx-vulkan/VKContext.cpp index 260c709f59..a08cf8311c 100644 --- a/native/cocos/renderer/gfx-vulkan/VKContext.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKContext.cpp @@ -96,10 +96,6 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugReportCallback(VkDebugReportFlagsEXT fl #endif } // namespace -CCVKContext::CCVKContext() = default; - -CCVKContext::~CCVKContext() = default; - bool CCVKContext::doInit(const ContextInfo &info) { if (!info.sharedCtx) { _isPrimaryContex = true; @@ -358,7 +354,7 @@ bool CCVKContext::doInit(const ContextInfo &info) { _gpuContext->vkSurface, &_gpuContext->queueFamilyPresentables[propertyIndex]); } - ///////////////////// Swapchain Preperation ///////////////////// + ///////////////////// Swapchain Preparation ///////////////////// _colorFmt = Format::BGRA8; _depthStencilFmt = Format::D24S8; @@ -379,7 +375,7 @@ bool CCVKContext::doInit(const ContextInfo &info) { VkFormat colorFormat = VK_FORMAT_B8G8R8A8_UNORM; VkColorSpaceKHR colorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; // If the surface format list only includes one entry with VK_FORMAT_UNDEFINED, - // there is no preferered format, so we assume VK_FORMAT_B8G8R8A8_UNORM + // there is no preferred format, so we assume VK_FORMAT_B8G8R8A8_UNORM if ((surfaceFormatCount == 1) && (surfaceFormats[0].format == VK_FORMAT_UNDEFINED)) { colorFormat = VK_FORMAT_B8G8R8A8_UNORM; colorSpace = surfaceFormats[0].colorSpace; diff --git a/native/cocos/renderer/gfx-vulkan/VKContext.h b/native/cocos/renderer/gfx-vulkan/VKContext.h index 6b016a96e3..4efadab9e0 100644 --- a/native/cocos/renderer/gfx-vulkan/VKContext.h +++ b/native/cocos/renderer/gfx-vulkan/VKContext.h @@ -39,8 +39,8 @@ class CCVKGPUSemaphorePool; class CC_VULKAN_API CCVKContext final : public Context { public: - CCVKContext(); - ~CCVKContext() override; + CCVKContext() = default; + ~CCVKContext() override = default; void present() override {} diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp index e23eb42de6..e5bbd63e79 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp @@ -83,9 +83,11 @@ CCVKGPUContext *CCVKDevice::gpuContext() const { return static_cast(_context)->gpuContext(); } -bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { +bool CCVKDevice::doInit(const DeviceInfo &info) { ContextInfo ctxInfo; ctxInfo.windowHandle = _windowHandle; + ctxInfo.msaaEnabled = info.isAntiAlias; + ctxInfo.performance = Performance::HIGH_QUALITY; _context = CC_NEW(CCVKContext); if (!_context->initialize(ctxInfo)) { @@ -695,7 +697,8 @@ bool CCVKDevice::checkSwapchainStatus() { } if (newWidth == 0 || newHeight == 0) { - return _swapchainReady = false; + _swapchainReady = false; + return false; } _transform = mapSurfaceTransform(preTransform); diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/constructor.c b/native/tools/bindings-generator/targets/spidermonkey/templates/constructor.c index 5cecdb48db..86658207b9 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/constructor.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/constructor.c @@ -2,13 +2,15 @@ SE_DECLARE_FINALIZE_FUNC(js_${underlined_class_name}_finalize) -static bool ${signature_name}(se::State& s) // constructor.c -{ #if $is_skip_constructor +static bool ${signature_name}(se::State& /*s*/) // NOLINT(readability-identifier-naming, google-runtime-references) constructor.c +{ //#3 ${namespaced_class_name}: is_skip_construtor ${is_skip_constructor} se::ScriptEngine::getInstance()->evalString("throw new Error(\"${namespaced_class_name} constructor is skipped\")"); return false; #else +static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) constructor.c +{ #if len($arguments) >= $min_args #set arg_count = len($arguments) #set arg_idx = $min_args diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/constructor_overloaded.c b/native/tools/bindings-generator/targets/spidermonkey/templates/constructor_overloaded.c index 4872b591f8..23ccf1e056 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/constructor_overloaded.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/constructor_overloaded.c @@ -2,7 +2,7 @@ SE_DECLARE_FINALIZE_FUNC(js_${underlined_class_name}_finalize) -static bool ${signature_name}(se::State& s) // constructor_overloaded.c +static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) constructor_overloaded.c { #if $is_skip_constructor //#1 ${namespaced_class_name}: is_skip_construtor ${is_skip_constructor} diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/ctor.c b/native/tools/bindings-generator/targets/spidermonkey/templates/ctor.c index 222bf31d0f..084ad84618 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/ctor.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/ctor.c @@ -1,6 +1,6 @@ ## ===== ctor function implementation template -static bool ${signature_name}(se::State& s) +static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) { #if $is_skip_constructor //#2 ${namespaced_class_name}: is_skip_construtor ${is_skip_constructor} diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/ctor_overloaded.c b/native/tools/bindings-generator/targets/spidermonkey/templates/ctor_overloaded.c index 690eed1987..5548110d86 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/ctor_overloaded.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/ctor_overloaded.c @@ -2,7 +2,7 @@ SE_DECLARE_FINALIZE_FUNC(js_${underlined_class_name}_finalize) -static bool ${signature_name}(se::State& s) +static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) { //ctor_overloaded.c CC_UNUSED bool ok = true; diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/enum.c b/native/tools/bindings-generator/targets/spidermonkey/templates/enum.c index 41d024477c..f84a82b535 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/enum.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/enum.c @@ -2,7 +2,7 @@ #set fields = $current_class.fields template<> -bool sevalue_to_native(const se::Value &from, ${current_class.namespaced_class_name} *to, se::Object *ctx) +bool sevalue_to_native(const se::Value &from, ${current_class.namespaced_class_name} *to, se::Object *ctx) // NOLINT(readability-identifier-naming, google-runtime-references) { typedef typename std::underlying_type_t<${current_class.namespaced_class_name}> under_type; under_type tmp; @@ -10,7 +10,7 @@ bool sevalue_to_native(const se::Value &from, ${current_class.namespaced_class_n return false; } -int js_register_${generator.prefix}_${current_class.class_name}(se::Object* obj) +int js_register_${generator.prefix}_${current_class.class_name}(se::Object* obj) // NOLINT(readability-identifier-naming, google-runtime-references) { auto enum_kls = se::Object::createPlainObject(); #for m in fields diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction.c b/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction.c index befdc57bae..7189381799 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction.c @@ -1,6 +1,6 @@ ## ===== instance function implementation template -static bool ${signature_name}(se::State& s) +static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) { auto* cobj = SE_THIS_OBJECT<${namespaced_class_name}>(s); SE_PRECONDITION2(cobj, false, "${signature_name} : Invalid Native Object"); diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction_overloaded.c b/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction_overloaded.c index 315fe9168b..f0c7014bb3 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction_overloaded.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/ifunction_overloaded.c @@ -1,6 +1,6 @@ ## ===== instance function implementation template - for overloaded functions -static bool ${signature_name}(se::State& s) +static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) { CC_UNUSED bool ok = true; auto* cobj = SE_THIS_OBJECT<${namespaced_class_name}>(s); diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/public_field.c b/native/tools/bindings-generator/targets/spidermonkey/templates/public_field.c index b7de116097..a1506e837f 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/public_field.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/public_field.c @@ -1,6 +1,6 @@ ## ===== member implementation template -static bool ${signature_name}_get_${name}(se::State& s) +static bool ${signature_name}_get_${name}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) { auto* cobj = SE_THIS_OBJECT<${namespaced_class_name}>(s); SE_PRECONDITION2(cobj, false, "${signature_name}_get_${name} : Invalid Native Object"); @@ -33,7 +33,7 @@ static bool ${signature_name}_get_${name}(se::State& s) } SE_BIND_PROP_GET(${signature_name}_get_${name}) -static bool ${signature_name}_set_${name}(se::State& s) +static bool ${signature_name}_set_${name}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) { const auto& args = s.args(); auto* cobj = SE_THIS_OBJECT<${namespaced_class_name}>(s); diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/register.c b/native/tools/bindings-generator/targets/spidermonkey/templates/register.c index c108b44b0a..f578740e95 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/register.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/register.c @@ -20,12 +20,8 @@ ${current_class.methods.constructor.generate_code($current_class)} #end if #end if -#if len($current_class.parents) > 0 -extern se::Object* __jsb_${current_class.parents[0].underlined_class_name}_proto; -#end if - #if not $current_class.is_abstract -static bool js_${current_class.underlined_class_name}_finalize(se::State& s) +static bool js_${current_class.underlined_class_name}_finalize(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) { #if $current_class.rename_destructor is None #if $current_class.is_ref_class @@ -51,7 +47,7 @@ SE_BIND_FINALIZE_FUNC(js_${current_class.underlined_class_name}_finalize) #end if #if $current_class.rename_destructor is not None -static bool js_${current_class.underlined_class_name}_${current_class.rename_destructor}(se::State& s) +static bool js_${current_class.underlined_class_name}_${current_class.rename_destructor}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) { #if $current_class.is_ref_class auto* cobj = SE_THIS_OBJECT<${current_class.namespaced_class_name}>(s); @@ -77,7 +73,7 @@ static bool js_${current_class.underlined_class_name}_${current_class.rename_des SE_BIND_FUNC(js_${current_class.underlined_class_name}_${current_class.rename_destructor}) #end if -bool js_register_${generator.prefix}_${current_class.class_name}(se::Object* obj) +bool js_register_${generator.prefix}_${current_class.class_name}(se::Object* obj) // NOLINT(readability-identifier-naming, google-runtime-references) { #if has_constructor #if len($current_class.parents) > 0 diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/sfunction.c b/native/tools/bindings-generator/targets/spidermonkey/templates/sfunction.c index f0fe0e383e..a3203494df 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/sfunction.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/sfunction.c @@ -1,6 +1,6 @@ ## ===== static function implementation template -static bool ${signature_name}(se::State& s) +static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) { const auto& args = s.args(); size_t argc = args.size(); @@ -63,7 +63,7 @@ static bool ${signature_name}(se::State& s) s.rval() = instanceVal; #else #if $ret_type.is_enum - $ret_type.enum_declare_type result = ($ret_type.enum_declare_type)${namespaced_class_name}::${func_name}($arg_list); + auto result = static_cast<$ret_type.enum_declare_type>(${namespaced_class_name}::${func_name}($arg_list)); #else ${ret_type.get_whole_name($generator)} result = ${namespaced_class_name}::${func_name}($arg_list); #end if diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/sfunction_overloaded.c b/native/tools/bindings-generator/targets/spidermonkey/templates/sfunction_overloaded.c index 11b14b1b6e..e4528d2013 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/sfunction_overloaded.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/sfunction_overloaded.c @@ -1,6 +1,6 @@ ## ===== static function implementation template - for overloaded functions -static bool ${signature_name}(se::State& s) +static bool ${signature_name}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) { CC_UNUSED bool ok = true; const auto& args = s.args(); @@ -45,7 +45,7 @@ static bool ${signature_name}(se::State& s) #set $arg_list = ", ".join($arg_array) #if str($func.ret_type) != "void" #if $func.ret_type.is_enum - $ret_type.enum_declare_type result = ($ret_type.enum_declare_type)${namespaced_class_name}::${func.func_name}($arg_list); + auto result = static_cast<$ret_type.enum_declare_type>(${namespaced_class_name}::${func.func_name}($arg_list)); #else ${func.ret_type.get_whole_name($generator)} result = ${namespaced_class_name}::${func.func_name}($arg_list); #end if diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/struct_constructor.c b/native/tools/bindings-generator/targets/spidermonkey/templates/struct_constructor.c index 0d723decdb..be0a19ab05 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/struct_constructor.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/struct_constructor.c @@ -27,7 +27,7 @@ bool sevalue_to_native(const se::Value &from, ${namespaced_class_name} * to, se: SE_DECLARE_FINALIZE_FUNC(js_${underlined_class_name}_finalize) -static bool ${struct_constructor_name}(se::State& s) +static bool ${struct_constructor_name}(se::State& s) // NOLINT(readability-identifier-naming, google-runtime-references) { CC_UNUSED bool ok = true; const auto& args = s.args(); diff --git a/native/tools/tojs/gfx.ini b/native/tools/tojs/gfx.ini index a447b93a5d..f724c21740 100644 --- a/native/tools/tojs/gfx.ini +++ b/native/tools/tojs/gfx.ini @@ -26,7 +26,7 @@ cxxgenerator_headers = extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s # what headers to parse -headers = %(cocosdir)s/cocos/renderer/gfx-base/GFXBase.h +headers = %(cocosdir)s/cocos/renderer/gfx-base/GFXBase.h %(cocosdir)s/cocos/renderer/GFXDeviceManager.h replace_headers = @@ -34,6 +34,7 @@ replace_headers = # expression, it will be enclosed in "^$", like this: "^Menu.*$". classes = + DeviceManager, # classes GFXObject Context DescriptorSet DescriptorSetLayout Device Buffer CommandBuffer Framebuffer GlobalBarrier InputAssembler, PipelineLayout PipelineState Queue RenderPass Sampler Shader Texture TextureBarrier, @@ -92,7 +93,7 @@ rename_functions = DepthStencilState::[getHash=hash], Queue::[submitForJS=submit], Device::[flushCommandsForJS=flushCommands] -rename_classes = Device::GFXDevice +rename_classes = # for all class names, should we remove something when registering in the target VM? remove_prefix =