Skip to content
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

3.2 version OHOS adaptation #20816

Merged
merged 4 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
37 changes: 37 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: 1.0.{build}
skip_tags: true
skip_branch_with_pr: true
image:
- Visual Studio 2015
environment:
PYTHON: "C:\\Python27"
PYTHON_VERSION: "2.7.13"
PYTHON_ARCH: "32"
matrix:
# - build_type: windows32_cmake_test
# - build_type: windows32_sln_test
# - build_type: android_lua_tests
# - build_type: android_cocos_new_test
# - build_type: android_cpp_empty_test
# - build_type: android_gen_libs


platform:
- x86

configuration:
- Release


branches:
except:
- v1
- v2
- v4-develop
- v3-doc
- v3.11_backup
- v35-for-tizen

clone_depth: 1

test: off
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ project.properties
/external/jpeg/
/external/json/
/external/linux-specific/
/external/ohos-specific/
/external/openssl/
/external/lua/
/external/png/
/external/zlib/
/external/sqlite3/
/external/tiff/
/external/tinyxml2/
Expand Down
36 changes: 31 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-std=c99")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11")
endif()

if(MINGW)
if(MINGW AND NOT OHOS)
add_definitions(-DGLEW_STATIC)
add_definitions(-D__SSIZE_T)
set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lws2_32")
Expand Down Expand Up @@ -126,14 +126,15 @@ if(WIN32) # Win32
set(PLATFORM_FOLDER win32)
elseif(APPLE)# osx or ios
set(PLATFORM_FOLDER mac)
elseif(OHOS)
set(PLATFORM_FOLDER ohos)
else() # Assume Linux
set(PLATFORM_FOLDER linux)
endif()

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cocos
${CMAKE_CURRENT_SOURCE_DIR}/cocos/platform/desktop
${CMAKE_CURRENT_SOURCE_DIR}/cocos/platform/${PLATFORM_FOLDER}
${CMAKE_CURRENT_SOURCE_DIR}/cocos/audio/include
${CMAKE_CURRENT_SOURCE_DIR}/cocos/editor-support
Expand All @@ -156,6 +157,10 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/external/xxtea
)

if(NOT OHOS)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/cocos/platform/desktop)
endif()

if(WIN32 AND NOT MINGW)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/gles/include/OGLES
Expand Down Expand Up @@ -223,6 +228,24 @@ add_subdirectory(external/tinyxml2)
# xxhash library
add_subdirectory(external/xxhash)

# pvmp3dec tremolo library
if(OHOS)
add_subdirectory(external/webp)
add_subdirectory(external/freetype2)
add_subdirectory(external/png)
add_subdirectory(external/jpeg)
add_subdirectory(external/tiff)
add_subdirectory(external/zlib)
add_subdirectory(external/ohos-specific/pvmp3dec)
add_subdirectory(external/ohos-specific/tremolo)
add_subdirectory(external/websockets)
add_subdirectory(external/lua/luajit)

add_subdirectory(external/lua/luasocket)
add_subdirectory(external/curl)
add_subdirectory(external/openssl)
endif()

# audio
add_subdirectory(cocos/audio)

Expand Down Expand Up @@ -268,13 +291,16 @@ endif(BUILD_LIBS_LUA)

# build tests

add_subdirectory(tests/cpp-empty-test)

if(NOT OHOS)
add_subdirectory(tests/cpp-empty-test)
endif()
if(BUILD_CppTests)
add_subdirectory(tests/cpp-tests)
endif(BUILD_CppTests)

if(BUILD_LuaTests)
add_subdirectory(tests/lua-tests/project)
add_subdirectory(tests/lua-empty-test/project)
if(NOT OHOS)
add_subdirectory(tests/lua-empty-test/project)
endif()
endif(BUILD_LuaTests)
4 changes: 2 additions & 2 deletions cocos/2d/CCLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ void Label::createSpriteWithFontDefinition()
void Label::setFontDefinition(const FontDefinition& textDefinition)
{
_fontDefinition = textDefinition;
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) && (CC_TARGET_PLATFORM != CC_PLATFORM_IOS)
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) && (CC_TARGET_PLATFORM != CC_PLATFORM_OHOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_IOS)
if (_fontDefinition._stroke._strokeEnabled)
{
CCLOGERROR("Currently only supported on iOS and Android!");
Expand Down Expand Up @@ -991,7 +991,7 @@ void Label::updateContent()
_fontDefinition._stroke._strokeEnabled = false;
}

