add furfaceNode to disply

Signed-off-by: zhirong <yangzhirong6@huawei.com>
Change-Id: If6a23adf34cb581c9fd54c5d22c912405f89e932
Signed-off-by: zhirong <yangzhirong6@huawei.com>
This commit is contained in:
zhirong 2023-02-27 10:24:44 +08:00
parent 5aab19f097
commit 4de6396eb7
17 changed files with 296 additions and 1 deletions

View File

@ -69,6 +69,9 @@ public:
virtual bool SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze);
virtual sptr<DisplayInfo> GetDisplayInfo(DisplayId displayId);
virtual sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId);
virtual DMError AddSurfaceNodeToDisplay(DisplayId displayId, std::shared_ptr<class RSSurfaceNode>& surfaceNode);
virtual DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId,
std::shared_ptr<class RSSurfaceNode>& surfaceNode);
private:
static inline SingletonDelegator<DisplayManagerAdapter> delegator;
};

View File

@ -18,6 +18,7 @@
#include <chrono>
#include <cinttypes>
#include <transaction/rs_interfaces.h>
#include <ui/rs_surface_node.h>
#include "display_manager_adapter.h"
#include "display_manager_agent_default.h"
@ -934,6 +935,18 @@ bool DisplayManager::Unfreeze(std::vector<DisplayId> displayIds)
return SingletonContainer::Get<DisplayManagerAdapter>().SetFreeze(displayIds, false);
}
DMError DisplayManager::AddSurfaceNodeToDisplay(DisplayId displayId,
std::shared_ptr<class RSSurfaceNode>& surfaceNode)
{
return SingletonContainer::Get<DisplayManagerAdapter>().AddSurfaceNodeToDisplay(displayId, surfaceNode);
}
DMError DisplayManager::RemoveSurfaceNodeFromDisplay(DisplayId displayId,
std::shared_ptr<class RSSurfaceNode>& surfaceNode)
{
return SingletonContainer::Get<DisplayManagerAdapter>().RemoveSurfaceNodeFromDisplay(displayId, surfaceNode);
}
void DisplayManager::Impl::OnRemoteDied()
{
WLOGFI("dms is died");

View File

@ -357,6 +357,28 @@ sptr<CutoutInfo> DisplayManagerAdapter::GetCutoutInfo(DisplayId displayId)
return displayManagerServiceProxy_->GetCutoutInfo(displayId);
}
DMError DisplayManagerAdapter::AddSurfaceNodeToDisplay(DisplayId displayId,
std::shared_ptr<class RSSurfaceNode>& surfaceNode)
{
if (displayId == DISPLAY_ID_INVALID) {
WLOGFE("screen id is invalid");
return DMError::DM_ERROR_INVALID_PARAM;
}
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
return displayManagerServiceProxy_->AddSurfaceNodeToDisplay(displayId, surfaceNode);
}
DMError DisplayManagerAdapter::RemoveSurfaceNodeFromDisplay(DisplayId displayId,
std::shared_ptr<class RSSurfaceNode>& surfaceNode)
{
if (displayId == DISPLAY_ID_INVALID) {
WLOGFE("screen id is invalid");
return DMError::DM_ERROR_INVALID_PARAM;
}
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
return displayManagerServiceProxy_->RemoveSurfaceNodeFromDisplay(displayId, surfaceNode);
}
sptr<ScreenGroupInfo> ScreenManagerAdapter::GetScreenGroupInfoById(ScreenId screenId)
{
if (screenId == SCREEN_ID_INVALID) {

View File

@ -51,6 +51,8 @@ public:
ScreenSourceMode GetSourceMode() const;
void UpdateRSTree(std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd);
DMError AddSurfaceNode(std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop);
DMError RemoveSurfaceNode(std::shared_ptr<RSSurfaceNode>& surfaceNode);
void UpdateDisplayGroupRSTree(std::shared_ptr<RSSurfaceNode>& surfaceNode, NodeId parentNodeId, bool isAdd);
void InitRSDisplayNode(RSDisplayNodeConfig& config, Point& startPoint);
ScreenId GetScreenGroupId() const;

View File

@ -69,6 +69,8 @@ public:
const std::shared_ptr<RSDisplayNode>& GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const;
void UpdateRSTree(ScreenId dmsScreenId, ScreenId parentScreenId, std::shared_ptr<RSSurfaceNode>& surfaceNode,
bool isAdd, bool isMultiDisplay);
DMError AddSurfaceNodeToScreen(ScreenId dmsScreenId, std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop);
DMError RemoveSurfaceNodeFromScreen(ScreenId dmsScreenId, std::shared_ptr<RSSurfaceNode>& surfaceNode);
DMError MakeMirror(ScreenId, std::vector<ScreenId> screens);
bool MakeExpand(std::vector<ScreenId> screenIds, std::vector<Point> startPoints);
void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens);

View File

@ -76,6 +76,8 @@ public:
TRANS_ID_SET_SCREEN_ROTATION_LOCKED,
TRANS_ID_HAS_PRIVATE_WINDOW,
TRANS_ID_GET_CUTOUT_INFO,
TRANS_ID_ADD_SURFACE_NODE,
TRANS_ID_REMOVE_SURFACE_NODE,
};
virtual sptr<DisplayInfo> GetDefaultDisplayInfo() = 0;
@ -126,6 +128,10 @@ public:
virtual void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens) = 0;
virtual DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId) = 0;
virtual DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) = 0;
virtual DMError AddSurfaceNodeToDisplay(DisplayId displayId,
std::shared_ptr<class RSSurfaceNode>& surfaceNode, bool onTop = true) = 0;
virtual DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId,
std::shared_ptr<class RSSurfaceNode>& surfaceNode) = 0;
};
} // namespace OHOS::Rosen

