• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "knuckle_glow_trace_system.h"
17 
18 #include "mmi_log.h"
19 
20 #undef MMI_LOG_TAG
21 #define MMI_LOG_TAG "KnuckleGlowTraceSystem"
22 
23 namespace OHOS {
24 namespace MMI {
25 namespace {
26 constexpr float BASIC_DISTANCE_BETWEEN_POINTS { 5.0f };
27 } // namespace
28 
KnuckleGlowTraceSystem(int32_t pointSize,std::shared_ptr<OHOS::Media::PixelMap> pixelMap,int32_t maxDivergenceNum)29 KnuckleGlowTraceSystem::KnuckleGlowTraceSystem(int32_t pointSize, std::shared_ptr<OHOS::Media::PixelMap> pixelMap,
30     int32_t maxDivergenceNum) : maxDivergenceNum_(maxDivergenceNum)
31 {
32     CALL_DEBUG_ENTER;
33     CHKPV(pixelMap);
34     for (int32_t i = 0; i < pointSize; ++i) {
35         divergentPoints_.emplace_back(std::make_shared<KnuckleDivergentPoint>(pixelMap));
36         glowPoints_.emplace_back(std::make_shared<KnuckleGlowPoint>(pixelMap));
37     }
38 }
39 
Clear()40 void KnuckleGlowTraceSystem::Clear()
41 {
42     CALL_DEBUG_ENTER;
43     for (const auto &divergentPoint : divergentPoints_) {
44         divergentPoint->Clear();
45     }
46 }
47 
Update()48 void KnuckleGlowTraceSystem::Update()
49 {
50     CALL_DEBUG_ENTER;
51     for (size_t i = 0; i < glowPoints_.size(); i++) {
52         glowPoints_[i]->Update();
53         divergentPoints_[i]->Update();
54     }
55 }
56 
Draw(Rosen::ExtendRecordingCanvas * canvas)57 void KnuckleGlowTraceSystem::Draw(Rosen::ExtendRecordingCanvas* canvas)
58 {
59     CALL_DEBUG_ENTER;
60     for (size_t i = 0; i < glowPoints_.size(); ++i) {
61         std::shared_ptr<KnuckleDivergentPoint> divergentPoint = divergentPoints_[i];
62         std::shared_ptr<KnuckleGlowPoint> glowPoint = glowPoints_[i];
63         if (divergentPoint != nullptr) {
64             divergentPoint->Draw(canvas);
65         }
66         if (glowPoint != nullptr) {
67             glowPoint->Draw(canvas);
68         }
69     }
70 }
71 
ResetDivergentPoints(double pointX,double pointY)72 void KnuckleGlowTraceSystem::ResetDivergentPoints(double pointX, double pointY)
73 {
74     CALL_DEBUG_ENTER;
75     int32_t divergenceNum = 0;
76     for (const auto &divergentPoint : divergentPoints_) {
77         CHKPC(divergentPoint);
78         if (divergentPoint->IsEnded() && divergenceNum < maxDivergenceNum_) {
79             divergenceNum++;
80             divergentPoint->Reset(pointX, pointY);
81         }
82     }
83 }
84 
AddGlowPoints(const Rosen::Drawing::Path & path,int64_t timeInterval)85 void KnuckleGlowTraceSystem::AddGlowPoints(const Rosen::Drawing::Path &path, int64_t timeInterval)
86 {
87     CALL_DEBUG_ENTER;
88     double pathlength = path.GetLength(false);
89     Rosen::Drawing::Point pathPoints;
90     Rosen::Drawing::Point tangent;
91     float distanceFromEnd = 0;
92     float lifespanOffset = timeInterval;
93     float splitRatio = static_cast<float>(std::ceil(pathlength / BASIC_DISTANCE_BETWEEN_POINTS));
94     float baseTime = timeInterval / splitRatio;
95     for (const auto &glowPoint : glowPoints_) {
96         if (glowPoint != nullptr && glowPoint->IsEnded() && distanceFromEnd <= pathlength) {
97             if (path.GetPositionAndTangent(distanceFromEnd, pathPoints, tangent, true)) {
98                 glowPoint->Reset(pathPoints.GetX(), pathPoints.GetY(), lifespanOffset);
99                 distanceFromEnd += BASIC_DISTANCE_BETWEEN_POINTS;
100                 lifespanOffset -= baseTime;
101             }
102         }
103     }
104 }
105 } // namespace MMI
106 } // namespace OHOS
107