Skip to content

Commit b4ff55d

Browse files
xianyinchenhuangwei1024
authored andcommitted
add optimization for OPPO. (cocos2d#19631)
1 parent 515c666 commit b4ff55d

File tree

23 files changed

+246
-1
lines changed

23 files changed

+246
-1
lines changed

Diff for: cocos/2d/CCScene.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ THE SOFTWARE.
3434
#include "base/ccUTF8.h"
3535
#include "renderer/CCRenderer.h"
3636
#include "renderer/CCFrameBuffer.h"
37+
#include "platform/CCDataManager.h"
3738

3839
#if CC_USE_PHYSICS
3940
#include "physics/CCPhysicsWorld.h"
@@ -76,6 +77,19 @@ Scene::Scene()
7677
_event->retain();
7778

7879
Camera::_visitingCamera = nullptr;
80+
81+
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
82+
DataManager::onSceneLoaderBegin();
83+
#endif
84+
}
85+
86+
void Scene::onEnter()
87+
{
88+
Node::onEnter();
89+
90+
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
91+
DataManager::onSceneLoaderEnd();
92+
#endif
7993
}
8094

8195
Scene::~Scene()

Diff for: cocos/2d/CCScene.h

+9
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ class CC_DLL Scene : public Node
126126
/** override function */
127127
virtual void removeAllChildren() override;
128128

129+
/**
130+
* Event callback that is invoked every time when Node enters the 'stage'.
131+
* If the Node enters the 'stage' with a transition, this event is called when the transition starts.
132+
* During onEnter you can't access a "sister/brother" node.
133+
* If you override onEnter, you shall call its parent's one, e.g., Node::onEnter().
134+
* @lua NA
135+
*/
136+
virtual void onEnter() override;
137+
129138
CC_CONSTRUCTOR_ACCESS:
130139
Scene();
131140
virtual ~Scene();

Diff for: cocos/Android.mk

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ cocos2d.cpp \
8989
2d/CCAutoPolygon.cpp \
9090
3d/CCFrustum.cpp \
9191
3d/CCPlane.cpp \
92+
platform/CCDataManager.cpp \
9293
platform/CCFileUtils.cpp \
9394
platform/CCGLView.cpp \
9495
platform/CCImage.cpp \

Diff for: cocos/platform/CCDataManager.cpp

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/****************************************************************************
2+
Copyright (c) 2010-2012 cocos2d-x.org
3+
Copyright (c) 2013-2016 Chukong Technologies Inc.
4+
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
5+
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.
6+
7+
http://www.cocos2d-x.org
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in
17+
all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
****************************************************************************/
27+
28+
#include "platform/CCDataManager.h"
29+
30+
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
31+
# include "platform/android/jni/JniHelper.h"
32+
# define DataManagerClassName "org/cocos2dx/lib/Cocos2dxDataManager"
33+
#endif
34+
35+
NS_CC_BEGIN
36+
37+
void DataManager::setProcessID(int pid){
38+
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
39+
JniHelper::callStaticVoidMethod(DataManagerClassName, "setProcessID", pid);
40+
#endif
41+
}
42+
void DataManager::setFrameSize(int width, int height){
43+
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
44+
JniHelper::callStaticVoidMethod(DataManagerClassName, "setFrameSize", width, height);
45+
#endif
46+
}
47+
void DataManager::onSceneLoaderBegin(){
48+
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
49+
JniHelper::callStaticVoidMethod(DataManagerClassName, "onSceneLoaderBegin");
50+
#endif
51+
}
52+
void DataManager::onSceneLoaderEnd(){
53+
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
54+
JniHelper::callStaticVoidMethod(DataManagerClassName, "onSceneLoaderEnd");
55+
#endif
56+
}
57+
void DataManager::onShaderLoaderBegin(){
58+
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
59+
JniHelper::callStaticVoidMethod(DataManagerClassName, "onShaderLoaderBegin");
60+
#endif
61+
}
62+
void DataManager::onShaderLoaderEnd(){
63+
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
64+
JniHelper::callStaticVoidMethod(DataManagerClassName, "onShaderLoaderEnd");
65+
#endif
66+
}
67+
68+
NS_CC_END

Diff for: cocos/platform/CCDataManager.h

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/****************************************************************************
2+
Copyright (c) 2010-2012 cocos2d-x.org
3+
Copyright (c) 2013-2016 Chukong Technologies Inc.
4+
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
5+
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.
6+
7+
http://www.cocos2d-x.org
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in
17+
all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
****************************************************************************/
27+
28+
#ifndef __CC_DataManager_H__
29+
#define __CC_DataManager_H__
30+
31+
#include "platform/CCPlatformMacros.h"
32+
#include "base/ccTypes.h"
33+
34+
NS_CC_BEGIN
35+
36+
/**
37+
* @addtogroup platform
38+
* @{
39+
*/
40+
41+
class CC_DLL DataManager
42+
{
43+
public:
44+
static void setProcessID(int pid);
45+
static void setFrameSize(int width, int height);
46+
static void onSceneLoaderBegin();
47+
static void onSceneLoaderEnd();
48+
static void onShaderLoaderBegin();
49+
static void onShaderLoaderEnd();
50+
};
51+
52+
// end of platform group
53+
/** @} */
54+
55+
NS_CC_END
56+
57+
#endif // __CC_DataManager_H__