View File

@ -77,6 +77,10 @@ public:
void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens) override;
DMError SetScreenActiveMode(ScreenId screenId, uint32_t modeId) override;
DMError SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) override;
DMError AddSurfaceNodeToDisplay(DisplayId displayId,
std::shared_ptr<class RSSurfaceNode>& surfaceNode, bool onTop = true) override;
DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId,
std::shared_ptr<class RSSurfaceNode>& surfaceNode) override;
private:
static inline BrokerDelegator<DisplayManagerProxy> delegator_;

View File

@ -86,7 +86,9 @@ public:
bool SetDisplayState(DisplayState state) override;
void UpdateRSTree(DisplayId displayId, DisplayId parentDisplayId, std::shared_ptr<RSSurfaceNode>& surfaceNode,
bool isAdd, bool isMultiDisplay);
DMError AddSurfaceNodeToDisplay(DisplayId displayId,
std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop = true) override;
DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId, std::shared_ptr<RSSurfaceNode>& surfaceNode) override;
DisplayState GetDisplayState(DisplayId displayId) override;
void NotifyDisplayEvent(DisplayEvent event) override;
bool SetFreeze(std::vector<DisplayId> displayIds, bool isFreeze) override;
@ -107,6 +109,7 @@ public:
void RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener);
void RegisterRSScreenChangeListener(const sptr<IRSScreenChangeListener>& listener);
void NotifyPrivateWindowStateChanged(bool hasPrivate);
private:
DisplayManagerService();
~DisplayManagerService() = default;

View File

