• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 
18 #include "display.h"
19 #include "display_info.h"
20 #include "display_manager.h"
21 #include "display_manager_proxy.h"
22 #include "modifier_render_thread/rs_modifiers_draw_thread.h"
23 #include "surface_draw.h"
24 #include "window_impl.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace {
32 const std::string IMAGE_PLACE_HOLDER_PNG_PATH = "/etc/window/resources/bg_place_holder.png";
33 const int WAIT_FOR_SYNC_US = 1000 * 500;                  // 500ms
34 constexpr float WIDTH_THRESHOLD_SMALL_VP = 320.0;         // 320.0 indicates small width threshold
35 constexpr float WIDTH_THRESHOLD_MEDIUM_VP = 600.0;        // 600.0 indicates medium width threshold
36 constexpr float WIDTH_THRESHOLD_LARGE_VP = 840.0;         // 840.0 indicates large width threshold
37 constexpr float VPRATIO = 1.5;                            // 1.5 indicates vpRatio
38 } // namespace
39 class SurfaceDrawTest : public testing::Test {
40 public:
41     static void SetUpTestCase();
42     static void TearDownTestCase();
43     void SetUp() override;
44     void TearDown() override;
45 
46 public:
47     struct WindowTestInfo {
48         std::string name;
49         Rect rect;
50         WindowType type;
51         WindowMode mode;
52         bool needAvoid;
53         bool parentLimit;
54         bool forbidSplitMove{ false };
55         bool showWhenLocked;
56         uint32_t parentId;
57     };
58     sptr<Window> CreateTestWindow(const std::string& name);
59 
60     static inline DisplayId displayId_;
61     static inline int32_t displayWidth_;
62     static inline int32_t displayHeight_;
63     WindowTestInfo windowInfo_;
64 };
65 
SetUpTestCase()66 void SurfaceDrawTest::SetUpTestCase()
67 {
68     displayId_ = DisplayManager::GetInstance().GetDefaultDisplayId();
69     sptr<Display> display = DisplayManager::GetInstance().GetDefaultDisplay();
70     if (display == nullptr) {
71         return;
72     }
73     displayWidth_ = display->GetWidth();
74     displayHeight_ = display->GetHeight();
75 }
76 
TearDownTestCase()77 void SurfaceDrawTest::TearDownTestCase()
78 {
79 #ifdef RS_ENABLE_VK
80     RSModifiersDrawThread::Destroy();
81 #endif
82 }
83 
SetUp()84 void SurfaceDrawTest::SetUp()
85 {
86     windowInfo_ = {
87         .name = "main",
88         .rect = { 100, 100, 250, 300 },
89         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
90         .mode = WindowMode::WINDOW_MODE_FLOATING,
91         .needAvoid = true,
92         .parentLimit = false,
93         .parentId = INVALID_WINDOW_ID,
94     };
95 }
96 
TearDown()97 void SurfaceDrawTest::TearDown() {}
98 
CreateTestWindow(const std::string & name)99 sptr<Window> SurfaceDrawTest::CreateTestWindow(const std::string& name)
100 {
101     sptr<WindowOption> option = new (std::nothrow) WindowOption();
102     if (option == nullptr) {
103         return nullptr;
104     }
105     option->SetDisplayId(displayId_);
106     option->SetWindowType(windowInfo_.type);
107     option->SetWindowRect(windowInfo_.rect);
108     option->SetWindowMode(windowInfo_.mode);
109     option->SetWindowName(name);
110     sptr<Window> window = Window::Create(option->GetWindowName(), option);
111     if (window == nullptr) {
112         return nullptr;
113     }
114     window->AddWindowFlag(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED);
115     return window;
116 }
117 
118 namespace {
119 /**
120  * @tc.name: DrawImage
121  * @tc.desc: SurfaceDraw::DrawImage test
122  * @tc.type: FUNC
123  */
124 HWTEST_F(SurfaceDrawTest, DrawImage01, TestSize.Level1)
125 {
126     ASSERT_FALSE(SurfaceDraw::DrawImage(nullptr, 0, 0, ""));
127     sptr<Window> window = CreateTestWindow("testDrawImage");
128     if (window == nullptr) {
129         return;
130     }
131     ASSERT_NE(nullptr, window);
132     window->Show();
133     usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated
134 
135     auto surfaceNode = window->GetSurfaceNode();
136     ASSERT_NE(surfaceNode, nullptr);
137     usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated
138     uint32_t width = window->GetRect().width_;
139     uint32_t height = window->GetRect().height_;
140     SurfaceDraw::DrawImage(surfaceNode, width, height, IMAGE_PLACE_HOLDER_PNG_PATH);
141     ASSERT_FALSE(SurfaceDraw::DrawImage(surfaceNode, -1, -1, IMAGE_PLACE_HOLDER_PNG_PATH));
142     window->Destroy();
143 }
144 
145 /**
146  * @tc.name: DecodeImageToPixelMap
147  * @tc.desc: SurfaceDraw::DecodeImageToPixelMap test
148  * @tc.type: FUNC
149  */
150 HWTEST_F(SurfaceDrawTest, DecodeImageToPixelMap01, TestSize.Level1)
151 {
152     ASSERT_EQ(SurfaceDraw::DecodeImageToPixelMap(""), nullptr);
153     ASSERT_NE(SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH), nullptr);
154 }
155 
156 /**
157  * @tc.name: DrawMasking
158  * @tc.desc: SurfaceDraw::DrawMasking test
159  * @tc.type: FUNC
160  */
161 HWTEST_F(SurfaceDrawTest, DrawMasking01, TestSize.Level1)
162 {
163     OHOS::Rosen::Rect screenRect = { 0, 0, 0, 0 };
164     OHOS::Rosen::Rect transRect = { 0, 0, 0, 0 };
165     ASSERT_FALSE(SurfaceDraw::DrawMasking(nullptr, screenRect, transRect));
166 
167     sptr<Window> window = CreateTestWindow("testDrawMasking");
168     if (window == nullptr) {
169         return;
170     }
171     ASSERT_NE(nullptr, window);
172     window->Show();
173     usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated
174 
175     auto surfaceNode = window->GetSurfaceNode();
176     ASSERT_NE(surfaceNode, nullptr);
177     ASSERT_FALSE(SurfaceDraw::DrawMasking(surfaceNode, screenRect, transRect));
178 
179     screenRect.width_ = displayWidth_;
180     screenRect.height_ = displayHeight_;
181     transRect.width_ = displayWidth_;
182     transRect.height_ = displayHeight_;
183     SurfaceDraw::DrawMasking(surfaceNode, screenRect, transRect);
184     window->Destroy();
185 }
186 
187 /**
188  * @tc.name: DoDrawImageRect
189  * @tc.desc: SurfaceDraw::DoDrawImageRect test
190  * @tc.type: FUNC
191  */
192 HWTEST_F(SurfaceDrawTest, DoDrawImageRect01, TestSize.Level1)
193 {
194     sptr<Window> window = CreateTestWindow("testDoDrawImageRect");
195     if (window == nullptr) {
196         return;
197     }
198     ASSERT_NE(window, nullptr);
199     window->Show();
200     usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated
201 
202     OHOS::Rosen::Rect rect = window->GetRect();
203     uint32_t color = 0x00660000;
204 
205     auto surfaceNode = window->GetSurfaceNode();
206     ASSERT_NE(surfaceNode, nullptr);
207     sptr<OHOS::Surface> layer = SurfaceDraw::GetLayer(surfaceNode);
208     ASSERT_NE(layer, nullptr);
209     sptr<OHOS::SurfaceBuffer> buffer = SurfaceDraw::GetSurfaceBuffer(layer, rect.width_, rect.height_);
210     if (buffer == nullptr) {
211         return;
212     }
213 
214     ASSERT_FALSE(SurfaceDraw::DoDrawImageRect(buffer, rect, nullptr, color, false));
215 
216     std::shared_ptr<Media::PixelMap> pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH);
217     ASSERT_NE(pixelMap, nullptr);
218 
219     ASSERT_TRUE(SurfaceDraw::DoDrawImageRect(buffer, rect, pixelMap, color, false));
220     window->Destroy();
221 }
222 
223 /**
224  * @tc.name: GetSurfaceSnapshot
225  * @tc.desc: SurfaceDraw::GetSurfaceSnapshot test
226  * @tc.type: FUNC
227  */
228 HWTEST_F(SurfaceDrawTest, GetSurfaceSnapshot01, TestSize.Level1)
229 {
230     sptr<Window> window = CreateTestWindow("testDoDrawImageRect");
231     if (window == nullptr) {
232         return;
233     }
234     ASSERT_NE(window, nullptr);
235     window->Show();
236     usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated
237 
238     auto surfaceNode = window->GetSurfaceNode();
239     ASSERT_NE(surfaceNode, nullptr);
240 
241     std::shared_ptr<Media::PixelMap> pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH);
242     ASSERT_NE(pixelMap, nullptr);
243 
244     ASSERT_FALSE(SurfaceDraw::GetSurfaceSnapshot(nullptr, pixelMap, 0, 0, 0));
245     ASSERT_FALSE(SurfaceDraw::GetSurfaceSnapshot(surfaceNode, pixelMap, 0, 0, 0));
246     window->Destroy();
247 }
248 
249 /**
250  * @tc.name: DrawColor
251  * @tc.desc: SurfaceDraw::DrawColor test
252  * @tc.type: FUNC
253  */
254 HWTEST_F(SurfaceDrawTest, DrawColor01, TestSize.Level1)
255 {
256     ASSERT_FALSE(SurfaceDraw::DrawColor(nullptr, 0, 0, 0));
257     sptr<Window> window = CreateTestWindow("DrawColor");
258     if (window == nullptr) {
259         return;
260     }
261     ASSERT_NE(nullptr, window);
262     window->Show();
263     usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated
264     auto surfaceNode = window->GetSurfaceNode();
265     ASSERT_NE(surfaceNode, nullptr);
266     uint32_t width = window->GetRect().width_;
267     uint32_t height = window->GetRect().height_;
268     uint32_t color = 0x00660000;
269     SurfaceDraw::DrawColor(surfaceNode, width, height, color);
270     SurfaceDraw::DrawColor(surfaceNode, -1, -1, color);
271     ASSERT_EQ(WMError::WM_OK, window->Destroy());
272 }
273 
274 /**
275  * @tc.name: DoDraw
276  * @tc.desc: SurfaceDraw::DoDraw test
277  * @tc.type: FUNC
278  */
279 HWTEST_F(SurfaceDrawTest, DoDraw01, TestSize.Level1)
280 {
281     sptr<Window> window = CreateTestWindow("DoDrawTest01");
282     if (window == nullptr) {
283         return;
284     }
285     ASSERT_NE(nullptr, window);
286     window->Show();
287     usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated
288     OHOS::Rosen::Rect rect = window->GetRect();
289     auto surfaceNode = window->GetSurfaceNode();
290     ASSERT_NE(surfaceNode, nullptr);
291     sptr<OHOS::Surface> layer = SurfaceDraw::GetLayer(surfaceNode);
292     ASSERT_NE(layer, nullptr);
293     sptr<OHOS::SurfaceBuffer> buffer = SurfaceDraw::GetSurfaceBuffer(layer, rect.width_, rect.height_);
294     ASSERT_NE(buffer, nullptr);
295     ASSERT_FALSE(SurfaceDraw::DoDraw(nullptr, 0, 0, ""));
296     window->Destroy();
297 }
298 
299 /**
300  * @tc.name: DoDraw
301  * @tc.desc: SurfaceDraw::DoDraw02 test
302  * @tc.type: FUNC
303  */
304 HWTEST_F(SurfaceDrawTest, DoDraw02, TestSize.Level1)
305 {
306     sptr<Window> window = CreateTestWindow("DoDraw02");
307     if (window == nullptr) {
308         return;
309     }
310     ASSERT_NE(window, nullptr);
311     window->Show();
312     usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated
313     OHOS::Rosen::Rect rect = window->GetRect();
314     auto surfaceNode = window->GetSurfaceNode();
315     ASSERT_NE(surfaceNode, nullptr);
316     sptr<OHOS::Surface> layer = SurfaceDraw::GetLayer(surfaceNode);
317     ASSERT_NE(layer, nullptr);
318     sptr<OHOS::SurfaceBuffer> buffer = SurfaceDraw::GetSurfaceBuffer(layer, rect.width_, rect.height_);
319     if (buffer == nullptr) {
320         return;
321     }
322     std::shared_ptr<Media::PixelMap> pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH);
323     ASSERT_NE(pixelMap, nullptr);
324     ASSERT_FALSE(SurfaceDraw::DoDraw(nullptr, 0, 0, pixelMap));
325     window->Destroy();
326 }
327 
328 /**
329  * @tc.name: DoDraw03
330  * @tc.desc: SurfaceDraw::DoDraw03 test
331  * @tc.type: FUNC
332  */
333 HWTEST_F(SurfaceDrawTest, DoDraw03, TestSize.Level1)
334 {
335     sptr<Window> window = CreateTestWindow("DoDrawTest03");
336     if (window == nullptr) {
337         return;
338     }
339     ASSERT_NE(nullptr, window);
340     window->Show();
341     usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated
342     OHOS::Rosen::Rect rect = window->GetRect();
343     uint32_t color = 0x00660000;
344     auto surfaceNode = window->GetSurfaceNode();
345     ASSERT_NE(surfaceNode, nullptr);
346     sptr<OHOS::Surface> layer = SurfaceDraw::GetLayer(surfaceNode);
347     ASSERT_NE(layer, nullptr);
348     sptr<OHOS::SurfaceBuffer> buffer = SurfaceDraw::GetSurfaceBuffer(layer, rect.width_, rect.height_);
349     if (buffer == nullptr) {
350         return;
351     }
352     ASSERT_FALSE(SurfaceDraw::DoDraw(nullptr, 0, 0, color));
353     window->Destroy();
354 }
355 
356 /**
357  * @tc.name: DrawImageRect
358  * @tc.desc: SurfaceDraw::DoDrawImageRect test
359  * @tc.type: FUNC
360  */
361 HWTEST_F(SurfaceDrawTest, DrawImageRect01, TestSize.Level1)
362 {
363     sptr<Window> window = CreateTestWindow("DrawImageRect");
364     if (window == nullptr) {
365         return;
366     }
367     ASSERT_NE(window, nullptr);
368     window->Show();
369     usleep(WAIT_FOR_SYNC_US / 20); // wait for rect updated
370     OHOS::Rosen::Rect rect = window->GetRect();
371     uint32_t color = 0x00660000;
372     auto surfaceNode = window->GetSurfaceNode();
373     ASSERT_NE(surfaceNode, nullptr);
374     ASSERT_FALSE(SurfaceDraw::DrawImageRect(surfaceNode, rect, nullptr, color, false));
375     std::shared_ptr<Media::PixelMap> pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH);
376     ASSERT_NE(pixelMap, nullptr);
377     SurfaceDraw::DrawImageRect(surfaceNode, rect, pixelMap, color, false);
378     window->Destroy();
379 }
380 
381 /**
382  * @tc.name: DrawCustomStartingWindow
383  * @tc.desc: SurfaceDraw::DrawCustomStartingWindow test failure
384  * @tc.type: FUNC
385  */
386 HWTEST_F(SurfaceDrawTest, DrawCustomStartingWindow01, TestSize.Level1)
387 {
388     sptr<Window> window = CreateTestWindow("DrawCustomStartingWindow test fail");
389     ASSERT_NE(window, nullptr);
390     window->Show();
391     usleep(WAIT_FOR_SYNC_US / 20); // wait 25ms for rect updated
392     OHOS::Rosen::Rect rect = window->GetRect();
393     auto info = std::make_shared<Rosen::StartingWindowPageDrawInfo>();
394     info->bgColor = 0x00660000;
395     auto surfaceNode = window->GetSurfaceNode();
396     std::array<uint32_t, size_t(StartWindowResType::Count)> frameIndex {};
397 
398     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(nullptr, rect, info, 1.0f, frameIndex), false);
399     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, nullptr, 1.0f, frameIndex), false);
400     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info, -1.0f, frameIndex), false);
401     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info, 0.0f, frameIndex), false);
402     rect.width_ = 0;
403     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info, 1.0f, frameIndex), false);
404     rect.height_ = 0;
405     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info, 1.0f, frameIndex), false);
406     window->Destroy();
407 }
408 
409 /**
410  * @tc.name: DrawCustomStartingWindow
411  * @tc.desc: SurfaceDraw::DrawCustomStartingWindow color
412  * @tc.type: FUNC
413  */
414 HWTEST_F(SurfaceDrawTest, DrawCustomStartingWindow02, TestSize.Level1)
415 {
416     sptr<Window> window = CreateTestWindow("DrawCustomStartingWindow test success");
417     ASSERT_NE(window, nullptr);
418     window->Show();
419     usleep(WAIT_FOR_SYNC_US / 20); // wait 25ms for rect updated
420     OHOS::Rosen::Rect rect = window->GetRect();
421     auto info = std::make_shared<Rosen::StartingWindowPageDrawInfo>();
422     info->bgColor = 0x00660000;
423     auto surfaceNode = window->GetSurfaceNode();
424     std::array<uint32_t, size_t(StartWindowResType::Count)> frameIndex {};
425 
426     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode,
427         rect, info, std::numeric_limits<float>::max(), frameIndex), true);
428     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode,
429         rect, info, std::numeric_limits<float>::min(), frameIndex), true);
430     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info, 1.0f, frameIndex), true);
431     window->Destroy();
432 }
433 
434 /**
435  * @tc.name: DrawCustomStartingWindow
436  * @tc.desc: SurfaceDraw::DrawCustomStartingWindow resource
437  * @tc.type: FUNC
438  */
439 HWTEST_F(SurfaceDrawTest, DrawCustomStartingWindow03, TestSize.Level1)
440 {
441     sptr<Window> window = CreateTestWindow("DrawCustomStartingWindow test success");
442     ASSERT_NE(window, nullptr);
443     window->Show();
444     usleep(WAIT_FOR_SYNC_US / 20); // wait 25ms for rect updated
445     OHOS::Rosen::Rect rect = window->GetRect();
446     auto info = std::make_shared<Rosen::StartingWindowPageDrawInfo>();
447     info->bgColor = 0x00660000;
448     auto surfaceNode = window->GetSurfaceNode();
449     std::array<uint32_t, size_t(StartWindowResType::Count)> frameIndex { 0, 0, 0, 0 };
450 
451     std::shared_ptr<Media::PixelMap> pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH);
452     info->appIcon = std::make_shared<ResourceInfo>();
453     info->bgImage = std::make_shared<ResourceInfo>();
454     info->branding = std::make_shared<ResourceInfo>();
455     info->appIcon->pixelMaps.push_back(pixelMap);
456     info->bgImage->pixelMaps.push_back(pixelMap);
457     info->branding->pixelMaps.push_back(pixelMap);
458 
459     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info, 1.0f, frameIndex), true);
460     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info,
461         std::numeric_limits<float>::max(), frameIndex), true);
462     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info,
463         std::numeric_limits<float>::min(), frameIndex), true);
464     window->Destroy();
465 }
466 
467 /**
468  * @tc.name: DrawCustomStartingWindow
469  * @tc.desc: SurfaceDraw::DrawCustomStartingWindow resource
470  * @tc.type: FUNC
471  */
472 HWTEST_F(SurfaceDrawTest, DrawCustomStartingWindow04, TestSize.Level1)
473 {
474     sptr<Window> window = CreateTestWindow("DrawCustomStartingWindow test success");
475     ASSERT_NE(window, nullptr);
476     window->Show();
477     usleep(WAIT_FOR_SYNC_US / 20); // wait 25ms for rect updated
478     OHOS::Rosen::Rect rect = window->GetRect();
479     auto info = std::make_shared<Rosen::StartingWindowPageDrawInfo>();
480     info->bgColor = 0x00660000;
481     auto surfaceNode = window->GetSurfaceNode();
482     std::array<uint32_t, size_t(StartWindowResType::Count)> frameIndex { 0, 0, 0, 0 };
483 
484     std::shared_ptr<Media::PixelMap> pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH);
485     info->branding = std::make_shared<ResourceInfo>();
486     info->branding->pixelMaps.push_back(pixelMap);
487     info->illustration = std::make_shared<ResourceInfo>();
488     info->illustration->pixelMaps.push_back(pixelMap);
489 
490     rect.height_ = 200; // height of rect
491     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info, 1.0f, frameIndex), true);
492     window->Destroy();
493 }
494 
495 /**
496  * @tc.name: DrawCustomStartingWindow
497  * @tc.desc: SurfaceDraw::DrawCustomStartingWindow appicon
498  * @tc.type: FUNC
499  */
500 HWTEST_F(SurfaceDrawTest, DrawCustomStartingWindow05, TestSize.Level1)
501 {
502     sptr<Window> window = CreateTestWindow("DrawCustomStartingWindow test success");
503     ASSERT_NE(window, nullptr);
504     window->Show();
505     usleep(WAIT_FOR_SYNC_US / 20); // wait 25ms for rect updated
506     OHOS::Rosen::Rect rect = window->GetRect();
507     auto info = std::make_shared<Rosen::StartingWindowPageDrawInfo>();
508     info->bgColor = 0x00660000;
509     auto surfaceNode = window->GetSurfaceNode();
510     std::array<uint32_t, size_t(StartWindowResType::Count)> frameIndex { 0, 0, 0, 0 };
511 
512     std::shared_ptr<Media::PixelMap> pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH);
513     info->appIcon = std::make_shared<ResourceInfo>();
514     info->appIcon->pixelMaps.push_back(pixelMap);
515 
516     rect.width_ = WIDTH_THRESHOLD_SMALL_VP * VPRATIO - 1; // shorter than small width threshold
517     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info, VPRATIO, frameIndex), true);
518 
519     rect.width_ = WIDTH_THRESHOLD_MEDIUM_VP * VPRATIO - 1; // shorter than medium width threshold
520     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info, VPRATIO, frameIndex), true);
521 
522     rect.width_ = WIDTH_THRESHOLD_LARGE_VP * VPRATIO - 1; // shorter than large width threshold
523     EXPECT_EQ(SurfaceDraw::DrawCustomStartingWindow(surfaceNode, rect, info, VPRATIO, frameIndex), true);
524     window->Destroy();
525 }
526 
527 /**
528  * @tc.name: DrawBackgroundImage01
529  * @tc.desc: SurfaceDraw::DoDrawBackgroundImage01 test
530  * @tc.type: FUNC
531  */
532 HWTEST_F(SurfaceDrawTest, DrawBackgroundImage01, TestSize.Level1)
533 {
534     std::shared_ptr<Media::PixelMap> pixelMap = SurfaceDraw::DecodeImageToPixelMap(IMAGE_PLACE_HOLDER_PNG_PATH);
535     ASSERT_NE(pixelMap, nullptr);
536     auto info = std::make_shared<Rosen::StartingWindowPageDrawInfo>();
537     info->bgColor = 0x00660000;
538     info->bgImage = std::make_shared<ResourceInfo>();
539     info->bgImage->pixelMaps.push_back(pixelMap);
540     sptr<Window> window = CreateTestWindow("DrawCustomResource");
541     ASSERT_NE(window, nullptr);
542     window->Show();
543     usleep(WAIT_FOR_SYNC_US / 20); // wait 25ms for rect updated
544     OHOS::Rosen::Rect rect = window->GetRect();
545     auto surfaceNode = window->GetSurfaceNode();
546     auto buffer = SurfaceDraw::GetSurfaceBuffer(SurfaceDraw::GetLayer(surfaceNode), rect.width_, rect.height_);
547     float ratio = 1.0f;
548     std::array<uint32_t, size_t(StartWindowResType::Count)> frameIndex { 0, 0, 0, 0 };
549 
550     info->startWindowBackgroundImageFit = "";
551     EXPECT_EQ(SurfaceDraw::DoDrawCustomStartingWindow(buffer, rect, info, ratio, frameIndex), true);
552     info->startWindowBackgroundImageFit = "Cover";
553     EXPECT_EQ(SurfaceDraw::DoDrawCustomStartingWindow(buffer, rect, info, ratio, frameIndex), true);
554     info->startWindowBackgroundImageFit = "Contain";
555     EXPECT_EQ(SurfaceDraw::DoDrawCustomStartingWindow(buffer, rect, info, ratio, frameIndex), true);
556     info->startWindowBackgroundImageFit = "Fill";
557     EXPECT_EQ(SurfaceDraw::DoDrawCustomStartingWindow(buffer, rect, info, ratio, frameIndex), true);
558     info->startWindowBackgroundImageFit = "Auto";
559     EXPECT_EQ(SurfaceDraw::DoDrawCustomStartingWindow(buffer, rect, info, ratio, frameIndex), true);
560     info->startWindowBackgroundImageFit = "ScaleDown";
561     EXPECT_EQ(SurfaceDraw::DoDrawCustomStartingWindow(buffer, rect, info, ratio, frameIndex), true);
562     info->startWindowBackgroundImageFit = "xxxxx";
563     EXPECT_EQ(SurfaceDraw::DoDrawCustomStartingWindow(buffer, rect, info, ratio, frameIndex), true);
564     info->startWindowBackgroundImageFit = "None";
565     EXPECT_EQ(SurfaceDraw::DoDrawCustomStartingWindow(buffer, rect, info, ratio, frameIndex), true);
566     window->Destroy();
567 }
568 } // namespace
569 } // namespace Rosen
570 } // namespace OHOS