Skip to content

add optimization for OPPO. #19631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cocos/2d/CCScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ THE SOFTWARE.
#include "base/ccUTF8.h"
#include "renderer/CCRenderer.h"
#include "renderer/CCFrameBuffer.h"
#include "platform/CCDataManager.h"

#if CC_USE_PHYSICS
#include "physics/CCPhysicsWorld.h"
Expand Down Expand Up @@ -76,6 +77,19 @@ Scene::Scene()
_event->retain();

Camera::_visitingCamera = nullptr;

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
DataManager::onSceneLoaderBegin();
#endif
}

void Scene::onEnter()
{
Node::onEnter();

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
DataManager::onSceneLoaderEnd();
#endif
}

Scene::~Scene()
Expand Down
9 changes: 9 additions & 0 deletions cocos/2d/CCScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ class CC_DLL Scene : public Node
/** override function */
virtual void removeAllChildren() override;

/**
* Event callback that is invoked every time when Node enters the 'stage'.
* If the Node enters the 'stage' with a transition, this event is called when the transition starts.
* During onEnter you can't access a "sister/brother" node.
* If you override onEnter, you shall call its parent's one, e.g., Node::onEnter().
* @lua NA
*/
virtual void onEnter() override;

CC_CONSTRUCTOR_ACCESS:
Scene();
virtual ~Scene();
Expand Down
1 change: 1 addition & 0 deletions cocos/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ cocos2d.cpp \
2d/CCAutoPolygon.cpp \
3d/CCFrustum.cpp \
3d/CCPlane.cpp \
platform/CCDataManager.cpp \
platform/CCFileUtils.cpp \
platform/CCGLView.cpp \
platform/CCImage.cpp \
Expand Down
68 changes: 68 additions & 0 deletions cocos/platform/CCDataManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#include "platform/CCDataManager.h"

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
# include "platform/android/jni/JniHelper.h"
# define DataManagerClassName "org/cocos2dx/lib/Cocos2dxDataManager"
#endif

NS_CC_BEGIN

void DataManager::setProcessID(int pid){
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
JniHelper::callStaticVoidMethod(DataManagerClassName, "setProcessID", pid);
#endif
}
void DataManager::setFrameSize(int width, int height){
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
JniHelper::callStaticVoidMethod(DataManagerClassName, "setFrameSize", width, height);
#endif
}
void DataManager::onSceneLoaderBegin(){
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
JniHelper::callStaticVoidMethod(DataManagerClassName, "onSceneLoaderBegin");
#endif
}
void DataManager::onSceneLoaderEnd(){
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
JniHelper::callStaticVoidMethod(DataManagerClassName, "onSceneLoaderEnd");
#endif
}
void DataManager::onShaderLoaderBegin(){
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
JniHelper::callStaticVoidMethod(DataManagerClassName, "onShaderLoaderBegin");
#endif
}
void DataManager::onShaderLoaderEnd(){
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
JniHelper::callStaticVoidMethod(DataManagerClassName, "onShaderLoaderEnd");
#endif
}

NS_CC_END
57 changes: 57 additions & 0 deletions cocos/platform/CCDataManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.

Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

#ifndef __CC_DataManager_H__
#define __CC_DataManager_H__

#include "platform/CCPlatformMacros.h"
#include "base/ccTypes.h"

NS_CC_BEGIN

/**
* @addtogroup platform
* @{
*/

class CC_DLL DataManager
{
public:
static void setProcessID(int pid);
static void setFrameSize(int width, int height);
static void onSceneLoaderBegin();
static void onSceneLoaderEnd();
static void onShaderLoaderBegin();
static void onShaderLoaderEnd();
};

// end of platform group
/** @} */

NS_CC_END

