From 34478c00d9b64281720197de72e29da90598cdf4 Mon Sep 17 00:00:00 2001 From: leafly2021 Date: Fri, 15 Nov 2024 15:53:58 +0800 Subject: [PATCH] add id from Xcomponent Signed-off-by: leafly2021 --- interfaces/inner_api/composer/native_vsync.h | 14 ++++++ .../composer/native_vsync/native_vsync.cpp | 48 ++++++++++++++++--- .../pipeline/rs_render_service_connection.cpp | 13 ++++- .../pipeline/rs_render_service_connection.h | 3 +- .../ohos/rs_irender_service_connection.h | 3 +- .../transaction/rs_render_service_client.h | 3 +- .../darwin/rs_render_service_client.cpp | 3 +- .../ohos/rs_render_service_client.cpp | 6 ++- .../rs_render_service_connection_proxy.cpp | 3 +- .../ohos/rs_render_service_connection_proxy.h | 3 +- .../windows/rs_render_service_client.cpp | 3 +- .../core/transaction/rs_interfaces.cpp | 5 +- .../core/transaction/rs_interfaces.h | 3 +- 13 files changed, 89 insertions(+), 21 deletions(-) diff --git a/interfaces/inner_api/composer/native_vsync.h b/interfaces/inner_api/composer/native_vsync.h index e0d811c18b..b5ccd5c393 100644 --- a/interfaces/inner_api/composer/native_vsync.h +++ b/interfaces/inner_api/composer/native_vsync.h @@ -58,6 +58,20 @@ typedef void (*OH_NativeVSync_FrameCallback)(long long timestamp, void *data); */ OH_NativeVSync* OH_NativeVSync_Create(const char* name, unsigned int length); +/** + * @brief Creates a associated with Xcomponentid NativeVsync instance.\n + * A new associated with XcomponentidNativeVsync instance is created each time this function is called. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeVsync + * @param windowID Indicates the Xcomponentid of the associated window. + * @param name Indicates the vsync connection name. + * @param length Indicates the name's length. + * @return Returns the pointer to the NativeVsync instance created. + * @since 14 + * @version 1.0 + */ +OH_NativeVSync* OH_NativeVSync_Create_ForAssociatedWindow(uint64_t windowID, const char* name, unsigned int length); + /** * @brief Delete the NativeVsync instance. * diff --git a/rosen/modules/composer/native_vsync/native_vsync.cpp b/rosen/modules/composer/native_vsync/native_vsync.cpp index 8b94c08635..35c1e9d3c9 100644 --- a/rosen/modules/composer/native_vsync/native_vsync.cpp +++ b/rosen/modules/composer/native_vsync/native_vsync.cpp @@ -35,15 +35,18 @@ static OH_NativeVSync* OH_NativeVSync_NativeVSyncToOHNativeVSync(NativeVSync* na return reinterpret_cast(nativeVSync); } -OH_NativeVSync* OH_NativeVSync_Create(const char* name, unsigned int length) +std::shared_ptr CreateAndInitVSyncReceiver( + const std::string& vsyncName, + uint64_t windowID = 0, + bool isAssociatedWindow = false) { - if (name == nullptr) { - VLOGE("name is nullptr, please check"); - return nullptr; - } - std::string vsyncName(name, length); auto& rsClient = OHOS::Rosen::RSInterfaces::GetInstance(); - std::shared_ptr receiver = rsClient.CreateVSyncReceiver(vsyncName); + std::shared_ptr receiver; + if (isAssociatedWindow) { + receiver = rsClient.CreateVSyncReceiver(vsyncName, 0, nullptr, windowID, true); + } else { + receiver = rsClient.CreateVSyncReceiver(vsyncName); + } if (receiver == nullptr) { VLOGE("Create VSyncReceiver failed"); return nullptr; @@ -53,6 +56,37 @@ OH_NativeVSync* OH_NativeVSync_Create(const char* name, unsigned int length) VLOGE("VSyncReceiver Init failed, ret:%{public}d", ret); return nullptr; } + return receiver; +} + +OH_NativeVSync* OH_NativeVSync_Create(const char* name, unsigned int length) +{ + if (name == nullptr) { + VLOGE("name is nullptr, please check"); + return nullptr; + } + std::string vsyncName(name, length); + auto receiver = CreateAndInitVSyncReceiver(vsyncName); + if (receiver == nullptr) { + return nullptr; + } + NativeVSync* nativeVSync = new NativeVSync; + nativeVSync->receiver_ = receiver; + return OH_NativeVSync_NativeVSyncToOHNativeVSync(nativeVSync); +} + +OH_NativeVSync* OH_NativeVSync_Create_ForAssociatedWindow(uint64_t windowID, const char* name, unsigned int length) +{ + if (name == nullptr) { + VLOGE("name is nullptr, please check"); + return nullptr; + } + std::string vsyncName(name, length); + auto receiver = CreateAndInitVSyncReceiver(vsyncName, windowID, true); + if (receiver == nullptr) { + VLOGE("receiver is nullptr, please check"); + return nullptr; + } NativeVSync* nativeVSync = new NativeVSync; nativeVSync->receiver_ = receiver; return OH_NativeVSync_NativeVSyncToOHNativeVSync(nativeVSync); diff --git a/rosen/modules/render_service/core/pipeline/rs_render_service_connection.cpp b/rosen/modules/render_service/core/pipeline/rs_render_service_connection.cpp index 2398030e6d..a729102903 100644 --- a/rosen/modules/render_service/core/pipeline/rs_render_service_connection.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_render_service_connection.cpp @@ -419,15 +419,24 @@ sptr RSRenderServiceConnection::CreateNodeAndSurface(const RSSurfaceRen return pSurface; } - sptr RSRenderServiceConnection::CreateVSyncConnection(const std::string& name, const sptr& token, uint64_t id, - NodeId windowNodeId) + NodeId windowNodeId, + bool fromXcomponent) { if (!mainThread_) { return nullptr; } + if (fromXcomponent) { + auto& node = RSMainThread::Instance()->GetContext().GetNodeMap() + .GetRenderNode(windowNodeId); + if (node == nullptr) { + RS_LOGE("RSRenderServiceConnection::CreateVSyncConnection:node is nullptr"); + return nullptr; + } + windowNodeId = node->GetInstanceRootNodeId(); + } sptr conn = new VSyncConnection(appVSyncDistributor_, name, token->AsObject(), 0, windowNodeId); if (ExtractPid(id) == remotePid_) { mainThread_->ScheduleTask([weakThis = wptr(this), id]() { diff --git a/rosen/modules/render_service/core/pipeline/rs_render_service_connection.h b/rosen/modules/render_service/core/pipeline/rs_render_service_connection.h index dd82aba8f6..48ca602bfe 100644 --- a/rosen/modules/render_service/core/pipeline/rs_render_service_connection.h +++ b/rosen/modules/render_service/core/pipeline/rs_render_service_connection.h @@ -71,7 +71,8 @@ private: sptr CreateVSyncConnection(const std::string& name, const sptr& token, uint64_t id, - NodeId windowNodeId = 0) override; + NodeId windowNodeId = 0, + bool fromXcomponent = false) override; std::shared_ptr CreatePixelMapFromSurface(sptr surface, const Rect &srcRect) override; diff --git a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service_connection.h b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service_connection.h index e49fdcf84f..51e577c69e 100644 --- a/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service_connection.h +++ b/rosen/modules/render_service_base/include/platform/ohos/rs_irender_service_connection.h @@ -66,7 +66,8 @@ public: virtual sptr CreateVSyncConnection(const std::string& name, const sptr& token = nullptr, uint64_t id = 0, - NodeId windowNodeId = 0) = 0; + NodeId windowNodeId = 0, + bool fromXcomponent = false) = 0; virtual std::shared_ptr CreatePixelMapFromSurface(sptr surface, const Rect &srcRect) = 0; diff --git a/rosen/modules/render_service_base/include/transaction/rs_render_service_client.h b/rosen/modules/render_service_base/include/transaction/rs_render_service_client.h index 67492d4e34..d294aaa78f 100644 --- a/rosen/modules/render_service_base/include/transaction/rs_render_service_client.h +++ b/rosen/modules/render_service_base/include/transaction/rs_render_service_client.h @@ -131,7 +131,8 @@ public: const std::string& name, const std::shared_ptr &looper = nullptr, uint64_t id = 0, - NodeId windowNodeId = 0); + NodeId windowNodeId = 0, + bool fromXcomponent = false); std::shared_ptr CreatePixelMapFromSurfaceId(uint64_t surfaceid, const Rect &srcRect); diff --git a/rosen/modules/render_service_base/src/platform/darwin/rs_render_service_client.cpp b/rosen/modules/render_service_base/src/platform/darwin/rs_render_service_client.cpp index 7760436d7e..837cbdaa7a 100644 --- a/rosen/modules/render_service_base/src/platform/darwin/rs_render_service_client.cpp +++ b/rosen/modules/render_service_base/src/platform/darwin/rs_render_service_client.cpp @@ -115,7 +115,8 @@ std::shared_ptr RSRenderServiceClient::CreateVSyncReceiver( const std::string& name, const std::shared_ptr &looper, uint64_t id, - NodeId windowNodeId) + NodeId windowNodeId, + bool fromXcomponent) { return std::make_shared(); } diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_client.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_client.cpp index b386c10d05..3cbfd0ff32 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_client.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_client.cpp @@ -157,7 +157,8 @@ std::shared_ptr RSRenderServiceClient::CreateVSyncReceiver( const std::string& name, const std::shared_ptr &looper, uint64_t id, - NodeId windowNodeId) + NodeId windowNodeId, + bool fromXcomponent) { ROSEN_LOGD("RSRenderServiceClient::CreateVSyncReceiver Start"); auto renderService = RSRenderServiceConnectHub::GetRenderService(); @@ -165,7 +166,8 @@ std::shared_ptr RSRenderServiceClient::CreateVSyncReceiver( return nullptr; } sptr token = new IRemoteStub(); - sptr conn = renderService->CreateVSyncConnection(name, token, id, windowNodeId); + sptr conn = renderService-> + CreateVSyncConnection(name, token, id, windowNodeId, fromXcomponent); if (conn == nullptr) { ROSEN_LOGE("RSRenderServiceClient::CreateVSyncReceiver Failed"); return nullptr; diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_connection_proxy.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_connection_proxy.cpp index e2449fb8c6..06452f58b4 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_connection_proxy.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_connection_proxy.cpp @@ -272,7 +272,8 @@ sptr RSRenderServiceConnectionProxy::CreateNodeAndSurface(const RSSurfa sptr RSRenderServiceConnectionProxy::CreateVSyncConnection(const std::string& name, const sptr& token, uint64_t id, - NodeId windowNodeId) + NodeId windowNodeId, + bool fromXcomponent) { if (token == nullptr) { ROSEN_LOGE("RSRenderServiceConnectionProxy::CreateVSyncConnection: token is nullptr."); diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_connection_proxy.h b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_connection_proxy.h index 176c2d38a9..71004e2f49 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_connection_proxy.h +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_connection_proxy.h @@ -46,7 +46,8 @@ public: virtual sptr CreateVSyncConnection(const std::string& name, const sptr& token, uint64_t id = 0, - NodeId windowNodeId = 0) override; + NodeId windowNodeId = 0, + bool fromXcomponent = false) override; std::shared_ptr CreatePixelMapFromSurface(sptr surface, const Rect &srcRect) override; diff --git a/rosen/modules/render_service_base/src/platform/windows/rs_render_service_client.cpp b/rosen/modules/render_service_base/src/platform/windows/rs_render_service_client.cpp index f325baf137..e147a00f44 100644 --- a/rosen/modules/render_service_base/src/platform/windows/rs_render_service_client.cpp +++ b/rosen/modules/render_service_base/src/platform/windows/rs_render_service_client.cpp @@ -115,7 +115,8 @@ std::shared_ptr RSRenderServiceClient::CreateVSyncReceiver( const std::string& name, const std::shared_ptr &looper, uint64_t id, - NodeId windowNodeId) + NodeId windowNodeId, + bool fromXcomponent) { return std::make_shared(); } diff --git a/rosen/modules/render_service_client/core/transaction/rs_interfaces.cpp b/rosen/modules/render_service_client/core/transaction/rs_interfaces.cpp index acf83d97d4..624c2d3179 100644 --- a/rosen/modules/render_service_client/core/transaction/rs_interfaces.cpp +++ b/rosen/modules/render_service_client/core/transaction/rs_interfaces.cpp @@ -497,9 +497,10 @@ std::shared_ptr RSInterfaces::CreateVSyncReceiver( const std::string& name, uint64_t id, const std::shared_ptr &looper, - NodeId windowNodeId) + NodeId windowNodeId, + bool fromXcomponent) { - return renderServiceClient_->CreateVSyncReceiver(name, looper, id, windowNodeId); + return renderServiceClient_->CreateVSyncReceiver(name, looper, id, windowNodeId, fromXcomponent); } std::shared_ptr RSInterfaces::CreatePixelMapFromSurfaceId(uint64_t surfaceId, const Rect &srcRect) diff --git a/rosen/modules/render_service_client/core/transaction/rs_interfaces.h b/rosen/modules/render_service_client/core/transaction/rs_interfaces.h index a4c9cc5e0a..df985f5a24 100644 --- a/rosen/modules/render_service_client/core/transaction/rs_interfaces.h +++ b/rosen/modules/render_service_client/core/transaction/rs_interfaces.h @@ -219,7 +219,8 @@ public: const std::string& name, uint64_t id, const std::shared_ptr &looper = nullptr, - NodeId windowNodeId = 0); + NodeId windowNodeId = 0, + bool fromXcomponent = false); std::shared_ptr CreatePixelMapFromSurfaceId(uint64_t surfaceId, const Rect &srcRect);