#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) && (CC_TARGET_PLATFORM != CC_PLATFORM_IOS)
#if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) && (CC_TARGET_PLATFORM != CC_PLATFORM_OHOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_IOS)
if (_fontDefinition._stroke._strokeEnabled)
{
CCLOGERROR("Currently only supported on iOS and Android!");
Expand Down
62 changes: 40 additions & 22 deletions cocos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,51 @@ endif()

elseif(APPLE)

elseif(OHOS)
find_library(hilog-lib hilog_ndk.z)
find_library(Drawing-lib native_drawing)
find_library(libace-lib ace_ndk.z)
find_library(libnapi-lib ace_napi.z)
find_library(libuv-lib uv)
find_library(rawfile-lib rawfile.z)
set(COCOS_LINK ext_freetype ext_png ext_jpeg ext_tiff ext_webp ext_zlib ext_pvmp3dec ext_tremolo EGL OpenSLES GLESv3 ${hilog-lib} ${Drawing-lib} ${libace-lib} ${libnapi-lib} ${libuv-lib} ${rawfile-lib})
else()
set(COCOS_LINK
jpeg
webp
tiff
freetype
fontconfig
png
pthread
glfw
GLEW
GL
X11
rt
z
)
set(COCOS_LINK
jpeg
webp
tiff
freetype
fontconfig
png
pthread
glfw
GLEW
GL
X11
rt
z
)
endif()

target_link_libraries(cocos2d
chipmunk_static
tinyxml2
unzip
xxhash
${COCOS_STORAGE_LINK}
if (OHOS)
target_link_libraries(cocos2d ${Drawing-lib} ${libace-lib} ${GLES-lib} ${libnapi-lib} ${libuv-lib} ${rawfile-lib} ${EGL-lib} ${hilog-lib} libohaudio.so libavplayer.so libnative_window.so libnative_buffer.so)
endif()

set(COMMON_LINK chipmunk_static tinyxml2 unzip xxhash)
if(OHOS)
target_link_libraries(cocos2d
${COMMON_LINK}
${COCOS_NETWORK_LINK}
${COCOS_LINK}
)
)
else()
target_link_libraries(cocos2d
${COMMON_LINK}
${COCOS_STORAGE_LINK}
${COCOS_NETWORK_LINK}
${COCOS_LINK}
)
endif()

set_target_properties(cocos2d
PROPERTIES
Expand Down
48 changes: 47 additions & 1 deletion cocos/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,42 @@ if(WIN32)
)
elseif(APPLE)


elseif(OHOS)
set(AUDIO_SRC
ohos/AudioEngine.cpp
ohos/SimpleAudioEngine.cpp
ohos/AudioEngine-inl.cpp
ohos/CCThreadPool.cpp
ohos/AssetFd.cpp
ohos/AudioDecoder.cpp
ohos/AudioDecoderProvider.cpp
ohos/AudioDecoderSLES.cpp
ohos/AudioDecoderOgg.cpp
ohos/AudioDecoderMp3.cpp
ohos/AudioDecoderWav.cpp
ohos/AudioPlayerProvider.cpp
ohos/AudioResampler.cpp
ohos/AudioResamplerCubic.cpp
ohos/CCData.cpp
ohos/PcmBufferProvider.cpp
ohos/PcmAudioPlayer.cpp
ohos/PcmData.cpp
ohos/PcmAudioService.cpp
ohos/UrlAudioPlayer.cpp
ohos/AudioMixerController.cpp
ohos/AudioMixer.cpp
ohos/mp3reader.cpp
ohos/tinysndfile.cpp
ohos/Track.cpp

ohos/audio_utils/RefCounted.cpp
ohos/audio_utils/Value.cpp
ohos/audio_utils/minifloat.cpp
ohos/audio_utils/primitives.cpp
ohos/utils/Utils.cpp
ohos/utils/CCAudioFileUtilsOhos.cpp
)
else()
set(AUDIO_SRC
linux/SimpleAudioEngineFMOD.cpp
Expand All @@ -32,8 +68,18 @@ add_library(audio STATIC
include/Export.h
include/SimpleAudioEngine.h
)
if(OHOS)
include_directories(
../../cocos
../../cocos/platform/ohos
)
target_link_libraries(audio
ext_pvmp3dec
ext_tremolo
)
endif()

if((NOT APPLE) AND (NOT WIN32))
if((NOT APPLE) AND (NOT WIN32) AND (NOT OHOS) )

if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set(FMOD_LIB "fmodex64")
Expand Down
38 changes: 38 additions & 0 deletions cocos/audio/ohos/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := cocosdenshion_static

LOCAL_MODULE_FILENAME := libcocosdenshion

LOCAL_SRC_FILES := cddSimpleAudioEngine.cpp \
ccdandroidUtils.cpp \
jni/cddandroidAndroidJavaEngine.cpp

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include \
$(LOCAL_PATH)/../.. \
$(LOCAL_PATH)/../../platform/android

include $(BUILD_STATIC_LIBRARY)

#new audio engine
include $(CLEAR_VARS)

LOCAL_MODULE := audioengine_static

LOCAL_MODULE_FILENAME := libaudioengine

LOCAL_SRC_FILES := AudioEngine-inl.cpp \
../AudioEngine.cpp

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include

LOCAL_EXPORT_LDLIBS := -lOpenSLES

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include \
$(LOCAL_PATH)/../.. \
$(LOCAL_PATH)/../../platform/android

include $(BUILD_STATIC_LIBRARY)
45 changes: 45 additions & 0 deletions cocos/audio/ohos/AssetFd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 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.
****************************************************************************/

#define LOG_TAG "AssetFd"

#include "cutils/log.h"
#include "AssetFd.h"

namespace cocos2d { namespace experimental {

AssetFd::AssetFd(int assetFd)
: _assetFd(assetFd) {
}

AssetFd::~AssetFd() {
ALOGV("~AssetFd: %d", _assetFd);
if (_assetFd > 0) {
::close(_assetFd);
_assetFd = 0;
}
};

}} // namespace CocosDenshion
Loading