no message
This commit is contained in:
98
cocos/platform/interfaces/modules/Device.cpp
Normal file
98
cocos/platform/interfaces/modules/Device.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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/interfaces/modules/Device.h"
|
||||
|
||||
#include "application/ApplicationManager.h"
|
||||
#include "platform/interfaces/modules/IAccelerometer.h"
|
||||
#include "platform/interfaces/modules/IBattery.h"
|
||||
#include "platform/interfaces/modules/INetwork.h"
|
||||
#include "platform/interfaces/modules/IScreen.h"
|
||||
#include "platform/interfaces/modules/IVibrator.h"
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
#include "platform/interfaces/modules/ISystemWindowManager.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
int Device::getDPI() {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(IScreen));
|
||||
return CC_GET_PLATFORM_INTERFACE(IScreen)->getDPI();
|
||||
}
|
||||
|
||||
float Device::getDevicePixelRatio() {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(IScreen));
|
||||
return CC_GET_PLATFORM_INTERFACE(IScreen)->getDevicePixelRatio();
|
||||
}
|
||||
|
||||
void Device::setKeepScreenOn(bool keepScreenOn) {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(IScreen));
|
||||
return CC_GET_PLATFORM_INTERFACE(IScreen)->setKeepScreenOn(keepScreenOn);
|
||||
}
|
||||
|
||||
void Device::setAccelerometerEnabled(bool isEnabled) {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(IAccelerometer));
|
||||
return CC_GET_PLATFORM_INTERFACE(IAccelerometer)->setAccelerometerEnabled(isEnabled);
|
||||
}
|
||||
|
||||
void Device::setAccelerometerInterval(float interval) {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(IAccelerometer));
|
||||
return CC_GET_PLATFORM_INTERFACE(IAccelerometer)->setAccelerometerInterval(interval);
|
||||
}
|
||||
|
||||
const IAccelerometer::MotionValue &Device::getDeviceMotionValue() {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(IAccelerometer));
|
||||
return CC_GET_PLATFORM_INTERFACE(IAccelerometer)->getDeviceMotionValue();
|
||||
}
|
||||
|
||||
IScreen::Orientation Device::getDeviceOrientation() {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(IScreen));
|
||||
return CC_GET_PLATFORM_INTERFACE(IScreen)->getDeviceOrientation();
|
||||
}
|
||||
|
||||
ccstd::string Device::getDeviceModel() {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(ISystem));
|
||||
return CC_GET_PLATFORM_INTERFACE(ISystem)->getDeviceModel();
|
||||
}
|
||||
|
||||
void Device::vibrate(float duration) {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(IVibrator));
|
||||
return CC_GET_PLATFORM_INTERFACE(IVibrator)->vibrate(duration);
|
||||
}
|
||||
|
||||
float Device::getBatteryLevel() {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(IBattery));
|
||||
return CC_GET_PLATFORM_INTERFACE(IBattery)->getBatteryLevel();
|
||||
}
|
||||
|
||||
INetwork::NetworkType Device::getNetworkType() {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(INetwork));
|
||||
return CC_GET_PLATFORM_INTERFACE(INetwork)->getNetworkType();
|
||||
}
|
||||
|
||||
Vec4 Device::getSafeAreaEdge() {
|
||||
CC_ASSERT_NOT_NULL(CC_GET_PLATFORM_INTERFACE(IScreen));
|
||||
return CC_GET_PLATFORM_INTERFACE(IScreen)->getSafeAreaEdge();
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
129
cocos/platform/interfaces/modules/Device.h
Normal file
129
cocos/platform/interfaces/modules/Device.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/Data.h"
|
||||
#include "base/Macros.h"
|
||||
#include "math/Vec4.h"
|
||||
|
||||
#include "platform/interfaces/modules/IAccelerometer.h"
|
||||
#include "platform/interfaces/modules/INetwork.h"
|
||||
#include "platform/interfaces/modules/IScreen.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
struct FontDefinition;
|
||||
|
||||
/**
|
||||
* @addtogroup platform
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class Device
|
||||
* @brief
|
||||
*/
|
||||
class CC_DLL Device {
|
||||
public:
|
||||
using Orientation = IScreen::Orientation;
|
||||
using MotionValue = IAccelerometer::MotionValue;
|
||||
|
||||
/**
|
||||
* Gets the DPI of device
|
||||
* @return The DPI of device.
|
||||
*/
|
||||
static int getDPI();
|
||||
|
||||
/**
|
||||
* Get device pixel ratio.
|
||||
*/
|
||||
static float getDevicePixelRatio();
|
||||
|
||||
/**
|
||||
* To enable or disable accelerometer.
|
||||
*/
|
||||
static void setAccelerometerEnabled(bool isEnabled);
|
||||
|
||||
/**
|
||||
* Sets the interval of accelerometer.
|
||||
*/
|
||||
static void setAccelerometerInterval(float interval);
|
||||
|
||||
/**
|
||||
* Gets the motion value of current device.
|
||||
*/
|
||||
static const IAccelerometer::MotionValue &getDeviceMotionValue();
|
||||
|
||||
/**
|
||||
* Gets the orientation of device.
|
||||
*/
|
||||
static IScreen::Orientation getDeviceOrientation();
|
||||
|
||||
/**
|
||||
* Gets device model information.
|
||||
*/
|
||||
static ccstd::string getDeviceModel();
|
||||
|
||||
/**
|
||||
* Controls whether the screen should remain on.
|
||||
*
|
||||
* @param keepScreenOn One flag indicating that the screen should remain on.
|
||||
*/
|
||||
static void setKeepScreenOn(bool keepScreenOn);
|
||||
|
||||
/**
|
||||
* Vibrate for the specified amount of time.
|
||||
* If vibrate is not supported, then invoking this method has no effect.
|
||||
* Some platforms limit to a maximum duration of 5 seconds.
|
||||
* Duration is ignored on iOS due to API limitations.
|
||||
* @param duration The duration in seconds.
|
||||
*/
|
||||
static void vibrate(float duration);
|
||||
|
||||
/**
|
||||
* Gets battery level, only avaiable on iOS and Android.
|
||||
* @return 0.0 ~ 1.0
|
||||
*/
|
||||
static float getBatteryLevel();
|
||||
|
||||
static INetwork::NetworkType getNetworkType();
|
||||
|
||||
/*
|
||||
* Gets the SafeArea edge.
|
||||
* Vec4(x, y, z, w) means Edge(top, left, bottom, right)
|
||||
*/
|
||||
static Vec4 getSafeAreaEdge();
|
||||
|
||||
private:
|
||||
Device();
|
||||
CC_DISALLOW_COPY_MOVE_ASSIGN(Device)
|
||||
};
|
||||
|
||||
// end group
|
||||
/// @}
|
||||
|
||||
} // namespace cc
|
||||
63
cocos/platform/interfaces/modules/IAccelerometer.h
Normal file
63
cocos/platform/interfaces/modules/IAccelerometer.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL IAccelerometer : public OSInterface {
|
||||
public:
|
||||
struct MotionValue {
|
||||
float accelerationX = 0.0F;
|
||||
float accelerationY = 0.0F;
|
||||
float accelerationZ = 0.0F;
|
||||
|
||||
float accelerationIncludingGravityX = 0.0F;
|
||||
float accelerationIncludingGravityY = 0.0F;
|
||||
float accelerationIncludingGravityZ = 0.0F;
|
||||
|
||||
float rotationRateAlpha = 0.0F;
|
||||
float rotationRateBeta = 0.0F;
|
||||
float rotationRateGamma = 0.0F;
|
||||
};
|
||||
|
||||
/**
|
||||
* To enable or disable accelerometer.
|
||||
*/
|
||||
virtual void setAccelerometerEnabled(bool isEnabled) = 0;
|
||||
|
||||
/**
|
||||
* Sets the interval of accelerometer.
|
||||
*/
|
||||
virtual void setAccelerometerInterval(float interval) = 0;
|
||||
|
||||
/**
|
||||
* Gets the motion value of current device.
|
||||
*/
|
||||
virtual const MotionValue &getDeviceMotionValue() = 0;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
40
cocos/platform/interfaces/modules/IBattery.h
Normal file
40
cocos/platform/interfaces/modules/IBattery.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL IBattery : public OSInterface {
|
||||
public:
|
||||
/**
|
||||
* Gets battery level, only avaiable on iOS and Android.
|
||||
* @return 0.0 ~ 1.0
|
||||
*/
|
||||
virtual float getBatteryLevel() const = 0;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
41
cocos/platform/interfaces/modules/INetwork.h
Normal file
41
cocos/platform/interfaces/modules/INetwork.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL INetwork : public OSInterface {
|
||||
public:
|
||||
enum class NetworkType {
|
||||
NONE,
|
||||
LAN,
|
||||
WWAN
|
||||
};
|
||||
virtual NetworkType getNetworkType() const = 0;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
65
cocos/platform/interfaces/modules/IScreen.h
Normal file
65
cocos/platform/interfaces/modules/IScreen.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "math/Vec4.h"
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
|
||||
namespace cc {
|
||||
class CC_DLL IScreen : public OSInterface {
|
||||
public:
|
||||
virtual int getDPI() const = 0;
|
||||
virtual float getDevicePixelRatio() const = 0;
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Window/orientation
|
||||
enum class Orientation {
|
||||
PORTRAIT = 0,
|
||||
LANDSCAPE_LEFT = -90,
|
||||
PORTRAIT_UPSIDE_DOWN = 180,
|
||||
LANDSCAPE_RIGHT = 90
|
||||
};
|
||||
virtual Orientation getDeviceOrientation() const = 0;
|
||||
|
||||
/**
|
||||
@brief Get current display stats.
|
||||
@return bool, is displaying stats or not.
|
||||
*/
|
||||
virtual bool isDisplayStats() = 0;
|
||||
|
||||
/**
|
||||
@brief set display stats information.
|
||||
*/
|
||||
virtual void setDisplayStats(bool isShow) = 0;
|
||||
|
||||
/**
|
||||
* Controls whether the screen should remain on.
|
||||
*
|
||||
* @param keepScreenOn One flag indicating that the screen should remain on.
|
||||
*/
|
||||
virtual void setKeepScreenOn(bool keepScreenOn) = 0;
|
||||
|
||||
virtual Vec4 getSafeAreaEdge() const = 0;
|
||||
};
|
||||
} // namespace cc
|
||||
101
cocos/platform/interfaces/modules/ISystem.cpp
Normal file
101
cocos/platform/interfaces/modules/ISystem.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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/interfaces/modules/ISystem.h"
|
||||
|
||||
namespace cc {
|
||||
ISystem::~ISystem() = default;
|
||||
|
||||
ccstd::string ISystem::getCurrentLanguageToString() {
|
||||
LanguageType language = getCurrentLanguage();
|
||||
ccstd::string languageStr = ""; // NOLINT
|
||||
switch (language) {
|
||||
case ISystem::LanguageType::ENGLISH:
|
||||
languageStr = "en";
|
||||
break;
|
||||
case ISystem::LanguageType::CHINESE:
|
||||
languageStr = "zh";
|
||||
break;
|
||||
case ISystem::LanguageType::FRENCH:
|
||||
languageStr = "fr";
|
||||
break;
|
||||
case ISystem::LanguageType::ITALIAN:
|
||||
languageStr = "it";
|
||||
break;
|
||||
case ISystem::LanguageType::GERMAN:
|
||||
languageStr = "de";
|
||||
break;
|
||||
case ISystem::LanguageType::SPANISH:
|
||||
languageStr = "es";
|
||||
break;
|
||||
case ISystem::LanguageType::DUTCH:
|
||||
languageStr = "du";
|
||||
break;
|
||||
case ISystem::LanguageType::RUSSIAN:
|
||||
languageStr = "ru";
|
||||
break;
|
||||
case ISystem::LanguageType::KOREAN:
|
||||
languageStr = "ko";
|
||||
break;
|
||||
case ISystem::LanguageType::JAPANESE:
|
||||
languageStr = "ja";
|
||||
break;
|
||||
case ISystem::LanguageType::HUNGARIAN:
|
||||
languageStr = "hu";
|
||||
break;
|
||||
case ISystem::LanguageType::PORTUGUESE:
|
||||
languageStr = "pt";
|
||||
break;
|
||||
case ISystem::LanguageType::ARABIC:
|
||||
languageStr = "ar";
|
||||
break;
|
||||
case ISystem::LanguageType::NORWEGIAN:
|
||||
languageStr = "no";
|
||||
break;
|
||||
case ISystem::LanguageType::POLISH:
|
||||
languageStr = "pl";
|
||||
break;
|
||||
case ISystem::LanguageType::TURKISH:
|
||||
languageStr = "tr";
|
||||
break;
|
||||
case ISystem::LanguageType::UKRAINIAN:
|
||||
languageStr = "uk";
|
||||
break;
|
||||
case ISystem::LanguageType::ROMANIAN:
|
||||
languageStr = "ro";
|
||||
break;
|
||||
case ISystem::LanguageType::BULGARIAN:
|
||||
languageStr = "bg";
|
||||
break;
|
||||
case ISystem::LanguageType::HINDI:
|
||||
languageStr = "hi";
|
||||
break;
|
||||
default:
|
||||
languageStr = "unknown";
|
||||
break;
|
||||
}
|
||||
return languageStr;
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
91
cocos/platform/interfaces/modules/ISystem.h
Normal file
91
cocos/platform/interfaces/modules/ISystem.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL ISystem : public OSInterface {
|
||||
public:
|
||||
~ISystem() override;
|
||||
enum class LanguageType {
|
||||
ENGLISH = 0,
|
||||
CHINESE,
|
||||
FRENCH,
|
||||
ITALIAN,
|
||||
GERMAN,
|
||||
SPANISH,
|
||||
DUTCH,
|
||||
RUSSIAN,
|
||||
KOREAN,
|
||||
JAPANESE,
|
||||
HUNGARIAN,
|
||||
PORTUGUESE,
|
||||
ARABIC,
|
||||
NORWEGIAN,
|
||||
POLISH,
|
||||
TURKISH,
|
||||
UKRAINIAN,
|
||||
ROMANIAN,
|
||||
BULGARIAN,
|
||||
HINDI
|
||||
};
|
||||
enum class OSType {
|
||||
WINDOWS, /**< Windows */
|
||||
LINUX, /**< Linux */
|
||||
MAC, /**< Mac OS X*/
|
||||
ANDROIDOS, /**< Android, because ANDROID is a macro, so use ANDROIDOS instead */
|
||||
IPHONE, /**< iPhone */
|
||||
IPAD, /**< iPad */
|
||||
OHOS, /**< HarmonyOS> */
|
||||
OPENHARMONY, /**< OpenHarmony> */
|
||||
QNX, /**< QNX */
|
||||
};
|
||||
/**
|
||||
@brief Get target system type.
|
||||
*/
|
||||
virtual OSType getOSType() const = 0;
|
||||
|
||||
//
|
||||
virtual ccstd::string getDeviceModel() const = 0;
|
||||
virtual LanguageType getCurrentLanguage() const = 0;
|
||||
virtual ccstd::string getCurrentLanguageCode() const = 0;
|
||||
virtual ccstd::string getSystemVersion() const = 0;
|
||||
|
||||
virtual ccstd::string getCurrentLanguageToString();
|
||||
|
||||
virtual void copyTextToClipboard(const ccstd::string& text) = 0;
|
||||
/**
|
||||
@brief Open url in default browser.
|
||||
@param String with url to open.
|
||||
@return True if the resource located by the URL was successfully opened; otherwise false.
|
||||
*/
|
||||
virtual bool openURL(const ccstd::string& url) = 0;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
107
cocos/platform/interfaces/modules/ISystemWindow.h
Normal file
107
cocos/platform/interfaces/modules/ISystemWindow.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include "base/std/container/array.h"
|
||||
#include "math/Geometry.h"
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL ISystemWindow : public OSInterface {
|
||||
public:
|
||||
static constexpr uint32_t mainWindowId = 1;
|
||||
|
||||
using Size = cc::Size;
|
||||
enum WindowFlags {
|
||||
/* !!! FIXME: change this to name = (1<<x). */
|
||||
CC_WINDOW_FULLSCREEN = 0x00000001, /**< fullscreen window */
|
||||
CC_WINDOW_OPENGL = 0x00000002, /**< window usable with OpenGL context */
|
||||
CC_WINDOW_SHOWN = 0x00000004, /**< window is visible */
|
||||
CC_WINDOW_HIDDEN = 0x00000008, /**< window is not visible */
|
||||
CC_WINDOW_BORDERLESS = 0x00000010, /**< no window decoration */
|
||||
CC_WINDOW_RESIZABLE = 0x00000020, /**< window can be resized */
|
||||
CC_WINDOW_MINIMIZED = 0x00000040, /**< window is minimized */
|
||||
CC_WINDOW_MAXIMIZED = 0x00000080, /**< window is maximized */
|
||||
CC_WINDOW_INPUT_GRABBED = 0x00000100, /**< window has grabbed input focus */
|
||||
CC_WINDOW_INPUT_FOCUS = 0x00000200, /**< window has input focus */
|
||||
CC_WINDOW_MOUSE_FOCUS = 0x00000400, /**< window has mouse focus */
|
||||
CC_WINDOW_FULLSCREEN_DESKTOP = (CC_WINDOW_FULLSCREEN | 0x00001000),
|
||||
CC_WINDOW_FOREIGN = 0x00000800, /**< window not created by SDL */
|
||||
CC_WINDOW_ALLOW_HIGHDPI = 0x00002000, /**< window should be created in high-DPI mode if supported.
|
||||
On macOS NSHighResolutionCapable must be set true in the
|
||||
application's Info.plist for this to have any effect. */
|
||||
CC_WINDOW_MOUSE_CAPTURE = 0x00004000, /**< window has mouse captured (unrelated to INPUT_GRABBED) */
|
||||
CC_WINDOW_ALWAYS_ON_TOP = 0x00008000, /**< window should always be above others */
|
||||
CC_WINDOW_SKIP_TASKBAR = 0x00010000, /**< window should not be added to the taskbar */
|
||||
CC_WINDOW_UTILITY = 0x00020000, /**< window should be treated as a utility window */
|
||||
CC_WINDOW_TOOLTIP = 0x00040000, /**< window should be treated as a tooltip */
|
||||
CC_WINDOW_POPUP_MENU = 0x00080000, /**< window should be treated as a popup menu */
|
||||
CC_WINDOW_VULKAN = 0x10000000 /**< window usable for Vulkan surface */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Create window.
|
||||
*@param title: Window title
|
||||
*@param x: x-axis coordinate
|
||||
*@param y: y-axis coordinate
|
||||
*@param w: Window width
|
||||
*@param h: Window height
|
||||
*@param flags: Window flag
|
||||
*/
|
||||
virtual bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @brief Create a window displayed in the bottom left.
|
||||
*@param title: Window title
|
||||
*@param w: Window width
|
||||
*@param h: Window height
|
||||
*@param flags: Window flag
|
||||
*/
|
||||
virtual bool createWindow(const char* title,
|
||||
int w, int h, int flags) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the window's unique ID
|
||||
*/
|
||||
virtual uint32_t getWindowId() const = 0;
|
||||
|
||||
virtual void closeWindow() {}
|
||||
virtual uintptr_t getWindowHandle() const = 0;
|
||||
virtual Size getViewSize() const = 0;
|
||||
virtual void setViewSize(uint32_t width, uint32_t height) {}
|
||||
/**
|
||||
@brief enable/disable(lock) the cursor, default is enabled
|
||||
*/
|
||||
virtual void setCursorEnabled(bool value) = 0;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
78
cocos/platform/interfaces/modules/ISystemWindowManager.h
Normal file
78
cocos/platform/interfaces/modules/ISystemWindowManager.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
|
||||
namespace cc {
|
||||
class ISystemWindow;
|
||||
|
||||
struct ISystemWindowInfo {
|
||||
ccstd::string title;
|
||||
int32_t x{-1};
|
||||
int32_t y{-1};
|
||||
int32_t width{-1};
|
||||
int32_t height{-1};
|
||||
int32_t flags{-1};
|
||||
void *externalHandle{nullptr};
|
||||
};
|
||||
|
||||
// key: window id
|
||||
using SystemWindowMap = ccstd::unordered_map<uint32_t, std::shared_ptr<ISystemWindow>>;
|
||||
|
||||
/**
|
||||
* Responsible for creating, finding ISystemWindow object and message handling
|
||||
*/
|
||||
class ISystemWindowManager : public OSInterface {
|
||||
public:
|
||||
/**
|
||||
* Initialize the NativeWindow environment
|
||||
* @return 0 Succeed -1 Failed
|
||||
*/
|
||||
virtual int init() = 0;
|
||||
|
||||
/**
|
||||
* Process messages at the PAL layer
|
||||
*/
|
||||
virtual void processEvent() = 0;
|
||||
|
||||
/**
|
||||
* Create an ISystemWindow object
|
||||
* @param info window description
|
||||
* @return The created ISystemWindow object,if failed then return nullptr
|
||||
*/
|
||||
virtual ISystemWindow *createWindow(const ISystemWindowInfo &info) = 0;
|
||||
|
||||
/**
|
||||
* Find an ISystemWindow object
|
||||
* @param windowId unique ID of window
|
||||
*/
|
||||
virtual ISystemWindow *getWindow(uint32_t windowId) const = 0;
|
||||
|
||||
/**
|
||||
* Retrive all windows
|
||||
*/
|
||||
virtual const SystemWindowMap &getWindows() const = 0;
|
||||
};
|
||||
} // namespace cc
|
||||
44
cocos/platform/interfaces/modules/IVibrator.h
Normal file
44
cocos/platform/interfaces/modules/IVibrator.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL IVibrator : public OSInterface {
|
||||
public:
|
||||
IVibrator() = default;
|
||||
/**
|
||||
* Vibrate for the specified amount of time.
|
||||
* If vibrate is not supported, then invoking this method has no effect.
|
||||
* Some platforms limit to a maximum duration of 5 seconds.
|
||||
* Duration is ignored on iOS due to API limitations.
|
||||
* @param duration The duration in seconds.
|
||||
*/
|
||||
virtual void vibrate(float duration) = 0;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
340
cocos/platform/interfaces/modules/IXRInterface.h
Normal file
340
cocos/platform/interfaces/modules/IXRInterface.h
Normal file
@@ -0,0 +1,340 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include "base/std/container/array.h"
|
||||
#include "gfx-base/GFXDef-common.h"
|
||||
#include "math/Vec2.h"
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
#if CC_USE_VULKAN
|
||||
#include "vulkan/vulkan_core.h"
|
||||
#endif
|
||||
#include "XRCommon.h"
|
||||
namespace cc {
|
||||
// forward declare
|
||||
namespace gfx {
|
||||
class GLES3GPUContext;
|
||||
}
|
||||
namespace scene {
|
||||
class Camera;
|
||||
}
|
||||
|
||||
enum class EGLSurfaceType {
|
||||
NONE,
|
||||
WINDOW,
|
||||
PBUFFER
|
||||
};
|
||||
|
||||
/**
|
||||
* @en Mainly responsible for the docking work of the engine and the xr library
|
||||
* @zh 主要负责引擎与xr库的对接工作
|
||||
*/
|
||||
class CC_DLL IXRInterface : public OSInterface {
|
||||
public:
|
||||
/**
|
||||
* @en get xr device vendor
|
||||
* @zh 获取XR设备品牌
|
||||
* @return xr::XRVendor
|
||||
*/
|
||||
virtual xr::XRVendor getVendor() = 0;
|
||||
|
||||
/**
|
||||
* @en get xr config parameter
|
||||
* @zh 获取XR配置参数
|
||||
*/
|
||||
virtual xr::XRConfigValue getXRConfig(xr::XRConfigKey key) = 0;
|
||||
|
||||
/**
|
||||
* @en set xr config parameter
|
||||
* @zh 设置XR配置参数
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
virtual void setXRConfig(xr::XRConfigKey key, xr::XRConfigValue value) = 0;
|
||||
|
||||
/**
|
||||
* @en get XR runtime version
|
||||
* @zh 获取XR运行时版本号
|
||||
* @return
|
||||
*/
|
||||
virtual uint32_t getRuntimeVersion() = 0;
|
||||
/**
|
||||
* @en initialize xr runtime envirment
|
||||
* @zh 初始化XR运行环境
|
||||
* @param javaVM android JVM
|
||||
* @param activity android activity
|
||||
*/
|
||||
virtual void initialize(void *javaVM, void *activity) = 0;
|
||||
|
||||
// render thread lifecycle
|
||||
/**
|
||||
* @en call when render pause
|
||||
* @zh 渲染暂停时调用
|
||||
*/
|
||||
virtual void onRenderPause() = 0;
|
||||
/**
|
||||
* @en call when render resume
|
||||
* @zh 渲染恢复时调用
|
||||
*/
|
||||
virtual void onRenderResume() = 0;
|
||||
/**
|
||||
* @en call when render destroy
|
||||
* @zh 渲染结束退出时调用
|
||||
*/
|
||||
virtual void onRenderDestroy() = 0;
|
||||
// render thread lifecycle
|
||||
|
||||
// gfx
|
||||
/**
|
||||
* @en call before gfx device initialize
|
||||
* @zh GFX设备初始化前调用
|
||||
* @param gfxApi
|
||||
*/
|
||||
virtual void preGFXDeviceInitialize(gfx::API gfxApi) = 0;
|
||||
/**
|
||||
* @en call after gfx device initialize
|
||||
* @zh GFX设备初始化后调用
|
||||
* @param gfxApi
|
||||
*/
|
||||
virtual void postGFXDeviceInitialize(gfx::API gfxApi) = 0;
|
||||
/**
|
||||
* @en call when gfx device acquire
|
||||
* @zh GFX设备请求渲染
|
||||
* @param gfxApi
|
||||
* @return
|
||||
*/
|
||||
virtual const xr::XRSwapchain &doGFXDeviceAcquire(gfx::API gfxApi) = 0;
|
||||
/**
|
||||
* @en call when gfx device present
|
||||
* @zh GFX设备是否需要展示操作
|
||||
*/
|
||||
virtual bool isGFXDeviceNeedsPresent(gfx::API gfxApi) = 0;
|
||||
/**
|
||||
* @en call after gfx device present
|
||||
* @zh GFX设备展示操作执行之后调用
|
||||
* @param gfxApi
|
||||
*/
|
||||
virtual void postGFXDevicePresent(gfx::API gfxApi) = 0;
|
||||
/**
|
||||
* @en call when create gfx device's swapchain
|
||||
* @zh 创建GFX交换链时调用
|
||||
*/
|
||||
virtual void createXRSwapchains() = 0;
|
||||
/**
|
||||
* @en get xr swapchain list
|
||||
* @zh 获取XR交换链列表
|
||||
* @return
|
||||
*/
|
||||
virtual const std::vector<cc::xr::XRSwapchain> &getXRSwapchains() = 0;
|
||||
/**
|
||||
* @en get xr swapchain's format
|
||||
* @zh 获取XR交换链格式
|
||||
* @return
|
||||
*/
|
||||
virtual gfx::Format getXRSwapchainFormat() = 0;
|
||||
/**
|
||||
* @en bind engine's swapchain with xr swapchain
|
||||
* @zh 绑定引擎交换链与XR交换链对应关系
|
||||
* @param typedID engine swapchain's type id
|
||||
*/
|
||||
virtual void updateXRSwapchainTypedID(uint32_t typedID) = 0;
|
||||
// gfx
|
||||
|
||||
// vulkan
|
||||
#ifdef CC_USE_VULKAN
|
||||
/**
|
||||
* @en get the vk version required by XR
|
||||
* @zh 获取XR要求的VK版本信息
|
||||
* @param engineVkApiVersion engine's vk version
|
||||
*/
|
||||
virtual uint32_t getXRVkApiVersion(uint32_t engineVkApiVersion) = 0;
|
||||
/**
|
||||
* @en initialize vulkan envirment
|
||||
* @zh 初始化vk运行环境
|
||||
* @param addr
|
||||
*/
|
||||
virtual void initializeVulkanData(const PFN_vkGetInstanceProcAddr &addr) = 0;
|
||||
/**
|
||||
* @en create vulkan instance
|
||||
* @zh 创建vk实例
|
||||
* @param instInfo
|
||||
* @return
|
||||
*/
|
||||
virtual VkInstance createXRVulkanInstance(const VkInstanceCreateInfo &instInfo) = 0;
|
||||
/**
|
||||
* @en create vulkan device
|
||||
* @zh 创建vk逻辑设备
|
||||
* @param deviceInfo
|
||||
* @return
|
||||
*/
|
||||
virtual VkDevice createXRVulkanDevice(const VkDeviceCreateInfo *deviceInfo) = 0;
|
||||
/**
|
||||
* @en get vulkan physical device
|
||||
* @zh 获取vk物理设备
|
||||
* @return
|
||||
*/
|
||||
virtual VkPhysicalDevice getXRVulkanGraphicsDevice() = 0;
|
||||
/**
|
||||
* @en get vkImage list from xrswapchain
|
||||
* @zh 获取xr交换链中vkimage列表
|
||||
* @param vkImages
|
||||
* @param eye
|
||||
*/
|
||||
virtual void getXRSwapchainVkImages(std::vector<VkImage> &vkImages, uint32_t eye) = 0;
|
||||
#endif
|
||||
// vulkan
|
||||
|
||||
// gles3
|
||||
#ifdef CC_USE_GLES3
|
||||
/**
|
||||
* @en initialize gles envirment
|
||||
* @zh 初始化gles运行环境
|
||||
* @param gles3wLoadFuncProc
|
||||
* @param gpuContext
|
||||
*/
|
||||
virtual void initializeGLESData(xr::PFNGLES3WLOADPROC gles3wLoadFuncProc, gfx::GLES3GPUContext *gpuContext) = 0;
|
||||
/**
|
||||
* @en attach current texture id to fbo
|
||||
* @zh 绑定当前纹理到帧缓冲区
|
||||
*/
|
||||
virtual void attachGLESFramebufferTexture2D() = 0;
|
||||
/**
|
||||
* @en acquire EGLSurfaceType by engine swapchain's type id
|
||||
* @zh 根据引擎交换链获取对应需要创建的EGLSurface类型
|
||||
* @param typedID
|
||||
* @return
|
||||
*/
|
||||
virtual EGLSurfaceType acquireEGLSurfaceType(uint32_t typedID) = 0;
|
||||
#endif
|
||||
// gles3
|
||||
|
||||
// stereo render loop
|
||||
/**
|
||||
* @en call when platform loop start
|
||||
* @zh 平台循环开始时调用
|
||||
* @return
|
||||
*/
|
||||
virtual bool platformLoopStart() = 0;
|
||||
/**
|
||||
* @en call when frame render begin
|
||||
* @zh 一帧开始时调用
|
||||
* @return
|
||||
*/
|
||||
virtual bool beginRenderFrame() = 0;
|
||||
/**
|
||||
* @en whether the current frame allows rendering
|
||||
* @zh 当前帧是否允许渲染
|
||||
* @return
|
||||
*/
|
||||
virtual bool isRenderAllowable() = 0;
|
||||
/**
|
||||
* @en call when single eye render begin
|
||||
* @zh 单眼渲染开始时调用
|
||||
* @param eye
|
||||
* @return
|
||||
*/
|
||||
virtual bool beginRenderEyeFrame(uint32_t eye) = 0;
|
||||
/**
|
||||
* @en call when single eye render end
|
||||
* @zh 单眼渲染结束时调用
|
||||
* @param eye
|
||||
* @return
|
||||
*/
|
||||
virtual bool endRenderEyeFrame(uint32_t eye) = 0;
|
||||
/**
|
||||
* @en call when frame render end
|
||||
* @zh 一帧结束时调用
|
||||
* @return
|
||||
*/
|
||||
virtual bool endRenderFrame() = 0;
|
||||
/**
|
||||
* @en call when platform loop end
|
||||
* @zh 平台循环结束时调用
|
||||
* @return
|
||||
*/
|
||||
virtual bool platformLoopEnd() = 0;
|
||||
// stereo render loop
|
||||
|
||||
/**
|
||||
* @en get hmd view position data
|
||||
* @zh 获取hmd双眼位置坐标
|
||||
* @param eye
|
||||
* @return
|
||||
*/
|
||||
virtual ccstd::vector<float> getHMDViewPosition(uint32_t eye, int trackingType) = 0;
|
||||
|
||||
/**
|
||||
* @en get xr view projection data
|
||||
* @zh 获取xr双眼投影矩阵数据
|
||||
* @param eye
|
||||
* @param near
|
||||
* @param far
|
||||
* @return
|
||||
*/
|
||||
virtual ccstd::vector<float> getXRViewProjectionData(uint32_t eye, float near, float far) = 0;
|
||||
|
||||
/**
|
||||
* @en get xr eye's fov
|
||||
* @zh 获取xr双眼视场角
|
||||
* @param eye
|
||||
* @return
|
||||
*/
|
||||
virtual ccstd::vector<float> getXREyeFov(uint32_t eye) = 0;
|
||||
|
||||
// renderwindow
|
||||
/**
|
||||
* @en get renderwindow's xreye type
|
||||
* @zh 获取当前RenderWindow的XREye类型
|
||||
* @param window
|
||||
* @return
|
||||
*/
|
||||
virtual xr::XREye getXREyeByRenderWindow(void *window) = 0;
|
||||
/**
|
||||
* @en bind renderwindow with xr eye
|
||||
* @zh 建立RenderWindow与XREye的对应关系
|
||||
* @param window
|
||||
* @param eye
|
||||
*/
|
||||
virtual void bindXREyeWithRenderWindow(void *window, xr::XREye eye) = 0;
|
||||
|
||||
/**
|
||||
* @en app's lifecycle callback
|
||||
* @zh 应用程序生命周期回调
|
||||
* @param appCmd
|
||||
*/
|
||||
virtual void handleAppCommand(int appCmd) = 0;
|
||||
|
||||
/**
|
||||
* @en adapt orthographic matrix(projection and view)
|
||||
* @zh 适配正交相机
|
||||
* @param camera
|
||||
* @param preTransform
|
||||
* @param proj
|
||||
* @param view
|
||||
*/
|
||||
virtual void adaptOrthographicMatrix(cc::scene::Camera *camera, const ccstd::array<float, 4> &preTransform, Mat4 &proj, Mat4 &view) = 0;
|
||||
};
|
||||
} // namespace cc
|
||||
428
cocos/platform/interfaces/modules/XRCommon.h
Normal file
428
cocos/platform/interfaces/modules/XRCommon.h
Normal file
@@ -0,0 +1,428 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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 XR_COMMON_H_
|
||||
#define XR_COMMON_H_
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace cc {
|
||||
namespace xr {
|
||||
#define XR_INTERFACE_RUNTIME_VERSION_1_0 1
|
||||
|
||||
enum class XREye {
|
||||
NONE = -1,
|
||||
LEFT = 0,
|
||||
RIGHT = 1,
|
||||
MONO = 2
|
||||
};
|
||||
|
||||
enum class XRVendor {
|
||||
MONADO,
|
||||
META,
|
||||
HUAWEIVR,
|
||||
PICO,
|
||||
ROKID,
|
||||
SEED,
|
||||
SPACESXR,
|
||||
GSXR,
|
||||
YVR,
|
||||
HTC,
|
||||
IQIYI,
|
||||
SKYWORTH,
|
||||
FFALCON,
|
||||
NREAL,
|
||||
INMO,
|
||||
LENOVO
|
||||
};
|
||||
|
||||
enum class XRConfigKey {
|
||||
MULTI_SAMPLES = 0,
|
||||
RENDER_SCALE = 1,
|
||||
SESSION_RUNNING = 2,
|
||||
INSTANCE_CREATED = 3,
|
||||
VK_QUEUE_FAMILY_INDEX = 4,
|
||||
METRICS_STATE = 5,
|
||||
VIEW_COUNT = 6,
|
||||
SWAPCHAIN_WIDTH = 7,
|
||||
SWAPCHAIN_HEIGHT = 8,
|
||||
SWAPCHAIN_FORMAT = 9,
|
||||
MULTITHREAD_MODE = 10,
|
||||
LOGIC_THREAD_ID = 11,
|
||||
RENDER_THREAD_ID = 12,
|
||||
DEVICE_VENDOR = 13,
|
||||
RUNTIME_VERSION = 14,
|
||||
PRESENT_ENABLE = 15,
|
||||
RENDER_EYE_FRAME_LEFT = 16,
|
||||
RENDER_EYE_FRAME_RIGHT = 17,
|
||||
FEATURE_PASSTHROUGH = 18,
|
||||
IMAGE_TRACKING = 19,
|
||||
IMAGE_TRACKING_CANDIDATEIMAGE = 20,
|
||||
IMAGE_TRACKING_DATA = 21,
|
||||
IMAGE_TRACKING_SUPPORT_STATUS = 22,
|
||||
HIT_TESTING = 23,
|
||||
HIT_TESTING_DATA = 24,
|
||||
HIT_TESTING_SUPPORT_STATUS = 25,
|
||||
PLANE_DETECTION = 26,
|
||||
PLANE_DETECTION_DATA = 27,
|
||||
PLANE_DETECTION_SUPPORT_STATUS = 28,
|
||||
SPATIAL_ANCHOR = 29,
|
||||
SPATIAL_ANCHOR_DATA = 30,
|
||||
SPATIAL_ANCHOR_SUPPORT_STATUS = 31,
|
||||
HAND_TRACKING = 32,
|
||||
HAND_TRACKING_DATA = 33,
|
||||
HAND_TRACKING_SUPPORT_STATUS = 34,
|
||||
APPLY_HAPTIC_CONTROLLER = 35,
|
||||
STOP_HAPTIC_CONTROLLER = 36,
|
||||
DEVICE_IPD = 37,
|
||||
APP_COMMAND = 38,
|
||||
ADB_COMMAND = 39,
|
||||
ACTIVITY_LIFECYCLE = 40,
|
||||
NATIVE_WINDOW = 41,
|
||||
SPLIT_AR_GLASSES = 42,
|
||||
ENGINE_VERSION = 43,
|
||||
RECENTER_HMD = 44,
|
||||
RECENTER_CONTROLLER = 45,
|
||||
FOVEATION_LEVEL = 46,
|
||||
DISPLAY_REFRESH_RATE = 47,
|
||||
CAMERA_ACCESS = 48,
|
||||
CAMERA_ACCESS_DATA = 49,
|
||||
CAMERA_ACCESS_SUPPORT_STATUS = 50,
|
||||
SPATIAL_MESHING = 51,
|
||||
SPATIAL_MESHING_DATA = 52,
|
||||
SPATIAL_MESHING_SUPPORT_STATUS = 53,
|
||||
EYE_RENDER_JS_CALLBACK = 54,
|
||||
ASYNC_LOAD_ASSETS_IMAGE = 55,
|
||||
ASYNC_LOAD_ASSETS_IMAGE_RESULTS = 56,
|
||||
LEFT_CONTROLLER_ACTIVE = 57,
|
||||
RIGHT_CONTROLLER_ACTIVE= 58,
|
||||
TS_EVENT_CALLBACK = 59,
|
||||
MAX_COUNT
|
||||
};
|
||||
|
||||
enum class XRConfigValueType {
|
||||
UNKNOWN,
|
||||
INT,
|
||||
FLOAT,
|
||||
BOOL,
|
||||
STRING,
|
||||
VOID_POINTER
|
||||
};
|
||||
|
||||
struct XRConfigValue {
|
||||
int vInt = 0;
|
||||
float vFloat = 0;
|
||||
bool vBool = false;
|
||||
void *vPtr = nullptr;
|
||||
std::string vString;
|
||||
XRConfigValueType valueType = XRConfigValueType::UNKNOWN;
|
||||
bool isInt() {
|
||||
return valueType == XRConfigValueType::INT;
|
||||
}
|
||||
|
||||
bool isFloat() {
|
||||
return valueType == XRConfigValueType::FLOAT;
|
||||
}
|
||||
|
||||
bool isBool() {
|
||||
return valueType == XRConfigValueType::BOOL;
|
||||
}
|
||||
|
||||
bool isPointer() {
|
||||
return valueType == XRConfigValueType::VOID_POINTER;
|
||||
}
|
||||
|
||||
bool isString() {
|
||||
return valueType == XRConfigValueType::STRING;
|
||||
}
|
||||
|
||||
bool getBool() {
|
||||
return vBool;
|
||||
}
|
||||
|
||||
int getInt() {
|
||||
return vInt;
|
||||
}
|
||||
|
||||
float getFloat() {
|
||||
return vFloat;
|
||||
}
|
||||
|
||||
std::string getString() {
|
||||
return vString;
|
||||
}
|
||||
|
||||
void *getPointer() {
|
||||
return vPtr;
|
||||
}
|
||||
|
||||
XRConfigValue() {
|
||||
}
|
||||
|
||||
XRConfigValue(int value) {
|
||||
valueType = XRConfigValueType::INT;
|
||||
vInt = value;
|
||||
}
|
||||
|
||||
XRConfigValue(float value) {
|
||||
valueType = XRConfigValueType::FLOAT;
|
||||
vFloat = value;
|
||||
}
|
||||
|
||||
XRConfigValue(std::string value) {
|
||||
valueType = XRConfigValueType::STRING;
|
||||
vString = value;
|
||||
}
|
||||
|
||||
XRConfigValue(bool value) {
|
||||
valueType = XRConfigValueType::BOOL;
|
||||
vBool = value;
|
||||
}
|
||||
|
||||
XRConfigValue(void *value) {
|
||||
valueType = XRConfigValueType::VOID_POINTER;
|
||||
vPtr = value;
|
||||
}
|
||||
};
|
||||
|
||||
enum class XREventType {
|
||||
CLICK,
|
||||
STICK,
|
||||
GRAB,
|
||||
POSE,
|
||||
TOUCH,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
struct XRControllerInfo {
|
||||
virtual ~XRControllerInfo() = default;
|
||||
virtual XREventType getXREventType() const = 0;
|
||||
};
|
||||
|
||||
struct XRClick : public XRControllerInfo {
|
||||
enum class Type {
|
||||
TRIGGER_LEFT,
|
||||
SHOULDER_LEFT,
|
||||
THUMBSTICK_LEFT,
|
||||
X,
|
||||
Y,
|
||||
MENU,
|
||||
TRIGGER_RIGHT,
|
||||
SHOULDER_RIGHT,
|
||||
THUMBSTICK_RIGHT,
|
||||
A,
|
||||
B,
|
||||
HOME,
|
||||
BACK,
|
||||
START,
|
||||
DPAD_UP,
|
||||
DPAD_DOWN,
|
||||
DPAD_LEFT,
|
||||
DPAD_RIGHT,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
bool isPress = false;
|
||||
Type type = Type::UNKNOWN;
|
||||
|
||||
XRClick(Type type, bool isPress)
|
||||
: type(type),
|
||||
isPress(isPress) {}
|
||||
|
||||
XREventType getXREventType() const override {
|
||||
return XREventType::CLICK;
|
||||
}
|
||||
};
|
||||
|
||||
struct XRStick : public XRControllerInfo {
|
||||
enum class Type {
|
||||
STICK_LEFT,
|
||||
STICK_RIGHT,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
bool isActive = false;
|
||||
float x = 0.F;
|
||||
float y = 0.F;
|
||||
Type type = Type::UNKNOWN;
|
||||
|
||||
XRStick(Type type, bool isActive)
|
||||
: type(type),
|
||||
isActive(isActive) {}
|
||||
|
||||
XRStick(Type type, float x, float y)
|
||||
: type(type),
|
||||
isActive(true),
|
||||
x(x),
|
||||
y(y) {}
|
||||
|
||||
XREventType getXREventType() const override {
|
||||
return XREventType::STICK;
|
||||
}
|
||||
};
|
||||
|
||||
struct XRGrab : public XRControllerInfo {
|
||||
enum class Type {
|
||||
TRIGGER_LEFT,
|
||||
GRIP_LEFT,
|
||||
TRIGGER_RIGHT,
|
||||
GRIP_RIGHT,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
bool isActive = false;
|
||||
float value = 0.F;
|
||||
Type type = Type::UNKNOWN;
|
||||
|
||||
XRGrab(Type type, bool isActive)
|
||||
: type(type),
|
||||
isActive(isActive) {}
|
||||
|
||||
XRGrab(Type type, float value)
|
||||
: type(type),
|
||||
isActive(true),
|
||||
value(value) {}
|
||||
|
||||
XREventType getXREventType() const override {
|
||||
return XREventType::GRAB;
|
||||
}
|
||||
};
|
||||
|
||||
struct XRTouch : public XRControllerInfo {
|
||||
enum class Type {
|
||||
TOUCH_A,
|
||||
TOUCH_B,
|
||||
TOUCH_X,
|
||||
TOUCH_Y,
|
||||
TOUCH_TRIGGER_LEFT,
|
||||
TOUCH_TRIGGER_RIGHT,
|
||||
TOUCH_THUMBSTICK_LEFT,
|
||||
TOUCH_THUMBSTICK_RIGHT,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
bool isActive = false;
|
||||
float value = 0.F;
|
||||
Type type = Type::UNKNOWN;
|
||||
|
||||
XRTouch(Type type, bool isActive)
|
||||
: type(type),
|
||||
isActive(isActive) {}
|
||||
|
||||
XRTouch(Type type, float value)
|
||||
: type(type),
|
||||
isActive(true),
|
||||
value(value) {}
|
||||
|
||||
XREventType getXREventType() const override {
|
||||
return XREventType::TOUCH;
|
||||
}
|
||||
};
|
||||
|
||||
struct XRPose : public XRControllerInfo {
|
||||
enum class Type {
|
||||
VIEW_LEFT,
|
||||
HAND_LEFT,
|
||||
AIM_LEFT,
|
||||
VIEW_RIGHT,
|
||||
HAND_RIGHT,
|
||||
AIM_RIGHT,
|
||||
HEAD_MIDDLE,
|
||||
AR_MOBILE,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
bool isActive = false;
|
||||
float px = 0.F;
|
||||
float py = 0.F;
|
||||
float pz = 0.F;
|
||||
float qx = 0.F;
|
||||
float qy = 0.F;
|
||||
float qz = 0.F;
|
||||
float qw = 1.F;
|
||||
Type type = Type::UNKNOWN;
|
||||
|
||||
XRPose(Type type, bool isActive)
|
||||
: type(type),
|
||||
isActive(isActive) {}
|
||||
|
||||
XRPose(Type type, float position[3], float quaternion[4])
|
||||
: type(type), isActive(true), px(position[0]), py(position[1]), pz(position[2]), qx(quaternion[0]), qy(quaternion[1]), qz(quaternion[2]), qw(quaternion[3]) {}
|
||||
|
||||
XREventType getXREventType() const override {
|
||||
return XREventType::POSE;
|
||||
}
|
||||
};
|
||||
|
||||
struct XRControllerEvent {
|
||||
std::vector<std::unique_ptr<XRControllerInfo>> xrControllerInfos;
|
||||
};
|
||||
typedef std::function<void(const XRControllerEvent &xrControllerEvent)> XRControllerCallback;
|
||||
using PFNGLES3WLOADPROC = void *(*)(const char *);
|
||||
|
||||
typedef std::function<void(XRConfigKey, XRConfigValue)> XRConfigChangeCallback;
|
||||
|
||||
struct XRSwapchain {
|
||||
void *xrSwapchainHandle = nullptr;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
uint32_t glDrawFramebuffer = 0;
|
||||
uint32_t swapchainImageIndex = 0;
|
||||
uint32_t eye = 0;
|
||||
};
|
||||
|
||||
struct XRTrackingImageData {
|
||||
std::string friendlyName;
|
||||
uint32_t id;
|
||||
uint8_t *buffer;
|
||||
uint32_t bufferSize;
|
||||
float physicalWidth;
|
||||
float physicalHeight;
|
||||
uint32_t pixelSizeWidth;
|
||||
uint32_t pixelSizeHeight;
|
||||
float posePosition[3];
|
||||
float poseQuaternion[4];
|
||||
};
|
||||
|
||||
#define GraphicsApiOpenglES "OpenGLES"
|
||||
#define GraphicsApiVulkan_1_0 "Vulkan1"
|
||||
#define GraphicsApiVulkan_1_1 "Vulkan2"
|
||||
|
||||
enum class XRActivityLifecycleType {
|
||||
UnKnown,
|
||||
Created,
|
||||
Started,
|
||||
Resumed,
|
||||
Paused,
|
||||
Stopped,
|
||||
SaveInstanceState,
|
||||
Destroyed
|
||||
};
|
||||
|
||||
} // namespace xr
|
||||
} // namespace cc
|
||||
#endif // XR_COMMON_H_
|
||||
@@ -0,0 +1,452 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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/interfaces/modules/canvas/CanvasRenderingContext2D.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <regex>
|
||||
#include "base/csscolorparser.h"
|
||||
#include "cocos/bindings/jswrapper/SeApi.h"
|
||||
#include "cocos/bindings/manual/jsb_platform.h"
|
||||
#include "math/Math.h"
|
||||
#include "platform/FileUtils.h"
|
||||
|
||||
#if defined(CC_SERVER_MODE)
|
||||
#include "platform/empty/modules/CanvasRenderingContext2DDelegate.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_WINDOWS)
|
||||
#include "platform/win32/modules/CanvasRenderingContext2DDelegate.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_OHOS)
|
||||
#include "platform/java/modules/CanvasRenderingContext2DDelegate.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MACOS || CC_PLATFORM == CC_PLATFORM_IOS)
|
||||
#include "platform/apple/modules/CanvasRenderingContext2DDelegate.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_LINUX)
|
||||
#include "platform/linux/modules/CanvasRenderingContext2DDelegate.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_QNX)
|
||||
#include "platform/qnx/modules/CanvasRenderingContext2DDelegate.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_OPENHARMONY)
|
||||
#include "platform/openharmony/modules/CanvasRenderingContext2DDelegate.h"
|
||||
#endif
|
||||
|
||||
using Vec2 = ccstd::array<float, 2>;
|
||||
using Color4F = ccstd::array<float, 4>;
|
||||
|
||||
namespace cc {
|
||||
//using Size = ccstd::array<float, 2>;
|
||||
CanvasGradient::CanvasGradient() = default;
|
||||
|
||||
CanvasGradient::~CanvasGradient() = default;
|
||||
|
||||
void CanvasGradient::addColorStop(float offset, const ccstd::string &color) {
|
||||
//SE_LOGD("CanvasGradient::addColorStop: %p\n", this);
|
||||
}
|
||||
|
||||
// CanvasRenderingContext2D
|
||||
|
||||
CanvasRenderingContext2D::CanvasRenderingContext2D(float width, float height)
|
||||
: _width(width),
|
||||
_height(height) {
|
||||
_delegate = ccnew CanvasRenderingContext2DDelegate();
|
||||
//SE_LOGD("CanvasRenderingContext2D constructor: %p, width: %f, height: %f\n", this, width, height);
|
||||
}
|
||||
|
||||
CanvasRenderingContext2D::~CanvasRenderingContext2D() {
|
||||
delete _delegate;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::clearRect(float x, float y, float width, float height) {
|
||||
//SE_LOGD("CanvasRenderingContext2D::clearRect: %p, %f, %f, %f, %f\n", this, x, y, width, height);
|
||||
recreateBufferIfNeeded();
|
||||
_delegate->clearRect(x, y, width, height);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::fillRect(float x, float y, float width, float height) {
|
||||
recreateBufferIfNeeded();
|
||||
_delegate->fillRect(x, y, width, height);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::fillText(const ccstd::string &text, float x, float y, float maxWidth) {
|
||||
//SE_LOGD("CanvasRenderingContext2D::fillText: %s, offset: (%f, %f), %f\n", text.c_str(), x, y, maxWidth);
|
||||
if (text.empty()) {
|
||||
return;
|
||||
}
|
||||
recreateBufferIfNeeded();
|
||||
_delegate->fillText(text, x, y, maxWidth);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::strokeText(const ccstd::string &text, float x, float y, float maxWidth) {
|
||||
//SE_LOGD("CanvasRenderingContext2D::strokeText: %s, %f, %f, %f\n", text.c_str(), x, y, maxWidth);
|
||||
if (text.empty()) {
|
||||
return;
|
||||
}
|
||||
recreateBufferIfNeeded();
|
||||
_delegate->strokeText(text, x, y, maxWidth);
|
||||
}
|
||||
|
||||
cc::Size CanvasRenderingContext2D::measureText(const ccstd::string &text) {
|
||||
//SE_LOGD("CanvasRenderingContext2D::measureText: %s\n", text.c_str());
|
||||
auto s = _delegate->measureText(text);
|
||||
return cc::Size(s[0], s[1]);
|
||||
}
|
||||
|
||||
ICanvasGradient *CanvasRenderingContext2D::createLinearGradient(float /*x0*/, float /*y0*/, float /*x1*/, float /*y1*/) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::save() {
|
||||
//SE_LOGD("CanvasRenderingContext2D::save\n");
|
||||
_delegate->saveContext();
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::beginPath() {
|
||||
//SE_LOGD("\n-----------begin------------------\nCanvasRenderingContext2D::beginPath\n");
|
||||
recreateBufferIfNeeded();
|
||||
_delegate->beginPath();
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::closePath() {
|
||||
//SE_LOGD("CanvasRenderingContext2D::closePath\n");
|
||||
_delegate->closePath();
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::moveTo(float x, float y) {
|
||||
//SE_LOGD("CanvasRenderingContext2D::moveTo\n");
|
||||
_delegate->moveTo(x, y);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::lineTo(float x, float y) {
|
||||
//SE_LOGD("CanvasRenderingContext2D::lineTo\n");
|
||||
_delegate->lineTo(x, y);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::stroke() {
|
||||
//SE_LOGD("CanvasRenderingContext2D::stroke\n");
|
||||
recreateBufferIfNeeded();
|
||||
_delegate->stroke();
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::restore() {
|
||||
//SE_LOGD("CanvasRenderingContext2D::restore\n");
|
||||
_delegate->restoreContext();
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setCanvasBufferUpdatedCallback(const CanvasBufferUpdatedCallback &cb) {
|
||||
_canvasBufferUpdatedCB = cb;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::fetchData() {
|
||||
recreateBufferIfNeeded();
|
||||
_delegate->updateData();
|
||||
if (_canvasBufferUpdatedCB != nullptr) {
|
||||
_canvasBufferUpdatedCB(_delegate->getDataRef());
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setWidth(float width) {
|
||||
//SE_LOGD("CanvasRenderingContext2D::set__width: %f\n", width);
|
||||
if (math::isEqualF(width, _width)) return;
|
||||
_width = width;
|
||||
_isBufferSizeDirty = true;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setHeight(float height) {
|
||||
//SE_LOGD("CanvasRenderingContext2D::set__height: %f\n", height);
|
||||
if (math::isEqualF(height, _height)) return;
|
||||
_height = height;
|
||||
_isBufferSizeDirty = true;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setLineWidth(float lineWidth) {
|
||||
//SE_LOGD("CanvasRenderingContext2D::set_lineWidth %d\n", lineWidth);
|
||||
_lineWidth = lineWidth;
|
||||
_delegate->setLineWidth(lineWidth);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setLineCap(const ccstd::string &lineCap) {
|
||||
//SE_LOGE("%s isn't implemented!\n", __FUNCTION__);
|
||||
#if CC_PLATFORM == CC_PLATFORM_WINDOWS
|
||||
|
||||
#elif CC_PLATFORM == CC_PLATFORM_ANDROID
|
||||
if (lineCap.empty()) return;
|
||||
_delegate->setLineCap(lineCap);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setLineJoin(const ccstd::string &lineJoin) {
|
||||
//SE_LOGE("%s isn't implemented!\n", __FUNCTION__);
|
||||
_delegate->setLineJoin(lineJoin);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::fill() {
|
||||
// SE_LOGE("%s isn't implemented!\n", __FUNCTION__);
|
||||
#if CC_PLATFORM == CC_PLATFORM_WINDOWS
|
||||
|
||||
#elif CC_PLATFORM == CC_PLATFORM_ANDROID
|
||||
_delegate->fill();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::rect(float x, float y, float w, float h) {
|
||||
recreateBufferIfNeeded();
|
||||
#if CC_PLATFORM == CC_PLATFORM_WINDOWS
|
||||
// SE_LOGE("%s isn't implemented!\n", __FUNCTION__);
|
||||
#elif CC_PLATFORM == CC_PLATFORM_ANDROID
|
||||
// SE_LOGD("CanvasRenderingContext2D::rect: %p, %f, %f, %f, %f\n", this, x, y, width, height);
|
||||
_delegate->rect(x, y, w, h);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setFont(const ccstd::string &font) {
|
||||
recreateBufferIfNeeded();
|
||||
#if CC_PLATFORM == CC_PLATFORM_WINDOWS
|
||||
if (_font != font) {
|
||||
_font = font;
|
||||
|
||||
ccstd::string boldStr;
|
||||
ccstd::string fontName = "Arial";
|
||||
ccstd::string fontSizeStr = "30";
|
||||
|
||||
std::regex re(R"(\s*((\d+)([\.]\d+)?)px\s+([^\r\n]*))");
|
||||
std::match_results<ccstd::string::const_iterator> results;
|
||||
if (std::regex_search(_font.cbegin(), _font.cend(), results, re)) {
|
||||
fontSizeStr = results[2].str();
|
||||
// support get font name from `60px American` or `60px "American abc-abc_abc"`
|
||||
// support get font name contain space,example `times new roman`
|
||||
// if regex rule that does not conform to the rules,such as Chinese,it defaults to Arial
|
||||
std::match_results<ccstd::string::const_iterator> fontResults;
|
||||
std::regex fontRe(R"(([\w\s-]+|"[\w\s-]+"$))");
|
||||
ccstd::string tmp(results[4].str());
|
||||
if (std::regex_match(tmp, fontResults, fontRe)) {
|
||||
fontName = results[4].str();
|
||||
}
|
||||
}
|
||||
|
||||
auto fontSize = static_cast<float>(atof(fontSizeStr.c_str()));
|
||||
bool isBold = !boldStr.empty() || font.find("bold", 0) != ccstd::string::npos || font.find("Bold", 0) != ccstd::string::npos;
|
||||
bool isItalic = font.find("italic", 0) != ccstd::string::npos || font.find("Italic", 0) != ccstd::string::npos;
|
||||
_delegate->updateFont(fontName, static_cast<float>(fontSize), isBold, isItalic, false, false);
|
||||
}
|
||||
#elif CC_PLATFORM == CC_PLATFORM_QNX
|
||||
if (_font != font) {
|
||||
_font = font;
|
||||
|
||||
ccstd::string boldStr;
|
||||
ccstd::string fontName = "Arial";
|
||||
ccstd::string fontSizeStr = "30";
|
||||
|
||||
// support get font name from `60px American` or `60px "American abc-abc_abc"`
|
||||
std::regex re("(bold)?\\s*((\\d+)([\\.]\\d+)?)px\\s+([\\w-]+|\"[\\w -]+\"$)");
|
||||
std::match_results<ccstd::string::const_iterator> results;
|
||||
if (std::regex_search(_font.cbegin(), _font.cend(), results, re)) {
|
||||
boldStr = results[1].str();
|
||||
fontSizeStr = results[2].str();
|
||||
fontName = results[5].str();
|
||||
}
|
||||
bool isItalic = font.find("italic", 0) != ccstd::string::npos || font.find("Italic", 0) != ccstd::string::npos;
|
||||
auto fontSize = static_cast<float>(atof(fontSizeStr.c_str()));
|
||||
bool isBold = !boldStr.empty() || font.find("bold", 0) != ccstd::string::npos || font.find("Bold", 0) != ccstd::string::npos;
|
||||
//SE_LOGD("CanvasRenderingContext2D::set_font: %s, Size: %f, isBold: %b\n", fontName.c_str(), fontSize, isBold);
|
||||
_delegate->updateFont(fontName, fontSize, isBold, isItalic, false, false);
|
||||
}
|
||||
#elif CC_PLATFORM == CC_PLATFORM_LINUX
|
||||
if (_font != font) {
|
||||
_font = font;
|
||||
|
||||
ccstd::string fontName = "sans-serif";
|
||||
ccstd::string fontSizeStr = "30";
|
||||
std::regex re(R"(\s*((\d+)([\.]\d+)?)px\s+([^\r\n]*))");
|
||||
std::match_results<ccstd::string::const_iterator> results;
|
||||
if (std::regex_search(_font.cbegin(), _font.cend(), results, re)) {
|
||||
fontSizeStr = results[2].str();
|
||||
// support get font name from `60px American` or `60px "American abc-abc_abc"`
|
||||
// support get font name contain space,example `times new roman`
|
||||
// if regex rule that does not conform to the rules,such as Chinese,it defaults to sans-serif
|
||||
std::match_results<ccstd::string::const_iterator> fontResults;
|
||||
std::regex fontRe(R"(([\w\s-]+|"[\w\s-]+"$))");
|
||||
ccstd::string tmp(results[4].str());
|
||||
if (std::regex_match(tmp, fontResults, fontRe)) {
|
||||
//fontName = results[4].str();
|
||||
}
|
||||
}
|
||||
|
||||
bool isBold = font.find("bold", 0) != ccstd::string::npos || font.find("Bold", 0) != ccstd::string::npos;
|
||||
bool isItalic = font.find("italic", 0) != ccstd::string::npos || font.find("Italic", 0) != ccstd::string::npos;
|
||||
float fontSize = static_cast<float>(atof(fontSizeStr.c_str()));
|
||||
//SE_LOGD("CanvasRenderingContext2D::set_font: %s, Size: %f, isBold: %b\n", fontName.c_str(), fontSize, isBold);
|
||||
_delegate->updateFont(fontName, fontSize, isBold, isItalic, false, false);
|
||||
}
|
||||
#elif CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_OHOS || CC_PLATFORM == CC_PLATFORM_OPENHARMONY
|
||||
if (_font != font) {
|
||||
_font = font;
|
||||
ccstd::string fontName = "sans-serif";
|
||||
ccstd::string fontSizeStr = "30";
|
||||
std::regex re(R"(\s*((\d+)([\.]\d+)?)px\s+([^\r\n]*))");
|
||||
std::match_results<ccstd::string::const_iterator> results;
|
||||
if (std::regex_search(_font.cbegin(), _font.cend(), results, re)) {
|
||||
fontSizeStr = results[2].str();
|
||||
// support get font name from `60px American` or `60px "American abc-abc_abc"`
|
||||
// support get font name contain space,example `times new roman`
|
||||
// if regex rule that does not conform to the rules,such as Chinese,it defaults to sans-serif
|
||||
std::match_results<ccstd::string::const_iterator> fontResults;
|
||||
std::regex fontRe(R"(([\w\s-]+|"[\w\s-]+"$))");
|
||||
ccstd::string tmp(results[4].str());
|
||||
if (std::regex_match(tmp, fontResults, fontRe)) {
|
||||
fontName = results[4].str();
|
||||
}
|
||||
}
|
||||
|
||||
double fontSize = atof(fontSizeStr.c_str());
|
||||
bool isBold = font.find("bold", 0) != ccstd::string::npos || font.find("Bold", 0) != ccstd::string::npos;
|
||||
bool isItalic = font.find("italic", 0) != ccstd::string::npos || font.find("Italic", 0) != ccstd::string::npos;
|
||||
bool isSmallCaps = font.find("small-caps", 0) != ccstd::string::npos || font.find("Small-Caps") != ccstd::string::npos;
|
||||
bool isOblique = font.find("oblique", 0) != ccstd::string::npos || font.find("Oblique", 0) != ccstd::string::npos;
|
||||
//font-style: italic, oblique, normal
|
||||
//font-weight: normal, bold
|
||||
//font-variant: normal, small-caps
|
||||
_delegate->updateFont(fontName, static_cast<float>(fontSize), isBold, isItalic, isOblique, isSmallCaps);
|
||||
}
|
||||
#elif CC_PLATFORM == CC_PLATFORM_MACOS || CC_PLATFORM == CC_PLATFORM_IOS
|
||||
if (_font != font) {
|
||||
_font = font;
|
||||
|
||||
ccstd::string boldStr;
|
||||
ccstd::string fontName = "Arial";
|
||||
ccstd::string fontSizeStr = "30";
|
||||
bool isItalic = font.find("italic", 0) != ccstd::string::npos || font.find("Italic", 0) != ccstd::string::npos;
|
||||
|
||||
// support get font name from `60px American` or `60px "American abc-abc_abc"`
|
||||
std::regex re("(bold)?\\s*((\\d+)([\\.]\\d+)?)px\\s+([\\w-]+|\"[\\w -]+\"$)");
|
||||
std::match_results<ccstd::string::const_iterator> results;
|
||||
if (std::regex_search(_font.cbegin(), _font.cend(), results, re)) {
|
||||
boldStr = results[1].str();
|
||||
fontSizeStr = results[2].str();
|
||||
fontName = results[5].str();
|
||||
}
|
||||
float fontSize = atof(fontSizeStr.c_str());
|
||||
bool isBold = !boldStr.empty() || font.find("bold", 0) != ccstd::string::npos || font.find("Bold", 0) != ccstd::string::npos;
|
||||
_delegate->updateFont(fontName, static_cast<float>(fontSize), isBold, isItalic, false, false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setTextAlign(const ccstd::string &textAlign) {
|
||||
//SE_LOGD("CanvasRenderingContext2D::set_textAlign: %s\n", textAlign.c_str());
|
||||
if (textAlign == "left") {
|
||||
_delegate->setTextAlign(TextAlign::LEFT);
|
||||
} else if (textAlign == "center" || textAlign == "middle") {
|
||||
_delegate->setTextAlign(TextAlign::CENTER);
|
||||
} else if (textAlign == "right") {
|
||||
_delegate->setTextAlign(TextAlign::RIGHT);
|
||||
} else {
|
||||
CC_ABORT();
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setTextBaseline(const ccstd::string &textBaseline) {
|
||||
//SE_LOGD("CanvasRenderingContext2D::set_textBaseline: %s\n", textBaseline.c_str());
|
||||
if (textBaseline == "top") {
|
||||
_delegate->setTextBaseline(TextBaseline::TOP);
|
||||
} else if (textBaseline == "middle") {
|
||||
_delegate->setTextBaseline(TextBaseline::MIDDLE);
|
||||
} else if (textBaseline == "bottom") //REFINE:, how to deal with alphabetic, currently we handle it as bottom mode.
|
||||
{
|
||||
_delegate->setTextBaseline(TextBaseline::BOTTOM);
|
||||
} else if (textBaseline == "alphabetic") {
|
||||
_delegate->setTextBaseline(TextBaseline::ALPHABETIC);
|
||||
} else {
|
||||
CC_ABORT();
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setFillStyle(const ccstd::string &fillStyle) {
|
||||
CSSColorParser::Color color = CSSColorParser::parse(fillStyle);
|
||||
_delegate->setFillStyle(color.r, color.g, color.b, static_cast<uint8_t>(color.a * 255));
|
||||
//SE_LOGD("CanvasRenderingContext2D::set_fillStyle: %s, (%d, %d, %d, %f)\n", fillStyle.c_str(), color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setStrokeStyle(const ccstd::string &strokeStyle) {
|
||||
CSSColorParser::Color color = CSSColorParser::parse(strokeStyle);
|
||||
_delegate->setStrokeStyle(color.r, color.g, color.b, static_cast<uint8_t>(color.a * 255));
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setShadowBlur(float blur) {
|
||||
_delegate->setShadowBlur(blur);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setShadowColor(const ccstd::string &shadowColor) {
|
||||
CSSColorParser::Color color = CSSColorParser::parse(shadowColor);
|
||||
_delegate->setShadowColor(color.r, color.g, color.b, static_cast<uint8_t>(color.a * 255));
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setShadowOffsetX(float offsetX) {
|
||||
_delegate->setShadowOffsetX(offsetX);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setShadowOffsetY(float offsetY) {
|
||||
_delegate->setShadowOffsetY(offsetY);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setGlobalCompositeOperation(const ccstd::string &globalCompositeOperation) {
|
||||
//SE_LOGE("%s isn't implemented!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::fillImageData(const Data &imageData, float imageWidth, float imageHeight, float offsetX, float offsetY) {
|
||||
recreateBufferIfNeeded();
|
||||
//SE_LOGE("%s isn't implemented!\n", __FUNCTION__);
|
||||
#if CC_PLATFORM == CC_PLATFORM_WINDOWS
|
||||
#elif CC_PLATFORM == CC_PLATFORM_ANDROID
|
||||
_delegate->fillImageData(imageData, imageWidth, imageHeight, offsetX, offsetY);
|
||||
#endif
|
||||
}
|
||||
// transform
|
||||
//REFINE:
|
||||
|
||||
void CanvasRenderingContext2D::translate(float x, float y) {
|
||||
//SE_LOGE("%s isn't implemented!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::scale(float x, float y) {
|
||||
//SE_LOGE("%s isn't implemented!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::rotate(float angle) {
|
||||
//SE_LOGE("%s isn't implemented!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::transform(float a, float b, float c, float d, float e, float f) {
|
||||
//SE_LOGE("%s isn't implemented!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::setTransform(float a, float b, float c, float d, float e, float f) {
|
||||
//SE_LOGE("%s isn't implemented!\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::recreateBufferIfNeeded() {
|
||||
if (_isBufferSizeDirty) {
|
||||
_isBufferSizeDirty = false;
|
||||
//SE_LOGD("Recreate buffer %p, w: %f, h:%f\n", this, __width, __height);
|
||||
_delegate->recreateBuffer(_width, _height);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
@@ -0,0 +1,128 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "platform/interfaces/modules/canvas/ICanvasRenderingContext2D.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL CanvasGradient : public ICanvasGradient {
|
||||
public:
|
||||
CanvasGradient();
|
||||
~CanvasGradient() override; // NOLINT(performance-trivially-destructible)
|
||||
void addColorStop(float offset, const ccstd::string &color) override;
|
||||
};
|
||||
|
||||
class CC_DLL CanvasRenderingContext2D : public ICanvasRenderingContext2D {
|
||||
public:
|
||||
CanvasRenderingContext2D(float width, float height);
|
||||
~CanvasRenderingContext2D() override;
|
||||
|
||||
// Rect
|
||||
void rect(float x, float y, float width, float height) override;
|
||||
void clearRect(float x, float y, float width, float height) override;
|
||||
void fillRect(float x, float y, float width, float height) override;
|
||||
|
||||
void fillText(const ccstd::string &text, float x, float y, float maxWidth) override;
|
||||
void strokeText(const ccstd::string &text, float x, float y, float maxWidth) override;
|
||||
Size measureText(const ccstd::string &text) override;
|
||||
ICanvasGradient *createLinearGradient(float x0, float y0, float x1, float y1) override;
|
||||
void save() override;
|
||||
// Paths
|
||||
void beginPath() override;
|
||||
void closePath() override;
|
||||
void moveTo(float x, float y) override;
|
||||
void lineTo(float x, float y) override;
|
||||
void fill() override;
|
||||
void stroke() override;
|
||||
void restore() override;
|
||||
|
||||
// callback
|
||||
using CanvasBufferUpdatedCallback = std::function<void(const cc::Data &)>;
|
||||
void setCanvasBufferUpdatedCallback(const CanvasBufferUpdatedCallback &cb) override;
|
||||
void fetchData() override;
|
||||
|
||||
// functions for properties
|
||||
void setWidth(float width) override;
|
||||
void setHeight(float height) override;
|
||||
void setLineWidth(float lineWidth) override;
|
||||
void setLineJoin(const ccstd::string &lineJoin) override;
|
||||
void setLineCap(const ccstd::string &lineCap) override;
|
||||
void setFont(const ccstd::string &font) override;
|
||||
void setTextAlign(const ccstd::string &textAlign) override;
|
||||
void setTextBaseline(const ccstd::string &textBaseline) override;
|
||||
void setFillStyle(const ccstd::string &fillStyle) override;
|
||||
void setStrokeStyle(const ccstd::string &strokeStyle) override;
|
||||
void setGlobalCompositeOperation(const ccstd::string &globalCompositeOperation) override;
|
||||
void setShadowBlur(float blur) override;
|
||||
void setShadowColor(const ccstd::string &shadowColor) override;
|
||||
void setShadowOffsetX(float offsetX) override;
|
||||
void setShadowOffsetY(float offsetY) override;
|
||||
|
||||
// fill image data into Context2D
|
||||
void fillImageData(const Data &imageData, float imageWidth, float imageHeight, float offsetX, float offsetY) override;
|
||||
|
||||
// transform
|
||||
void translate(float x, float y) override;
|
||||
void scale(float x, float y) override;
|
||||
void rotate(float angle) override;
|
||||
|
||||
void transform(float a, float b, float c, float d, float e, float f) override;
|
||||
void setTransform(float a, float b, float c, float d, float e, float f) override;
|
||||
|
||||
private:
|
||||
void recreateBufferIfNeeded() override;
|
||||
|
||||
public:
|
||||
float _width = 0.0F;
|
||||
float _height = 0.0F;
|
||||
|
||||
// Line styles
|
||||
float _lineWidth = 1.0F;
|
||||
ccstd::string _lineJoin = "miter";
|
||||
ccstd::string _lineCap = "butt";
|
||||
|
||||
// Text styles
|
||||
ccstd::string _font = "10px sans-serif";
|
||||
ccstd::string _textAlign = "start";
|
||||
ccstd::string _textBaseline = "alphabetic";
|
||||
|
||||
// Fill and stroke styles
|
||||
ccstd::string _fillStyle = "#000";
|
||||
|
||||
ccstd::string _strokeStyle = "#000";
|
||||
|
||||
// Compositing
|
||||
ccstd::string _globalCompositeOperation = "source-over";
|
||||
|
||||
private:
|
||||
ICanvasRenderingContext2D::Delegate *_delegate;
|
||||
|
||||
CanvasBufferUpdatedCallback _canvasBufferUpdatedCB = nullptr;
|
||||
|
||||
bool _isBufferSizeDirty = true;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
@@ -0,0 +1,150 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2018-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/Data.h"
|
||||
#include "base/std/container/array.h"
|
||||
#include "base/std/container/string.h"
|
||||
#include "math/Geometry.h"
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL ICanvasGradient {
|
||||
public:
|
||||
ICanvasGradient() = default;
|
||||
virtual ~ICanvasGradient() = default; // NOLINT(performance-trivially-destructible)
|
||||
virtual void addColorStop(float offset, const ccstd::string &color) = 0;
|
||||
};
|
||||
|
||||
class CC_DLL ICanvasRenderingContext2D : public OSInterface {
|
||||
public:
|
||||
enum class TextAlign {
|
||||
LEFT,
|
||||
CENTER,
|
||||
RIGHT
|
||||
};
|
||||
|
||||
enum class TextBaseline {
|
||||
TOP,
|
||||
MIDDLE,
|
||||
BOTTOM,
|
||||
ALPHABETIC
|
||||
};
|
||||
|
||||
class Delegate {
|
||||
public:
|
||||
using Size = ccstd::array<float, 2>;
|
||||
virtual ~Delegate() = default;
|
||||
virtual void recreateBuffer(float w, float h) = 0;
|
||||
virtual void beginPath() = 0;
|
||||
virtual void closePath() = 0;
|
||||
virtual void moveTo(float x, float y) = 0;
|
||||
virtual void lineTo(float x, float y) = 0;
|
||||
virtual void stroke() = 0;
|
||||
virtual void saveContext() = 0;
|
||||
virtual void restoreContext() = 0;
|
||||
virtual void clearRect(float /*x*/, float /*y*/, float w, float h) = 0;
|
||||
virtual void fill() = 0;
|
||||
virtual void rect(float x, float y, float w, float h) = 0;
|
||||
virtual void setLineCap(const ccstd::string &lineCap) = 0;
|
||||
virtual void setLineJoin(const ccstd::string &lineCap) = 0;
|
||||
virtual void fillImageData(const Data &imageData, float imageWidth, float imageHeight, float offsetX, float offsetY) = 0;
|
||||
virtual void fillRect(float x, float y, float w, float h) = 0;
|
||||
virtual void fillText(const ccstd::string &text, float x, float y, float /*maxWidth*/) = 0;
|
||||
virtual void strokeText(const ccstd::string &text, float /*x*/, float /*y*/, float /*maxWidth*/) = 0;
|
||||
virtual Size measureText(const ccstd::string &text) = 0;
|
||||
virtual void updateFont(const ccstd::string &fontName, float fontSize, bool bold, bool italic, bool oblique, bool smallCaps) = 0;
|
||||
virtual void setTextAlign(TextAlign align) = 0;
|
||||
virtual void setTextBaseline(TextBaseline baseline) = 0;
|
||||
virtual void setFillStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) = 0;
|
||||
virtual void setStrokeStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) = 0;
|
||||
virtual void setLineWidth(float lineWidth) = 0;
|
||||
virtual void setShadowBlur(float blur) = 0;
|
||||
virtual void setShadowColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) = 0;
|
||||
virtual void setShadowOffsetX(float offsetX) = 0;
|
||||
virtual void setShadowOffsetY(float offsetY) = 0;
|
||||
virtual const cc::Data &getDataRef() const = 0;
|
||||
virtual void updateData() = 0;
|
||||
};
|
||||
//static OSInterface::Ptr getInterface();
|
||||
// Rect
|
||||
virtual void rect(float x, float y, float width, float height) = 0;
|
||||
virtual void clearRect(float x, float y, float width, float height) = 0;
|
||||
virtual void fillRect(float x, float y, float width, float height) = 0;
|
||||
|
||||
virtual void fillText(const ccstd::string &text, float x, float y, float maxWidth) = 0;
|
||||
virtual void strokeText(const ccstd::string &text, float x, float y, float maxWidth) = 0;
|
||||
virtual Size measureText(const ccstd::string &text) = 0;
|
||||
virtual ICanvasGradient *createLinearGradient(float x0, float y0, float x1, float y1) = 0;
|
||||
virtual void save() = 0;
|
||||
// Paths
|
||||
virtual void beginPath() = 0;
|
||||
virtual void closePath() = 0;
|
||||
virtual void moveTo(float x, float y) = 0;
|
||||
virtual void lineTo(float x, float y) = 0;
|
||||
virtual void fill() = 0;
|
||||
virtual void stroke() = 0;
|
||||
virtual void restore() = 0;
|
||||
|
||||
// callback
|
||||
using CanvasBufferUpdatedCallback = std::function<void(const cc::Data &)>;
|
||||
virtual void setCanvasBufferUpdatedCallback(const CanvasBufferUpdatedCallback &cb) = 0;
|
||||
|
||||
// functions for properties
|
||||
virtual void setWidth(float width) = 0;
|
||||
virtual void setHeight(float height) = 0;
|
||||
virtual void setLineWidth(float lineWidth) = 0;
|
||||
virtual void setLineJoin(const ccstd::string &lineJoin) = 0;
|
||||
virtual void setLineCap(const ccstd::string &lineCap) = 0;
|
||||
virtual void setFont(const ccstd::string &font) = 0;
|
||||
virtual void setTextAlign(const ccstd::string &textAlign) = 0;
|
||||
virtual void setTextBaseline(const ccstd::string &textBaseline) = 0;
|
||||
virtual void setFillStyle(const ccstd::string &fillStyle) = 0;
|
||||
virtual void setStrokeStyle(const ccstd::string &strokeStyle) = 0;
|
||||
virtual void setGlobalCompositeOperation(const ccstd::string &globalCompositeOperation) = 0;
|
||||
virtual void setShadowBlur(float blur) = 0;
|
||||
virtual void setShadowColor(const ccstd::string &shadowColor) = 0;
|
||||
virtual void setShadowOffsetX(float offsetX) = 0;
|
||||
virtual void setShadowOffsetY(float offsetY) = 0;
|
||||
|
||||
// fill image data into Context2D
|
||||
virtual void fillImageData(const Data &imageData, float imageWidth, float imageHeight, float offsetX, float offsetY) = 0;
|
||||
|
||||
// transform
|
||||
virtual void translate(float x, float y) = 0;
|
||||
virtual void scale(float x, float y) = 0;
|
||||
virtual void rotate(float angle) = 0;
|
||||
|
||||
virtual void transform(float a, float b, float c, float d, float e, float f) = 0;
|
||||
virtual void setTransform(float a, float b, float c, float d, float e, float f) = 0;
|
||||
|
||||
virtual void fetchData() = 0;
|
||||
|
||||
private:
|
||||
virtual void recreateBufferIfNeeded() = 0;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
Reference in New Issue
Block a user