@ -24,6 +24,7 @@
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractScreenGroup"};
constexpr float MAX_ZORDER = 100000.0f;
}
AbstractScreen::AbstractScreen(sptr<AbstractScreenController> screenController, const std::string& name, ScreenId dmsId,
@ -84,6 +85,40 @@ void AbstractScreen::UpdateRSTree(std::shared_ptr<RSSurfaceNode>& surfaceNode, b
}
}
DMError AbstractScreen::AddSurfaceNode(std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop)
{
if (rsDisplayNode_ == nullptr || surfaceNode == nullptr) {
WLOGFE("node is nullptr");
return DMError::DM_ERROR_NULLPTR;
}
surfaceNode->SetVisible(true);
if (onTop) {
rsDisplayNode_->AddChild(surfaceNode, -1);
surfaceNode->SetPositionZ(MAX_ZORDER);
} else {
rsDisplayNode_->AddChild(surfaceNode, -1);
}
auto transactionProxy = RSTransactionProxy::GetInstance();
if (transactionProxy != nullptr) {
transactionProxy->FlushImplicitTransaction();
}
return DMError::DM_OK;
}
DMError AbstractScreen::RemoveSurfaceNode(std::shared_ptr<RSSurfaceNode>& surfaceNode)
{
if (rsDisplayNode_ == nullptr || surfaceNode == nullptr) {
WLOGFE("node is nullptr");
return DMError::DM_ERROR_NULLPTR;
}
rsDisplayNode_->RemoveChild(surfaceNode);
auto transactionProxy = RSTransactionProxy::GetInstance();
if (transactionProxy != nullptr) {
transactionProxy->FlushImplicitTransaction();
}
return DMError::DM_OK;
}
void AbstractScreen::UpdateDisplayGroupRSTree(std::shared_ptr<RSSurfaceNode>& surfaceNode, NodeId parentNodeId,
bool isAdd)
{

View File

@ -142,6 +142,28 @@ void AbstractScreenController::UpdateRSTree(ScreenId dmsScreenId, ScreenId paren
}
}
DMError AbstractScreenController::AddSurfaceNodeToScreen(ScreenId dmsScreenId,
std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop)
{
sptr<AbstractScreen> abstractScreen = GetAbstractScreen(dmsScreenId);
if (abstractScreen == nullptr) {
WLOGFE("Can not find abstractScreen");
return DMError::DM_ERROR_NULLPTR;
}
return abstractScreen->AddSurfaceNode(surfaceNode, onTop);
}
DMError AbstractScreenController::RemoveSurfaceNodeFromScreen(ScreenId dmsScreenId,
std::shared_ptr<RSSurfaceNode>& surfaceNode)
{
sptr<AbstractScreen> abstractScreen = GetAbstractScreen(dmsScreenId);
if (abstractScreen == nullptr) {
WLOGFE("Can not find abstractScreen");
return DMError::DM_ERROR_NULLPTR;
}
return abstractScreen->RemoveSurfaceNode(surfaceNode);
}
sptr<AbstractScreen> AbstractScreenController::GetAbstractScreen(ScreenId dmsScreenId) const
{
WLOGD("GetAbstractScreen: screenId: %{public}" PRIu64"", dmsScreenId);

View File

@ -18,6 +18,7 @@
#include <cinttypes>
#include <ipc_types.h>
#include <parcel.h>
#include <ui/rs_surface_node.h>
#include "marshalling_helper.h"
#include "window_manager_hilog.h"
@ -748,6 +749,60 @@ sptr<CutoutInfo> DisplayManagerProxy::GetCutoutInfo(DisplayId displayId)
return info;
}
DMError DisplayManagerProxy::AddSurfaceNodeToDisplay(DisplayId displayId,
std::shared_ptr<class RSSurfaceNode>& surfaceNode, bool onTop)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return DMError::DM_ERROR_IPC_FAILED;
}
if (!data.WriteUint64(displayId)) {
WLOGFE("write displayId failed");
return DMError::DM_ERROR_IPC_FAILED;
}
if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) {
WLOGFE("Write windowProperty failed");
return DMError::DM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_ADD_SURFACE_NODE),
data, reply, option) != ERR_NONE) {
WLOGFW("Send request failed");
return DMError::DM_ERROR_IPC_FAILED;
}
DMError ret = static_cast<DMError>(reply.ReadUint32());
return ret;
}
DMError DisplayManagerProxy::RemoveSurfaceNodeFromDisplay(DisplayId displayId,
std::shared_ptr<class RSSurfaceNode>& surfaceNode)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return DMError::DM_ERROR_IPC_FAILED;
}
if (!data.WriteUint64(displayId)) {
WLOGFE("write displayId failed");
return DMError::DM_ERROR_IPC_FAILED;
}
if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) {
WLOGFE("Write windowProperty failed");
return DMError::DM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_REMOVE_SURFACE_NODE),
data, reply, option) != ERR_NONE) {
WLOGFW("Send request failed");
return DMError::DM_ERROR_IPC_FAILED;
}
DMError ret = static_cast<DMError>(reply.ReadUint32());
return ret;
}
DMError DisplayManagerProxy::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
{
MessageParcel data;

View File

@ -546,6 +546,30 @@ void DisplayManagerService::UpdateRSTree(DisplayId displayId, DisplayId parentDi
abstractScreenController_->UpdateRSTree(screenId, parentScreenId, surfaceNode, isAdd, isMultiDisplay);
}
DMError DisplayManagerService::AddSurfaceNodeToDisplay(DisplayId displayId,
std::shared_ptr<RSSurfaceNode>& surfaceNode, bool onTop)
{
WLOGFI("DisplayId: %{public}" PRIu64", onTop: %{public}d", displayId, onTop);
if (surfaceNode == nullptr) {
WLOGFW("Surface is null");
return DMError::DM_ERROR_NULLPTR;
}
ScreenId screenId = GetScreenIdByDisplayId(displayId);
return abstractScreenController_->AddSurfaceNodeToScreen(screenId, surfaceNode, true);
}
DMError DisplayManagerService::RemoveSurfaceNodeFromDisplay(DisplayId displayId,
std::shared_ptr<RSSurfaceNode>& surfaceNode)
{
WLOGFI("DisplayId: %{public}" PRIu64"", displayId);
if (surfaceNode == nullptr) {
WLOGFW("Surface is null");
return DMError::DM_ERROR_NULLPTR;
}
ScreenId screenId = GetScreenIdByDisplayId(displayId);
return abstractScreenController_->RemoveSurfaceNodeFromScreen(screenId, surfaceNode);
}
sptr<ScreenInfo> DisplayManagerService::GetScreenInfoById(ScreenId screenId)
{
auto screen = abstractScreenController_->GetAbstractScreen(screenId);

View File

@ -348,6 +348,20 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
reply.WriteParcelable(cutoutInfo);
break;
}
case DisplayManagerMessage::TRANS_ID_ADD_SURFACE_NODE: {
DisplayId displayId = static_cast<DisplayId>(data.ReadUint64());
std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
auto ret = AddSurfaceNodeToDisplay(displayId, surfaceNode, true);
reply.WriteUint32(static_cast<uint32_t>(ret));
break;
}
case DisplayManagerMessage::TRANS_ID_REMOVE_SURFACE_NODE: {
DisplayId displayId = static_cast<DisplayId>(data.ReadUint64());
std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
auto ret = RemoveSurfaceNodeFromDisplay(displayId, surfaceNode);
reply.WriteUint32(static_cast<uint32_t>(ret));
break;
}
default:
WLOGFW("unknown transaction code");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);

