fix rootnode command register, capture weakptr in lambda

Change-Id: Ib07ae61ebbadc49580d1c729b73bc1a598548b3d
Signed-off-by: Zhang Peng <zhangpeng280@huawei.com>
This commit is contained in:
Zhang Peng 2022-03-01 16:02:08 +08:00
parent 8757403ab5
commit 6130776eaf
No known key found for this signature in database
GPG Key ID: CCBB4C0B66096A23
3 changed files with 23 additions and 13 deletions

View File

@ -25,6 +25,7 @@
#include "command/rs_canvas_node_command.h"
#include "command/rs_display_node_command.h"
#include "command/rs_node_command.h"
#include "command/rs_root_node_command.h"
#include "command/rs_surface_node_command.h"
// animation
#include "command/rs_animation_command.h"
@ -53,7 +54,8 @@ void RSCommandFactory::Register(uint16_t type, uint16_t subtype, UnmarshallingFu
{
auto result = unmarshallingFuncLUT_.try_emplace(MakeKey(type, subtype), func);
if (!result.second) {
ROSEN_LOGE("RSCommandFactory::Register, Duplicate command & sub_command detected! type: %d subtype: %d", type, subtype);
ROSEN_LOGE("RSCommandFactory::Register, Duplicate command & sub_command detected! type: %d subtype: %d", type,
subtype);
}
}

View File

@ -199,12 +199,16 @@ void RSSurfaceRenderNode::RegisterBufferAvailableListener(sptr<RSIBufferAvailabl
void RSSurfaceRenderNode::ConnectToNodeInRenderService()
{
ROSEN_LOGI("RSSurfaceRenderNode::ConnectToNodeInRenderService nodeId = %llu", this->GetId());
auto renderServiceClinet =
auto renderServiceClient =
std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient());
if (renderServiceClinet != nullptr) {
renderServiceClinet->RegisterBufferAvailableListener(GetId(),
[this](bool isBufferAvailable) {
this->NotifyBufferAvailable(isBufferAvailable);
if (renderServiceClient != nullptr) {
renderServiceClient->RegisterBufferAvailableListener(
GetId(), [weakThis = weak_from_this()](bool isBufferAvailable) {
auto node = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(weakThis.lock());
if (node == nullptr) {
return;
}
node->NotifyBufferAvailable(isBufferAvailable);
});
}
}

View File

@ -105,13 +105,6 @@ RSRenderThread::RSRenderThread()
ROSEN_LOGD("RSRenderThread DrawFrame took %fs.", drawTime);
}
};
#ifdef ROSEN_OHOS
RSRenderServiceConnectHub::SetOnConnectCallback([this](sptr<RSIRenderServiceConnection>& conn) {
sptr<IApplicationRenderThread> renderThreadSptr = sptr<RSRenderThread>(this);
conn->RegisterApplicationRenderThread(getpid(), renderThreadSptr);
});
#endif
}
RSRenderThread::~RSRenderThread()
@ -132,6 +125,17 @@ void RSRenderThread::Start()
if (thread_ == nullptr) {
thread_ = std::make_unique<std::thread>(&RSRenderThread::RenderLoop, this);
}
#ifdef ROSEN_OHOS
RSRenderServiceConnectHub::SetOnConnectCallback(
[weakThis = wptr<RSRenderThread>(this)](sptr<RSIRenderServiceConnection>& conn) {
sptr<IApplicationRenderThread> renderThreadSptr = weakThis.promote();
if (renderThreadSptr == nullptr) {
return;
}
conn->RegisterApplicationRenderThread(getpid(), renderThreadSptr);
});
#endif
}
void RSRenderThread::Stop()