!17172 浏览器接入vsync动态帧率

Merge pull request !17172 from leafly2021/add_window_id_from_Xcomponent
This commit is contained in:
openharmony_ci 2024-11-22 04:31:59 +00:00 committed by Gitee
commit 181788b7fd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
13 changed files with 89 additions and 21 deletions

View File

@ -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 <b>NativeVsync</b> instance.\n
* A new associated with Xcomponentid<b>NativeVsync</b> 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 <b>NativeVsync</b> 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.
*

View File

@ -35,15 +35,18 @@ static OH_NativeVSync* OH_NativeVSync_NativeVSyncToOHNativeVSync(NativeVSync* na
return reinterpret_cast<OH_NativeVSync*>(nativeVSync);
}
OH_NativeVSync* OH_NativeVSync_Create(const char* name, unsigned int length)
std::shared_ptr<OHOS::Rosen::VSyncReceiver> 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<OHOS::Rosen::VSyncReceiver> receiver = rsClient.CreateVSyncReceiver(vsyncName);
std::shared_ptr<OHOS::Rosen::VSyncReceiver> 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);

View File

@ -423,15 +423,24 @@ sptr<Surface> RSRenderServiceConnection::CreateNodeAndSurface(const RSSurfaceRen
return pSurface;
}
sptr<IVSyncConnection> RSRenderServiceConnection::CreateVSyncConnection(const std::string& name,
const sptr<VSyncIConnectionToken>& token,
uint64_t id,
NodeId windowNodeId)
NodeId windowNodeId,
bool fromXcomponent)
{
if (!mainThread_) {
return nullptr;
}
if (fromXcomponent) {
auto& node = RSMainThread::Instance()->GetContext().GetNodeMap()
.GetRenderNode<RSRenderNode>(windowNodeId);
if (node == nullptr) {
RS_LOGE("RSRenderServiceConnection::CreateVSyncConnection:node is nullptr");
return nullptr;
}
windowNodeId = node->GetInstanceRootNodeId();
}
sptr<VSyncConnection> conn = new VSyncConnection(appVSyncDistributor_, name, token->AsObject(), 0, windowNodeId);
if (ExtractPid(id) == remotePid_) {
auto observer = [] (const RSRenderFrameRateLinker& linker) {

View File

@ -71,7 +71,8 @@ private:
sptr<IVSyncConnection> CreateVSyncConnection(const std::string& name,
const sptr<VSyncIConnectionToken>& token,
uint64_t id,
NodeId windowNodeId = 0) override;
NodeId windowNodeId = 0,
bool fromXcomponent = false) override;
std::shared_ptr<Media::PixelMap> CreatePixelMapFromSurface(sptr<Surface> surface, const Rect &srcRect) override;

View File

@ -66,7 +66,8 @@ public:
virtual sptr<IVSyncConnection> CreateVSyncConnection(const std::string& name,
const sptr<VSyncIConnectionToken>& token = nullptr,
uint64_t id = 0,
NodeId windowNodeId = 0) = 0;
NodeId windowNodeId = 0,
bool fromXcomponent = false) = 0;
virtual std::shared_ptr<Media::PixelMap> CreatePixelMapFromSurface(sptr<Surface> surface,
const Rect &srcRect) = 0;

View File

@ -132,7 +132,8 @@ public:
const std::string& name,
const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr,
uint64_t id = 0,
NodeId windowNodeId = 0);
NodeId windowNodeId = 0,
bool fromXcomponent = false);
std::shared_ptr<Media::PixelMap> CreatePixelMapFromSurfaceId(uint64_t surfaceid, const Rect &srcRect);

View File

@ -115,7 +115,8 @@ std::shared_ptr<VSyncReceiver> RSRenderServiceClient::CreateVSyncReceiver(
const std::string& name,
const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper,
uint64_t id,
NodeId windowNodeId)
NodeId windowNodeId,
bool fromXcomponent)
{
return std::make_shared<VSyncReceiverDarwin>();
}

View File

@ -157,7 +157,8 @@ std::shared_ptr<VSyncReceiver> RSRenderServiceClient::CreateVSyncReceiver(
const std::string& name,
const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &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<VSyncReceiver> RSRenderServiceClient::CreateVSyncReceiver(
return nullptr;
}
sptr<VSyncIConnectionToken> token = new IRemoteStub<VSyncIConnectionToken>();
sptr<IVSyncConnection> conn = renderService->CreateVSyncConnection(name, token, id, windowNodeId);
sptr<IVSyncConnection> conn = renderService->
CreateVSyncConnection(name, token, id, windowNodeId, fromXcomponent);
if (conn == nullptr) {
ROSEN_LOGE("RSRenderServiceClient::CreateVSyncReceiver Failed");
return nullptr;

View File

@ -273,7 +273,8 @@ sptr<Surface> RSRenderServiceConnectionProxy::CreateNodeAndSurface(const RSSurfa
sptr<IVSyncConnection> RSRenderServiceConnectionProxy::CreateVSyncConnection(const std::string& name,
const sptr<VSyncIConnectionToken>& token,
uint64_t id,
NodeId windowNodeId)
NodeId windowNodeId,
bool fromXcomponent)
{
if (token == nullptr) {
ROSEN_LOGE("RSRenderServiceConnectionProxy::CreateVSyncConnection: token is nullptr.");

View File

@ -46,7 +46,8 @@ public:
virtual sptr<IVSyncConnection> CreateVSyncConnection(const std::string& name,
const sptr<VSyncIConnectionToken>& token,
uint64_t id = 0,
NodeId windowNodeId = 0) override;
NodeId windowNodeId = 0,
bool fromXcomponent = false) override;
std::shared_ptr<Media::PixelMap> CreatePixelMapFromSurface(sptr<Surface> surface, const Rect &srcRect) override;

View File

@ -115,7 +115,8 @@ std::shared_ptr<VSyncReceiver> RSRenderServiceClient::CreateVSyncReceiver(
const std::string& name,
const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper,
uint64_t id,
NodeId windowNodeId)
NodeId windowNodeId,
bool fromXcomponent)
{
return std::make_shared<VSyncReceiverWindows>();
}

View File

@ -507,9 +507,10 @@ std::shared_ptr<VSyncReceiver> RSInterfaces::CreateVSyncReceiver(
const std::string& name,
uint64_t id,
const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &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<Media::PixelMap> RSInterfaces::CreatePixelMapFromSurfaceId(uint64_t surfaceId, const Rect &srcRect)

View File

@ -225,7 +225,8 @@ public:
const std::string& name,
uint64_t id,
const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr,
NodeId windowNodeId = 0);
NodeId windowNodeId = 0,
bool fromXcomponent = false);
std::shared_ptr<Media::PixelMap> CreatePixelMapFromSurfaceId(uint64_t surfaceId, const Rect &srcRect);