Skip to content

Commit f959404

Browse files
dumganharIceBBBBB
andauthored
Add HarmonyOS-Next support for cocos2d-x-4.0 release. (#20854) (#20855)
* 添加鸿蒙平台适配 * 代码优化 * opengles removed * 4.0 version OHOS adaptation * 4.0 version OHOS adaptation * 4.0 version OHOS adaptation * Review and revise based on feedback * ohos code optimization --------- Signed-off-by: 冰冰冰 <[email protected]> Co-authored-by: 冰冰冰 <[email protected]>
1 parent 7a5282a commit f959404

File tree

285 files changed

+23981
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+23981
-101
lines changed

.appveyor.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ environment:
88
PYTHON_VERSION: "2.7.13"
99
PYTHON_ARCH: "32"
1010
matrix:
11-
- build_type: windows32_cmake_test
12-
- build_type: android_cpp_tests
13-
- build_type: android_lua_tests
11+
# - build_type: windows32_cmake_test
12+
# - build_type: android_cpp_tests
13+
# - build_type: android_lua_tests
1414
# - build_type: android_cocos_new_test
1515
# - build_type: android_cpp_empty_test
1616
# - build_type: android_gen_libs

.gitmodules

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[submodule "tools/cocos2d-console"]
22
path = tools/cocos2d-console
3-
url = git://github.com/cocos2d/cocos2d-console.git
3+
url = https://github.com/cocos2d/cocos2d-console.git
44
[submodule "tools/bindings-generator"]
55
path = tools/bindings-generator
6-
url = git://github.com/cocos2d/bindings-generator.git
6+
url = https://github.com/cocos2d/bindings-generator.git
77
[submodule "tests/cpp-tests/Resources/ccs-res"]
88
path = tests/cpp-tests/Resources/ccs-res
9-
url = git://github.com/dumganhar/ccs-res.git
9+
url = https://github.com/dumganhar/ccs-res.git

.travis.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ matrix:
3030
sudo: required
3131
dist: xenial
3232
# android_lua cmake
33-
- os: linux
34-
env: BUILD_TARGET=android_lua_cmake
35-
language: android
36-
sudo: required
37-
dist: xenial
38-
addons:
39-
apt:
40-
sources:
41-
- ubuntu-toolchain-r-test
42-
packages:
43-
- g++-6
33+
#- os: linux
34+
# env: BUILD_TARGET=android_lua_cmake
35+
# language: android
36+
# sudo: required
37+
# dist: xenial
38+
# addons:
39+
# apt:
40+
# sources:
41+
# - ubuntu-toolchain-r-test
42+
# packages:
43+
# - g++-6
4444
# android_js cmake
4545
# - os: linux
4646
# env: BUILD_TARGET=android_js_cmake

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
5555
set(BUILD_ENGINE_DONE ON)
5656

5757
# add cpp tests default
58+
if(!OHOS)
5859
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-empty-test ${ENGINE_BINARY_PATH}/tests/cpp-empty-test)
60+
endif()
5961
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/cpp-tests ${ENGINE_BINARY_PATH}/tests/cpp-tests)
6062

6163
if(BUILD_LUA_LIBS)
64+
if(!OHOS)
6265
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-empty-test/project ${ENGINE_BINARY_PATH}/tests/lua-empty-test)
66+
endif()
6367
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests/lua-tests/project ${ENGINE_BINARY_PATH}/tests/lua-test)
6468
endif(BUILD_LUA_LIBS)
6569

cmake/Modules/CocosConfigDefine.cmake

