Skip to content

Commit 776ab10

Browse files
xianyinchenminggo
authored andcommitted
add optimization for OPPO. (cocos2d#19631)
1 parent 79893ef commit 776ab10

File tree

23 files changed

+246
-1
lines changed

23 files changed

+246
-1
lines changed

cocos/2d/CCScene.cpp

Lines changed: 14 additions & 0 deletions
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()

cocos/2d/CCScene.h

Lines changed: 9 additions & 0 deletions
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();

cocos/Android.mk

Lines changed: 1 addition & 0 deletions
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 \

cocos/platform/CCDataManager.cpp

Lines changed: 68 additions & 0 deletions
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

cocos/platform/CCDataManager.h

Lines changed: 57 additions & 0 deletions
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__

cocos/platform/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
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
10.4 KB
Binary file not shown.
Lines changed: 57 additions & 0 deletions
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+
}

cocos/platform/android/javaactivity-android.cpp

Lines changed: 5 additions & 0 deletions
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)

cocos/platform/android/libcocos2dx/proguard-rules.pro

Lines changed: 2 additions & 0 deletions
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.**

0 commit comments

Comments
 (0)