mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Merge branch 'v3.4.2' into v3.5.0_merge_v3.4.2
Conflicts: cocos/platform/android/jni/JniCocosActivity.cpp cocos/platform/apple/JsbBridgeWrapper.mm cocos/platform/ohos/jni/JniCocosAbility.cpp cocos/renderer/gfx-metal/MTLCommandBuffer.mm external/config.json
This commit is contained in:
@@ -24,9 +24,9 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "cocos/bindings/manual/JavaScriptJavaBridge.h"
|
||||
#include "cocos/application/ApplicationManager.h"
|
||||
#include "cocos/base/UTF8.h"
|
||||
#include "cocos/bindings/manual/jsb_conversions.h"
|
||||
#include "cocos/application/ApplicationManager.h"
|
||||
|
||||
#if CC_PLATFORM == CC_PLATFORM_ANDROID
|
||||
#include <android/log.h>
|
||||
@@ -44,7 +44,7 @@
|
||||
#ifndef ORG_JAVABRIDGE_CLASS_NAME
|
||||
#define ORG_JAVABRIDGE_CLASS_NAME com_cocos_lib_CocosJavascriptJavaBridge
|
||||
#endif
|
||||
#define JNI_JSJAVABRIDGE(FUNC) JNI_METHOD1(ORG_JAVABRIDGE_CLASS_NAME, FUNC)
|
||||
#define JNI_JSJAVABRIDGE(FUNC) JNI_METHOD1(ORG_JAVABRIDGE_CLASS_NAME, FUNC)
|
||||
#define JSJ_ERR_OK (0)
|
||||
#define JSJ_ERR_TYPE_NOT_SUPPORT (-1)
|
||||
#define JSJ_ERR_INVALID_SIGNATURES (-2)
|
||||
@@ -81,10 +81,9 @@ public:
|
||||
class CallInfo {
|
||||
public:
|
||||
CallInfo(const char *className, const char *methodName, const char *methodSig)
|
||||
: _mClassName(className),
|
||||
_mMethodName(methodName),
|
||||
_mMethodSig(methodSig)
|
||||
{
|
||||
: _mClassName(className),
|
||||
_mMethodName(methodName),
|
||||
_mMethodSig(methodSig) {
|
||||
memset(&_mRet, 0, sizeof(_mRet));
|
||||
_mValid = validateMethodSig() && getMethodInfo();
|
||||
}
|
||||
@@ -126,7 +125,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
JNIEnv *getEnv() const{
|
||||
JNIEnv *getEnv() const {
|
||||
return _mEnv;
|
||||
}
|
||||
|
||||
@@ -173,17 +172,17 @@ public:
|
||||
};
|
||||
|
||||
static bool convertReturnValue(ReturnValue retValue, ValueType type, se::Value *ret);
|
||||
|
||||
};
|
||||
using JsCallback = std::function<void(const std::string&, const std::string&)>;
|
||||
class ScriptNativeBridge{
|
||||
using JsCallback = std::function<void(const std::string &, const std::string &)>;
|
||||
class ScriptNativeBridge {
|
||||
public:
|
||||
void callByNative(const std::string& arg0, const std::string& arg1);
|
||||
inline void setCallback(const JsCallback& cb){
|
||||
void callByNative(const std::string &arg0, const std::string &arg1);
|
||||
inline void setCallback(const JsCallback &cb) {
|
||||
_callback = cb;
|
||||
}
|
||||
static ScriptNativeBridge* bridgeCxxInstance;
|
||||
se::Value jsCb;
|
||||
static ScriptNativeBridge *bridgeCxxInstance;
|
||||
se::Value jsCb;
|
||||
|
||||
private:
|
||||
JsCallback _callback{nullptr}; // NOLINT(readability-identifier-naming)
|
||||
};
|
||||
@@ -216,10 +215,12 @@ Java_com_cocos_lib_JsbBridge_nativeSendToScript(JNIEnv *env, jclass clazz, jstri
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
ScriptNativeBridge* ScriptNativeBridge::bridgeCxxInstance{nullptr};
|
||||
ScriptNativeBridge *ScriptNativeBridge::bridgeCxxInstance{nullptr};
|
||||
|
||||
JavaScriptJavaBridge::CallInfo::~CallInfo() {
|
||||
_mEnv->DeleteLocalRef(_mClassID);
|
||||
if (_mReturnType == ValueType::STRING && _mRet.stringValue) {
|
||||
_mEnv->DeleteLocalRef(_mRetjstring);
|
||||
delete _mRet.stringValue;
|
||||
}
|
||||
}
|
||||
@@ -612,8 +613,7 @@ static bool JavaScriptJavaBridge_callStaticMethod(se::State &s) { //NOLINT(reada
|
||||
}
|
||||
SE_BIND_FUNC(JavaScriptJavaBridge_callStaticMethod)
|
||||
|
||||
|
||||
static bool ScriptNativeBridge_getCallback(se::State &s){ //NOLINT(readability-identifier-naming)
|
||||
static bool ScriptNativeBridge_getCallback(se::State &s) { //NOLINT(readability-identifier-naming)
|
||||
auto *cobj = static_cast<ScriptNativeBridge *>(s.nativeThisObject());
|
||||
assert(cobj == ScriptNativeBridge::bridgeCxxInstance);
|
||||
s.rval() = cobj->jsCb;
|
||||
@@ -622,31 +622,30 @@ static bool ScriptNativeBridge_getCallback(se::State &s){ //NOLINT(readability-i
|
||||
}
|
||||
SE_BIND_PROP_GET(ScriptNativeBridge_getCallback)
|
||||
|
||||
static bool ScriptNativeBridge_setCallback(se::State &s){ //NOLINT(readability-identifier-naming)
|
||||
static bool ScriptNativeBridge_setCallback(se::State &s) { //NOLINT(readability-identifier-naming)
|
||||
auto *cobj = static_cast<ScriptNativeBridge *>(s.nativeThisObject());
|
||||
assert(cobj == ScriptNativeBridge::bridgeCxxInstance);
|
||||
const auto &args = s.args();
|
||||
se::Value jsFunc = args[0];
|
||||
cobj->jsCb = jsFunc;
|
||||
if(jsFunc.isNullOrUndefined())
|
||||
{
|
||||
const auto &args = s.args();
|
||||
se::Value jsFunc = args[0];
|
||||
cobj->jsCb = jsFunc;
|
||||
if (jsFunc.isNullOrUndefined()) {
|
||||
cobj->setCallback(nullptr);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
assert(jsFunc.isObject() && jsFunc.toObject()->isFunction());
|
||||
s.thisObject()->attachObject(jsFunc.toObject());
|
||||
cobj->setCallback([jsFunc](const std::string& arg0, const std::string& arg1){
|
||||
cobj->setCallback([jsFunc](const std::string &arg0, const std::string &arg1) {
|
||||
se::AutoHandleScope hs;
|
||||
se::ValueArray args;
|
||||
se::ValueArray args;
|
||||
args.push_back(se::Value(arg0));
|
||||
if(!arg1.empty()) {
|
||||
if (!arg1.empty()) {
|
||||
args.push_back(se::Value(arg1));
|
||||
}
|
||||
jsFunc.toObject()->call(args, nullptr);
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}SE_BIND_PROP_SET(ScriptNativeBridge_setCallback)
|
||||
}
|
||||
SE_BIND_PROP_SET(ScriptNativeBridge_setCallback)
|
||||
|
||||
static bool ScriptNativeBridge_sendToNative(se::State &s) { //NOLINT(readability-identifier-naming)
|
||||
const auto &args = s.args();
|
||||
@@ -716,12 +715,10 @@ bool register_script_native_bridge(se::Object *obj) { //NOLINT(readability-ident
|
||||
return true;
|
||||
}
|
||||
void callPlatformStringMethod(const std::string &arg0, const std::string &arg1) {
|
||||
cc::JniHelper::callStaticVoidMethod(
|
||||
"com/cocos/lib/JsbBridge", "callByScript", arg0, arg1);
|
||||
cc::JniHelper::callStaticVoidMethod(
|
||||
"com/cocos/lib/JsbBridge", "callByScript", arg0, arg1);
|
||||
}
|
||||
|
||||
void ScriptNativeBridge::callByNative(const std::string& arg0, const std::string& arg1){
|
||||
void ScriptNativeBridge::callByNative(const std::string &arg0, const std::string &arg1) {
|
||||
_callback(arg0, arg1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user