+10
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ endif()
1010
#IOS = iOS
1111
#MACOSX = MacOS X
1212
#LINUX = Linux
13+
#OHOS = OHOS
1314
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
1415
set(WINDOWS TRUE)
1516
set(PLATFORM_FOLDER win32)
1617
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
1718
set(PLATFORM_FOLDER android)
19+
elseif(CMAKE_SYSTEM_NAME MATCHES "OHOS")
20+
set(PLATFORM_FOLDER ohos)
1821
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
1922
if(ANDROID)
2023
set(PLATFORM_FOLDER android)
@@ -60,7 +63,11 @@ define_property(TARGET
6063
# check c++ standard
6164
set(CMAKE_C_STANDARD 99)
6265
set(CMAKE_C_STANDARD_REQUIRED ON)
66+
if(OHOS)
67+
set(CMAKE_CXX_STANDARD 14)
68+
else()
6369
set(CMAKE_CXX_STANDARD 11)
70+
endif()
6471
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6572
set(CMAKE_CXX_EXTENSIONS OFF)
6673

@@ -92,6 +99,9 @@ endif()
9299
elseif(ANDROID)
93100
target_compile_definitions(${target} PUBLIC ANDROID)
94101
target_compile_definitions(${target} PUBLIC USE_FILE32API)
102+
elseif(OHOS)
103+
target_compile_definitions(${target} PUBLIC OHOS)
104+
target_compile_definitions(${target} PUBLIC USE_FILE32API)
95105
elseif(WINDOWS)
96106
target_compile_definitions(${target}
97107
PUBLIC WIN32

cmake/Modules/CocosConfigDepend.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ macro(cocos2dx_depend)
2121
set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
2222
elseif(ANDROID)
2323
list(APPEND PLATFORM_SPECIFIC_LIBS GLESv2 EGL log android OpenSLES)
24+
elseif(OHOS)
25+
list(APPEND PLATFORM_SPECIFIC_LIBS native_drawing EGL GLESv3 hilog_ndk.z ace_ndk.z ace_napi.z uv rawfile.z OpenSLES)
2426
elseif(APPLE)
2527

2628
include_directories(/System/Library/Frameworks)

cocos/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ use_cocos2dx_compile_define(cocos2d)
118118
use_cocos2dx_compile_options(cocos2d)
119119

120120
# use all platform related system libs
121+
if (OHOS)
122+
include_directories(cocos2d ${COCOS2DX_ROOT_PATH}/external/ohos-specific/aki/include)
123+
target_link_libraries(cocos2d ${Drawing-lib} ${libace-lib} ${GLES-lib} ${libnapi-lib} ${libuv-lib} ${rawfile-lib}
124+
${EGL-lib} ${hilog-lib} libohaudio.so libavplayer.so libnative_window.so libnative_buffer.so
125+
libnative_display_manager.so libohsensor.so libnative_media_codecbase.so libnative_media_core.so libnative_media_acodec.so libnative_media_avdemuxer.so libnative_media_avsource.so)
126+
endif()
121127
use_cocos2dx_libs_depend(cocos2d)
122128

123129
target_include_directories(cocos2d

cocos/audio/AudioEngine.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include "audio/win32/AudioEngine-win32.h"
4040
#elif CC_TARGET_PLATFORM == CC_PLATFORM_LINUX
4141
#include "audio/linux/AudioEngine-linux.h"
42+
#elif CC_TARGET_PLATFORM == CC_PLATFORM_OHOS
43+
#include "audio/ohos/AudioEngine-inl.h"
4244
#endif
4345

4446
#define TIME_DELAY_PRECISION 0.0001

cocos/audio/CMakeLists.txt

+68
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,74 @@ elseif(ANDROID)
105105
audio/android/tinysndfile.cpp
106106
)
107107

108+
elseif(OHOS)
109+
set(COCOS_AUDIO_PLATFORM_HEADER
110+
audio/ohos/PcmAudioService.h
111+
audio/ohos/AudioBufferProvider.h
112+
audio/ohos/IAudioPlayer.h
113+
audio/ohos/AudioResampler.h
114+
audio/ohos/AudioDecoder.h
115+
audio/ohos/AudioResamplerPublic.h
116+
audio/ohos/AudioMixer.h
117+
audio/ohos/tinysndfile.h
118+
audio/ohos/AudioMixerOps.h
119+
audio/ohos/cutils/bitops.h
120+
audio/ohos/cutils/log.h
121+
audio/ohos/audio.h
122+
audio/ohos/AudioPlayerProvider.h
123+
audio/ohos/utils/Utils.h
124+
audio/ohos/utils/Errors.h
125+
audio/ohos/utils/Compat.h
126+
audio/ohos/Track.h
127+
audio/ohos/OpenSLHelper.h
128+
audio/ohos/PcmAudioPlayer.h
129+
audio/ohos/AssetFd.h
130+
audio/ohos/PcmBufferProvider.h
131+
audio/ohos/CCThreadPool.h
132+
audio/ohos/audio_utils/include/audio_utils/minifloat.h
133+
audio/ohos/audio_utils/include/audio_utils/primitives.h
134+
audio/ohos/audio_utils/AudioDef.h
135+
audio/ohos/audio_utils/RefCounted.h
136+
audio/ohos/ICallerThreadUtils.h
137+
audio/ohos/AudioDecoderWav.h
138+
audio/ohos/AudioDecoderProvider.h
139+
audio/ohos/AudioDecoderOH.h
140+
audio/ohos/BigAudioPlayer.h
141+
audio/ohos/BigAudioService.h
142+
audio/ohos/PcmData.h
143+
audio/ohos/AudioMixerController.h
144+
audio/ohos/AudioResamplerCubic.h
145+
audio/ohos/AudioEngine-inl.h
146+
audio/ohos/IVolumeProvider.h
147+
audio/ohos/Macros.h
148+
)
149+
150+
set(COCOS_AUDIO_PLATFORM_SRC
151+
audio/ohos/AudioEngine-inl.cpp
152+
audio/ohos/CCThreadPool.cpp
153+
audio/ohos/AssetFd.cpp
154+
audio/ohos/AudioDecoder.cpp
155+
audio/ohos/AudioDecoderProvider.cpp
156+
audio/ohos/AudioDecoderWav.cpp
157+
audio/ohos/AudioDecoderOH.cpp
158+
audio/ohos/AudioPlayerProvider.cpp
159+
audio/ohos/AudioResampler.cpp
160+
audio/ohos/AudioResamplerCubic.cpp
161+
audio/ohos/PcmBufferProvider.cpp
162+
audio/ohos/PcmAudioPlayer.cpp
163+
audio/ohos/PcmData.cpp
164+
audio/ohos/PcmAudioService.cpp
165+
audio/ohos/BigAudioPlayer.cpp
166+
audio/ohos/BigAudioService.cpp
167+
audio/ohos/AudioMixerController.cpp
168+
audio/ohos/AudioMixer.cpp
169+
audio/ohos/tinysndfile.cpp
170+
audio/ohos/Track.cpp
171+
audio/ohos/audio_utils/RefCounted.cpp
172+
audio/ohos/audio_utils/minifloat.cpp
173+
audio/ohos/audio_utils/primitives.cpp
174+
audio/ohos/utils/Utils.cpp
175+
)
108176
elseif(LINUX)
109177
set(COCOS_AUDIO_PLATFORM_HEADER
110178
audio/linux/AudioEngine-linux.h

cocos/audio/ohos/AssetFd.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/****************************************************************************
2+
Copyright (c) 2016 Chukong Technologies Inc.
3+
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
4+
5+
http://www.cocos2d-x.org
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
****************************************************************************/
25+
26+
#define LOG_TAG "AssetFd"
27+
28+
#include "cutils/log.h"
29+
#include "AssetFd.h"
30+
31+
namespace cocos2d {
32+
33+
AssetFd::AssetFd(int assetFd)
34+
: _assetFd(assetFd) {
35+
}
36+
37+
AssetFd::~AssetFd() {
38+
ALOGV("~AssetFd: %d", _assetFd);
39+
if (_assetFd > 0) {
40+
::close(_assetFd);
41+
_assetFd = 0;
42+
}
43+
};
44+
45+
} // namespace CocosDenshion

cocos/audio/ohos/AssetFd.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/****************************************************************************
2+
Copyright (c) 2016 Chukong Technologies Inc.
3+
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
4+
5+
http://www.cocos2d-x.org
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
****************************************************************************/
25+
#pragma once
26+
27+
#include <unistd.h>
28+
29+
namespace cocos2d {
30+
31+
class AssetFd {
32+
public:
33+
AssetFd(int assetFd);
34+
~AssetFd();
35+
36+
inline int getFd() const { return _assetFd; };
37+
38+
private:
39+
int _assetFd;
40+
};
41+
42+
} // namespace CocosDenshion
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#pragma once
2+
3+
#include <stddef.h>
4+
#include <stdint.h>
5+
#include "utils/Errors.h"
6+
7+
namespace cocos2d {
8+
// ----------------------------------------------------------------------------
9+
10+
class AudioBufferProvider {
11+
public:
12+
// IDEA: merge with AudioTrackShared::Buffer, AudioTrack::Buffer, and AudioRecord::Buffer
13+
// and rename getNextBuffer() to obtainBuffer()
14+
struct Buffer {
15+
Buffer() : raw(NULL), frameCount(0) {}
16+
union {
17+
void *raw;
18+
short *i16;
19+
int8_t *i8;
20+
};
21+
size_t frameCount;
22+
};
23+
24+
virtual ~AudioBufferProvider() {}
25+
26+
// value representing an invalid presentation timestamp
27+
static const int64_t kInvalidPTS = 0x7FFFFFFFFFFFFFFFLL; // <stdint.h> is too painful
28+
29+
// pts is the local time when the next sample yielded by getNextBuffer
30+
// will be rendered.
31+
// Pass kInvalidPTS if the PTS is unknown or not applicable.
32+
// On entry:
33+
// buffer != NULL
34+
// buffer->raw unused
35+
// buffer->frameCount maximum number of desired frames
36+
// On successful return:
37+
// status NO_ERROR
38+
// buffer->raw non-NULL pointer to buffer->frameCount contiguous available frames
39+
// buffer->frameCount number of contiguous available frames at buffer->raw,
40+
// 0 < buffer->frameCount <= entry value
41+
// On error return:
42+
// status != NO_ERROR
43+
// buffer->raw NULL
44+
// buffer->frameCount 0
45+
virtual status_t getNextBuffer(Buffer *buffer, int64_t pts = kInvalidPTS) = 0;
46+
47+
// Release (a portion of) the buffer previously obtained by getNextBuffer().
48+
// It is permissible to call releaseBuffer() multiple times per getNextBuffer().
49+
// On entry:
50+
// buffer->frameCount number of frames to release, must be <= number of frames
51+
// obtained but not yet released
52+
// buffer->raw unused
53+
// On return:
54+
// buffer->frameCount 0; implementation MUST set to zero
55+
// buffer->raw undefined; implementation is PERMITTED to set to any value,
56+
// so if caller needs to continue using this buffer it must
57+
// keep track of the pointer itself
58+
virtual void releaseBuffer(Buffer *buffer) = 0;
59+
};
60+
61+
// ----------------------------------------------------------------------------
62+
} // namespace CocosDenshion

0 commit comments

Comments
 (0)