Refactor Openharmony platform code to support switching between napi (ark js runtime) and v8 (#16093)

* OH could use v8 now.

* napi addon works.

* Use Napi addon to refactor code.

* Fix compilation errors.

* tweak

* Refactor oh platform, remove some hacking for oh.

* Fix log in runScript.

* Fix the issues in napi mode.

* Revert.

* Remove an unused comment.

* Refactor log output in NapiHelper.cpp and OpenHarmonyPlatform.cpp

* Update oh template.

* Remove unused code.

* Remove unused debug log in jsb-gfx.js

* Update include

* Revert Screen::isDisplayStats.

* update OH template for v8 backend

* update

* Update CMakeLists.txt for OH

* Fix a compilation error in NapiHelper.cpp while switching to NAPI mode

* Keep the symbol of entry function.

* Add -Wl,--gc-sections and add -Wl,-s for release mode.

* Update external to 3.8.2-1

* Don't use `console.assert` directly.

* Remove oh specific methods ( getInnerWidth/Height, getWindowHandle ) in Device class.

---------

Co-authored-by: PP_Pro <chinese1236@qq.com>
This commit is contained in:
James Chen
2023-09-01 16:27:08 +08:00
committed by GitHub
parent 772bfcea22
commit d2c3429f95
38 changed files with 10482 additions and 605 deletions
@@ -22,24 +22,15 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include <ace/xcomponent/native_interface_xcomponent.h>
#include "bindings/jswrapper/SeApi.h"
#include "platform/openharmony/napi/NapiHelper.h"
const char kLibname[] = "cocos";
static const char kLibname[] = "cocos";
/*
* function for module exports
*/
static napi_value init(napi_env env, napi_value exports) {
napi_property_descriptor desc[] = {
DECLARE_NAPI_FUNCTION("getContext", cc::NapiHelper::getContext),
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
bool ret = cc::NapiHelper::exportFunctions(env, exports);
if (!ret) {
LOGE("Init failed");
}
cc::NapiHelper::init(Napi::Env(env), Napi::Object(env, exports));
return exports;
}
@@ -58,6 +49,6 @@ static napi_module cocos2dModule = {
/*
* Module register function
*/
extern "C" __attribute__((constructor)) void RegisterModule(void) {
extern "C" __attribute__((visibility ("default"))) __attribute__((constructor)) void RegisterModule(void) {
napi_module_register(&cocos2dModule);
}