#endif // __CC_DataManager_H__
1 change: 1 addition & 0 deletions cocos/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ set(COCOS_PLATFORM_HEADER

set(COCOS_PLATFORM_SRC
${COCOS_PLATFORM_SPECIFIC_SRC}
platform/CCDataManager.cpp
platform/CCSAXParser.cpp
platform/CCThread.cpp
platform/CCGLView.cpp
Expand Down
Binary file added cocos/platform/android/java/libs/oppoSDK.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.

http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

package org.cocos2dx.lib;
import android.util.Log;

import com.oppo.oiface.engine.OifaceGameEngineManager;

public class Cocos2dxDataManager {
public static void setOptimise(String thing, float value){
String jsonStr = "{\"" + thing + "\":" + String.valueOf(value) + "}";
OifaceGameEngineManager.getInstance().updateGameEngineInfo(jsonStr);
}

public static void setProcessID(int pid){
setOptimise("render_pid", pid);
}
public static void setFrameSize(int width, int height){
setOptimise("buffer_size", width * height);
}
public static void onSceneLoaderBegin(){
setOptimise("load_scene", 1);
}
public static void onSceneLoaderEnd(){
setOptimise("load_scene", 0);
}
public static void onShaderLoaderBegin(){
setOptimise("shader_compile", 1);
}
public static void onShaderLoaderEnd(){
setOptimise("shader_compile", 0);
}
}
5 changes: 5 additions & 0 deletions cocos/platform/android/javaactivity-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ THE SOFTWARE.
#include "renderer/ccGLStateCache.h"
#include "2d/CCDrawingPrimitives.h"
#include "platform/android/jni/JniHelper.h"
#include "platform/CCDataManager.h"
#include "network/CCDownloader-android.h"
#include <unistd.h>
#include <android/log.h>
#include <android/api-level.h>
#include <jni.h>
Expand Down Expand Up @@ -86,6 +88,9 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)

JNIEXPORT void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{
DataManager::setProcessID(getpid());
DataManager::setFrameSize(w, h);

auto director = cocos2d::Director::getInstance();
auto glview = director->getOpenGLView();
if (!glview)
Expand Down
2 changes: 2 additions & 0 deletions cocos/platform/android/libcocos2dx/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@

-keep public class org.cocos2dx.lib.**
-keepclassmembers public class org.cocos2dx.lib.** { *; }
-keep public class com.oppo.oiface.engine.** { *; }
-dontwarn com.oppo.oiface.engine.**
8 changes: 7 additions & 1 deletion cocos/renderer/CCGLProgramCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ THE SOFTWARE.
#include "base/CCEventListenerCustom.h"
#include "base/CCDirector.h"
#include "base/CCEventDispatcher.h"
#include "platform/CCDataManager.h"

NS_CC_BEGIN

Expand Down Expand Up @@ -127,12 +128,17 @@ GLProgramCache::~GLProgramCache()

bool GLProgramCache::init()
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
DataManager::onShaderLoaderBegin();
#endif
loadDefaultGLPrograms();

auto listener = EventListenerCustom::create(Configuration::CONFIG_FILE_LOADED, [this](EventCustom* /*event*/){
reloadDefaultGLProgramsRelativeToLights();
});

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
DataManager::onShaderLoaderEnd();
#endif
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(listener, -1);

return true;
Expand Down
3 changes: 3 additions & 0 deletions templates/cocos2dx_files.json
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,8 @@
"cocos/platform/CCApplicationProtocol.h",
"cocos/platform/CCCommon.h",
"cocos/platform/CCDevice.h",
"cocos/platform/CCDataManager.cpp",
"cocos/platform/CCDataManager.h",
"cocos/platform/CCFileUtils.cpp",
"cocos/platform/CCFileUtils.h",
"cocos/platform/CCGL.h",
Expand Down Expand Up @@ -1050,6 +1052,7 @@
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxGLSurfaceView.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHandler.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxDataManager.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHttpURLConnection.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxJavascriptJavaBridge.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxLocalStorage.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
-dontwarn com.chukong.**
-keep public class com.huawei.android.** { *; }
-dontwarn com.huawei.android.**
-keep public class com.oppo.oiface.engine.** { *; }
-dontwarn com.oppo.oiface.engine.**

# Proguard Apache HTTP for release
-keep class org.apache.http.** { *; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
-dontwarn com.chukong.**
-keep public class com.huawei.android.** { *; }
-dontwarn com.huawei.android.**
-keep public class com.oppo.oiface.engine.** { *; }
-dontwarn com.oppo.oiface.engine.**

# Proguard Apache HTTP for release
-keep class org.apache.http.** { *; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
-dontwarn com.chukong.**
-keep public class com.huawei.android.** { *; }
-dontwarn com.huawei.android.**
-keep public class com.oppo.oiface.engine.** { *; }
-dontwarn com.oppo.oiface.engine.**

# Proguard Apache HTTP for release
-keep class org.apache.http.** { *; }
Expand Down
2 changes: 2 additions & 0 deletions tests/cpp-empty-test/proj.android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
-dontwarn com.chukong.**
-keep public class com.huawei.android.** { *; }
-dontwarn com.huawei.android.**
-keep public class com.oppo.oiface.engine.** { *; }
-dontwarn com.oppo.oiface.engine.**

# Proguard Apache HTTP for release
-keep class org.apache.http.** { *; }
Expand Down
2 changes: 2 additions & 0 deletions tests/cpp-tests/proj.android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
-dontwarn com.chukong.**
-keep public class com.huawei.android.** { *; }
-dontwarn com.huawei.android.**
-keep public class com.oppo.oiface.engine.** { *; }
-dontwarn com.oppo.oiface.engine.**

# Proguard Apache HTTP for release
-keep class org.apache.http.** { *; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
-dontwarn com.chukong.**
-keep public class com.huawei.android.** { *; }
-dontwarn com.huawei.android.**
-keep public class com.oppo.oiface.engine.** { *; }
-dontwarn com.oppo.oiface.engine.**

# Proguard Apache HTTP for release
-keep class org.apache.http.** { *; }
Expand Down
2 changes: 2 additions & 0 deletions tests/js-tests/project/proj.android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
-dontwarn com.chukong.**
-keep public class com.huawei.android.** { *; }
-dontwarn com.huawei.android.**
-keep public class com.oppo.oiface.engine.** { *; }
-dontwarn com.oppo.oiface.engine.**

# Proguard Apache HTTP for release
-keep class org.apache.http.** { *; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
-dontwarn com.chukong.**
-keep public class com.huawei.android.** { *; }
-dontwarn com.huawei.android.**
-keep public class com.oppo.oiface.engine.** { *; }
-dontwarn com.oppo.oiface.engine.**

# Proguard Apache HTTP for release
-keep class org.apache.http.** { *; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
-dontwarn com.chukong.**
-keep public class com.huawei.android.** { *; }
-dontwarn com.huawei.android.**
-keep public class com.oppo.oiface.engine.** { *; }
-dontwarn com.oppo.oiface.engine.**

# Proguard Apache HTTP for release
-keep class org.apache.http.** { *; }
Expand Down
Loading