View File

@ -19,6 +19,7 @@
#include "display_manager_service.h"
#include "display_manager_agent_default.h"
#include "common_test_utils.h"
#include "mock_rs_display_node.h"
using namespace testing;
@ -35,6 +36,8 @@ public:
void SetAceessTokenPermission(const std::string processName);
static sptr<DisplayManagerService> dms_;
static constexpr DisplayId DEFAULT_DISPLAY = 0ULL;
static constexpr DisplayId DEFAULT_SCREEN = 0ULL;
};
sptr<DisplayManagerService> DisplayManagerServiceTest::dms_ = nullptr;
@ -399,6 +402,39 @@ HWTEST_F(DisplayManagerServiceTest, ScreenRotationLock, Function | SmallTest | L
ASSERT_NE(nullptr, dms_->GetCutoutInfo(10));
}
/**
* @tc.name: AddSurfaceNodeToDisplay | RemoveSurfaceNodeFromDisplay
* @tc.desc: add/remove surfaceNode to/from display
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerServiceTest, AddAndRemoveSurfaceNode, Function | SmallTest | Level3)
{
sptr<DisplayManagerService> dms = new DisplayManagerService();
std::shared_ptr<RSSurfaceNode> surfaceNode = nullptr;
ASSERT_EQ(DMError::DM_ERROR_NULLPTR, dms->AddSurfaceNodeToDisplay(DEFAULT_DISPLAY, surfaceNode, true));
surfaceNode = std::make_shared<RSSurfaceNode>(RSSurfaceNodeConfig{}, true);
ASSERT_EQ(DMError::DM_ERROR_NULLPTR, dms->AddSurfaceNodeToDisplay(DEFAULT_DISPLAY, surfaceNode, true));
std::shared_ptr<RSDisplayNode> displayNode = std::make_shared<MockRSDisplayNode>(RSDisplayNodeConfig{});
sptr<SupportedScreenModes> info = new SupportedScreenModes;
sptr<AbstractScreen> absScreen =
new AbstractScreen(nullptr, "", INVALID_SCREEN_ID, INVALID_SCREEN_ID);
dms->abstractDisplayController_->abstractDisplayMap_[DEFAULT_DISPLAY] =
new AbstractDisplay(DEFAULT_DISPLAY, "", info, absScreen);
dms->abstractDisplayController_->abstractDisplayMap_[DEFAULT_DISPLAY]->screenId_ = DEFAULT_SCREEN;
dms->abstractScreenController_->dmsScreenMap_[DEFAULT_SCREEN] =
new AbstractScreen(dms->abstractScreenController_, "", INVALID_SCREEN_ID, INVALID_SCREEN_ID);
ASSERT_EQ(DMError::DM_ERROR_NULLPTR, dms->AddSurfaceNodeToDisplay(DEFAULT_DISPLAY, surfaceNode, true));
dms->abstractScreenController_->dmsScreenMap_[DEFAULT_SCREEN]->rsDisplayNode_ = displayNode;
EXPECT_CALL(*reinterpret_cast<MockRSDisplayNode*>(displayNode.get()), AddChild(_, _));
ASSERT_EQ(DMError::DM_OK, dms->AddSurfaceNodeToDisplay(DEFAULT_DISPLAY, surfaceNode, false));
EXPECT_CALL(*reinterpret_cast<MockRSDisplayNode*>(displayNode.get()), RemoveChild(_));
ASSERT_EQ(DMError::DM_OK, dms->RemoveSurfaceNodeFromDisplay(DEFAULT_DISPLAY, surfaceNode));
testing::Mock::AllowLeak(displayNode.get());
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -80,6 +80,9 @@ public:
DMError RegisterPrivateWindowListener(sptr<IPrivateWindowListener> listener);
DMError UnregisterPrivateWindowListener(sptr<IPrivateWindowListener> listener);
DMError AddSurfaceNodeToDisplay(DisplayId displayId, std::shared_ptr<class RSSurfaceNode>& surfaceNode);
DMError RemoveSurfaceNodeFromDisplay(DisplayId displayId, std::shared_ptr<class RSSurfaceNode>& surfaceNode);
constexpr static int32_t MAX_RESOLUTION_SIZE_SCREENSHOT = 3840; // max resolution, 4K
private:

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FRAMEWORKS_WM_TEST_UT_MOCK_RS_DISPLAY_NODE_H
#define FRAMEWORKS_WM_TEST_UT_MOCK_RS_DISPLAY_NODE_H
#include <gmock/gmock.h>
#include <ui/rs_display_node.h>
namespace OHOS {
namespace Rosen {
class MockRSDisplayNode : public RSDisplayNode {
public:
MockRSDisplayNode(const RSDisplayNodeConfig& config) : RSDisplayNode(config) {}
using RSDisplayNode::AddChild;
MOCK_METHOD2(AddChild, void(SharedPtr child, int index));
using RSDisplayNode::RemoveChild;
MOCK_METHOD1(RemoveChild, void(SharedPtr child));
};
} // namespace Rosen
} // namespace OHOS
#endif // FRAMEWORKS_WM_TEST_UT_MOCK_RS_DISPLAY_NODE_H

View File

@ -14,6 +14,7 @@
*/
#include <gtest/gtest.h>
#include <transaction/rs_transaction.h>
#include <ui/rs_surface_node.h>
#include "display_test_utils.h"
#include "display.h"
#include "screen.h"
@ -297,5 +298,21 @@ HWTEST_F(DisplayManagerTest, HasPrivateWindowSkipSnapShot, Function | SmallTest
ASSERT_TRUE(!hasPrivateWindow);
}
/**
* @tc.name: AddSurfaceNodeToDisplay | RemoveSurfaceNodeFromDisplay
* @tc.desc: add/remove surfaceNode to/from display
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerTest, AddAndRemoveSurfaceNode, Function | SmallTest | Level2)
{
RSSurfaceNodeConfig config;
config.SurfaceNodeName = "TestSurfaceNode";
auto surfaceNode = RSSurfaceNode::Create(config);
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
ASSERT_EQ(DMError::DM_OK, DisplayManager::GetInstance().AddSurfaceNodeToDisplay(id, surfaceNode));
sleep(2);
ASSERT_EQ(DMError::DM_OK, DisplayManager::GetInstance().RemoveSurfaceNodeFromDisplay(id, surfaceNode));
}
}
} // namespace OHOS::Rosen