• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 SENSOR_ILLUMINATION_TASK
17 #define SENSOR_ILLUMINATION_TASK
18 
19 #include <mutex>
20 
21 #include "display_manager.h"
22 #include "nocopyable.h"
23 #include "timer.h"
24 #include "transaction/rs_interfaces.h"
25 #include "ui/rs_surface_node.h"
26 
27 #include "iam_common_defines.h"
28 
29 #include "isensor_illumination_task.h"
30 
31 namespace OHOS {
32 namespace UserIam {
33 namespace FingerprintAuth {
34 using CanvasParam = struct {
35     uint32_t centerXInPx;
36     uint32_t centerYInPy;
37     uint32_t radius;
38     uint32_t color;
39     uint32_t alpha;
40     int32_t frameWidth;
41     int32_t frameHeight;
42 };
43 
44 class SensorIlluminationTask : public ISensorIlluminationTask,
45                                public std::enable_shared_from_this<SensorIlluminationTask>,
46                                public NoCopyable {
47 public:
48     SensorIlluminationTask();
49     ~SensorIlluminationTask() override;
50 
51     UserAuth::ResultCode EnableSensorIllumination(uint32_t centerX, uint32_t centerY, uint32_t radius,
52         uint32_t color) override;
53     UserAuth::ResultCode DisableSensorIllumination() override;
54     UserAuth::ResultCode TurnOnSensorIllumination() override;
55     UserAuth::ResultCode TurnOffSensorIllumination() override;
56     void OnDisplayTimeOut() override;
57     void RegisterDestructCallback(DestructCallback callback) override;
58 
59 private:
60     UserAuth::ResultCode DrawSurfaceNode();
61 
62     static constexpr uint32_t INVALID_BRIGHTNESS = UINT32_MAX;
63     static constexpr int32_t INVALID_DISPLAY_ID = -1;
64 
65     std::shared_ptr<Rosen::RSSurfaceNode> rsSurfaceNode_ = nullptr;
66     std::shared_ptr<Rosen::RSSurface> rsSurface_ = nullptr;
67     std::shared_ptr<Rosen::RenderContext> renderContext_ = nullptr;
68     Rosen::DisplayId defaultDisplayId_ = INVALID_DISPLAY_ID;
69     Rosen::ScreenId defaultScreenId_ = Rosen::INVALID_SCREEN_ID;
70     CanvasParam canvasParam_ = {};
71     uint32_t brightness_ = INVALID_BRIGHTNESS;
72 
73     Utils::Timer timer_;
74     uint32_t currTimerId_ = 0;
75     std::recursive_mutex recursiveMutex_;
76     bool isIlluminationOn_ = false;
77     DestructCallback destructCallback_;
78 };
79 std::shared_ptr<ISensorIlluminationTask> GetSensorIlluminationTask();
80 } // namespace FingerprintAuth
81 } // namespace UserIam
82 } // namespace OHOS
83 
84 #endif // SENSOR_ILLUMINATION_TASK