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 #ifndef SHADOW_TEST_H
17 #define SHADOW_TEST_H
18 
19 #include "draw/brush.h"
20 #include "draw/canvas.h"
21 #include "draw/color.h"
22 #include "draw/pen.h"
23 #include "utils/log.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace Drawing {
28 class ShadowTest {
29 public:
30     using TestFunc = std::function<void(Canvas&, uint32_t, uint32_t)>;
GetInstance()31     inline static ShadowTest& GetInstance()
32     {
33         static ShadowTest shadowTestCase;
34         return shadowTestCase;
35     }
36 
37     static void TestDrawShadow(Canvas& canvas, uint32_t width, uint32_t height);
38     static void TestDrawShadowStyle(Canvas& canvas, uint32_t width, uint32_t height);
39     std::vector<TestFunc> ShadowTestCase();
40 
41 private:
42     ShadowTest() = default;
43     virtual ~ShadowTest() = default;
44 };
45 
TestDrawShadow(Canvas & canvas,uint32_t width,uint32_t height)46 void ShadowTest::TestDrawShadow(Canvas& canvas, uint32_t width, uint32_t height)
47 {
48     LOGI("+++++++ TestDrawShadow");
49 
50     Path path;
51     // Add oval to path, bounds of ellipse added is {200, 200, 600, 1000}.
52     path.AddOval({ 200, 200, 600, 1000 });
53     Point3 planeParams = { 540.0, 0.0, 600.0 };
54     Point3 devLightPos = { 0, 0, 0 };
55     scalar lightRadius = 0.5;
56     Drawing::Color ambientColor = Drawing::Color::ColorQuadSetARGB(0, 0, 0, 0);
57     Drawing::Color spotColor = Drawing::Color::COLOR_RED;
58     ShadowFlags flag = ShadowFlags::TRANSPARENT_OCCLUDER;
59     canvas.DrawShadow(path, planeParams, devLightPos, lightRadius, ambientColor, spotColor, flag);
60     LOGI("------- TestDrawShadow");
61 }
62 
TestDrawShadowStyle(Canvas & canvas,uint32_t width,uint32_t height)63 void ShadowTest::TestDrawShadowStyle(Canvas& canvas, uint32_t width, uint32_t height)
64 {
65     LOGI("+++++++ TestDrawShadowStyle");
66 
67     Path path;
68     // Add oval to path, bounds of ellipse added is {200, 200, 600, 1000}.
69     path.AddOval({ 200, 200, 600, 1000 });
70     Point3 planeParams = { 540.0, 0.0, 600.0 };
71     Point3 devLightPos = { 0, 0, 0 };
72     scalar lightRadius = 0.5;
73     Drawing::Color ambientColor = Drawing::Color::ColorQuadSetARGB(0, 0, 0, 0);
74     Drawing::Color spotColor = Drawing::Color::COLOR_RED;
75     ShadowFlags flag = ShadowFlags::TRANSPARENT_OCCLUDER;
76     canvas.DrawShadowStyle(path, planeParams, devLightPos, lightRadius, ambientColor, spotColor, flag, true);
77     LOGI("------- TestDrawShadowStyle");
78 }
79 
ShadowTestCase()80 std::vector<ShadowTest::TestFunc> ShadowTest::ShadowTestCase()
81 {
82     std::vector<TestFunc> testFuncVec;
83     testFuncVec.push_back(TestDrawShadow);
84     testFuncVec.push_back(TestDrawShadowStyle);
85     return testFuncVec;
86 }
87 } // namespace Drawing
88 } // namespace Rosen
89 } // namespace OHOS
90 #endif // SHADOW_TEST_H