• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <gtest/gtest.h>
17 #include <hilog/log.h>
18 #include <memory>
19 #include <unistd.h>
20 
21 #include "pipeline/rs_dirty_region_manager.h"
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 using namespace HiviewDFX;
28 class RSDirtyManagerTest : public testing::Test {
29 public:
30     static constexpr HiLogLabel LOG_LABEL = { LOG_CORE, 0xD001400, "RSDirtyManagerTest" };
31 
SetUpTestCase()32     static void SetUpTestCase()
33     {
34         rsDirtyManager = std::make_shared<RSDirtyRegionManager>();
35     }
36 
TearDownTestCase()37     static void TearDownTestCase() {
38         rsDirtyManager = nullptr;
39     }
40 
41     static inline std::shared_ptr<RSDirtyRegionManager> rsDirtyManager = nullptr;
42     static RectI defaultRect;
43 };
44 RectI RSDirtyManagerTest::defaultRect = RectI();
45 
46 /*
47  * @tc.name: GetDefaultDirtyRegion
48  * @tc.desc: Get dirtyManager's default dirty region
49  * @tc.type: FUNC
50  * @tc.require: issueI5PWM0
51 */
52 HWTEST_F(RSDirtyManagerTest, GetDefaultDirtyRegion, Function | SmallTest | Level2)
53 {
54     RectI dirtyRect = rsDirtyManager->GetDirtyRegion();
55     EXPECT_EQ(dirtyRect, defaultRect);
56 }
57 
58 /*
59  * @tc.name: MergeDirtyRectInvalid
60  * @tc.desc: DirtyManager's dirty region will not be changed if it merges invalid rect
61  * @tc.type: FUNC
62  * @tc.require: issueI5PWM0
63 */
64 HWTEST_F(RSDirtyManagerTest, MergeDirtyRectInvalid, Function | SmallTest | Level2)
65 {
66     std::vector<RectI> invalidRects;
67     // invalid rect with negative width and height
68     invalidRects.push_back(RectI(0, 0, -360, -360));
69     // invalid rect with empty height
70     invalidRects.push_back(RectI(0, 0, 0, 360));
71     // invalid rect with empty width
72     invalidRects.push_back(RectI(0, 0, 360, 0));
73     RectI joinedRect = RectI();
74     RectI curDirtyRect = rsDirtyManager->GetDirtyRegion();
75     EXPECT_EQ(curDirtyRect, defaultRect);
76 
77     for (auto invalidRect : invalidRects) {
78         rsDirtyManager->MergeDirtyRect(invalidRect);
79         if (!invalidRect.IsEmpty()){
80             joinedRect = joinedRect.JoinRect(invalidRect);
81         }
82         curDirtyRect = rsDirtyManager->GetDirtyRegion();
83         HiLog::Info(LOG_LABEL, "MergeDirtyRectInvalid curDirtyRect[%d, %d, %d, %d] invalidRect[%d, %d, %d, %d]",
84             curDirtyRect.left_, curDirtyRect.top_, curDirtyRect.width_, curDirtyRect.height_,
85             invalidRect.left_, invalidRect.top_, invalidRect.width_, invalidRect.height_);
86         EXPECT_EQ(curDirtyRect, joinedRect);
87     }
88 }
89 
90 /*
91  * @tc.name: MergeDirtyRectValid
92  * @tc.desc: DirtyManager's dirty region will be changed if it merges valid rects
93  * @tc.type: FUNC
94  * @tc.require: issueI5PWM0
95 */
96 HWTEST_F(RSDirtyManagerTest, MergeDirtyRectValid, Function | SmallTest | Level2)
97 {
98     std::vector<RectI> validRects;
99     validRects.push_back(RectI(0, 0, 360, 360));
100     validRects.push_back(RectI(-100, 10, 30, 540));
101     validRects.push_back(RectI(20, -50, 180, 360));
102     RectI joinedRect = RectI();
103     RectI curDirtyRect = rsDirtyManager->GetDirtyRegion();
104     EXPECT_EQ(curDirtyRect, defaultRect);
105 
106     for (auto validRect : validRects) {
107         rsDirtyManager->MergeDirtyRect(validRect);
108         joinedRect = joinedRect.JoinRect(validRect);
109         curDirtyRect = rsDirtyManager->GetDirtyRegion();
110         HiLog::Info(LOG_LABEL, "MergeDirtyRectValid curDirtyRect[%d, %d, %d, %d] validRect[%d, %d, %d, %d]",
111             curDirtyRect.left_, curDirtyRect.top_, curDirtyRect.width_, curDirtyRect.height_,
112             validRect.left_, validRect.top_, validRect.width_, validRect.height_);
113         EXPECT_EQ(curDirtyRect, joinedRect);
114     }
115 }
116 
117 /*
118  * @tc.name: ClearDirtyRegion
119  * @tc.desc: Reset dirtyManager's dirty region
120  * @tc.type: FUNC
121  * @tc.require: issueI5PWM0
122 */
123 HWTEST_F(RSDirtyManagerTest, ClearDirtyRegion, Function | SmallTest | Level2)
124 {
125     rsDirtyManager->Clear();
126     RectI dirtyRect = rsDirtyManager->GetDirtyRegion();
127     EXPECT_EQ(dirtyRect, defaultRect);
128 }
129 
130 /*
131  * @tc.name: UpdateDirtyInvalid
132  * @tc.desc: DirtyManager's dirty history will not be changed if dirtyRegion_ is invalid
133  * @tc.type: FUNC
134  * @tc.require: issueI5PWM0
135 */
136 HWTEST_F(RSDirtyManagerTest, UpdateDirtyInvalid, Function | SmallTest | Level2)
137 {
138     std::vector<RectI> invalidRects;
139     // invalid rect with negative width and height
140     invalidRects.push_back(RectI(0, 0, -360, -360));
141     // invalid rect with empty height
142     invalidRects.push_back(RectI(0, 0, 0, 360));
143     // invalid rect with empty width
144     invalidRects.push_back(RectI(0, 0, 360, 0));
145     RectI curDirtyRect = RectI();
146 
147     for (auto invalidRect : invalidRects) {
148         rsDirtyManager->Clear();
149         rsDirtyManager->MergeDirtyRect(invalidRect);
150         rsDirtyManager->UpdateDirty();
151         // get current frame's dirty
152         curDirtyRect = rsDirtyManager->GetLatestDirtyRegion();
153         HiLog::Info(LOG_LABEL, "UpdateDirtyInvalid curDirtyRect[%d, %d, %d, %d] invalidRect[%d, %d, %d, %d]",
154             curDirtyRect.left_, curDirtyRect.top_, curDirtyRect.width_, curDirtyRect.height_,
155             invalidRect.left_, invalidRect.top_, invalidRect.width_, invalidRect.height_);
156         EXPECT_EQ(curDirtyRect, defaultRect);
157 
158         // get merged frames' dirty(buffer age)
159         curDirtyRect = rsDirtyManager->GetDirtyRegion();
160         EXPECT_EQ(curDirtyRect, defaultRect);
161     }
162 }
163 
164 /*
165  * @tc.name: UpdateDirtyValid
166  * @tc.desc: DirtyManager's dirty history will be pushed if dirtyRegion_ is valid
167  * @tc.type: FUNC
168  * @tc.require: issueI5PWM0
169 */
170 HWTEST_F(RSDirtyManagerTest, UpdateDirtyValid, Function | SmallTest | Level2)
171 {
172     std::vector<RectI> validRects;
173     validRects.push_back(RectI(0, 0, 360, 360));
174     validRects.push_back(RectI(-100, 10, 30, 540));
175     validRects.push_back(RectI(20, -50, 180, 360));
176     RectI joinedRect = RectI();
177     RectI curDirtyRect = RectI();
178 
179     for (auto validRect : validRects) {
180         rsDirtyManager->Clear();
181         rsDirtyManager->MergeDirtyRect(validRect);
182         rsDirtyManager->UpdateDirty();
183         // get current frame's dirty
184         curDirtyRect = rsDirtyManager->GetLatestDirtyRegion();
185         HiLog::Info(LOG_LABEL, "UpdateDirtyValid curDirtyRect[%d, %d, %d, %d] validRect[%d, %d, %d, %d]",
186             curDirtyRect.left_, curDirtyRect.top_, curDirtyRect.width_, curDirtyRect.height_,
187             validRect.left_, validRect.top_, validRect.width_, validRect.height_);
188         EXPECT_EQ(curDirtyRect, validRect);
189 
190         joinedRect = joinedRect.JoinRect(validRect);
191         // get merged frames' dirty(buffer age)
192         curDirtyRect = rsDirtyManager->GetDirtyRegion();
193         HiLog::Info(LOG_LABEL, "UpdateDirtyValid hisDirtyRect[%d, %d, %d, %d] joinedRect[%d, %d, %d, %d]",
194             curDirtyRect.left_, curDirtyRect.top_, curDirtyRect.width_, curDirtyRect.height_,
195             joinedRect.left_, joinedRect.top_, joinedRect.width_, joinedRect.height_);
196         EXPECT_EQ(curDirtyRect, joinedRect);
197     }
198 }
199 
200 /*
201  * @tc.name: SetSurfaceSizeInvalid
202  * @tc.desc: Set surface size invalid and get return false
203  * @tc.type: FUNC
204  * @tc.require: issueI5SXX0
205 */
206 HWTEST_F(RSDirtyManagerTest, SetSurfaceSizeInvalid, Function | SmallTest | Level2)
207 {
208     int32_t validWidth = 1920;
209     int32_t validHeight = 1080;
210     int32_t invalidVal = -1;
211     bool ret = rsDirtyManager->SetSurfaceSize(invalidVal, invalidVal);
212     EXPECT_EQ(ret, false);
213     ret = rsDirtyManager->SetSurfaceSize(invalidVal, validHeight);
214     EXPECT_EQ(ret, false);
215     ret = rsDirtyManager->SetSurfaceSize(validWidth, invalidVal);
216     EXPECT_EQ(ret, false);
217 }
218 
219 /*
220  * @tc.name: SetSurfaceSizeValid
221  * @tc.desc: Set surface size valid and get return true
222  * @tc.type: FUNC
223  * @tc.require: issueI5SXX0
224 */
225 HWTEST_F(RSDirtyManagerTest, SetSurfaceSizeValid, Function | SmallTest | Level2)
226 {
227     int32_t validWidth = 1920;
228     int32_t validHeight = 1080;
229     bool ret = rsDirtyManager->SetSurfaceSize(validWidth, validHeight);
230     EXPECT_EQ(ret, true);
231     validWidth = 1;
232     validHeight = 1;
233     ret = rsDirtyManager->SetSurfaceSize(validWidth, validHeight);
234     EXPECT_EQ(ret, true);
235 }
236 
237 /*
238  * @tc.name: GetRectFlipWithinSurface
239  * @tc.desc: Set surface size and get rect flipped within surface
240  * @tc.type: FUNC
241  * @tc.require: issueI5SXX0
242 */
243 HWTEST_F(RSDirtyManagerTest, GetRectFlipWithinSurface, Function | SmallTest | Level2)
244 {
245     int32_t surfaceWidth = 1920;
246     int32_t surfaceHeight = 1080;
247     bool ret = rsDirtyManager->SetSurfaceSize(surfaceWidth, surfaceHeight);
248     EXPECT_EQ(ret, true);
249     RectI oriRect = RectI(31, 31, 32, 65);
250     RectI flippedRect = rsDirtyManager->GetRectFlipWithinSurface(oriRect);
251     int32_t flippedTop = surfaceHeight - oriRect.top_ - oriRect.height_;
252     RectI expectedRect = RectI(oriRect.left_, flippedTop, oriRect.width_, oriRect.height_);
253     EXPECT_EQ(flippedRect, expectedRect);
254 }
255 
256 /*
257  * @tc.name: GetPixelAlignedRect
258  * @tc.desc: Get pixel aligned rect by assigned aligned bits
259  * @tc.type: FUNC
260  * @tc.require: issueI5SXX0
261 */
262 HWTEST_F(RSDirtyManagerTest, GetPixelAlignedRect, Function | SmallTest | Level2)
263 {
264     // When aligned bits is no more than 1, aligned rect does not change
265     int32_t alignedBits = 1;
266     RectI oriRect = RectI(31, 31, 32, 65);
267     RectI alignedRect = RSDirtyRegionManager::GetPixelAlignedRect(oriRect, alignedBits);
268     EXPECT_EQ(alignedRect, oriRect);
269     // When aligned bits is more than 1, aligned rect zooms to fit aligned area
270     alignedBits = RSDirtyRegionManager::ALIGNED_BITS;
271     RectI expectedRect = RectI(0, 0, 64, 96);
272     alignedRect = RSDirtyRegionManager::GetPixelAlignedRect(oriRect, alignedBits);
273     EXPECT_EQ(alignedRect, expectedRect);
274 }
275 } // namespace Rosen
276 } // namespace OHOS
277