mirror of
https://github.com/cocos/cocos-engine.git
synced 2026-09-09 09:08:54 +08:00
support create surfaceview dynamically at android platform (#12551)
* support create surfaceview dynamically at android platform
This commit is contained in:
@@ -36,11 +36,14 @@
|
||||
#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 {
|
||||
@@ -56,11 +59,25 @@ void SystemWindow::copyTextToClipboard(const ccstd::string &text) {
|
||||
}
|
||||
|
||||
void SystemWindow::setWindowHandle(void *handle) {
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
std::lock_guard lock(_handleMutex);
|
||||
bool needNotify = _windowHandle == nullptr;
|
||||
_windowHandle = handle;
|
||||
if (needNotify) {
|
||||
_windowHandlePromise.set_value();
|
||||
}
|
||||
#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
|
||||
@@ -89,4 +106,22 @@ void SystemWindow::closeWindow() {
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user