no message
This commit is contained in:
60
cocos/platform/java/modules/Accelerometer.cpp
Normal file
60
cocos/platform/java/modules/Accelerometer.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/****************************************************************************
|
||||
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/java/modules/Accelerometer.h"
|
||||
#include "platform/java/jni/JniImp.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
void Accelerometer::setAccelerometerEnabled(bool isEnabled) {
|
||||
setAccelerometerEnabledJNI(isEnabled);
|
||||
}
|
||||
|
||||
void Accelerometer::setAccelerometerInterval(float interval) {
|
||||
setAccelerometerIntervalJNI(interval);
|
||||
}
|
||||
|
||||
const Accelerometer::MotionValue &Accelerometer::getDeviceMotionValue() {
|
||||
static MotionValue motionValue;
|
||||
float *v = getDeviceMotionValueJNI();
|
||||
|
||||
if (v) {
|
||||
motionValue.accelerationIncludingGravityX = v[0];
|
||||
motionValue.accelerationIncludingGravityY = v[1];
|
||||
motionValue.accelerationIncludingGravityZ = v[2];
|
||||
|
||||
motionValue.accelerationX = v[3];
|
||||
motionValue.accelerationY = v[4];
|
||||
motionValue.accelerationZ = v[5];
|
||||
|
||||
motionValue.rotationRateAlpha = v[6];
|
||||
motionValue.rotationRateBeta = v[7];
|
||||
motionValue.rotationRateGamma = v[8];
|
||||
} else {
|
||||
memset(&motionValue, 0, sizeof(motionValue));
|
||||
}
|
||||
return motionValue;
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
49
cocos/platform/java/modules/Accelerometer.h
Normal file
49
cocos/platform/java/modules/Accelerometer.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
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/modules/IAccelerometer.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class Accelerometer : public IAccelerometer {
|
||||
public:
|
||||
/**
|
||||
* To enable or disable accelerometer.
|
||||
*/
|
||||
void setAccelerometerEnabled(bool isEnabled) override;
|
||||
|
||||
/**
|
||||
* Sets the interval of accelerometer.
|
||||
*/
|
||||
void setAccelerometerInterval(float interval) override;
|
||||
|
||||
/**
|
||||
* Gets the motion value of current device.
|
||||
*/
|
||||
const MotionValue &getDeviceMotionValue() override;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
34
cocos/platform/java/modules/Battery.cpp
Normal file
34
cocos/platform/java/modules/Battery.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/****************************************************************************
|
||||
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/java/modules/Battery.h"
|
||||
#include "platform/java/jni/JniImp.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
float Battery::getBatteryLevel() const {
|
||||
return getBatteryLevelJNI();
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
36
cocos/platform/java/modules/Battery.h
Normal file
36
cocos/platform/java/modules/Battery.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/****************************************************************************
|
||||
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/modules/IBattery.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class Battery : public IBattery {
|
||||
public:
|
||||
float getBatteryLevel() const override;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
343
cocos/platform/java/modules/CanvasRenderingContext2DDelegate.cpp
Normal file
343
cocos/platform/java/modules/CanvasRenderingContext2DDelegate.cpp
Normal file
@@ -0,0 +1,343 @@
|
||||
/****************************************************************************
|
||||
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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "platform/java/modules/CanvasRenderingContext2DDelegate.h"
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
#include <android/bitmap.h>
|
||||
#else
|
||||
#include <multimedia/image/image_pixel_map.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
#define CLAMP(V, HI) std::min((V), (HI))
|
||||
|
||||
namespace cc {
|
||||
CanvasRenderingContext2DDelegate::CanvasRenderingContext2DDelegate() {
|
||||
jobject obj = JniHelper::newObject(JCLS_CANVASIMPL);
|
||||
_obj = JniHelper::getEnv()->NewGlobalRef(obj);
|
||||
ccDeleteLocalRef(JniHelper::getEnv(), obj);
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DDelegate::~CanvasRenderingContext2DDelegate() {
|
||||
JniHelper::getEnv()->DeleteGlobalRef(_obj);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::recreateBuffer(float w, float h) {
|
||||
_bufferWidth = w;
|
||||
_bufferHeight = h;
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "recreateBuffer", w, h);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::beginPath() {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "beginPath");
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::closePath() {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "closePath");
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::moveTo(float x, float y) {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "moveTo", x, y);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::lineTo(float x, float y) {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "lineTo", x, y);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::stroke() {
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "stroke");
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::fill() {
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "fill");
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::rect(float x, float y, float w, float h) {
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "rect", x, y, w, h);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::saveContext() {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "saveContext");
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::restoreContext() {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "restoreContext");
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::clearRect(float x, float y, float w, float h) {
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
if (x >= _bufferWidth || y >= _bufferHeight) {
|
||||
return;
|
||||
}
|
||||
if (x + w > _bufferWidth) {
|
||||
w = _bufferWidth - x;
|
||||
}
|
||||
if (y + h > _bufferHeight) {
|
||||
h = _bufferHeight - y;
|
||||
}
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "clearRect", x, y, w, h);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::fillRect(float x, float y, float w, float h) {
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
if (x >= _bufferWidth || y >= _bufferHeight) {
|
||||
return;
|
||||
}
|
||||
if (x + w > _bufferWidth) {
|
||||
w = _bufferWidth - x;
|
||||
}
|
||||
if (y + h > _bufferHeight) {
|
||||
h = _bufferHeight - y;
|
||||
}
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "fillRect", x, y, w, h);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::fillText(const ccstd::string &text, float x, float y, float maxWidth) {
|
||||
if (text.empty() || _bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "fillText", text, x, y, maxWidth);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::strokeText(const ccstd::string &text, float x, float y, float maxWidth) {
|
||||
if (text.empty() || _bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "strokeText", text, x, y, maxWidth);
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DDelegate::Size CanvasRenderingContext2DDelegate::measureText(const ccstd::string &text) {
|
||||
if (text.empty()) {
|
||||
return ccstd::array<float, 2>{0.0F, 0.0F};
|
||||
}
|
||||
float measureText1 = JniHelper::callObjectFloatMethod(_obj, JCLS_CANVASIMPL, "measureText", text);
|
||||
Size size{measureText1, 0.0F};
|
||||
return size;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::updateFont(const ccstd::string &fontName, float fontSize, bool bold, bool italic, bool oblique, bool smallCaps) {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "updateFont", fontName, fontSize, bold, italic, oblique, smallCaps);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setLineCap(const ccstd::string &lineCap) {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "setLineCap", lineCap);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setLineJoin(const ccstd::string &lineJoin) {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "setLineJoin", lineJoin);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setTextAlign(TextAlign align) {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "setTextAlign", static_cast<int>(align));
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setTextBaseline(TextBaseline baseline) {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "setTextBaseline", static_cast<int>(baseline));
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setFillStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "setFillStyle",
|
||||
static_cast<jint>(r),
|
||||
static_cast<jint>(g),
|
||||
static_cast<jint>(b),
|
||||
static_cast<jint>(a));
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setStrokeStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "setStrokeStyle",
|
||||
static_cast<jint>(r),
|
||||
static_cast<jint>(g),
|
||||
static_cast<jint>(b),
|
||||
static_cast<jint>(a));
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setLineWidth(float lineWidth) {
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "setLineWidth", lineWidth);
|
||||
}
|
||||
|
||||
const cc::Data &CanvasRenderingContext2DDelegate::getDataRef() const {
|
||||
return _data;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::fillImageData(const Data &imageData, float imageWidth, float imageHeight, float offsetX, float offsetY) {
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto *arr = JniHelper::getEnv()->NewIntArray(imageData.getSize() / 4);
|
||||
JniHelper::getEnv()->SetIntArrayRegion(arr, 0, imageData.getSize() / 4,
|
||||
reinterpret_cast<const jint *>(imageData.getBytes()));
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "_fillImageData", arr, imageWidth,
|
||||
imageHeight, offsetX, offsetY);
|
||||
ccDeleteLocalRef(JniHelper::getEnv(), arr);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::updateData() {
|
||||
jobject bmpObj = nullptr;
|
||||
JniMethodInfo methodInfo;
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
if (JniHelper::getMethodInfo(methodInfo, JCLS_CANVASIMPL, "getBitmap", "()Landroid/graphics/Bitmap;")) {
|
||||
bmpObj = methodInfo.env->CallObjectMethod(_obj, methodInfo.methodID);
|
||||
methodInfo.env->DeleteLocalRef(methodInfo.classID);
|
||||
}
|
||||
#else
|
||||
if (JniHelper::getMethodInfo(methodInfo, JCLS_CANVASIMPL, "getBitmap", "()Lohos/media/image/PixelMap;")) {
|
||||
bmpObj = methodInfo.env->CallObjectMethod(_obj, methodInfo.methodID);
|
||||
methodInfo.env->DeleteLocalRef(methodInfo.classID);
|
||||
}
|
||||
#endif
|
||||
JNIEnv *env = JniHelper::getEnv();
|
||||
do {
|
||||
if (nullptr == bmpObj) {
|
||||
break;
|
||||
}
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
AndroidBitmapInfo bmpInfo;
|
||||
if (AndroidBitmap_getInfo(env, bmpObj, &bmpInfo) != ANDROID_BITMAP_RESULT_SUCCESS) {
|
||||
CC_LOG_ERROR("AndroidBitmap_getInfo() failed ! error");
|
||||
break;
|
||||
}
|
||||
if (bmpInfo.width < 1 || bmpInfo.height < 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
void *pixelData;
|
||||
if (AndroidBitmap_lockPixels(env, bmpObj, &pixelData) != ANDROID_BITMAP_RESULT_SUCCESS) {
|
||||
CC_LOG_ERROR("AndroidBitmap_lockPixels() failed ! error");
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t size = bmpInfo.stride * bmpInfo.height;
|
||||
#else
|
||||
OhosPixelMapInfo bmpInfo;
|
||||
void *pixelData = nullptr;
|
||||
if (GetImageInfo(env, bmpObj, bmpInfo) ==
|
||||
OHOS_IMAGE_RESULT_SUCCESS &&
|
||||
bmpInfo.width > 0 &&
|
||||
bmpInfo.height > 0 &&
|
||||
bmpInfo.pixelFormat == OHOS_PIXEL_MAP_FORMAT_RGBA_8888) {
|
||||
if (AccessPixels(env, bmpObj, &pixelData) != OHOS_IMAGE_RESULT_SUCCESS) {
|
||||
CC_LOG_ERROR("AccessPixels() failed ! error");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
uint32_t size = bmpInfo.rowSize * bmpInfo.height;
|
||||
#endif
|
||||
auto *bmpData = static_cast<jbyte *>(malloc(size));
|
||||
memcpy(bmpData, pixelData, size);
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
unMultiplyAlpha(reinterpret_cast<unsigned char *>(bmpData), size);
|
||||
#endif
|
||||
_data.fastSet(reinterpret_cast<unsigned char *>(bmpData), size);
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
AndroidBitmap_unlockPixels(env, bmpObj);
|
||||
#else
|
||||
UnAccessPixels(env, bmpObj);
|
||||
#endif
|
||||
} while (false);
|
||||
if (bmpObj) {
|
||||
env->DeleteLocalRef(bmpObj);
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::unMultiplyAlpha(unsigned char *ptr, uint32_t size) { // NOLINT(readability-convert-member-functions-to-static)
|
||||
// Android source data is not premultiplied alpha when API >= 19
|
||||
// please refer CanvasRenderingContext2DImpl::recreateBuffer(float w, float h)
|
||||
// in CanvasRenderingContext2DImpl.java
|
||||
// if (getAndroidSDKInt() >= 19)
|
||||
// return;
|
||||
|
||||
float alpha;
|
||||
for (int i = 0; i < size; i += 4) {
|
||||
alpha = static_cast<float>(ptr[i + 3]);
|
||||
if (alpha > 0) {
|
||||
ptr[i] = CLAMP((int)((float)ptr[i] / alpha * 255), 255);
|
||||
ptr[i + 1] = CLAMP((int)((float)ptr[i + 1] / alpha * 255), 255);
|
||||
ptr[i + 2] = CLAMP((int)((float)ptr[i + 2] / alpha * 255), 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setShadowBlur(float blur) {
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "setShadowBlur", blur);
|
||||
#else
|
||||
CC_LOG_WARNING("shadowBlur not implemented");
|
||||
#endif
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setShadowColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "setShadowColor",
|
||||
static_cast<jint>(r),
|
||||
static_cast<jint>(g),
|
||||
static_cast<jint>(b),
|
||||
static_cast<jint>(a));
|
||||
#else
|
||||
CC_LOG_WARNING("shadowColor not implemented");
|
||||
#endif
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setShadowOffsetX(float offsetX) {
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "setShadowOffsetX", offsetX);
|
||||
#else
|
||||
CC_LOG_WARNING("shadowOffsetX not implemented");
|
||||
#endif
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setShadowOffsetY(float offsetY) {
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
JniHelper::callObjectVoidMethod(_obj, JCLS_CANVASIMPL, "setShadowOffsetY", offsetY);
|
||||
#else
|
||||
CC_LOG_WARNING("shadowOffsetY not implemented");
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
101
cocos/platform/java/modules/CanvasRenderingContext2DDelegate.h
Normal file
101
cocos/platform/java/modules/CanvasRenderingContext2DDelegate.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
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"
|
||||
|
||||
#include "base/csscolorparser.h"
|
||||
#include "bindings/jswrapper/config.h"
|
||||
#include "math/Math.h"
|
||||
|
||||
#include "cocos/bindings/jswrapper/SeApi.h"
|
||||
#include "platform/java/jni/JniHelper.h"
|
||||
#include "platform/java/jni/JniImp.h"
|
||||
|
||||
#if __OHOS__
|
||||
#include <hilog/log.h>
|
||||
#endif
|
||||
|
||||
#include <regex>
|
||||
|
||||
#ifndef JCLS_CANVASIMPL
|
||||
#define JCLS_CANVASIMPL "com/cocos/lib/CanvasRenderingContext2DImpl"
|
||||
#endif
|
||||
#include "base/std/container/array.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CanvasRenderingContext2DDelegate : public ICanvasRenderingContext2D::Delegate {
|
||||
public:
|
||||
using Size = ccstd::array<float, 2>;
|
||||
using TextAlign = ICanvasRenderingContext2D::TextAlign;
|
||||
using TextBaseline = ICanvasRenderingContext2D::TextBaseline;
|
||||
|
||||
CanvasRenderingContext2DDelegate();
|
||||
~CanvasRenderingContext2DDelegate() override;
|
||||
|
||||
void recreateBuffer(float w, float h) override;
|
||||
void beginPath() override;
|
||||
void closePath() override;
|
||||
void moveTo(float x, float y) override;
|
||||
void lineTo(float x, float y) override;
|
||||
void stroke() override;
|
||||
void saveContext() override;
|
||||
void restoreContext() override;
|
||||
void clearRect(float /*x*/, float /*y*/, float w, float h) override;
|
||||
void fill() override;
|
||||
void setLineCap(const ccstd::string &lineCap) override;
|
||||
void setLineJoin(const ccstd::string &lineJoin) override;
|
||||
void rect(float x, float y, float w, float h) override;
|
||||
void fillRect(float x, float y, float w, float h) 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;
|
||||
void updateFont(const ccstd::string &fontName, float fontSize, bool bold, bool italic, bool oblique, bool smallCaps) override;
|
||||
void setTextAlign(TextAlign align) override;
|
||||
void setTextBaseline(TextBaseline baseline) override;
|
||||
void setFillStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) override;
|
||||
void setStrokeStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) override;
|
||||
void setLineWidth(float lineWidth) override;
|
||||
const cc::Data &getDataRef() const override;
|
||||
void fillImageData(const Data &imageData, float imageWidth, float imageHeight, float offsetX, float offsetY) override;
|
||||
void updateData() override;
|
||||
void setShadowBlur(float blur) override;
|
||||
void setShadowColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) override;
|
||||
void setShadowOffsetX(float offsetX) override;
|
||||
void setShadowOffsetY(float offsetY) override;
|
||||
|
||||
private:
|
||||
void unMultiplyAlpha(unsigned char *ptr, uint32_t size);
|
||||
|
||||
public:
|
||||
private:
|
||||
jobject _obj = nullptr;
|
||||
Data _data;
|
||||
float _bufferWidth = 0.0F;
|
||||
float _bufferHeight = 0.0F;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
103
cocos/platform/java/modules/CommonScreen.cpp
Normal file
103
cocos/platform/java/modules/CommonScreen.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/****************************************************************************
|
||||
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/java/modules/CommonScreen.h"
|
||||
#include "cocos/bindings/jswrapper/SeApi.h"
|
||||
#include "platform/java/jni/JniImp.h"
|
||||
|
||||
namespace {
|
||||
// constant from Android API:
|
||||
// reference: https://developer.android.com/reference/android/view/Surface#ROTATION_0
|
||||
enum Rotation {
|
||||
ROTATION_0 = 0,
|
||||
ROTATION_90,
|
||||
ROTATION_180,
|
||||
ROTATION_270
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace cc {
|
||||
|
||||
// int Screen::getDPI() {
|
||||
// static int dpi = -1;
|
||||
// if (dpi == -1) {
|
||||
// AConfiguration *config = AConfiguration_new();
|
||||
// //AConfiguration_fromAssetManager(config, cocosApp.assetManager);
|
||||
// int32_t density = AConfiguration_getDensity(config);
|
||||
// AConfiguration_delete(config);
|
||||
// const int stdDpi = 160;
|
||||
// dpi = density * stdDpi;
|
||||
// }
|
||||
// return dpi;
|
||||
// }
|
||||
|
||||
float CommonScreen::getDevicePixelRatio() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void CommonScreen::setKeepScreenOn(bool keepScreenOn) {
|
||||
// JniHelper::callStaticVoidMethod(JCLS_HELPER, "setKeepScreenOn", value);
|
||||
// ANativeActivity_setWindowFlags(JniHelper::getAndroidApp()->activity, AWINDOW_FLAG_KEEP_SCREEN_ON, 0);
|
||||
//CC_UNUSED_PARAM(keepScreenOn);
|
||||
return setKeepScreenOnJNI(keepScreenOn);
|
||||
}
|
||||
|
||||
IScreen::Orientation CommonScreen::getDeviceOrientation() const {
|
||||
int rotation = getDeviceRotationJNI();
|
||||
switch (rotation) {
|
||||
case ROTATION_0:
|
||||
return Orientation::PORTRAIT;
|
||||
case ROTATION_90:
|
||||
return Orientation::LANDSCAPE_RIGHT;
|
||||
case ROTATION_180:
|
||||
return Orientation::PORTRAIT_UPSIDE_DOWN;
|
||||
case ROTATION_270:
|
||||
return Orientation::LANDSCAPE_LEFT;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return Orientation::PORTRAIT;
|
||||
}
|
||||
|
||||
Vec4 CommonScreen::getSafeAreaEdge() const {
|
||||
float *data = getSafeAreaEdgeJNI();
|
||||
return cc::Vec4(data[0], data[1], data[2], data[3]);
|
||||
}
|
||||
|
||||
bool CommonScreen::isDisplayStats() { //NOLINT
|
||||
se::AutoHandleScope hs;
|
||||
se::Value ret;
|
||||
char commandBuf[100] = "cc.debug.isDisplayStats();";
|
||||
se::ScriptEngine::getInstance()->evalString(commandBuf, 100, &ret);
|
||||
return ret.toBoolean();
|
||||
}
|
||||
|
||||
void CommonScreen::setDisplayStats(bool isShow) { //NOLINT
|
||||
se::AutoHandleScope hs;
|
||||
char commandBuf[100] = {0};
|
||||
sprintf(commandBuf, "cc.debug.setDisplayStats(%s);", isShow ? "true" : "false");
|
||||
se::ScriptEngine::getInstance()->evalString(commandBuf);
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
49
cocos/platform/java/modules/CommonScreen.h
Normal file
49
cocos/platform/java/modules/CommonScreen.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
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/modules/IScreen.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CommonScreen : public IScreen {
|
||||
public:
|
||||
float getDevicePixelRatio() const override;
|
||||
void setKeepScreenOn(bool keepScreenOn) override;
|
||||
Orientation getDeviceOrientation() const override;
|
||||
Vec4 getSafeAreaEdge() const override;
|
||||
/**
|
||||
@brief Get current display stats.
|
||||
@return bool, is displaying stats or not.
|
||||
*/
|
||||
bool isDisplayStats() override;
|
||||
|
||||
/**
|
||||
@brief set display stats information.
|
||||
*/
|
||||
void setDisplayStats(bool isShow) override;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
102
cocos/platform/java/modules/CommonSystem.cpp
Normal file
102
cocos/platform/java/modules/CommonSystem.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
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/java/modules/CommonSystem.h"
|
||||
#include "platform/java/jni/JniHelper.h"
|
||||
#include "platform/java/jni/JniImp.h"
|
||||
|
||||
namespace cc {
|
||||
CommonSystem::CommonSystem() = default;
|
||||
CommonSystem::~CommonSystem() = default;
|
||||
|
||||
ccstd::string CommonSystem::getDeviceModel() const {
|
||||
return getDeviceModelJNI();
|
||||
}
|
||||
|
||||
CommonSystem::LanguageType CommonSystem::getCurrentLanguage() const {
|
||||
ccstd::string languageName = getCurrentLanguageJNI();
|
||||
const char *pLanguageName = languageName.c_str();
|
||||
LanguageType ret = LanguageType::ENGLISH;
|
||||
|
||||
if (0 == strcmp("zh", pLanguageName)) {
|
||||
ret = LanguageType::CHINESE;
|
||||
} else if (0 == strcmp("en", pLanguageName)) {
|
||||
ret = LanguageType::ENGLISH;
|
||||
} else if (0 == strcmp("fr", pLanguageName)) {
|
||||
ret = LanguageType::FRENCH;
|
||||
} else if (0 == strcmp("it", pLanguageName)) {
|
||||
ret = LanguageType::ITALIAN;
|
||||
} else if (0 == strcmp("de", pLanguageName)) {
|
||||
ret = LanguageType::GERMAN;
|
||||
} else if (0 == strcmp("es", pLanguageName)) {
|
||||
ret = LanguageType::SPANISH;
|
||||
} else if (0 == strcmp("ru", pLanguageName)) {
|
||||
ret = LanguageType::RUSSIAN;
|
||||
} else if (0 == strcmp("nl", pLanguageName)) {
|
||||
ret = LanguageType::DUTCH;
|
||||
} else if (0 == strcmp("ko", pLanguageName)) {
|
||||
ret = LanguageType::KOREAN;
|
||||
} else if (0 == strcmp("ja", pLanguageName)) {
|
||||
ret = LanguageType::JAPANESE;
|
||||
} else if (0 == strcmp("hu", pLanguageName)) {
|
||||
ret = LanguageType::HUNGARIAN;
|
||||
} else if (0 == strcmp("pt", pLanguageName)) {
|
||||
ret = LanguageType::PORTUGUESE;
|
||||
} else if (0 == strcmp("ar", pLanguageName)) {
|
||||
ret = LanguageType::ARABIC;
|
||||
} else if (0 == strcmp("nb", pLanguageName)) {
|
||||
ret = LanguageType::NORWEGIAN;
|
||||
} else if (0 == strcmp("pl", pLanguageName)) {
|
||||
ret = LanguageType::POLISH;
|
||||
} else if (0 == strcmp("tr", pLanguageName)) {
|
||||
ret = LanguageType::TURKISH;
|
||||
} else if (0 == strcmp("uk", pLanguageName)) {
|
||||
ret = LanguageType::UKRAINIAN;
|
||||
} else if (0 == strcmp("ro", pLanguageName)) {
|
||||
ret = LanguageType::ROMANIAN;
|
||||
} else if (0 == strcmp("bg", pLanguageName)) {
|
||||
ret = LanguageType::BULGARIAN;
|
||||
} else if (0 == strcmp("hi", pLanguageName)) {
|
||||
ret = LanguageType::HINDI;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ccstd::string CommonSystem::getCurrentLanguageCode() const {
|
||||
return getCurrentLanguageCodeJNI();
|
||||
}
|
||||
|
||||
ccstd::string CommonSystem::getSystemVersion() const {
|
||||
return getSystemVersionJNI();
|
||||
}
|
||||
|
||||
bool CommonSystem::openURL(const ccstd::string &url) {
|
||||
return openURLJNI(url);
|
||||
}
|
||||
|
||||
void CommonSystem::copyTextToClipboard(const ccstd::string &text) {
|
||||
copyTextToClipboardJNI(text);
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
64
cocos/platform/java/modules/CommonSystem.h
Normal file
64
cocos/platform/java/modules/CommonSystem.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/****************************************************************************
|
||||
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/modules/ISystem.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CommonSystem : public ISystem {
|
||||
public:
|
||||
CommonSystem();
|
||||
~CommonSystem() override;
|
||||
/**
|
||||
@brief Get target device model.
|
||||
*/
|
||||
ccstd::string getDeviceModel() const override;
|
||||
/**
|
||||
@brief Get current language config.
|
||||
@return Current language config.
|
||||
*/
|
||||
LanguageType getCurrentLanguage() const override;
|
||||
/**
|
||||
@brief Get current language iso 639-1 code.
|
||||
@return Current language iso 639-1 code.
|
||||
*/
|
||||
ccstd::string getCurrentLanguageCode() const override;
|
||||
/**
|
||||
@brief Get system version.
|
||||
@return system version.
|
||||
*/
|
||||
ccstd::string getSystemVersion() const override;
|
||||
/**
|
||||
@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.
|
||||
*/
|
||||
bool openURL(const ccstd::string& url) override;
|
||||
|
||||
void copyTextToClipboard(const std::string& text) override;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
34
cocos/platform/java/modules/Network.cpp
Normal file
34
cocos/platform/java/modules/Network.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/****************************************************************************
|
||||
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/java/modules/Network.h"
|
||||
#include "platform/java/jni/JniImp.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
INetwork::NetworkType Network::getNetworkType() const {
|
||||
return static_cast<INetwork::NetworkType>(getNetworkTypeJNI());
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
36
cocos/platform/java/modules/Network.h
Normal file
36
cocos/platform/java/modules/Network.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/****************************************************************************
|
||||
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/modules/INetwork.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class Network : public INetwork {
|
||||
public:
|
||||
NetworkType getNetworkType() const override;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
126
cocos/platform/java/modules/SystemWindow.cpp
Normal file
126
cocos/platform/java/modules/SystemWindow.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/****************************************************************************
|
||||
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/java/modules/SystemWindow.h"
|
||||
#include <fcntl.h>
|
||||
#include <jni.h>
|
||||
#include <unistd.h>
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
#include <android/native_window.h>
|
||||
#endif
|
||||
|
||||
#include "BasePlatform.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/Macros.h"
|
||||
#include "platform/java/jni/JniHelper.h"
|
||||
#include "platform/java/jni/JniImp.h"
|
||||
#include "platform/java/jni/glue/JniNativeGlue.h"
|
||||
|
||||
namespace {
|
||||
#ifndef JCLS_COCOSACTIVITY
|
||||
#define JCLS_COCOSACTIVITY "com/cocos/lib/CocosActivity"
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
namespace cc {
|
||||
SystemWindow::SystemWindow(uint32_t windowId, void *externalHandle)
|
||||
: _windowHandle(externalHandle), _windowId(windowId) {
|
||||
}
|
||||
|
||||
void SystemWindow::setCursorEnabled(bool value) {
|
||||
}
|
||||
|
||||
void SystemWindow::setWindowHandle(void *handle) {
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
//The getWindowHandle interface may have been called earlier, causing _handleMutex to be occupied all the time.
|
||||
bool lockSuccess = _handleMutex.try_lock();
|
||||
bool needNotify = _windowHandle == nullptr;
|
||||
_windowHandle = handle;
|
||||
if (needNotify) {
|
||||
_windowHandlePromise.set_value();
|
||||
}
|
||||
if (lockSuccess) {
|
||||
_handleMutex.unlock();
|
||||
}
|
||||
#else
|
||||
_windowHandle = handle;
|
||||
#endif
|
||||
}
|
||||
|
||||
uintptr_t SystemWindow::getWindowHandle() const {
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
std::lock_guard lock(const_cast<std::mutex &>(_handleMutex));
|
||||
if (!_windowHandle) {
|
||||
auto &future = const_cast<std::promise<void> &>(_windowHandlePromise);
|
||||
future.get_future().get();
|
||||
}
|
||||
CC_ASSERT(_windowHandle);
|
||||
return reinterpret_cast<uintptr_t>(_windowHandle);
|
||||
#else
|
||||
return reinterpret_cast<uintptr_t>(
|
||||
JNI_NATIVE_GLUE()->getWindowHandle());
|
||||
#endif
|
||||
}
|
||||
|
||||
SystemWindow::Size SystemWindow::getViewSize() const {
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
CC_ASSERT(_windowHandle);
|
||||
auto *nativeWindow = static_cast<ANativeWindow *>(_windowHandle);
|
||||
return Size{static_cast<float>(ANativeWindow_getWidth(nativeWindow)),
|
||||
static_cast<float>(ANativeWindow_getHeight(nativeWindow))};
|
||||
#else
|
||||
return Size{static_cast<float>(JNI_NATIVE_GLUE()->getWidth()),
|
||||
static_cast<float>(JNI_NATIVE_GLUE()->getHeight())};
|
||||
#endif
|
||||
}
|
||||
void SystemWindow::closeWindow() {
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
finishActivity();
|
||||
#else
|
||||
events::Close::broadcast();
|
||||
exit(0); //TODO(cc): better exit for ohos
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title, int x, int y, int w, int h, int flags) {
|
||||
CC_UNUSED_PARAM(title);
|
||||
CC_UNUSED_PARAM(flags);
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
cc::JniHelper::callObjectVoidMethod(cc::JniHelper::getActivity(), JCLS_COCOSACTIVITY, "createSurface", x, y, w, h, static_cast<jint>(_windowId));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title, int w, int h, int flags) {
|
||||
CC_UNUSED_PARAM(title);
|
||||
CC_UNUSED_PARAM(flags);
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
cc::JniHelper::callObjectVoidMethod(cc::JniHelper::getActivity(), JCLS_COCOSACTIVITY, "createSurface", 0, 0, w, h, static_cast<jint>(_windowId));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
61
cocos/platform/java/modules/SystemWindow.h
Normal file
61
cocos/platform/java/modules/SystemWindow.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
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 <future>
|
||||
#include <iostream>
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class SystemWindow : public ISystemWindow {
|
||||
public:
|
||||
SystemWindow(uint32_t windowId, void *externalHandle);
|
||||
|
||||
bool createWindow(const char *title, int x, int y, int w, int h, int flags) override;
|
||||
|
||||
bool createWindow(const char *title, int w, int h, int flags) override;
|
||||
|
||||
/**
|
||||
@brief enable/disable(lock) the cursor, default is enabled
|
||||
*/
|
||||
void setCursorEnabled(bool value) override;
|
||||
|
||||
void setWindowHandle(void *handle);
|
||||
uintptr_t getWindowHandle() const override;
|
||||
uint32_t getWindowId() const override { return _windowId; }
|
||||
|
||||
Size getViewSize() const override;
|
||||
|
||||
void closeWindow() override;
|
||||
|
||||
private:
|
||||
std::mutex _handleMutex;
|
||||
std::promise<void> _windowHandlePromise;
|
||||
uint32_t _windowId{0};
|
||||
void *_windowHandle{nullptr};
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
85
cocos/platform/java/modules/SystemWindowManager.cpp
Normal file
85
cocos/platform/java/modules/SystemWindowManager.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
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 "SystemWindowManager.h"
|
||||
#include "BasePlatform.h"
|
||||
#include "platform/java/modules/SystemWindow.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
int SystemWindowManager::init() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SystemWindowManager::processEvent() {
|
||||
}
|
||||
|
||||
ISystemWindow *SystemWindowManager::createWindow(const ISystemWindowInfo &info) {
|
||||
if (!isExternalHandleExist(info.externalHandle)) {
|
||||
ISystemWindow *window = BasePlatform::getPlatform()->createNativeWindow(_nextWindowId, info.externalHandle);
|
||||
if (window) {
|
||||
if (!info.externalHandle) {
|
||||
window->createWindow(info.title.c_str(), info.x, info.y, info.width, info.height, info.flags);
|
||||
}
|
||||
_windows[_nextWindowId] = std::shared_ptr<ISystemWindow>(window);
|
||||
_nextWindowId++;
|
||||
}
|
||||
return window;
|
||||
}
|
||||
return getWindowFromANativeWindow(static_cast<ANativeWindow *>(info.externalHandle));
|
||||
}
|
||||
|
||||
ISystemWindow *SystemWindowManager::getWindow(uint32_t windowId) const {
|
||||
if (windowId == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto iter = _windows.find(windowId);
|
||||
if (iter != _windows.end()) {
|
||||
return iter->second.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ISystemWindow *SystemWindowManager::getWindowFromANativeWindow(ANativeWindow *window) const {
|
||||
if (!window) {
|
||||
return nullptr;
|
||||
}
|
||||
for (const auto &pair : _windows) {
|
||||
ISystemWindow *sysWindow = pair.second.get();
|
||||
auto *nativeWindow = reinterpret_cast<ANativeWindow *>(sysWindow->getWindowHandle());
|
||||
if (nativeWindow == window) {
|
||||
return sysWindow;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool SystemWindowManager::isExternalHandleExist(void *externalHandle) const {
|
||||
return std::any_of(_windows.begin(), _windows.end(), [externalHandle](const auto &pair) {
|
||||
auto *handle = reinterpret_cast<void *>(pair.second->getWindowHandle());
|
||||
return handle == externalHandle;
|
||||
});
|
||||
}
|
||||
} // namespace cc
|
||||
52
cocos/platform/java/modules/SystemWindowManager.h
Normal file
52
cocos/platform/java/modules/SystemWindowManager.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
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 "base/std/container/unordered_map.h"
|
||||
#include "platform/interfaces/modules/ISystemWindowManager.h"
|
||||
|
||||
struct ANativeWindow;
|
||||
|
||||
namespace cc {
|
||||
class ISystemWindow;
|
||||
|
||||
class SystemWindowManager : public ISystemWindowManager {
|
||||
public:
|
||||
SystemWindowManager() = default;
|
||||
|
||||
int init() override;
|
||||
void processEvent() override;
|
||||
ISystemWindow *createWindow(const ISystemWindowInfo &info) override;
|
||||
ISystemWindow *getWindow(uint32_t windowId) const override;
|
||||
const SystemWindowMap &getWindows() const override { return _windows; }
|
||||
|
||||
ISystemWindow *getWindowFromANativeWindow(ANativeWindow *window) const;
|
||||
bool isExternalHandleExist(void *handle) const;
|
||||
|
||||
private:
|
||||
uint32_t _nextWindowId{1}; // start from 1, 0 means an invalid ID
|
||||
SystemWindowMap _windows;
|
||||
};
|
||||
} // namespace cc
|
||||
34
cocos/platform/java/modules/Vibrator.cpp
Normal file
34
cocos/platform/java/modules/Vibrator.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/****************************************************************************
|
||||
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/java/modules/Vibrator.h"
|
||||
#include "platform/java/jni/JniImp.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
void Vibrator::vibrate(float duration) {
|
||||
setVibrateJNI(duration);
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
43
cocos/platform/java/modules/Vibrator.h
Normal file
43
cocos/platform/java/modules/Vibrator.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/****************************************************************************
|
||||
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/modules/IVibrator.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class Vibrator : public IVibrator {
|
||||
public:
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void vibrate(float duration) override;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
1252
cocos/platform/java/modules/XRInterface.cpp
Normal file
1252
cocos/platform/java/modules/XRInterface.cpp
Normal file
File diff suppressed because it is too large
Load Diff
140
cocos/platform/java/modules/XRInterface.h
Normal file
140
cocos/platform/java/modules/XRInterface.h
Normal file
@@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
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 "base/Ptr.h"
|
||||
#include "base/ThreadPool.h"
|
||||
#include "platform/interfaces/modules/IXRInterface.h"
|
||||
#if CC_USE_XR_REMOTE_PREVIEW
|
||||
#include "xr/XRRemotePreviewManager.h"
|
||||
#endif
|
||||
namespace se {
|
||||
class Object;
|
||||
}
|
||||
|
||||
namespace cc {
|
||||
|
||||
class XRInterface : public IXRInterface {
|
||||
public:
|
||||
xr::XRVendor getVendor() override;
|
||||
xr::XRConfigValue getXRConfig(xr::XRConfigKey key) override;
|
||||
void setXRConfig(xr::XRConfigKey key, xr::XRConfigValue value) override;
|
||||
|
||||
uint32_t getRuntimeVersion() override;
|
||||
void initialize(void *javaVM, void *activity) override;
|
||||
|
||||
// render thread lifecycle
|
||||
void onRenderPause() override;
|
||||
void onRenderResume() override;
|
||||
void onRenderDestroy() override;
|
||||
// render thread lifecycle
|
||||
|
||||
// gfx
|
||||
void preGFXDeviceInitialize(gfx::API gfxApi) override;
|
||||
void postGFXDeviceInitialize(gfx::API gfxApi) override;
|
||||
const xr::XRSwapchain &doGFXDeviceAcquire(gfx::API gfxApi) override;
|
||||
bool isGFXDeviceNeedsPresent(gfx::API gfxApi) override;
|
||||
void postGFXDevicePresent(gfx::API gfxApi) override;
|
||||
void createXRSwapchains() override;
|
||||
const std::vector<cc::xr::XRSwapchain> &getXRSwapchains() override;
|
||||
gfx::Format getXRSwapchainFormat() override;
|
||||
void updateXRSwapchainTypedID(uint32_t typedID) override;
|
||||
// gfx
|
||||
|
||||
// vulkan
|
||||
#ifdef CC_USE_VULKAN
|
||||
uint32_t getXRVkApiVersion(uint32_t engineVkApiVersion) override;
|
||||
void initializeVulkanData(const PFN_vkGetInstanceProcAddr &addr) override;
|
||||
VkInstance createXRVulkanInstance(const VkInstanceCreateInfo &instInfo) override;
|
||||
VkDevice createXRVulkanDevice(const VkDeviceCreateInfo *deviceInfo) override;
|
||||
VkPhysicalDevice getXRVulkanGraphicsDevice() override;
|
||||
void getXRSwapchainVkImages(std::vector<VkImage> &vkImages, uint32_t eye) override;
|
||||
#endif
|
||||
// vulkan
|
||||
|
||||
// gles
|
||||
#ifdef CC_USE_GLES3
|
||||
void initializeGLESData(xr::PFNGLES3WLOADPROC gles3wLoadFuncProc, gfx::GLES3GPUContext *gpuContext) override;
|
||||
void attachGLESFramebufferTexture2D() override;
|
||||
EGLSurfaceType acquireEGLSurfaceType(uint32_t typedID) override;
|
||||
#endif
|
||||
// gles
|
||||
|
||||
// stereo render loop
|
||||
bool platformLoopStart() override;
|
||||
bool beginRenderFrame() override;
|
||||
bool isRenderAllowable() override;
|
||||
bool beginRenderEyeFrame(uint32_t eye) override;
|
||||
bool endRenderEyeFrame(uint32_t eye) override;
|
||||
bool endRenderFrame() override;
|
||||
bool platformLoopEnd() override;
|
||||
// stereo render loop
|
||||
|
||||
ccstd::vector<float> getHMDViewPosition(uint32_t eye, int trackingType) override;
|
||||
ccstd::vector<float> getXRViewProjectionData(uint32_t eye, float near, float far) override;
|
||||
ccstd::vector<float> getXREyeFov(uint32_t eye) override;
|
||||
// renderwindow
|
||||
xr::XREye getXREyeByRenderWindow(void *window) override;
|
||||
void bindXREyeWithRenderWindow(void *window, xr::XREye eye) override;
|
||||
void handleAppCommand(int appCmd) override;
|
||||
void adaptOrthographicMatrix(cc::scene::Camera *camera, const ccstd::array<float, 4> &preTransform, Mat4 &proj, Mat4 &view) override;
|
||||
|
||||
private:
|
||||
void loadImageTrackingData(const std::string &imageInfo);
|
||||
void asyncLoadAssetsImage(const std::string &imagePath);
|
||||
void dispatchGamepadEventInternal(const xr::XRControllerEvent &xrControllerEvent);
|
||||
void dispatchHandleEventInternal(const xr::XRControllerEvent &xrControllerEvent);
|
||||
void dispatchHMDEventInternal(const xr::XRControllerEvent &xrControllerEvent);
|
||||
ControllerEvent _controllerEvent;
|
||||
se::Object *_jsPoseEventArray{nullptr};
|
||||
|
||||
#if CC_USE_VULKAN
|
||||
PFN_vkGetInstanceProcAddr _vkGetInstanceProcAddr{nullptr};
|
||||
VkPhysicalDevice _vkPhysicalDevice{nullptr};
|
||||
VkInstance _vkInstance{nullptr};
|
||||
VkDevice _vkDevice{nullptr};
|
||||
#endif
|
||||
|
||||
#if CC_USE_GLES3
|
||||
xr::PFNGLES3WLOADPROC _gles3wLoadFuncProc{nullptr};
|
||||
gfx::GLES3GPUContext *_gles3GPUContext{nullptr};
|
||||
#endif
|
||||
xr::XRSwapchain _acquireSwapchain;
|
||||
std::vector<cc::xr::XRSwapchain> _xrSwapchains;
|
||||
bool _renderPaused{false};
|
||||
bool _renderResumed{false};
|
||||
bool _isXrEntryInstanceValid{false};
|
||||
std::unordered_map<void *, xr::XREye> _xrWindowMap;
|
||||
std::unordered_map<uint32_t, EGLSurfaceType> _eglSurfaceTypeMap;
|
||||
bool _committedFrame{false};
|
||||
#if CC_USE_XR_REMOTE_PREVIEW
|
||||
cc::IntrusivePtr<XRRemotePreviewManager> _xrRemotePreviewManager{nullptr};
|
||||
#endif
|
||||
LegacyThreadPool *_gThreadPool{nullptr};
|
||||
bool _isFlipPixelY{false};
|
||||
bool _isEnabledEyeRenderJsCallback{false};
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
Reference in New Issue
Block a user