接入android项目
This commit is contained in:
parent
3b98db173d
commit
833ae805ba
101
cocos/Android.mk
101
cocos/Android.mk
@ -54,18 +54,12 @@ network/CCDownloader.cpp \
|
||||
network/CCDownloader-android.cpp \
|
||||
network/Uri.cpp \
|
||||
network/HttpClient-android.cpp \
|
||||
scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp \
|
||||
scripting/js-bindings/auto/jsb_cocos2dx_extension_auto.cpp \
|
||||
scripting/js-bindings/auto/jsb_cocos2dx_network_auto.cpp \
|
||||
scripting/js-bindings/manual/JavaScriptJavaBridge.cpp \
|
||||
scripting/js-bindings/manual/jsb_opengl_manual.cpp \
|
||||
scripting/js-bindings/manual/jsb_opengl_utils.cpp \
|
||||
scripting/js-bindings/manual/jsb_classtype.cpp \
|
||||
scripting/js-bindings/manual/jsb_conversions.cpp \
|
||||
scripting/js-bindings/manual/jsb_cocos2dx_manual.cpp \
|
||||
scripting/js-bindings/manual/jsb_global.cpp \
|
||||
scripting/js-bindings/manual/jsb_xmlhttprequest.cpp \
|
||||
scripting/js-bindings/manual/jsb_cocos2dx_network_manual.cpp \
|
||||
scripting/js-bindings/manual/jsb_platform_android.cpp \
|
||||
scripting/js-bindings/jswrapper/config.cpp \
|
||||
scripting/js-bindings/jswrapper/HandleObject.cpp \
|
||||
@ -87,14 +81,7 @@ scripting/js-bindings/event/EventDispatcher.cpp \
|
||||
../external/sources/ConvertUTF/ConvertUTFWrapper.cpp \
|
||||
../external/sources/ConvertUTF/ConvertUTF.c \
|
||||
../external/sources/edtaa3func/edtaa3func.cpp \
|
||||
../external/sources/edtaa3func/edtaa3func.h \
|
||||
ui/edit-box/EditBox-android.cpp \
|
||||
2d/CCFontAtlas.cpp \
|
||||
2d/CCFontFreetype.cpp \
|
||||
2d/CCLabelLayout.cpp \
|
||||
2d/CCTTFLabelAtlasCache.cpp \
|
||||
2d/CCTTFLabelRenderer.cpp \
|
||||
2d/CCTTFTypes.cpp
|
||||
../external/sources/edtaa3func/edtaa3func.h
|
||||
|
||||
# v8 debugger source files, always enable it
|
||||
LOCAL_SRC_FILES += \
|
||||
@ -113,87 +100,8 @@ LOCAL_STATIC_LIBRARIES += uv_static
|
||||
LOCAL_STATIC_LIBRARIES += v8_inspector
|
||||
LOCAL_STATIC_LIBRARIES += cocos_extension_static
|
||||
|
||||
# opengl bindings depend on GFXUtils "_JSB_GL_CHECK"
|
||||
LOCAL_SRC_FILES += \
|
||||
renderer/gfx/GFXUtils.cpp
|
||||
|
||||
ifeq ($(USE_GFX_RENDERER),1)
|
||||
LOCAL_SRC_FILES += \
|
||||
renderer/Types.cpp \
|
||||
renderer/gfx/DeviceGraphics.cpp \
|
||||
renderer/gfx/FrameBuffer.cpp \
|
||||
renderer/gfx/GFX.cpp \
|
||||
renderer/gfx/GraphicsHandle.cpp \
|
||||
renderer/gfx/IndexBuffer.cpp \
|
||||
renderer/gfx/Program.cpp \
|
||||
renderer/gfx/RenderBuffer.cpp \
|
||||
renderer/gfx/RenderTarget.cpp \
|
||||
renderer/gfx/State.cpp \
|
||||
renderer/gfx/Texture.cpp \
|
||||
renderer/gfx/Texture2D.cpp \
|
||||
renderer/gfx/VertexBuffer.cpp \
|
||||
renderer/gfx/VertexFormat.cpp \
|
||||
renderer/renderer/BaseRenderer.cpp \
|
||||
renderer/renderer/Camera.cpp \
|
||||
renderer/renderer/Config.cpp \
|
||||
renderer/renderer/Effect.cpp \
|
||||
renderer/renderer/InputAssembler.cpp \
|
||||
renderer/renderer/Light.cpp \
|
||||
renderer/renderer/Model.cpp \
|
||||
renderer/renderer/Pass.cpp \
|
||||
renderer/renderer/ProgramLib.cpp \
|
||||
renderer/renderer/Scene.cpp \
|
||||
renderer/renderer/Technique.cpp \
|
||||
renderer/renderer/View.cpp \
|
||||
renderer/renderer/ForwardRenderer.cpp \
|
||||
renderer/scene/assembler/Assembler.cpp \
|
||||
renderer/scene/assembler/AssemblerBase.cpp \
|
||||
renderer/scene/assembler/CustomAssembler.cpp \
|
||||
renderer/scene/assembler/MaskAssembler.cpp \
|
||||
renderer/scene/assembler/RenderData.cpp \
|
||||
renderer/scene/assembler/RenderDataList.cpp \
|
||||
renderer/scene/assembler/TiledMapAssembler.cpp \
|
||||
renderer/scene/assembler/AssemblerSprite.cpp \
|
||||
renderer/scene/assembler/SimpleSprite2D.cpp \
|
||||
renderer/scene/assembler/SlicedSprite2D.cpp \
|
||||
renderer/scene/assembler/SimpleSprite3D.cpp \
|
||||
renderer/scene/assembler/SlicedSprite3D.cpp \
|
||||
renderer/scene/assembler/MeshAssembler.cpp \
|
||||
renderer/scene/assembler/Particle3DAssembler.cpp \
|
||||
renderer/scene/MeshBuffer.cpp \
|
||||
renderer/scene/ModelBatcher.cpp \
|
||||
renderer/scene/NodeProxy.cpp \
|
||||
renderer/scene/RenderFlow.cpp \
|
||||
renderer/scene/StencilManager.cpp \
|
||||
renderer/scene/MemPool.cpp \
|
||||
renderer/scene/NodeMemPool.cpp \
|
||||
renderer/scene/ParallelTask.cpp \
|
||||
renderer/memop/RecyclePool.hpp \
|
||||
renderer/renderer/EffectVariant.cpp \
|
||||
renderer/renderer/EffectBase.cpp \
|
||||
scripting/js-bindings/auto/jsb_gfx_auto.cpp \
|
||||
scripting/js-bindings/auto/jsb_renderer_auto.cpp \
|
||||
scripting/js-bindings/manual/jsb_renderer_manual.cpp \
|
||||
scripting/js-bindings/manual/jsb_gfx_manual.cpp
|
||||
endif # USE_GFX_RENDERER
|
||||
|
||||
ifeq ($(USE_VIDEO),1)
|
||||
LOCAL_SRC_FILES += \
|
||||
ui/videoplayer/VideoPlayer-android.cpp \
|
||||
scripting/js-bindings/auto/jsb_video_auto.cpp
|
||||
endif # USE_VIDEO
|
||||
|
||||
ifeq ($(USE_WEB_VIEW),1)
|
||||
LOCAL_SRC_FILES += \
|
||||
ui/webview/WebViewImpl-android.cpp \
|
||||
scripting/js-bindings/auto/jsb_webview_auto.cpp
|
||||
endif # USE_WEB_VIEW
|
||||
|
||||
ifeq ($(USE_AUDIO),1)
|
||||
LOCAL_SRC_FILES += \
|
||||
scripting/js-bindings/auto/jsb_cocos2dx_audioengine_auto.cpp
|
||||
LOCAL_STATIC_LIBRARIES += audioengine_static
|
||||
endif # USE_AUDIO
|
||||
|
||||
ifeq ($(USE_SOCKET),1)
|
||||
LOCAL_SRC_FILES += \
|
||||
@ -210,20 +118,15 @@ LOCAL_STATIC_LIBRARIES += cocos_crypto_static
|
||||
LOCAL_STATIC_LIBRARIES += uv_static
|
||||
endif # USE_SOCKET
|
||||
|
||||
ifneq ($(USE_MIDDLEWARE),0)
|
||||
LOCAL_STATIC_LIBRARIES += editor_support_static
|
||||
endif # USE_MIDDLEWARE
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
|
||||
$(LOCAL_PATH)/.. \
|
||||
$(LOCAL_PATH)/platform \
|
||||
$(LOCAL_PATH)/editor-support \
|
||||
$(LOCAL_PATH)/../external/android/$(TARGET_ARCH_ABI)/include \
|
||||
$(LOCAL_PATH)/../external/sources \
|
||||
$(LOCAL_PATH)/renderer \
|
||||
$(LOCAL_PATH)/scripting/js-bindings/manual \
|
||||
$(LOCAL_PATH)/scripting/js-bindings/manual/platform/android \
|
||||
$(LOCAL_PATH)/scripting/js-bindings/auto \
|
||||
$(LOCAL_PATH)/renderer/gfx
|
||||
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
|
||||
@ -268,8 +171,6 @@ include $(BUILD_STATIC_LIBRARY)
|
||||
#==============================================================
|
||||
#$(call import-module,.)
|
||||
$(call import-module,android)
|
||||
$(call import-module,editor-support)
|
||||
$(call import-module,platform/android)
|
||||
$(call import-module,audio/android)
|
||||
$(call import-module,extensions)
|
||||
$(call import-module,android/cpufeatures)
|
||||
|
@ -73,28 +73,10 @@ THE SOFTWARE.
|
||||
// platform
|
||||
#include "platform/CCDevice.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "platform/CCImage.h"
|
||||
#include "platform/CCPlatformConfig.h"
|
||||
#include "base/ccMacros.h"
|
||||
#include "platform/CCSAXParser.h"
|
||||
#include "platform/CCCanvasRenderingContext2D.h"
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
#include "platform/ios/CCGL-ios.h"
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
#include "platform/android/CCGL-android.h"
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
#include "platform/win32/CCGL-win32.h"
|
||||
#include "platform/win32/CCStdC-win32.h"
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
#include "platform/mac/CCGL-mac.h"
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_MAC
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -10,7 +10,6 @@ LOCAL_SRC_FILES := \
|
||||
CCDevice-android.cpp \
|
||||
CCFileUtils-android.cpp \
|
||||
CCApplication-android.cpp \
|
||||
CCCanvasRenderingContext2D-android.cpp \
|
||||
jni/JniImp.cpp \
|
||||
jni/JniHelper.cpp \
|
||||
|
||||
|
@ -31,7 +31,6 @@ THE SOFTWARE.
|
||||
#include "platform/android/CCGL-android.h"
|
||||
#include "base/CCScheduler.h"
|
||||
#include "base/CCConfiguration.h"
|
||||
#include "audio/include/AudioEngine.h"
|
||||
#include "scripting/js-bindings/jswrapper/SeApi.h"
|
||||
#include "scripting/js-bindings/event/EventDispatcher.h"
|
||||
|
||||
@ -104,9 +103,6 @@ Application::Application(const std::string& name, int width, int height)
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
#if USE_AUDIO
|
||||
AudioEngine::end();
|
||||
#endif
|
||||
|
||||
EventDispatcher::destroy();
|
||||
se::ScriptEngine::destroyInstance();
|
||||
|
@ -219,17 +219,17 @@ public class Cocos2dxHelper {
|
||||
|
||||
sInited = true;
|
||||
|
||||
int versionCode = 1;
|
||||
try {
|
||||
versionCode = Cocos2dxActivity.getContext().getPackageManager().getPackageInfo(Cocos2dxHelper.getPackageName(), 0).versionCode;
|
||||
} catch (NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Cocos2dxHelper.sOBBFile = APKExpansionSupport.getAPKExpansionZipFile(Cocos2dxActivity.getContext(), versionCode, 0);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// int versionCode = 1;
|
||||
// try {
|
||||
// versionCode = Cocos2dxActivity.getContext().getPackageManager().getPackageInfo(Cocos2dxHelper.getPackageName(), 0).versionCode;
|
||||
// } catch (NameNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// try {
|
||||
// Cocos2dxHelper.sOBBFile = APKExpansionSupport.getAPKExpansionZipFile(Cocos2dxActivity.getContext(), versionCode, 0);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,10 @@ public class Cocos2dxLocalStorage {
|
||||
* @return
|
||||
*/
|
||||
public static boolean init(String dbName, String tableName) {
|
||||
if (Cocos2dxActivity.getContext() != null) {
|
||||
if (CocosJSHelper.getContext() != null) {
|
||||
DATABASE_NAME = dbName;
|
||||
TABLE_NAME = tableName;
|
||||
mDatabaseOpenHelper = new DBOpenHelper(Cocos2dxActivity.getContext());
|
||||
mDatabaseOpenHelper = new DBOpenHelper(CocosJSHelper.getContext());
|
||||
mDatabase = mDatabaseOpenHelper.getWritableDatabase();
|
||||
return true;
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package org.cocos2dx.lib;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class CocosJSHelper {
|
||||
private final static String TAG = "CocosJSHelper";
|
||||
private static Context sContext;
|
||||
// Create JNI Function for this
|
||||
private static native void nativeJSInit(final String resourcePath);
|
||||
|
||||
public static void initJSEnv(Context context) {
|
||||
sContext = context;
|
||||
CocosJSHelper.nativeJSInit("");
|
||||
}
|
||||
|
||||
public static Context getContext() {
|
||||
return sContext;
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@
|
||||
#endif
|
||||
#define JNI_RENDER(FUNC) JNI_METHOD1(ORG_RENDER_CLASS_NAME,FUNC)
|
||||
|
||||
|
||||
#ifndef ORG_ACTIVITY_CLASS_NAME
|
||||
#define ORG_ACTIVITY_CLASS_NAME org_cocos2dx_lib_Cocos2dxActivity
|
||||
#endif
|
||||
@ -461,6 +462,7 @@ extern "C"
|
||||
|
||||
JNIEXPORT void JNICALL JNI_HELPER(nativeSetApkPath)(JNIEnv* env, jobject thiz, jstring apkPath)
|
||||
{
|
||||
LOGD("nativeSetApkPath: %s", apkPath);
|
||||
g_apkPath = JniHelper::jstring2string(apkPath);
|
||||
}
|
||||
|
||||
@ -511,6 +513,16 @@ extern "C"
|
||||
{
|
||||
// cocos_audioengine_focus_change(focusChange);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_CocosJSHelper_nativeJSInit(JNIEnv *env, jclass clazz, jstring resource_path) {
|
||||
g_app = cocos_android_app_init(env, 1, 1);
|
||||
se::ScriptEngine* se = se::ScriptEngine::getInstance();
|
||||
// se->addRegisterCallback(setCanvasCallback);
|
||||
|
||||
EventDispatcher::init();
|
||||
|
||||
g_app->start();
|
||||
}
|
||||
} // end of extern "C"
|
||||
|
||||
void restartJSVM()
|
||||
@ -677,4 +689,3 @@ int getAndroidSDKInt()
|
||||
return g_SDKInt;
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,48 +72,6 @@ private:
|
||||
std::string _currentValue;
|
||||
};
|
||||
|
||||
// cc.PlistParser.getInstance()
|
||||
//static bool js_PlistParser_getInstance(se::State& s)
|
||||
//{
|
||||
// __JSPlistDelegator* delegator = __JSPlistDelegator::getInstance();
|
||||
// SAXParser* parser = delegator->getParser();
|
||||
//
|
||||
// if (parser) {
|
||||
// native_ptr_to_rooted_seval<SAXParser>(parser, __jsb_cocos2d_SAXParser_class, &s.rval());
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
//SE_BIND_FUNC(js_PlistParser_getInstance)
|
||||
|
||||
// cc.PlistParser.getInstance().parse(text)
|
||||
//static bool js_PlistParser_parse(se::State& s)
|
||||
//{
|
||||
// const auto& args = s.args();
|
||||
// size_t argc = args.size();
|
||||
// __JSPlistDelegator* delegator = __JSPlistDelegator::getInstance();
|
||||
//
|
||||
// bool ok = true;
|
||||
// if (argc == 1) {
|
||||
// std::string arg0;
|
||||
// ok &= seval_to_std_string(args[0], &arg0);
|
||||
// SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
//
|
||||
// std::string parsedStr = delegator->parseText(arg0);
|
||||
// std::replace(parsedStr.begin(), parsedStr.end(), '\n', ' ');
|
||||
//
|
||||
// se::Value strVal;
|
||||
// std_string_to_seval(parsedStr, &strVal);
|
||||
//
|
||||
// se::HandleObject robj(se::Object::createJSONObject(strVal.toString()));
|
||||
// s.rval().setObject(robj);
|
||||
// return true;
|
||||
// }
|
||||
// SE_REPORT_ERROR("js_PlistParser_parse : wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
// return false;
|
||||
//}
|
||||
//SE_BIND_FUNC(js_PlistParser_parse)
|
||||
|
||||
cocos2d::SAXParser* __JSPlistDelegator::getParser() {
|
||||
return &_parser;
|
||||
}
|
||||
@ -200,19 +158,6 @@ void __JSPlistDelegator::textHandler(void*, const char *ch, int len) {
|
||||
}
|
||||
}
|
||||
|
||||
//static bool register_plist_parser(se::Object* obj)
|
||||
//{
|
||||
// se::Value v;
|
||||
// __jsbObj->getProperty("PlistParser", &v);
|
||||
// assert(v.isObject());
|
||||
// v.toObject()->defineFunction("getInstance", _SE(js_PlistParser_getInstance));
|
||||
//
|
||||
// __jsb_cocos2d_SAXParser_proto->defineFunction("parse", _SE(js_PlistParser_parse));
|
||||
//
|
||||
// se::ScriptEngine::getInstance()->clearException();
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
|
||||
// cc.sys.localStorage
|
||||
|
||||
@ -397,170 +342,15 @@ static bool js_##cls_get_##property(se::State& s) \
|
||||
} \
|
||||
SE_BIND_PROP_GET(js_##cls_get_##property)
|
||||
|
||||
BIND_PROP_WITH_TYPE__CONV_FUNC__RETURN(CanvasRenderingContext2D, _width, float, seval_to_float, setFloat)
|
||||
BIND_PROP_WITH_TYPE__CONV_FUNC__RETURN(CanvasRenderingContext2D, _height, float, seval_to_float, setFloat)
|
||||
BIND_PROP_WITH_TYPE__CONV_FUNC__RETURN(CanvasRenderingContext2D, lineWidth, float, seval_to_float, setFloat)
|
||||
BIND_PROP_WITH_TYPE__CONV_FUNC__RETURN(CanvasRenderingContext2D, lineJoin, std::string, seval_to_std_string, setString)
|
||||
BIND_PROP_WITH_TYPE__CONV_FUNC__RETURN(CanvasRenderingContext2D, lineCap, std::string, seval_to_std_string, setString)
|
||||
BIND_PROP_WITH_TYPE__CONV_FUNC__RETURN(CanvasRenderingContext2D, font, std::string, seval_to_std_string, setString)
|
||||
BIND_PROP_WITH_TYPE__CONV_FUNC__RETURN(CanvasRenderingContext2D, textAlign, std::string, seval_to_std_string, setString)
|
||||
BIND_PROP_WITH_TYPE__CONV_FUNC__RETURN(CanvasRenderingContext2D, textBaseline, std::string, seval_to_std_string, setString)
|
||||
BIND_PROP_WITH_TYPE__CONV_FUNC__RETURN(CanvasRenderingContext2D, fillStyle, std::string, seval_to_std_string, setString)
|
||||
BIND_PROP_WITH_TYPE__CONV_FUNC__RETURN(CanvasRenderingContext2D, strokeStyle, std::string, seval_to_std_string, setString)
|
||||
BIND_PROP_WITH_TYPE__CONV_FUNC__RETURN(CanvasRenderingContext2D, globalCompositeOperation, std::string, seval_to_std_string, setString)
|
||||
|
||||
|
||||
|
||||
#define _SE_DEFINE_PROP(cls, property) \
|
||||
__jsb_cocos2d_##cls##_proto->defineProperty(#property, _SE(js_##cls_get_##property), _SE(js_##cls_set_##property));
|
||||
|
||||
//IDEA: move to auto bindings.
|
||||
static bool js_CanvasRenderingContext2D_setCanvasBufferUpdatedCallback(se::State& s)
|
||||
{
|
||||
cocos2d::CanvasRenderingContext2D* cobj = (cocos2d::CanvasRenderingContext2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_CanvasRenderingContext2D_setCanvasBufferUpdatedCallback : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
std::function<void (const cocos2d::Data &)> arg0;
|
||||
do {
|
||||
if (args[0].isObject() && args[0].toObject()->isFunction())
|
||||
{
|
||||
se::Value jsThis(s.thisObject());
|
||||
se::Value jsFunc(args[0]);
|
||||
jsThis.toObject()->attachObject(jsFunc.toObject());
|
||||
auto lambda = [=](const cocos2d::Data & larg0) -> void {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
se::AutoHandleScope hs;
|
||||
|
||||
CC_UNUSED bool ok = true;
|
||||
se::ValueArray args;
|
||||
args.resize(1);
|
||||
ok &= Data_to_seval(larg0, &args[0]);
|
||||
se::Value rval;
|
||||
se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr;
|
||||
se::Object* funcObj = jsFunc.toObject();
|
||||
bool succeed = funcObj->call(args, thisObj, &rval);
|
||||
if (!succeed) {
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
}
|
||||
};
|
||||
// Add an unroot to avoid the root of the copy constructor caused by the internal reference of Lambda.
|
||||
if (jsThis.isObject())
|
||||
{
|
||||
jsThis.toObject()->unroot();
|
||||
}
|
||||
jsFunc.toObject()->unroot();
|
||||
arg0 = lambda;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg0 = nullptr;
|
||||
}
|
||||
} while(false)
|
||||
;
|
||||
SE_PRECONDITION2(ok, false, "js_CanvasRenderingContext2D_setCanvasBufferUpdatedCallback : Error processing arguments");
|
||||
cobj->setCanvasBufferUpdatedCallback(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_CanvasRenderingContext2D_setCanvasBufferUpdatedCallback)
|
||||
|
||||
static bool js_CanvasRenderingContext2D_setPremultiply(se::State& s)
|
||||
{
|
||||
cocos2d::CanvasRenderingContext2D* cobj = (cocos2d::CanvasRenderingContext2D*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_CanvasRenderingContext2D_setPremultiply : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 1) {
|
||||
bool arg0;
|
||||
ok &= seval_to_boolean(args[0], &arg0);
|
||||
SE_PRECONDITION2(ok, false, "js_CanvasRenderingContext2D_setPremultiply : Error processing arguments");
|
||||
cobj->setPremultiply(arg0);
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_CanvasRenderingContext2D_setPremultiply)
|
||||
|
||||
|
||||
//static bool register_device(se::Object* obj)
|
||||
//{
|
||||
// se::Value device;
|
||||
// __jsbObj->getProperty("Device", &device);
|
||||
//
|
||||
// device.toObject()->defineFunction("getDeviceMotionValue", _SE(JSB_getDeviceMotionValue));
|
||||
//
|
||||
// se::ScriptEngine::getInstance()->addBeforeCleanupHook([](){
|
||||
// if (__deviceMotionObject != nullptr)
|
||||
// {
|
||||
// __deviceMotionObject->unroot();
|
||||
// __deviceMotionObject->decRef();
|
||||
// __deviceMotionObject = nullptr;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// se::ScriptEngine::getInstance()->clearException();
|
||||
// return true;
|
||||
//}
|
||||
|
||||
//static bool register_canvas_context2d(se::Object* obj)
|
||||
//{
|
||||
// _SE_DEFINE_PROP(CanvasRenderingContext2D, _width)
|
||||
// _SE_DEFINE_PROP(CanvasRenderingContext2D, _height)
|
||||
// _SE_DEFINE_PROP(CanvasRenderingContext2D, lineWidth)
|
||||
// _SE_DEFINE_PROP(CanvasRenderingContext2D, lineJoin)
|
||||
// _SE_DEFINE_PROP(CanvasRenderingContext2D, lineCap)
|
||||
// _SE_DEFINE_PROP(CanvasRenderingContext2D, font)
|
||||
// _SE_DEFINE_PROP(CanvasRenderingContext2D, textAlign)
|
||||
// _SE_DEFINE_PROP(CanvasRenderingContext2D, textBaseline)
|
||||
// _SE_DEFINE_PROP(CanvasRenderingContext2D, fillStyle)
|
||||
// _SE_DEFINE_PROP(CanvasRenderingContext2D, strokeStyle)
|
||||
// _SE_DEFINE_PROP(CanvasRenderingContext2D, globalCompositeOperation)
|
||||
//
|
||||
// __jsb_cocos2d_CanvasRenderingContext2D_proto->defineFunction("_setCanvasBufferUpdatedCallback", _SE(js_CanvasRenderingContext2D_setCanvasBufferUpdatedCallback));
|
||||
//
|
||||
// __jsb_cocos2d_CanvasRenderingContext2D_proto->defineFunction("_setPremultiply", _SE(js_CanvasRenderingContext2D_setPremultiply));
|
||||
//
|
||||
// se::ScriptEngine::getInstance()->clearException();
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
|
||||
//static bool js_engine_FileUtils_listFilesRecursively(se::State& s)
|
||||
//{
|
||||
// cocos2d::FileUtils* cobj = (cocos2d::FileUtils*)s.nativeThisObject();
|
||||
// SE_PRECONDITION2(cobj, false, "js_engine_FileUtils_listFilesRecursively : Invalid Native Object");
|
||||
// const auto& args = s.args();
|
||||
// size_t argc = args.size();
|
||||
// CC_UNUSED bool ok = true;
|
||||
// if (argc == 2) {
|
||||
// std::string arg0;
|
||||
// std::vector<std::string> arg1;
|
||||
// ok &= seval_to_std_string(args[0], &arg0);
|
||||
// SE_PRECONDITION2(ok, false, "js_engine_FileUtils_listFilesRecursively : Error processing arguments");
|
||||
// cobj->listFilesRecursively(arg0, &arg1);
|
||||
// se::Object *list = args[1].toObject();
|
||||
// SE_PRECONDITION2(args[1].isObject() && list->isArray(), false, "js_engine_FileUtils_listFilesRecursively : 2nd argument should be an Array");
|
||||
// for(int i = 0; i < arg1.size(); i++ ) {
|
||||
// list->setArrayElement(i, se::Value(arg1[i]));
|
||||
// }
|
||||
// list->setProperty("length", se::Value(arg1.size()));
|
||||
// return true;
|
||||
// }
|
||||
// SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
// return false;
|
||||
//}
|
||||
//SE_BIND_FUNC(js_engine_FileUtils_listFilesRecursively)
|
||||
|
||||
//static bool register_filetuils_ext(se::Object* obj) {
|
||||
// __jsb_cocos2d_FileUtils_proto->defineFunction("listFilesRecursively", _SE(js_engine_FileUtils_listFilesRecursively));
|
||||
// return true;
|
||||
//}
|
||||
|
||||
static bool js_se_setExceptionCallback(se::State &s) {
|
||||
|
||||
@ -602,13 +392,6 @@ SE_BIND_FUNC(js_se_setExceptionCallback)
|
||||
ss << "}";} while(false)
|
||||
|
||||
|
||||
//static bool register_labelrenderer_ext(se::Object *obj)
|
||||
//{
|
||||
// __jsb_cocos2d_LabelRenderer_proto->defineFunction("init", _SE(js_engine_LabelRenderer_init));
|
||||
// js_engine_LabelRenderer_export_structs_info(obj);
|
||||
// return true;
|
||||
//}
|
||||
|
||||
static bool register_se_setExceptionCallback(se::Object *obj)
|
||||
{
|
||||
se::Value jsb;
|
||||
@ -623,12 +406,7 @@ static bool register_se_setExceptionCallback(se::Object *obj)
|
||||
|
||||
bool register_all_cocos2dx_manual(se::Object* obj)
|
||||
{
|
||||
//register_plist_parser(obj);
|
||||
register_sys_localStorage(obj);
|
||||
// register_device(obj);
|
||||
// register_canvas_context2d(obj);
|
||||
// register_filetuils_ext(obj);
|
||||
// register_labelrenderer_ext(obj);
|
||||
register_se_setExceptionCallback(obj);
|
||||
return true;
|
||||
}
|
||||
|
@ -32,9 +32,7 @@
|
||||
#include "network/CCDownloader.h"
|
||||
#include "extensions/cocos-ext.h"
|
||||
|
||||
#if USE_SPINE
|
||||
#include "cocos/editor-support/spine/spine.h"
|
||||
#endif
|
||||
|
||||
|
||||
//#include "Box2D/Box2D.h"
|
||||
|
||||
@ -560,93 +558,7 @@ bool Vector_to_seval(const cocos2d::Vector<T*>& v, se::Value* ret)
|
||||
//}
|
||||
|
||||
// Spine conversions
|
||||
#if USE_SPINE
|
||||
|
||||
template<typename T>
|
||||
bool spine_Vector_T_to_seval(const spine::Vector<T>& v, se::Value* ret)
|
||||
{
|
||||
assert(ret != nullptr);
|
||||
se::HandleObject obj(se::Object::createArrayObject(v.size()));
|
||||
bool ok = true;
|
||||
|
||||
spine::Vector<T> tmpv = v;
|
||||
for (uint32_t i = 0, count = (uint32_t)tmpv.size(); i < count; i++)
|
||||
{
|
||||
if (!obj->setArrayElement(i, se::Value(tmpv[i])))
|
||||
{
|
||||
ok = false;
|
||||
ret->setUndefined();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok)
|
||||
ret->setObject(obj);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool spine_Vector_T_ptr_to_seval(const spine::Vector<T*>& v, se::Value* ret)
|
||||
{
|
||||
assert(ret != nullptr);
|
||||
se::HandleObject obj(se::Object::createArrayObject(v.size()));
|
||||
bool ok = true;
|
||||
|
||||
spine::Vector<T*> tmpv = v;
|
||||
for (uint32_t i = 0, count = (uint32_t)tmpv.size(); i < count; i++)
|
||||
{
|
||||
se::Value tmp;
|
||||
ok = native_ptr_to_rooted_seval<T>(tmpv[i], &tmp);
|
||||
if (!ok || !obj->setArrayElement(i, tmp))
|
||||
{
|
||||
ok = false;
|
||||
ret->setUndefined();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) ret->setObject(obj);
|
||||
return ok;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool seval_to_spine_Vector_T_ptr(const se::Value& v, spine::Vector<T*>* ret)
|
||||
{
|
||||
assert(ret != nullptr);
|
||||
assert(v.isObject());
|
||||
se::Object* obj = v.toObject();
|
||||
assert(obj->isArray());
|
||||
|
||||
bool ok = true;
|
||||
uint32_t len = 0;
|
||||
ok = obj->getArrayLength(&len);
|
||||
if (!ok)
|
||||
{
|
||||
ret->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
se::Value tmp;
|
||||
for (uint32_t i = 0; i < len; ++i)
|
||||
{
|
||||
ok = obj->getArrayElement(i, &tmp);
|
||||
if (!ok || !tmp.isObject())
|
||||
{
|
||||
ret->clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
T* nativeObj = (T*)tmp.toObject()->getPrivateData();
|
||||
ret->add(nativeObj);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool seval_to_spine_Vector_String(const se::Value& v, spine::Vector<spine::String>* ret);
|
||||
bool spine_Vector_String_to_seval(const spine::Vector<spine::String>& v, se::Value* ret);
|
||||
#endif
|
||||
|
||||
//
|
||||
//// Box2d
|
||||
|
@ -708,360 +708,6 @@ static bool js_performance_now(se::State& s)
|
||||
}
|
||||
SE_BIND_FUNC(js_performance_now)
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ImageInfo
|
||||
{
|
||||
~ImageInfo()
|
||||
{
|
||||
if (freeData)
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
uint32_t length = 0;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
uint8_t* data = nullptr;
|
||||
GLenum glFormat = GL_RGBA;
|
||||
GLenum glInternalFormat = GL_RGBA;
|
||||
GLenum type = GL_UNSIGNED_BYTE;
|
||||
uint8_t bpp = 0;
|
||||
uint8_t numberOfMipmaps = 0;
|
||||
bool hasAlpha = false;
|
||||
bool hasPremultipliedAlpha = false;
|
||||
bool compressed = false;
|
||||
|
||||
bool freeData = false;
|
||||
};
|
||||
|
||||
uint8_t* convertRGB2RGBA (uint32_t length, uint8_t* src) {
|
||||
uint8_t* dst = new uint8_t[length];
|
||||
for (uint32_t i = 0; i < length; i += 4) {
|
||||
dst[i] = *src++;
|
||||
dst[i + 1] = *src++;
|
||||
dst[i + 2] = *src++;
|
||||
dst[i + 3] = 255;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
uint8_t* convertIA2RGBA (uint32_t length, uint8_t* src) {
|
||||
uint8_t* dst = new uint8_t[length];
|
||||
for (uint32_t i = 0; i < length; i += 4) {
|
||||
dst[i] = *src;
|
||||
dst[i + 1] = *src;
|
||||
dst[i + 2] = *src++;
|
||||
dst[i + 3] = *src++;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
uint8_t* convertI2RGBA (uint32_t length, uint8_t* src) {
|
||||
uint8_t* dst = new uint8_t[length];
|
||||
for (uint32_t i = 0; i < length; i += 4) {
|
||||
dst[i] = *src;
|
||||
dst[i + 1] = *src;
|
||||
dst[i + 2] = *src++;
|
||||
dst[i + 3] = 255;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
struct ImageInfo* createImageInfo(const Image* img)
|
||||
{
|
||||
struct ImageInfo* imgInfo = new struct ImageInfo();
|
||||
imgInfo->length = (uint32_t)img->getDataLen();
|
||||
imgInfo->width = img->getWidth();
|
||||
imgInfo->height = img->getHeight();
|
||||
imgInfo->data = img->getData();
|
||||
|
||||
const auto& pixelFormatInfo = img->getPixelFormatInfo();
|
||||
imgInfo->glFormat = pixelFormatInfo.format;
|
||||
imgInfo->glInternalFormat = pixelFormatInfo.internalFormat;
|
||||
imgInfo->type = pixelFormatInfo.type;
|
||||
|
||||
imgInfo->bpp = img->getBitPerPixel();
|
||||
imgInfo->numberOfMipmaps = img->getNumberOfMipmaps();
|
||||
imgInfo->hasAlpha = img->hasAlpha();
|
||||
imgInfo->hasPremultipliedAlpha = img->hasPremultipliedAlpha();
|
||||
imgInfo->compressed = img->isCompressed();
|
||||
|
||||
// Convert to RGBA888 because standard web api will return only RGBA888.
|
||||
// If not, then it may have issue in glTexSubImage. For example, engine
|
||||
// will create a big texture, and update its content with small pictures.
|
||||
// The big texture is RGBA888, then the small picture should be the same
|
||||
// format, or it will cause 0x502 error on OpenGL ES 2.
|
||||
if (!imgInfo->compressed && imgInfo->glFormat != GL_RGBA) {
|
||||
imgInfo->length = img->getWidth() * img->getHeight() * 4;
|
||||
uint8_t* dst = nullptr;
|
||||
uint32_t length = imgInfo->length;
|
||||
uint8_t* src = imgInfo->data;
|
||||
switch(imgInfo->glFormat) {
|
||||
case GL_LUMINANCE_ALPHA:
|
||||
dst = convertIA2RGBA(length, src);
|
||||
break;
|
||||
case GL_ALPHA:
|
||||
case GL_LUMINANCE:
|
||||
dst = convertI2RGBA(length, src);
|
||||
break;
|
||||
case GL_RGB:
|
||||
dst = convertRGB2RGBA(length, src);
|
||||
break;
|
||||
default:
|
||||
SE_LOGE("unknown image format");
|
||||
break;
|
||||
}
|
||||
|
||||
imgInfo->data = dst;
|
||||
imgInfo->hasAlpha = true;
|
||||
imgInfo->bpp = 32;
|
||||
imgInfo->glFormat = GL_RGBA;
|
||||
imgInfo->glInternalFormat = GL_RGBA;
|
||||
imgInfo->freeData = true;
|
||||
}
|
||||
|
||||
return imgInfo;
|
||||
}
|
||||
}
|
||||
bool jsb_global_load_image(const std::string& path, const se::Value& callbackVal) {
|
||||
if (path.empty())
|
||||
{
|
||||
se::ValueArray seArgs;
|
||||
callbackVal.toObject()->call(seArgs, nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<se::Value> callbackPtr = std::make_shared<se::Value>(callbackVal);
|
||||
|
||||
auto initImageFunc = [path, callbackPtr](const std::string& fullPath, unsigned char* imageData, int imageBytes, const std::string& errorMsg){
|
||||
std::shared_ptr<uint8_t> imageDataGuard(imageData, free);
|
||||
|
||||
auto pool = g_threadPool;
|
||||
if (!pool)
|
||||
return;
|
||||
pool->pushTask([=](int tid) mutable {
|
||||
// NOTE: FileUtils::getInstance()->fullPathForFilename isn't a threadsafe method,
|
||||
// Image::initWithImageFile will call fullPathForFilename internally which may
|
||||
// cause thread race issues. Therefore, we get the full path of file before
|
||||
// going into task callback.
|
||||
// Be careful of invoking any Cocos2d-x interface in a sub-thread.
|
||||
bool loadSucceed = false;
|
||||
std::shared_ptr<Image> img(new Image(), [](Image *image) {
|
||||
image->release();
|
||||
});
|
||||
|
||||
if (!errorMsg.empty()) {
|
||||
loadSucceed = false;
|
||||
}
|
||||
else if (fullPath.empty())
|
||||
{
|
||||
loadSucceed = img->initWithImageData(imageDataGuard.get(), imageBytes);
|
||||
imageDataGuard = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
loadSucceed = img->initWithImageFile(fullPath);
|
||||
}
|
||||
|
||||
std::shared_ptr<ImageInfo> imgInfo;
|
||||
if(loadSucceed)
|
||||
{
|
||||
imgInfo.reset(createImageInfo(img.get()));
|
||||
}
|
||||
|
||||
Application::getInstance()->getScheduler()->performFunctionInCocosThread([=]() mutable {
|
||||
se::AutoHandleScope hs;
|
||||
se::ValueArray seArgs;
|
||||
se::Value dataVal;
|
||||
|
||||
if (loadSucceed)
|
||||
{
|
||||
se::HandleObject retObj(se::Object::createPlainObject());
|
||||
Data data;
|
||||
data.fastSet(imgInfo->data, imgInfo->length);
|
||||
Data_to_seval(data, &dataVal);
|
||||
data.takeBuffer();
|
||||
retObj->setProperty("data", dataVal);
|
||||
retObj->setProperty("width", se::Value(imgInfo->width));
|
||||
retObj->setProperty("height", se::Value(imgInfo->height));
|
||||
retObj->setProperty("premultiplyAlpha", se::Value(imgInfo->hasPremultipliedAlpha));
|
||||
retObj->setProperty("bpp", se::Value(imgInfo->bpp));
|
||||
retObj->setProperty("hasAlpha", se::Value(imgInfo->hasAlpha));
|
||||
retObj->setProperty("compressed", se::Value(imgInfo->compressed));
|
||||
retObj->setProperty("numberOfMipmaps", se::Value(imgInfo->numberOfMipmaps));
|
||||
if (imgInfo->numberOfMipmaps > 0)
|
||||
{
|
||||
se::HandleObject mipmapArray(se::Object::createArrayObject(imgInfo->numberOfMipmaps));
|
||||
retObj->setProperty("mipmaps", se::Value(mipmapArray));
|
||||
auto mipmapInfo = img->getMipmaps();
|
||||
for (int i = 0; i < imgInfo->numberOfMipmaps; ++i)
|
||||
{
|
||||
se::HandleObject info(se::Object::createPlainObject());
|
||||
info->setProperty("offset", se::Value(mipmapInfo[i].offset));
|
||||
info->setProperty("length", se::Value(mipmapInfo[i].len));
|
||||
mipmapArray->setArrayElement(i, se::Value(info));
|
||||
}
|
||||
}
|
||||
|
||||
retObj->setProperty("glFormat", se::Value(imgInfo->glFormat));
|
||||
retObj->setProperty("glInternalFormat", se::Value(imgInfo->glInternalFormat));
|
||||
retObj->setProperty("glType", se::Value(imgInfo->type));
|
||||
|
||||
seArgs.push_back(se::Value(retObj));
|
||||
|
||||
imgInfo = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
SE_REPORT_ERROR("initWithImageFile: %s failed!", path.c_str());
|
||||
}
|
||||
|
||||
if (!errorMsg.empty()) {
|
||||
se::HandleObject retObj(se::Object::createPlainObject());
|
||||
retObj->setProperty("errorMsg", se::Value(errorMsg));
|
||||
seArgs.push_back(se::Value(retObj));
|
||||
}
|
||||
|
||||
callbackPtr->toObject()->call(seArgs, nullptr);
|
||||
img = nullptr;
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
size_t pos = std::string::npos;
|
||||
if (path.find("http://") == 0 || path.find("https://") == 0)
|
||||
{
|
||||
localDownloaderCreateTask(path, initImageFunc);
|
||||
|
||||
}
|
||||
else if (path.find("data:") == 0 && (pos = path.find("base64,")) != std::string::npos)
|
||||
{
|
||||
int imageBytes = 0;
|
||||
unsigned char* imageData = nullptr;
|
||||
size_t dataStartPos = pos + strlen("base64,");
|
||||
const char* base64Data = path.data() + dataStartPos;
|
||||
size_t dataLen = path.length() - dataStartPos;
|
||||
imageBytes = base64Decode((const unsigned char *)base64Data, (unsigned int)dataLen, &imageData);
|
||||
if (imageBytes <= 0 || imageData == nullptr)
|
||||
{
|
||||
SE_REPORT_ERROR("Decode base64 image data failed!");
|
||||
return false;
|
||||
}
|
||||
initImageFunc("", imageData, imageBytes, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string fullPath(FileUtils::getInstance()->fullPathForFilename(path));
|
||||
if (0 == path.find("file://"))
|
||||
fullPath = FileUtils::getInstance()->fullPathForFilename(path.substr(strlen("file://")));
|
||||
|
||||
if (fullPath.empty())
|
||||
{
|
||||
SE_REPORT_ERROR("File (%s) doesn't exist!", path.c_str());
|
||||
return false;
|
||||
}
|
||||
initImageFunc(fullPath, nullptr, 0, "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool js_loadImage(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 2) {
|
||||
std::string path;
|
||||
ok &= seval_to_std_string(args[0], &path);
|
||||
SE_PRECONDITION2(ok, false, "js_loadImage : Error processing arguments");
|
||||
|
||||
se::Value callbackVal = args[1];
|
||||
assert(callbackVal.isObject());
|
||||
assert(callbackVal.toObject()->isFunction());
|
||||
|
||||
return jsb_global_load_image(path, callbackVal);
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_loadImage)
|
||||
|
||||
//pixels(RGBA), width, height, fullFilePath(*.png/*.jpg)
|
||||
static bool js_saveImageData(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 4) {
|
||||
cocos2d::Data data;
|
||||
ok &= seval_to_Data(args[0], &data);
|
||||
|
||||
uint32_t width, height;
|
||||
ok &= seval_to_uint32(args[1], &width);
|
||||
ok &= seval_to_uint32(args[2], &height);
|
||||
|
||||
std::string filePath;
|
||||
ok &= seval_to_std_string(args[3], &filePath);
|
||||
SE_PRECONDITION2(ok, false, "js_saveImageData : Error processing arguments");
|
||||
|
||||
Image* img = new Image();
|
||||
img->initWithRawData(data.getBytes(), data.getSize(), width, height, 8);
|
||||
// isToRGB = false, to keep alpha channel
|
||||
bool ret = img->saveToFile(filePath, false);
|
||||
s.rval().setBoolean(ret);
|
||||
|
||||
img->release();
|
||||
return ret;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_saveImageData)
|
||||
|
||||
static bool js_setDebugViewText(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 2) {
|
||||
int32_t index;
|
||||
ok = seval_to_int32(args[0], &index);
|
||||
SE_PRECONDITION2(ok, false, "Convert arg0 index failed!");
|
||||
|
||||
std::string text;
|
||||
ok = seval_to_std_string(args[1], &text);
|
||||
SE_PRECONDITION2(ok, false, "Convert arg1 text failed!");
|
||||
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
setGameInfoDebugViewTextJNI(index, text);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(js_setDebugViewText)
|
||||
|
||||
static bool js_openDebugView(se::State& s)
|
||||
{
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
openDebugViewJNI();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_openDebugView)
|
||||
|
||||
static bool js_disableBatchGLCommandsToNative(se::State& s)
|
||||
{
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
disableBatchGLCommandsToNativeJNI();
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_disableBatchGLCommandsToNative)
|
||||
|
||||
static bool JSB_openURL(se::State& s)
|
||||
{
|
||||
@ -1137,11 +783,6 @@ bool jsb_register_global_variables(se::Object* global)
|
||||
__jsbObj->defineFunction("garbageCollect", _SE(jsc_garbageCollect));
|
||||
__jsbObj->defineFunction("dumpNativePtrToSeObjectMap", _SE(jsc_dumpNativePtrToSeObjectMap));
|
||||
|
||||
__jsbObj->defineFunction("loadImage", _SE(js_loadImage));
|
||||
__jsbObj->defineFunction("saveImageData", _SE(js_saveImageData));
|
||||
__jsbObj->defineFunction("setDebugViewText", _SE(js_setDebugViewText));
|
||||
__jsbObj->defineFunction("openDebugView", _SE(js_openDebugView));
|
||||
__jsbObj->defineFunction("disableBatchGLCommandsToNative", _SE(js_disableBatchGLCommandsToNative));
|
||||
__jsbObj->defineFunction("openURL", _SE(JSB_openURL));
|
||||
__jsbObj->defineFunction("copyTextToClipboard", _SE(JSB_copyTextToClipboard));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user