1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 // gtest
17 #include <gtest/gtest.h>
18 #include "future.h"
19 #include "rs_interfaces_test_utils.h"
20 #include "screen.h"
21 #include "transaction/rs_interfaces.h"
22 #include "transaction/rs_transaction.h"
23 #include "window.h"
24 #include "window_option.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 class RSInterfacesVirtualScreenTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37     static sptr<Display> defaultDisplay_;
38     static DisplayId defaultDisplayId_;
39     static ScreenId defaultScreenId_;
40     static std::string defaultName_;
41     static uint32_t defaultWidth_;
42     static uint32_t defaultHeight_;
43     static float defaultDensity_;
44     static int32_t defaultFlags_;
45     static VirtualScreenOption defaultOption_;
46     static constexpr uint32_t TEST_SLEEP_S = 1; // test sleep time
47 };
48 
49 sptr<Display> RSInterfacesVirtualScreenTest::defaultDisplay_ = nullptr;
50 DisplayId RSInterfacesVirtualScreenTest::defaultDisplayId_ = DISPLAY_ID_INVALID;
51 ScreenId RSInterfacesVirtualScreenTest::defaultScreenId_ = INVALID_SCREEN_ID;
52 std::string RSInterfacesVirtualScreenTest::defaultName_ = "virtualScreen01";
53 uint32_t RSInterfacesVirtualScreenTest::defaultWidth_ = 480;
54 uint32_t RSInterfacesVirtualScreenTest::defaultHeight_ = 320;
55 float RSInterfacesVirtualScreenTest::defaultDensity_ = 2.0;
56 int32_t RSInterfacesVirtualScreenTest::defaultFlags_ = 0;
57 VirtualScreenOption RSInterfacesVirtualScreenTest::defaultOption_ = {
58     defaultName_, defaultWidth_, defaultHeight_, defaultDensity_, nullptr, defaultFlags_
59 };
60 
SetUpTestCase()61 void RSInterfacesVirtualScreenTest::SetUpTestCase()
62 {
63     defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay();
64     defaultDisplayId_ = defaultDisplay_->GetId();
65     defaultScreenId_ = defaultDisplay_->GetScreenId();
66     defaultWidth_ = defaultDisplay_->GetWidth();
67     defaultHeight_ = defaultDisplay_->GetHeight();
68     defaultOption_.width_ = defaultWidth_;
69     defaultOption_.height_ = defaultHeight_;
70 }
71 
TearDownTestCase()72 void RSInterfacesVirtualScreenTest::TearDownTestCase()
73 {
74 }
75 
SetUp()76 void RSInterfacesVirtualScreenTest::SetUp()
77 {
78 }
79 
TearDown()80 void RSInterfacesVirtualScreenTest::TearDown()
81 {
82 }
83 
84 namespace {
85 /**
86  * @tc.name: VirtualScreenTest
87  * @tc.desc: Test VirtualScreen SetScreenSkipFrameInterval
88  * @tc.type: FUNC
89  */
90 HWTEST_F(RSInterfacesVirtualScreenTest, VirtualScreenTest, Function | MediumTest | Level2)
91 {
92     RSInterfacesTestUtils utils;
93     ASSERT_TRUE(utils.CreateSurface());
94     defaultOption_.surface_ = utils.pSurface_;
95     defaultOption_.isForShot_ = false;
96 
97     ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
98     sleep(TEST_SLEEP_S);
99 
100     std::vector<ScreenId> mirrorIds;
101     mirrorIds.push_back(virtualScreenId);
102     ScreenId screenGroupId;
103     ScreenManager::GetInstance().MakeMirror(defaultScreenId_, mirrorIds, screenGroupId);
104 
105     uint32_t virtualScreenSkipFrameInterval = 2;
106     auto ids = RSInterfaces::GetInstance().GetAllScreenIds();
107     ScreenId defaultScreenId = RSInterfaces::GetInstance().GetDefaultScreenId();
108     std::cout << "ids.size = " << ids.size() << ", defaultScreenId:" << defaultScreenId << std::endl;
109     for (ScreenId screenId : ids) {
110         if (screenId == defaultScreenId) {
111             continue;
112         }
113         int32_t ret = RSInterfaces::GetInstance().SetScreenSkipFrameInterval(screenId, virtualScreenSkipFrameInterval);
114         EXPECT_EQ(ret, StatusCode::SUCCESS);
115         std::cout << "Set Screen:" << screenId << ", SkipFrameInterval:" << virtualScreenSkipFrameInterval << std::endl;
116     }
117 
118     std::cout << "sleeping for 30s ..." << std::endl;
119     sleep(30 * TEST_SLEEP_S);
120 
121     // recover
122     for (ScreenId screenId : ids) {
123         int32_t ret = RSInterfaces::GetInstance().SetScreenSkipFrameInterval(screenId, 1);
124         EXPECT_EQ(ret, StatusCode::SUCCESS);
125         std::cout << "recover Screen:" << screenId << ", SkipFrameInterval:" << 1 << std::endl;
126     }
127 
128     auto res = ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId);
129     ASSERT_EQ(DMError::DM_OK, res);
130 }
131 }
132 } // namespace Rosen
133 } // namespace OHOS
134