mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 03:22:39 +08:00
use IntrusivePtr to share object (#11729)
This commit is contained in:
@@ -59,7 +59,7 @@ DeviceAgent::DeviceAgent(Device *device) : Agent(device) {
|
||||
}
|
||||
|
||||
DeviceAgent::~DeviceAgent() {
|
||||
CC_SAFE_DELETE(_actor);
|
||||
destroy();
|
||||
DeviceAgent::instance = nullptr;
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ bool DeviceAgent::doInit(const DeviceInfo &info) {
|
||||
// TODO(PatriceJiang): replace with: _mainMessageQueue = ccnew MessageQueue;
|
||||
_mainMessageQueue = ccnew_placement(CC_MALLOC_ALIGN(sizeof(MessageQueue), alignof(MessageQueue))) MessageQueue; // NOLINT
|
||||
|
||||
static_cast<CommandBufferAgent *>(_cmdBuff)->_queue = _queue;
|
||||
static_cast<CommandBufferAgent *>(_cmdBuff)->initAgent();
|
||||
static_cast<CommandBufferAgent *>(_cmdBuff.get())->_queue = _queue;
|
||||
static_cast<CommandBufferAgent *>(_cmdBuff.get())->initAgent();
|
||||
|
||||
setMultithreaded(true);
|
||||
|
||||
@@ -96,33 +96,28 @@ void DeviceAgent::doDestroy() {
|
||||
_mainMessageQueue, DeviceDestroy,
|
||||
actor, _actor,
|
||||
{
|
||||
actor->destroy();
|
||||
if (actor) {
|
||||
actor->destroy();
|
||||
}
|
||||
});
|
||||
|
||||
if (_cmdBuff) {
|
||||
static_cast<CommandBufferAgent *>(_cmdBuff)->destroyAgent();
|
||||
static_cast<CommandBufferAgent *>(_cmdBuff)->_actor = nullptr;
|
||||
delete _cmdBuff;
|
||||
static_cast<CommandBufferAgent *>(_cmdBuff.get())->destroyAgent();
|
||||
_cmdBuff = nullptr;
|
||||
}
|
||||
if (_queryPool) {
|
||||
static_cast<QueryPoolAgent *>(_queryPool)->_actor = nullptr;
|
||||
delete _queryPool;
|
||||
_queryPool = nullptr;
|
||||
}
|
||||
if (_queue) {
|
||||
static_cast<QueueAgent *>(_queue)->_actor = nullptr;
|
||||
delete _queue;
|
||||
_queue = nullptr;
|
||||
}
|
||||
|
||||
_mainMessageQueue->terminateConsumerThread();
|
||||
_queryPool = nullptr;
|
||||
_queue = nullptr;
|
||||
|
||||
// NOTE: C++17 required when enable alignment
|
||||
// TODO(PatriceJiang): replace with: CC_SAFE_DELETE(_mainMessageQueue);
|
||||
_mainMessageQueue->~MessageQueue();
|
||||
CC_FREE_ALIGN(_mainMessageQueue);
|
||||
_mainMessageQueue = nullptr;
|
||||
if (_mainMessageQueue) {
|
||||
_mainMessageQueue->terminateConsumerThread();
|
||||
|
||||
// NOTE: C++17 required when enable alignment
|
||||
// TODO(PatriceJiang): replace with: CC_SAFE_DELETE(_mainMessageQueue);
|
||||
_mainMessageQueue->~MessageQueue();
|
||||
CC_FREE_ALIGN(_mainMessageQueue);
|
||||
_mainMessageQueue = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceAgent::acquire(Swapchain *const *swapchains, uint32_t count) {
|
||||
@@ -357,11 +352,11 @@ void doBufferTextureCopy(const uint8_t *const *buffers, Texture *texture, const
|
||||
}
|
||||
|
||||
void DeviceAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) {
|
||||
doBufferTextureCopy(buffers, dst, regions, count, _mainMessageQueue, _actor);
|
||||
doBufferTextureCopy(buffers, dst, regions, count, _mainMessageQueue, _actor.get());
|
||||
}
|
||||
|
||||
void CommandBufferAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) {
|
||||
doBufferTextureCopy(buffers, texture, regions, count, _messageQueue, _actor);
|
||||
doBufferTextureCopy(buffers, texture, regions, count, _messageQueue, _actor.get());
|
||||
}
|
||||
|
||||
void DeviceAgent::copyTextureToBuffers(Texture *srcTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint32_t count) {
|
||||
|
||||
Reference in New Issue
Block a user