Diff for: cocos/platform/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ set(COCOS_PLATFORM_HEADER
157157

158158
set(COCOS_PLATFORM_SRC
159159
${COCOS_PLATFORM_SPECIFIC_SRC}
160+
platform/CCDataManager.cpp
160161
platform/CCSAXParser.cpp
161162
platform/CCThread.cpp
162163
platform/CCGLView.cpp

Diff for: cocos/platform/android/java/libs/oppoSDK.jar

10.4 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/****************************************************************************
2+
Copyright (c) 2010-2012 cocos2d-x.org
3+
Copyright (c) 2013-2016 Chukong Technologies Inc.
4+
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
5+
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.
6+
7+
http://www.cocos2d-x.org
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in
17+
all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
****************************************************************************/
27+
28+
package org.cocos2dx.lib;
29+
import android.util.Log;
30+
31+
import com.oppo.oiface.engine.OifaceGameEngineManager;
32+
33+
public class Cocos2dxDataManager {
34+
public static void setOptimise(String thing, float value){
35+
String jsonStr = "{\"" + thing + "\":" + String.valueOf(value) + "}";
36+
OifaceGameEngineManager.getInstance().updateGameEngineInfo(jsonStr);
37+
}
38+
39+
public static void setProcessID(int pid){
40+
setOptimise("render_pid", pid);
41+
}
42+
public static void setFrameSize(int width, int height){
43+
setOptimise("buffer_size", width * height);
44+
}
45+
public static void onSceneLoaderBegin(){
46+
setOptimise("load_scene", 1);
47+
}
48+
public static void onSceneLoaderEnd(){
49+
setOptimise("load_scene", 0);
50+
}
51+
public static void onShaderLoaderBegin(){
52+
setOptimise("shader_compile", 1);
53+
}
54+
public static void onShaderLoaderEnd(){
55+
setOptimise("shader_compile", 0);
56+
}
57+
}

Diff for: cocos/platform/android/javaactivity-android.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ THE SOFTWARE.
3737
#include "renderer/ccGLStateCache.h"
3838
#include "2d/CCDrawingPrimitives.h"
3939
#include "platform/android/jni/JniHelper.h"
40+
#include "platform/CCDataManager.h"
4041
#include "network/CCDownloader-android.h"
42+
#include <unistd.h>
4143
#include <android/log.h>
4244
#include <android/api-level.h>
4345
#include <jni.h>
@@ -86,6 +88,9 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
8688

8789
JNIEXPORT void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
8890
{
91+
DataManager::setProcessID(getpid());
92+
DataManager::setFrameSize(w, h);
93+
8994
auto director = cocos2d::Director::getInstance();
9095
auto glview = director->getOpenGLView();
9196
if (!glview)

Diff for: cocos/platform/android/libcocos2dx/proguard-rules.pro

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@
2020

2121
-keep public class org.cocos2dx.lib.**
2222
-keepclassmembers public class org.cocos2dx.lib.** { *; }
23+
-keep public class com.oppo.oiface.engine.** { *; }
24+
-dontwarn com.oppo.oiface.engine.**

Diff for: cocos/renderer/CCGLProgramCache.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ THE SOFTWARE.
3535
#include "base/CCEventListenerCustom.h"
3636
#include "base/CCDirector.h"
3737
#include "base/CCEventDispatcher.h"
38+
#include "platform/CCDataManager.h"
3839

3940
NS_CC_BEGIN
4041

@@ -127,12 +128,17 @@ GLProgramCache::~GLProgramCache()
127128

128129
bool GLProgramCache::init()
129130
{
131+
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
132+
DataManager::onShaderLoaderBegin();
133+
#endif
130134
loadDefaultGLPrograms();
131135

132136
auto listener = EventListenerCustom::create(Configuration::CONFIG_FILE_LOADED, [this](EventCustom* /*event*/){
133137
reloadDefaultGLProgramsRelativeToLights();
134138
});
135-
139+
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
140+
DataManager::onShaderLoaderEnd();
141+
#endif
136142
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(listener, -1);
137143

138144
return true;

Diff for: templates/cocos2dx_files.json

+3
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,8 @@
974974
"cocos/platform/CCApplicationProtocol.h",
975975
"cocos/platform/CCCommon.h",
976976
"cocos/platform/CCDevice.h",
977+
"cocos/platform/CCDataManager.cpp",
978+
"cocos/platform/CCDataManager.h",
977979
"cocos/platform/CCFileUtils.cpp",
978980
"cocos/platform/CCFileUtils.h",
979981
"cocos/platform/CCGL.h",
@@ -1050,6 +1052,7 @@
10501052
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxGLSurfaceView.java",
10511053
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHandler.java",
10521054
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java",
1055+
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxDataManager.java",
10531056
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHttpURLConnection.java",
10541057
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxJavascriptJavaBridge.java",
10551058
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxLocalStorage.java",

Diff for: templates/cpp-template-default/proj.android/app/proguard-rules.pro

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
-dontwarn com.chukong.**
2424
-keep public class com.huawei.android.** { *; }
2525
-dontwarn com.huawei.android.**
26+
-keep public class com.oppo.oiface.engine.** { *; }
27+
-dontwarn com.oppo.oiface.engine.**
2628

2729
# Proguard Apache HTTP for release
2830
-keep class org.apache.http.** { *; }

Diff for: templates/js-template-default/frameworks/runtime-src/proj.android/app/proguard-rules.pro

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
-dontwarn com.chukong.**
2424
-keep public class com.huawei.android.** { *; }
2525
-dontwarn com.huawei.android.**
26+
-keep public class com.oppo.oiface.engine.** { *; }
27+
-dontwarn com.oppo.oiface.engine.**
2628

2729
# Proguard Apache HTTP for release
2830
-keep class org.apache.http.** { *; }

Diff for: templates/lua-template-default/frameworks/runtime-src/proj.android/app/proguard-rules.pro

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
-dontwarn com.chukong.**
2424
-keep public class com.huawei.android.** { *; }
2525
-dontwarn com.huawei.android.**
26+
-keep public class com.oppo.oiface.engine.** { *; }
27+
-dontwarn com.oppo.oiface.engine.**
2628

2729
# Proguard Apache HTTP for release
2830
-keep class org.apache.http.** { *; }

Diff for: tests/cpp-empty-test/proj.android/app/proguard-rules.pro

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
-dontwarn com.chukong.**
2424
-keep public class com.huawei.android.** { *; }
2525
-dontwarn com.huawei.android.**
26+
-keep public class com.oppo.oiface.engine.** { *; }
27+
-dontwarn com.oppo.oiface.engine.**
2628

2729
# Proguard Apache HTTP for release
2830
-keep class org.apache.http.** { *; }

Diff for: tests/cpp-tests/proj.android/app/proguard-rules.pro

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
-dontwarn com.chukong.**
2424
-keep public class com.huawei.android.** { *; }
2525
-dontwarn com.huawei.android.**
26+
-keep public class com.oppo.oiface.engine.** { *; }
27+
-dontwarn com.oppo.oiface.engine.**
2628

2729
# Proguard Apache HTTP for release
2830
-keep class org.apache.http.** { *; }

Diff for: tests/game-controller-test/proj.android/app/proguard-rules.pro

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
-dontwarn com.chukong.**
2424
-keep public class com.huawei.android.** { *; }
2525
-dontwarn com.huawei.android.**
26+
-keep public class com.oppo.oiface.engine.** { *; }
27+
-dontwarn com.oppo.oiface.engine.**
2628

2729
# Proguard Apache HTTP for release
2830
-keep class org.apache.http.** { *; }

Diff for: tests/js-tests/project/proj.android/app/proguard-rules.pro

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
-dontwarn com.chukong.**
2424
-keep public class com.huawei.android.** { *; }
2525
-dontwarn com.huawei.android.**
26+
-keep public class com.oppo.oiface.engine.** { *; }
27+
-dontwarn com.oppo.oiface.engine.**
2628

2729
# Proguard Apache HTTP for release
2830
-keep class org.apache.http.** { *; }

Diff for: tests/lua-empty-test/project/proj.android/app/proguard-rules.pro

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
-dontwarn com.chukong.**
2424
-keep public class com.huawei.android.** { *; }
2525
-dontwarn com.huawei.android.**
26+
-keep public class com.oppo.oiface.engine.** { *; }
27+
-dontwarn com.oppo.oiface.engine.**
2628

2729
# Proguard Apache HTTP for release
2830
-keep class org.apache.http.** { *; }

Diff for: tests/lua-game-controller-test/project/proj.android/app/proguard-rules.pro

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
-dontwarn com.chukong.**
2424
-keep public class com.huawei.android.** { *; }
2525
-dontwarn com.huawei.android.**
26+
-keep public class com.oppo.oiface.engine.** { *; }
27+
-dontwarn com.oppo.oiface.engine.**
2628

2729
# Proguard Apache HTTP for release
2830
-keep class org.apache.http.** { *; }

0 commit comments

Comments
 (0)