fix android background event for device thread (#3411)

This commit is contained in:
Yun Hsiao Wu
2021-04-16 09:51:23 +08:00
committed by GitHub
parent 0bbb16e273
commit 2913d86720
20 changed files with 413 additions and 353 deletions
+4
View File
@@ -1743,6 +1743,10 @@ if(WIN32)
endif()
if(ANDROID)
target_compile_options(cocos2d PRIVATE
-Wno-comment # nested block comments are actually useful sometimes
)
find_library(LIB_EGL NAMES EGL)
find_library(LIB_GLESv2 NAMES GLESv2)
target_link_libraries(cocos2d PUBLIC
+31 -25
View File
@@ -47,26 +47,26 @@ std::unordered_map<int, int> keyCodeMap = {
{AKEYCODE_DPAD_RIGHT, 1001},
{AKEYCODE_DPAD_CENTER, 1005}};
void dispatchTouchEvent(int index, AInputEvent *event, cc::TouchEvent &touchEvent) {
void dispatchTouchEvent(int index, AInputEvent *event, cc::TouchEvent *touchEvent) {
int pointerID = AMotionEvent_getPointerId(event, index);
touchEvent.touches.push_back({AMotionEvent_getX(event, index), // x
AMotionEvent_getY(event, index), // y
pointerID});
touchEvent->touches.emplace_back(AMotionEvent_getX(event, index), // x
AMotionEvent_getY(event, index), // y
pointerID);
cc::EventDispatcher::dispatchTouchEvent(touchEvent);
touchEvent.touches.clear();
cc::EventDispatcher::dispatchTouchEvent(*touchEvent);
touchEvent->touches.clear();
}
void dispatchTouchEvents(AInputEvent *event, cc::TouchEvent &touchEvent) {
void dispatchTouchEvents(AInputEvent *event, cc::TouchEvent *touchEvent) {
size_t pointerCount = AMotionEvent_getPointerCount(event);
for (size_t i = 0; i < pointerCount; ++i) {
touchEvent.touches.push_back({AMotionEvent_getX(event, i),
AMotionEvent_getY(event, i),
AMotionEvent_getPointerId(event, i)});
touchEvent->touches.emplace_back(AMotionEvent_getX(event, i),
AMotionEvent_getY(event, i),
AMotionEvent_getPointerId(event, i));
}
cc::EventDispatcher::dispatchTouchEvent(touchEvent);
touchEvent.touches.clear();
cc::EventDispatcher::dispatchTouchEvent(*touchEvent);
touchEvent->touches.clear();
}
} // namespace
@@ -90,15 +90,18 @@ void View::engineHandleCmd(int cmd) {
case APP_CMD_TERM_WINDOW: {
cc::CustomEvent event;
event.name = EVENT_DESTROY_WINDOW;
event.args->ptrVal = cocosApp.window;
cc::EventDispatcher::dispatchCustomEvent(event);
} break;
case APP_CMD_RESUME:
if (Application::getInstance())
if (Application::getInstance()) {
Application::getInstance()->onResume();
}
break;
case APP_CMD_PAUSE:
if (Application::getInstance())
if (Application::getInstance()) {
Application::getInstance()->onPause();
}
break;
case APP_CMD_LOW_MEMORY:
cc::EventDispatcher::dispatchMemoryWarningEvent();
@@ -111,19 +114,21 @@ void View::engineHandleCmd(int cmd) {
/**
* Process the next input event.
*/
int32_t View::engineHandleInput(struct android_app *app, AInputEvent *event) {
int32_t View::engineHandleInput(struct android_app * /*app*/, AInputEvent *event) {
int type = AInputEvent_getType(event);
if (type == AINPUT_EVENT_TYPE_KEY) {
int action = AKeyEvent_getAction(event);
if (action == AKEY_EVENT_ACTION_MULTIPLE)
if (action == AKEY_EVENT_ACTION_MULTIPLE) {
return 0;
}
int keyCode = AKeyEvent_getKeyCode(event);
if (keyCodeMap.count(keyCode) > 0)
if (keyCodeMap.count(keyCode) > 0) {
keyCode = keyCodeMap[keyCode];
else
} else {
keyCode = 0;
}
keyboardEvent.key = keyCode;
keyboardEvent.action = action == AKEY_EVENT_ACTION_DOWN
@@ -132,37 +137,38 @@ int32_t View::engineHandleInput(struct android_app *app, AInputEvent *event) {
cc::EventDispatcher::dispatchKeyboardEvent(keyboardEvent);
return 1;
} else if (type == AINPUT_EVENT_TYPE_MOTION) {
}
if (type == AINPUT_EVENT_TYPE_MOTION) {
int action = AMotionEvent_getAction(event);
switch (action & AMOTION_EVENT_ACTION_MASK) {
case AMOTION_EVENT_ACTION_DOWN:
touchEvent.type = cc::TouchEvent::Type::BEGAN;
dispatchTouchEvent(0, event, touchEvent);
dispatchTouchEvent(0, event, &touchEvent);
break;
case AMOTION_EVENT_ACTION_POINTER_DOWN:
touchEvent.type = cc::TouchEvent::Type::BEGAN;
dispatchTouchEvent((action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT,
event,
touchEvent);
&touchEvent);
break;
case AMOTION_EVENT_ACTION_UP:
touchEvent.type = cc::TouchEvent::Type::ENDED;
dispatchTouchEvent(0, event, touchEvent);
dispatchTouchEvent(0, event, &touchEvent);
break;
case AMOTION_EVENT_ACTION_POINTER_UP:
touchEvent.type = cc::TouchEvent::Type::ENDED;
dispatchTouchEvent((action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT,
event,
touchEvent);
&touchEvent);
break;
case AMOTION_EVENT_ACTION_MOVE:
touchEvent.type = cc::TouchEvent::Type::MOVED;
dispatchTouchEvents(event, touchEvent);
dispatchTouchEvents(event, &touchEvent);
break;
case AMOTION_EVENT_ACTION_CANCEL:
touchEvent.type = cc::TouchEvent::Type::CANCELLED;
dispatchTouchEvents(event, touchEvent);
dispatchTouchEvents(event, &touchEvent);
break;
default:
return 0;
+126 -124
View File
@@ -1,124 +1,126 @@
/****************************************************************************
Copyright (c) 2019-2021 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 engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
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 "bindings/event/CustomEventTypes.h"
#include "bindings/event/EventDispatcher.h"
#include "gfx-agent/DeviceAgent.h"
#include "gfx-empty/EmptyDevice.h"
#include "gfx-validator/DeviceValidator.h"
//#undef CC_USE_VULKAN
//#undef CC_USE_GLES3
//#undef CC_USE_GLES2
#ifdef CC_USE_VULKAN
#include "gfx-vulkan/GFXVulkan.h"
#endif
#ifdef CC_USE_METAL
#include "gfx-metal/GFXMTL.h"
#endif
#ifdef CC_USE_GLES3
#include "gfx-gles3/GFXGLES3.h"
#endif
#ifdef CC_USE_GLES2
#include "gfx-gles2/GFXGLES2.h"
#endif
namespace cc {
namespace gfx {
class CC_DLL DeviceManager final {
public:
static Device *create(const DeviceInfo &info) {
Device *device = nullptr;
#ifdef CC_USE_VULKAN
if (tryCreate<CCVKDevice>(info, device)) return device;
#endif
#ifdef CC_USE_METAL
if (tryCreate<CCMTLDevice>(info, device)) return device;
#endif
#ifdef CC_USE_GLES3
if (tryCreate<GLES3Device>(info, device)) return device;
#endif
#ifdef CC_USE_GLES2
if (tryCreate<GLES2Device>(info, device)) return device;
#endif
if (tryCreate<EmptyDevice>(info, device)) return device;
return nullptr;
}
static void destroy() {
CC_SAFE_DESTROY(Device::instance);
}
private:
template <typename DeviceCtor, typename Enable = std::enable_if_t<std::is_base_of<Device, DeviceCtor>::value>>
static bool tryCreate(const DeviceInfo &info, Device *&device) {
device = CC_NEW(DeviceCtor);
device = CC_NEW(gfx::DeviceAgent(device));
if (CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION) {
device = CC_NEW(gfx::DeviceValidator(device));
//((gfx::DeviceValidator *)device)->enableRecording(true);
}
if (!device->initialize(info)) {
CC_SAFE_DELETE(device);
return false;
}
EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [device](const CustomEvent &e) -> void {
device->releaseSurface(reinterpret_cast<uintptr_t>(e.args->ptrVal));
});
EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [device](const CustomEvent &e) -> void {
device->acquireSurface(reinterpret_cast<uintptr_t>(e.args->ptrVal));
});
return true;
}
#ifndef CC_DEBUG
static constexpr int CC_DEBUG{0};
#endif
static constexpr bool FORCE_DISABLE_VALIDATION{false};
static constexpr bool FORCE_ENABLE_VALIDATION{false};
};
} // namespace gfx
} // namespace cc
/****************************************************************************
Copyright (c) 2019-2021 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 engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
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 "bindings/event/CustomEventTypes.h"
#include "bindings/event/EventDispatcher.h"
#include "gfx-agent/DeviceAgent.h"
#include "gfx-empty/EmptyDevice.h"
#include "gfx-validator/DeviceValidator.h"
//#undef CC_USE_VULKAN
//#undef CC_USE_GLES3
//#undef CC_USE_GLES2
#ifdef CC_USE_VULKAN
#include "gfx-vulkan/GFXVulkan.h"
#endif
#ifdef CC_USE_METAL
#include "gfx-metal/GFXMTL.h"
#endif
#ifdef CC_USE_GLES3
#include "gfx-gles3/GFXGLES3.h"
#endif
#ifdef CC_USE_GLES2
#include "gfx-gles2/GFXGLES2.h"
#endif
namespace cc {
namespace gfx {
class CC_DLL DeviceManager final {
public:
static Device *create(const DeviceInfo &info) {
Device *device = nullptr;
#ifdef CC_USE_VULKAN
if (tryCreate<CCVKDevice>(info, &device)) return device;
#endif
#ifdef CC_USE_METAL
if (tryCreate<CCMTLDevice>(info, &device)) return device;
#endif
#ifdef CC_USE_GLES3
if (tryCreate<GLES3Device>(info, &device)) return device;
#endif
#ifdef CC_USE_GLES2
if (tryCreate<GLES2Device>(info, &device)) return device;
#endif
if (tryCreate<EmptyDevice>(info, &device)) return device;
return nullptr;
}
static void destroy() {
CC_SAFE_DESTROY(Device::instance);
}
private:
template <typename DeviceCtor, typename Enable = std::enable_if_t<std::is_base_of<Device, DeviceCtor>::value>>
static bool tryCreate(const DeviceInfo &info, Device **pDevice) {
Device *device = CC_NEW(DeviceCtor);
device = CC_NEW(gfx::DeviceAgent(device));
if (CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION) {
device = CC_NEW(gfx::DeviceValidator(device));
//((gfx::DeviceValidator *)device)->enableRecording(true);
}
if (!device->initialize(info)) {
CC_SAFE_DELETE(device);
return false;
}
EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [device](const CustomEvent &e) -> void {
device->releaseSurface(reinterpret_cast<uintptr_t>(e.args->ptrVal));
});
EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [device](const CustomEvent &e) -> void {
device->acquireSurface(reinterpret_cast<uintptr_t>(e.args->ptrVal));
});
*pDevice = device;
return true;
}
#ifndef CC_DEBUG
static constexpr int CC_DEBUG{0};
#endif
static constexpr bool FORCE_DISABLE_VALIDATION{false};
static constexpr bool FORCE_ENABLE_VALIDATION{false};
};
} // namespace gfx
} // namespace cc
@@ -84,7 +84,7 @@ bool DeviceAgent::doInit(const DeviceInfo &info) {
}
static_cast<CommandBufferAgent *>(_cmdBuff)->initMessageQueue();
//setMultithreaded(true);
setMultithreaded(true);
return true;
}
@@ -194,7 +194,27 @@ void DeviceAgent::setMultithreaded(bool multithreaded) {
}
}
CommandBuffer *DeviceAgent::createCommandBuffer(const CommandBufferInfo &info, bool /*hasAgent*/) {
void DeviceAgent::releaseSurface(uintptr_t windowHandle) {
ENQUEUE_MESSAGE_2(
_mainEncoder, DeviceReleaseSurface,
actor, _actor,
windowHandle, windowHandle,
{
actor->releaseSurface(windowHandle);
});
}
void DeviceAgent::acquireSurface(uintptr_t windowHandle) {
ENQUEUE_MESSAGE_2(
_mainEncoder, DeviceAcquireSurface,
actor, _actor,
windowHandle, windowHandle,
{
actor->acquireSurface(windowHandle);
});
}
CommandBuffer *DeviceAgent::createCommandBuffer(const CommandBufferInfo &info, bool /*hasAgent*/) {
CommandBuffer *actor = _actor->createCommandBuffer(info, true);
return CC_NEW(CommandBufferAgent(actor));
}
@@ -110,11 +110,8 @@ protected:
bool doInit(const DeviceInfo &info) override;
void doDestroy() override;
void releaseSurface(uintptr_t windowHandle) override { _actor->releaseSurface(windowHandle); }
void acquireSurface(uintptr_t windowHandle) override { _actor->acquireSurface(windowHandle); }
void bindRenderContext(bool bound) override { _actor->bindRenderContext(bound); }
void bindDeviceContext(bool bound) override { _actor->bindDeviceContext(bound); }
void releaseSurface(uintptr_t windowHandle) override;
void acquireSurface(uintptr_t windowHandle) override;
bool _multithreaded{false};
MessageQueue *_mainEncoder{nullptr};
@@ -98,7 +98,6 @@ GLES2Context::~GLES2Context() = default;
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_MAC_OSX)
bool GLES2Context::doInit(const ContextInfo &info) {
_vsyncMode = info.vsyncMode;
_windowHandle = info.windowHandle;
@@ -235,7 +234,7 @@ bool GLES2Context::doInit(const ContextInfo &info) {
EGLint ctxAttribs[32];
uint n = 0;
bool hasKHRCreateCtx = CheckExtension(CC_TOSTR(EGL_KHR_create_context));
bool hasKHRCreateCtx = checkExtension(CC_TOSTR(EGL_KHR_create_context));
if (hasKHRCreateCtx) {
#if CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION
ctxAttribs[n++] = EGL_CONTEXT_FLAGS_KHR;
@@ -258,58 +257,26 @@ bool GLES2Context::doInit(const ContextInfo &info) {
return false;
}
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [=](const CustomEvent & /*unused*/) -> void {
if (_eglSurface != EGL_NO_SURFACE) {
eglDestroySurface(_eglDisplay, _eglSurface);
_eglSurface = EGL_NO_SURFACE;
}
});
// guaranteed to be invoked in the order they were added
EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [=](const CustomEvent &event) -> void {
_windowHandle = reinterpret_cast<uintptr_t>(event.args->ptrVal);
EGLint nFmt = 0;
if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) {
CC_LOG_ERROR("Getting configuration attributes failed.");
return;
}
uint width = GLES2Device::getInstance()->getWidth();
uint height = GLES2Device::getInstance()->getHeight();
ANativeWindow_setBuffersGeometry(reinterpret_cast<ANativeWindow *>(_windowHandle), width, height, nFmt);
EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (EGLNativeWindowType)_windowHandle, nullptr));
if (_eglSurface == EGL_NO_SURFACE) {
CC_LOG_ERROR("Recreate window surface failed.");
return;
}
static_cast<GLES2Context *>(GLES2Device::getInstance()->getContext())->MakeCurrent();
GLES2Device::getInstance()->stateCache()->reset();
});
#endif
_eglSharedContext = _eglContext;
} else {
auto *sharedCtx = static_cast<GLES2Context *>(info.sharedCtx);
_majorVersion = sharedCtx->major_ver();
_minorVersion = sharedCtx->minor_ver();
_nativeDisplay = sharedCtx->native_display();
_eglDisplay = sharedCtx->egl_display();
_eglConfig = sharedCtx->egl_config();
_eglSharedContext = sharedCtx->egl_shared_ctx();
_eglSurface = sharedCtx->egl_surface();
_majorVersion = sharedCtx->majorVer();
_minorVersion = sharedCtx->minorVer();
_nativeDisplay = sharedCtx->nativeDisplay();
_eglDisplay = sharedCtx->eglDisplay();
_eglConfig = sharedCtx->eglConfig();
_eglSharedContext = sharedCtx->eglSharedCtx();
_eglSurface = sharedCtx->eglSurface();
_colorFmt = sharedCtx->getColorFormat();
_depthStencilFmt = sharedCtx->getDepthStencilFormat();
_majorVersion = sharedCtx->major_ver();
_minorVersion = sharedCtx->minor_ver();
_majorVersion = sharedCtx->majorVer();
_minorVersion = sharedCtx->minorVer();
_extensions = sharedCtx->_extensions;
_isInitialized = sharedCtx->_isInitialized;
bool hasKHRCreateCtx = CheckExtension(CC_TOSTR(EGL_KHR_create_context));
bool hasKHRCreateCtx = checkExtension(CC_TOSTR(EGL_KHR_create_context));
if (!hasKHRCreateCtx) {
CC_LOG_INFO(
"EGL context creation: EGL_KHR_create_context not supported. Minor version will be discarded, and debug disabled.");
@@ -379,7 +346,40 @@ void GLES2Context::doDestroy() {
_isInitialized = false;
}
bool GLES2Context::MakeCurrentImpl(bool bound) {
void GLES2Context::releaseSurface(uintptr_t /*windowHandle*/) {
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
if (_eglSurface != EGL_NO_SURFACE) {
eglDestroySurface(_eglDisplay, _eglSurface);
_eglSurface = EGL_NO_SURFACE;
}
#endif
}
void GLES2Context::acquireSurface(uintptr_t windowHandle) {
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
_windowHandle = windowHandle;
EGLint nFmt = 0;
if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) {
CC_LOG_ERROR("Getting configuration attributes failed.");
return;
}
uint width = GLES2Device::getInstance()->getWidth();
uint height = GLES2Device::getInstance()->getHeight();
ANativeWindow_setBuffersGeometry(reinterpret_cast<ANativeWindow *>(_windowHandle), width, height, nFmt);
EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (EGLNativeWindowType)_windowHandle, nullptr));
if (_eglSurface == EGL_NO_SURFACE) {
CC_LOG_ERROR("Recreate window surface failed.");
return;
}
static_cast<GLES2Context *>(GLES2Device::getInstance()->getContext())->makeCurrent();
GLES2Device::getInstance()->stateCache()->reset();
#endif
}
bool GLES2Context::makeCurrentImpl(bool bound) {
bool succeeded;
EGL_CHECK(succeeded = eglMakeCurrent(_eglDisplay,
bound ? _eglSurface : EGL_NO_SURFACE,
@@ -394,15 +394,14 @@ void GLES2Context::present() {
#endif
bool GLES2Context::MakeCurrent(bool bound) {
bool GLES2Context::makeCurrent(bool bound) {
if (!bound) {
CC_LOG_DEBUG("eglMakeCurrent() - UNBOUNDED, Context: 0x%p", this);
return MakeCurrentImpl(false);
return makeCurrentImpl(false);
}
if (MakeCurrentImpl(bound)) {
if (makeCurrentImpl(bound)) {
if (!_isInitialized) {
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_ANDROID)
// Turn on or off the vertical sync depending on the input bool value.
int interval = 1;
@@ -477,7 +476,7 @@ bool GLES2Context::MakeCurrent(bool bound) {
return false;
}
bool GLES2Context::CheckExtension(const String &extension) const {
bool GLES2Context::checkExtension(const String &extension) const {
return (std::find(_extensions.begin(), _extensions.end(), extension) != _extensions.end());
}
+31 -27
View File
@@ -25,8 +25,9 @@
#pragma once
#include "gfx-base/GFXContext.h"
#include "GLES2Std.h"
#include "GLES2Wrangler.h"
#include "gfx-base/GFXContext.h"
namespace cc {
namespace gfx {
@@ -34,60 +35,63 @@ namespace gfx {
class CC_GLES2_API GLES2Context final : public Context {
public:
GLES2Context();
~GLES2Context();
~GLES2Context() override;
void present() override;
bool MakeCurrent(bool bound);
bool makeCurrent(bool bound);
bool CheckExtension(const String &extension) const;
bool checkExtension(const String &extension) const;
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
CC_INLINE intptr_t eagl_context() const { return _eaglContext; }
CC_INLINE intptr_t eagl_shared_ctx() const { return _eaglSharedContext; }
CC_INLINE uint getDefaultFramebuffer() const { return _defaultFBO; }
CC_INLINE uint getDefaultFramebuffer() const { return _defaultFBO; }
#else
CC_INLINE NativeDisplayType native_display() const { return _nativeDisplay; }
CC_INLINE EGLDisplay egl_display() const { return _eglDisplay; }
CC_INLINE EGLConfig egl_config() const { return _eglConfig; }
CC_INLINE EGLSurface egl_surface() const { return _eglSurface; }
CC_INLINE EGLContext egl_context() const { return _eglContext; }
CC_INLINE EGLContext egl_shared_ctx() const { return _eglSharedContext; }
CC_INLINE NativeDisplayType nativeDisplay() const { return _nativeDisplay; }
CC_INLINE EGLDisplay eglDisplay() const { return _eglDisplay; }
CC_INLINE EGLConfig eglConfig() const { return _eglConfig; }
CC_INLINE EGLSurface eglSurface() const { return _eglSurface; }
CC_INLINE EGLContext eglContext() const { return _eglContext; }
CC_INLINE EGLContext eglSharedCtx() const { return _eglSharedContext; }
#endif
CC_INLINE bool MakeCurrent() { return MakeCurrent(true); }
CC_INLINE int major_ver() const { return _majorVersion; }
CC_INLINE int minor_ver() const { return _minorVersion; }
CC_INLINE bool makeCurrent() { return makeCurrent(true); }
CC_INLINE int majorVer() const { return _majorVersion; }
CC_INLINE int minorVer() const { return _minorVersion; }
bool MakeCurrentImpl(bool bound);
bool makeCurrentImpl(bool bound);
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
bool createCustomFrameBuffer();
void doDestroyCustomFrameBuffer();
#endif
void releaseSurface(uintptr_t windowHandle);
void acquireSurface(uintptr_t windowHandle);
protected:
bool doInit(const ContextInfo &info) override;
void doDestroy() override;
bool _isPrimaryContex = false;
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
intptr_t _eaglContext = 0;
intptr_t _eaglContext = 0;
intptr_t _eaglSharedContext = 0;
// iOS needs to created frame buffer and attach color/depth/stencil buffer.
uint _defaultFBO = 0;
uint _defaultColorBuffer = 0;
uint _defaultFBO = 0;
uint _defaultColorBuffer = 0;
uint _defaultDepthStencilBuffer = 0;
#else
NativeDisplayType _nativeDisplay = 0;
EGLDisplay _eglDisplay = EGL_NO_DISPLAY;
EGLConfig _eglConfig = EGL_NO_CONFIG_KHR;
EGLSurface _eglSurface = EGL_NO_SURFACE;
EGLContext _eglContext = EGL_NO_CONTEXT;
EGLContext _eglSharedContext = EGL_NO_CONTEXT;
NativeDisplayType _nativeDisplay = 0; // NOLINT(modernize-use-nullptr) portability issues
EGLDisplay _eglDisplay = EGL_NO_DISPLAY;
EGLConfig _eglConfig = EGL_NO_CONFIG_KHR;
EGLSurface _eglSurface = EGL_NO_SURFACE;
EGLContext _eglContext = EGL_NO_CONTEXT;
EGLContext _eglSharedContext = EGL_NO_CONTEXT;
#endif
int _majorVersion = 0;
int _minorVersion = 0;
int _majorVersion = 0;
int _minorVersion = 0;
StringArray _extensions;
bool _isInitialized = false;
bool _isInitialized = false;
};
} // namespace gfx
@@ -205,6 +205,14 @@ void GLES2Device::doDestroy() {
CC_SAFE_DESTROY(_renderContext);
}
void GLES2Device::releaseSurface(uintptr_t windowHandle) {
static_cast<GLES2Context *>(_context)->releaseSurface(windowHandle);
}
void GLES2Device::acquireSurface(uintptr_t windowHandle) {
static_cast<GLES2Context *>(_context)->acquireSurface(windowHandle);
}
void GLES2Device::resize(uint width, uint height) {
_width = width;
_height = height;
@@ -229,7 +237,7 @@ void GLES2Device::present() {
}
void GLES2Device::bindRenderContext(bool bound) {
_renderContext->MakeCurrent(bound);
_renderContext->makeCurrent(bound);
_context = bound ? _renderContext : nullptr;
if (bound) {
@@ -247,7 +255,7 @@ void GLES2Device::bindDeviceContext(bool bound) {
_deviceContext = CC_NEW(GLES2Context);
_deviceContext->initialize(ctxInfo);
}
_deviceContext->MakeCurrent(bound);
_deviceContext->makeCurrent(bound);
_context = bound ? _deviceContext : nullptr;
if (bound) {
@@ -114,6 +114,9 @@ protected:
TextureBarrier * createTextureBarrier() override;
void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override;
void releaseSurface(uintptr_t windowHandle) override;
void acquireSurface(uintptr_t windowHandle) override;
void bindRenderContext(bool bound) override;
void bindDeviceContext(bool bound) override;
@@ -91,7 +91,6 @@ GLES3Context::~GLES3Context() = default;
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_MAC_OSX)
bool GLES3Context::doInit(const ContextInfo &info) {
_vsyncMode = info.vsyncMode;
_windowHandle = info.windowHandle;
@@ -226,7 +225,7 @@ bool GLES3Context::doInit(const ContextInfo &info) {
EGLint ctxAttribs[32];
uint n = 0;
bool hasKHRCreateCtx = CheckExtension(CC_TOSTR(EGL_KHR_create_context));
bool hasKHRCreateCtx = checkExtension(CC_TOSTR(EGL_KHR_create_context));
if (hasKHRCreateCtx) {
for (int m = 2; m >= 0; --m) {
#if (CC_PLATFORM == CC_PLATFORM_MAC_OSX)
@@ -267,19 +266,19 @@ bool GLES3Context::doInit(const ContextInfo &info) {
} else {
auto *sharedCtx = static_cast<GLES3Context *>(info.sharedCtx);
_majorVersion = sharedCtx->major_ver();
_minorVersion = sharedCtx->minor_ver();
_nativeDisplay = sharedCtx->native_display();
_eglDisplay = sharedCtx->egl_display();
_eglConfig = sharedCtx->egl_config();
_eglSharedContext = sharedCtx->egl_shared_ctx();
_eglSurface = sharedCtx->egl_surface();
_majorVersion = sharedCtx->majorVer();
_minorVersion = sharedCtx->minorVer();
_nativeDisplay = sharedCtx->nativeDisplay();
_eglDisplay = sharedCtx->eglDisplay();
_eglConfig = sharedCtx->eglConfig();
_eglSharedContext = sharedCtx->eglSharedCtx();
_eglSurface = sharedCtx->eglSurface();
_colorFmt = sharedCtx->getColorFormat();
_depthStencilFmt = sharedCtx->getDepthStencilFormat();
_extensions = sharedCtx->_extensions;
_isInitialized = sharedCtx->_isInitialized;
bool hasKHRCreateCtx = CheckExtension(CC_TOSTR(EGL_KHR_create_context));
bool hasKHRCreateCtx = checkExtension(CC_TOSTR(EGL_KHR_create_context));
if (!hasKHRCreateCtx) {
CC_LOG_INFO("EGL context creation: EGL_KHR_create_context not supported. Minor version will be discarded, and debug disabled.");
_minorVersion = 0;
@@ -376,12 +375,12 @@ void GLES3Context::acquireSurface(uintptr_t windowHandle) {
return;
}
static_cast<GLES3Context *>(GLES3Device::getInstance()->getContext())->MakeCurrent();
static_cast<GLES3Context *>(GLES3Device::getInstance()->getContext())->makeCurrent();
GLES3Device::getInstance()->stateCache()->reset();
#endif
}
bool GLES3Context::MakeCurrentImpl(bool bound) {
bool GLES3Context::makeCurrentImpl(bool bound) {
bool succeeded;
EGL_CHECK(succeeded = eglMakeCurrent(_eglDisplay,
bound ? _eglSurface : EGL_NO_SURFACE,
@@ -396,13 +395,13 @@ void GLES3Context::present() {
#endif
bool GLES3Context::MakeCurrent(bool bound) {
bool GLES3Context::makeCurrent(bool bound) {
if (!bound) {
CC_LOG_DEBUG("eglMakeCurrent() - UNBOUNDED, Context: 0x%p", this);
return MakeCurrentImpl(false);
return makeCurrentImpl(false);
}
if (MakeCurrentImpl(bound)) {
if (makeCurrentImpl(bound)) {
if (!_isInitialized) {
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_ANDROID)
// Turn on or off the vertical sync depending on the input bool value.
@@ -478,7 +477,7 @@ bool GLES3Context::MakeCurrent(bool bound) {
return false;
}
bool GLES3Context::CheckExtension(const String &extension) const {
bool GLES3Context::checkExtension(const String &extension) const {
return (std::find(_extensions.begin(), _extensions.end(), extension) != _extensions.end());
}
+26 -28
View File
@@ -25,9 +25,9 @@
#pragma once
#include "gfx-base/GFXContext.h"
#include "GLES3Std.h"
#include "GLES3Wrangler.h"
#include "gfx-base/GFXContext.h"
namespace cc {
namespace gfx {
@@ -35,40 +35,39 @@ namespace gfx {
class CC_GLES3_API GLES3Context final : public Context {
public:
GLES3Context();
~GLES3Context();
~GLES3Context() override;
void present() override;
bool MakeCurrent(bool bound);
bool CheckExtension(const String &extension) const;
bool makeCurrent(bool bound);
bool checkExtension(const String &extension) const;
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
CC_INLINE intptr_t eagl_context() const { return _eaglContext; }
CC_INLINE intptr_t eagl_shared_ctx() const { return _eaglSharedContext; }
CC_INLINE uint getDefaultFramebuffer() const { return _defaultFBO; }
#else
CC_INLINE NativeDisplayType native_display() const { return _nativeDisplay; }
CC_INLINE EGLDisplay egl_display() const { return _eglDisplay; }
CC_INLINE EGLConfig egl_config() const { return _eglConfig; }
CC_INLINE EGLSurface egl_surface() const { return _eglSurface; }
CC_INLINE EGLContext egl_context() const { return _eglContext; }
CC_INLINE EGLContext egl_shared_ctx() const { return _eglSharedContext; }
CC_INLINE NativeDisplayType nativeDisplay() const { return _nativeDisplay; }
CC_INLINE EGLDisplay eglDisplay() const { return _eglDisplay; }
CC_INLINE EGLConfig eglConfig() const { return _eglConfig; }
CC_INLINE EGLSurface eglSurface() const { return _eglSurface; }
CC_INLINE EGLContext eglContext() const { return _eglContext; }
CC_INLINE EGLContext eglSharedCtx() const { return _eglSharedContext; }
#endif
CC_INLINE bool MakeCurrent() { return MakeCurrent(true); }
CC_INLINE int major_ver() const { return _majorVersion; }
CC_INLINE int minor_ver() const { return _minorVersion; }
CC_INLINE bool makeCurrent() { return makeCurrent(true); }
CC_INLINE int majorVer() const { return _majorVersion; }
CC_INLINE int minorVer() const { return _minorVersion; }
void releaseSurface(uintptr_t windowHandle);
void acquireSurface(uintptr_t windowHandle);
protected:
bool MakeCurrentImpl(bool bound);
bool makeCurrentImpl(bool bound);
#if (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
bool createCustomFrameBuffer();
void doDestroyCustomFrameBuffer();
#endif
protected:
bool doInit(const ContextInfo &info) override;
void doDestroy() override;
@@ -81,19 +80,18 @@ protected:
uint _defaultColorBuffer = 0;
uint _defaultDepthStencilBuffer = 0;
#else
NativeDisplayType _nativeDisplay = 0;
EGLDisplay _eglDisplay = EGL_NO_DISPLAY;
EGLConfig _eglConfig = EGL_NO_CONFIG_KHR;
EGLSurface _eglSurface = EGL_NO_SURFACE;
EGLContext _eglContext = EGL_NO_CONTEXT;
EGLContext _eglSharedContext = EGL_NO_CONTEXT;
int _majorVersion = 0;
int _minorVersion = 0;
StringArray _extensions;
bool _isInitialized = false;
NativeDisplayType _nativeDisplay = 0; // NOLINT(modernize-use-nullptr) portability issues
EGLDisplay _eglDisplay = EGL_NO_DISPLAY;
EGLConfig _eglConfig = EGL_NO_CONFIG_KHR;
EGLSurface _eglSurface = EGL_NO_SURFACE;
EGLContext _eglContext = EGL_NO_CONTEXT;
EGLContext _eglSharedContext = EGL_NO_CONTEXT;
#endif
int _majorVersion = 0;
int _minorVersion = 0;
StringArray _extensions;
bool _isInitialized = false;
};
} // namespace gfx
} // namespace cc
#endif // CC_GFXGLES3_EGL_CONTEXT_H_
@@ -101,7 +101,7 @@ bool GLES3Device::doInit(const DeviceInfo & /*info*/) {
_features[static_cast<uint>(Feature::BLEND_MINMAX)] = true;
_features[static_cast<uint>(Feature::ELEMENT_INDEX_UINT)] = true;
uint minorVersion = static_cast<GLES3Context *>(_context)->minor_ver();
uint minorVersion = static_cast<GLES3Context *>(_context)->minorVer();
if (minorVersion) {
_features[static_cast<uint>(Feature::COMPUTE_SHADER)] = true;
}
@@ -239,7 +239,7 @@ void GLES3Device::present() {
}
void GLES3Device::bindRenderContext(bool bound) {
_renderContext->MakeCurrent(bound);
_renderContext->makeCurrent(bound);
_context = bound ? _renderContext : nullptr;
if (bound) {
@@ -257,7 +257,7 @@ void GLES3Device::bindDeviceContext(bool bound) {
_deviceContext = CC_NEW(GLES3Context);
_deviceContext->initialize(ctxInfo);
}
_deviceContext->MakeCurrent(bound);
_deviceContext->makeCurrent(bound);
_context = bound ? _deviceContext : nullptr;
if (bound) {
@@ -266,7 +266,7 @@ void GLES3Device::bindDeviceContext(bool bound) {
}
}
uint GLES3Device::getMinorVersion() const { return static_cast<GLES3Context *>(_context)->minor_ver(); }
uint GLES3Device::getMinorVersion() const { return static_cast<GLES3Context *>(_context)->minorVer(); }
CommandBuffer *GLES3Device::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) {
if (hasAgent || info.type == CommandBufferType::PRIMARY) return CC_NEW(GLES3PrimaryCommandBuffer);
+35 -37
View File
@@ -34,9 +34,6 @@
#include "VKUtils.h"
#include "bindings/event/CustomEventTypes.h"
#include "bindings/event/EventDispatcher.h"
namespace cc {
namespace gfx {
@@ -267,6 +264,7 @@ bool CCVKContext::doInit(const ContextInfo &info) {
} else {
VK_CHECK(vkCreateDebugReportCallbackEXT(_gpuContext->vkInstance, &debugReportCreateInfo, nullptr, &_gpuContext->vkDebugReport));
}
_validationEnabled = true;
#endif
///////////////////// Surface Creation /////////////////////
@@ -275,40 +273,6 @@ bool CCVKContext::doInit(const ContextInfo &info) {
VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo{VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
surfaceCreateInfo.window = reinterpret_cast<ANativeWindow *>(_windowHandle);
VK_CHECK(vkCreateAndroidSurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface));
EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [this](const CustomEvent &/*event*/) -> void {
if (_gpuContext && _gpuContext->vkSurface != VK_NULL_HANDLE) {
CCVKDevice *device = CCVKDevice::getInstance();
auto *queue = static_cast<CCVKQueue *>(device->getQueue());
uint fenceCount = device->gpuFencePool()->size();
if (fenceCount) {
VK_CHECK(vkWaitForFences(device->gpuDevice()->vkDevice, fenceCount,
device->gpuFencePool()->data(), VK_TRUE, DEFAULT_TIMEOUT));
}
device->destroySwapchain();
device->_swapchainReady = false;
vkDestroySurfaceKHR(_gpuContext->vkInstance, _gpuContext->vkSurface, nullptr);
_gpuContext->vkSurface = VK_NULL_HANDLE;
}
});
EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [this](const CustomEvent &event) -> void {
_windowHandle = reinterpret_cast<uintptr_t>(event.args->ptrVal);
if (_gpuContext && _gpuContext->vkSurface == VK_NULL_HANDLE) {
VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo{VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
surfaceCreateInfo.window = reinterpret_cast<ANativeWindow *>(_windowHandle);
VK_CHECK(vkCreateAndroidSurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo,
nullptr, &_gpuContext->vkSurface));
CCVKDevice::getInstance()->checkSwapchainStatus();
}
});
#elif defined(VK_USE_PLATFORM_WIN32_KHR)
VkWin32SurfaceCreateInfoKHR surfaceCreateInfo{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
surfaceCreateInfo.hinstance = static_cast<HINSTANCE>(GetModuleHandle(0));
@@ -573,5 +537,39 @@ void CCVKContext::doDestroy() {
}
}
void CCVKContext::releaseSurface(uintptr_t /*windowHandle*/) {
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
if (_gpuContext && _gpuContext->vkSurface == VK_NULL_HANDLE) return;
CCVKDevice *device = CCVKDevice::getInstance();
uint fenceCount = device->gpuFencePool()->size();
if (fenceCount) {
VK_CHECK(vkWaitForFences(device->gpuDevice()->vkDevice, fenceCount,
device->gpuFencePool()->data(), VK_TRUE, DEFAULT_TIMEOUT));
}
device->destroySwapchain();
device->_swapchainReady = false;
vkDestroySurfaceKHR(_gpuContext->vkInstance, _gpuContext->vkSurface, nullptr);
_gpuContext->vkSurface = VK_NULL_HANDLE;
#endif
}
void CCVKContext::acquireSurface(uintptr_t windowHandle) {
#if (CC_PLATFORM == CC_PLATFORM_ANDROID)
_windowHandle = windowHandle;
if (_gpuContext && _gpuContext->vkSurface != VK_NULL_HANDLE) return;
VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo{VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
surfaceCreateInfo.window = reinterpret_cast<ANativeWindow *>(_windowHandle);
VK_CHECK(vkCreateAndroidSurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo,
nullptr, &_gpuContext->vkSurface));
CCVKDevice::getInstance()->checkSwapchainStatus();
#endif
}
} // namespace gfx
} // namespace cc
@@ -56,6 +56,11 @@ public:
inline const vector<const char *> &getLayers() const { return _layers; }
inline const vector<const char *> &getExtensions() const { return _extensions; }
inline bool validationEnabled() const { return _validationEnabled; }
void releaseSurface(uintptr_t windowHandle);
void acquireSurface(uintptr_t windowHandle);
protected:
bool doInit(const ContextInfo &info) override;
void doDestroy() override;
@@ -66,6 +71,8 @@ protected:
int _minorVersion = 0;
vector<const char *> _layers;
vector<const char *> _extensions;
bool _validationEnabled = false;
};
} // namespace gfx
+33 -30
View File
@@ -106,12 +106,7 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) {
_gpuDevice->minorVersion = context->minorVersion();
// only enable the absolute essentials for now
vector<const char *> requestedValidationLayers{};
#if CC_DEBUG > 0
requestedValidationLayers.push_back("VK_LAYER_KHRONOS_validation");
#endif
vector<const char *> requestedLayers{};
vector<const char *> requestedExtensions{
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
};
@@ -132,13 +127,14 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) {
requestedFeatures2.features.depthBounds = deviceFeatures.depthBounds;
requestedFeatures2.features.multiDrawIndirect = deviceFeatures.multiDrawIndirect;
#if CC_DEBUG > 0
// GPU-assisted validation
requestedFeatures2.features.shaderInt64 = deviceFeatures.shaderInt64;
requestedFeatures2.features.fragmentStoresAndAtomics = deviceFeatures.fragmentStoresAndAtomics;
requestedFeatures2.features.vertexPipelineStoresAndAtomics = deviceFeatures.vertexPipelineStoresAndAtomics;
requestedExtensions.push_back(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME);
#endif
if (context->validationEnabled()) {
requestedLayers.push_back("VK_LAYER_KHRONOS_validation");
// GPU-assisted validation
requestedFeatures2.features.shaderInt64 = deviceFeatures.shaderInt64;
requestedFeatures2.features.fragmentStoresAndAtomics = deviceFeatures.fragmentStoresAndAtomics;
requestedFeatures2.features.vertexPipelineStoresAndAtomics = deviceFeatures.vertexPipelineStoresAndAtomics;
requestedExtensions.push_back(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME);
}
// check extensions
uint availableLayerCount;
@@ -152,7 +148,7 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) {
VK_CHECK(vkEnumerateDeviceExtensionProperties(gpuContext->physicalDevice, nullptr, &availableExtensionCount, _gpuDevice->extensions.data()));
// just filter out the unsupported layers & extensions
for (const char *layer : requestedValidationLayers) {
for (const char *layer : requestedLayers) {
if (isLayerSupported(layer, _gpuDevice->layers)) {
_layers.push_back(layer);
}
@@ -379,8 +375,7 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) {
gpuTransportHub()->checkIn(
[&barrier](const CCVKGPUCommandBuffer *gpuCommandBuffer) {
cmdFuncCCVKImageMemoryBarrier(gpuCommandBuffer, barrier);
},
true); // submit immediately
});
_gpuDevice->defaultBuffer.usage = BufferUsage::UNIFORM;
_gpuDevice->defaultBuffer.memUsage = MemoryUsage::HOST | MemoryUsage::DEVICE;
@@ -452,27 +447,27 @@ void CCVKDevice::doDestroy() {
}
for (CCVKTexture *texture : _depthStencilTextures) {
CC_SAFE_DESTROY(texture);
CC_SAFE_DESTROY(texture)
}
_depthStencilTextures.clear();
CC_SAFE_DESTROY(_queue);
CC_SAFE_DESTROY(_cmdBuff);
CC_SAFE_DESTROY(_queue)
CC_SAFE_DESTROY(_cmdBuff)
CC_SAFE_DELETE(_gpuBufferHub);
CC_SAFE_DELETE(_gpuTransportHub);
CC_SAFE_DELETE(_gpuSemaphorePool);
CC_SAFE_DELETE(_gpuDescriptorHub);
CC_SAFE_DELETE(_gpuBarrierManager);
CC_SAFE_DELETE(_gpuDescriptorSetHub);
CC_SAFE_DELETE(_gpuBufferHub)
CC_SAFE_DELETE(_gpuTransportHub)
CC_SAFE_DELETE(_gpuSemaphorePool)
CC_SAFE_DELETE(_gpuDescriptorHub)
CC_SAFE_DELETE(_gpuBarrierManager)
CC_SAFE_DELETE(_gpuDescriptorSetHub)
uint backBufferCount = static_cast<CCVKContext *>(_context)->gpuContext()->swapchainCreateInfo.minImageCount;
for (uint i = 0U; i < backBufferCount; i++) {
_gpuRecycleBins[i]->clear();
CC_SAFE_DELETE(_gpuStagingBufferPools[i]);
CC_SAFE_DELETE(_gpuRecycleBins[i]);
CC_SAFE_DELETE(_gpuFencePools[i]);
CC_SAFE_DELETE(_gpuStagingBufferPools[i])
CC_SAFE_DELETE(_gpuRecycleBins[i])
CC_SAFE_DELETE(_gpuFencePools[i])
}
_gpuStagingBufferPools.clear();
_gpuRecycleBins.clear();
@@ -517,7 +512,7 @@ void CCVKDevice::doDestroy() {
for (CCVKGPUDevice::CommandBufferPools::iterator it = _gpuDevice->_commandBufferPools.begin();
it != _gpuDevice->_commandBufferPools.end(); ++it) {
CC_SAFE_DELETE(it->second);
CC_SAFE_DELETE(it->second)
}
_gpuDevice->_commandBufferPools.clear();
_gpuDevice->_descriptorSetPools.clear();
@@ -531,7 +526,7 @@ void CCVKDevice::doDestroy() {
_gpuDevice = nullptr;
}
CC_SAFE_DESTROY(_context);
CC_SAFE_DESTROY(_context)
}
// no-op since we maintain surface size internally
@@ -816,5 +811,13 @@ void CCVKDevice::destroySwapchain() {
}
}
void CCVKDevice::releaseSurface(uintptr_t windowHandle) {
static_cast<CCVKContext *>(_context)->releaseSurface(windowHandle);
}
void CCVKDevice::acquireSurface(uintptr_t windowHandle) {
static_cast<CCVKContext *>(_context)->acquireSurface(windowHandle);
}
} // namespace gfx
} // namespace cc
@@ -126,6 +126,9 @@ protected:
void destroySwapchain();
bool checkSwapchainStatus();
void releaseSurface(uintptr_t windowHandle) override;
void acquireSurface(uintptr_t windowHandle) override;
CCVKGPUDevice * _gpuDevice = nullptr;
CCVKGPUSwapchain * _gpuSwapchain = nullptr;
vector<CCVKTexture *> _depthStencilTextures;
@@ -1221,6 +1221,8 @@ public:
void flush(CCVKGPUTransportHub *transportHub) {
auto &buffers = _buffersToBeUpdated[_device->curBackBufferIndex];
if (buffers.empty()) return;
transportHub->checkIn([&](const CCVKGPUCommandBuffer *gpuCommandBuffer) {
VkBufferCopy region;
for (auto &buffer : buffers) {
+9 -2
View File
@@ -83,7 +83,7 @@ Another fairly decent choice is to install the `clangd` extension only: (`clangd
![](imgs/clangd.png)
`clangd` is the official language server by LLVM. Compared to the first approach, it has real-time linting & fixing support (much better performance and IDE integration). However it only supports a portion of clang-tidy rules, so the reports won't be identical to the CI environment and it doesn't provide a 'fix-all' command. But combined with the CLI approach below it still can be of a great help.
`clangd` is the official language server by LLVM. Compared to the first approach, it has real-time linting & fixing support (much better performance and IDE integration). However it only supports a subset of clang-tidy rules, so the reports won't be identical to the CI environment and it doesn't provide a 'fix-all' command. But combined with the CLI approach below it still can be of a great help.
## Command Line Interface
@@ -101,7 +101,14 @@ utils/tidy-fix-commit.sh HEAD~3..HEAD # run auto-fix on files in the last 3 comm
All the issues will be reported in the standard output. This can be used as local self-test runs for CI checks.
The CLI scripts can(and are recommended to) be used as complements to the VS Code environment.
Also, you can install the `Command Runner` extension in VSCode:
![](imgs/command-runner.png)
And assign a suitable key binding for fixing the current file:
```bash
clang-tidy -fix ${file}
```
## Other IDEs
Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

+1 -1
View File
@@ -8,5 +8,5 @@ filtered=`node .github/workflows/filter_by_cdb.js $changes`
if [[ "$filtered-xxx" == "-xxx" ]]; then
echo "No source to be fixed"
else
clang-tidy --format-style=file --fix $filtered
clang-tidy --format-style=file --fix $2 $filtered
fi