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 std::vector<TestFunc> ShadowTestCase();
39
40 private:
41 ShadowTest() = default;
42 virtual ~ShadowTest() = default;
43 };
44
TestDrawShadow(Canvas & canvas,uint32_t width,uint32_t height)45 void ShadowTest::TestDrawShadow(Canvas& canvas, uint32_t width, uint32_t height)
46 {
47 LOGI("+++++++ TestDrawShadow");
48
49 Path path;
50 // Add oval to path, bounds of ellipse added is {200, 200, 600, 1000}.
51 path.AddOval({ 200, 200, 600, 1000 });
52 Point3 planeParams = { 540.0, 0.0, 600.0 };
53 Point3 devLightPos = { 0, 0, 0 };
54 scalar lightRadius = 0.5;
55 Drawing::Color ambientColor = Drawing::Color::ColorQuadSetARGB(0, 0, 0, 0);
56 Drawing::Color spotColor = Drawing::Color::COLOR_RED;
57 ShadowFlags flag = ShadowFlags::TRANSPARENT_OCCLUDER;
58 canvas.DrawShadow(path, planeParams, devLightPos, lightRadius, ambientColor, spotColor, flag);
59 LOGI("------- TestDrawShadow");
60 }
61
ShadowTestCase()62 std::vector<ShadowTest::TestFunc> ShadowTest::ShadowTestCase()
63 {
64 std::vector<TestFunc> testFuncVec;
65 testFuncVec.push_back(TestDrawShadow);
66 return testFuncVec;
67 }
68 } // namespace Drawing
69 } // namespace Rosen
70 } // namespace OHOS
71 #endif // SHADOW_TEST_H