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 RENDER_SERVICE_BASE_PROPERTY_RS_GLOBAL_LIGHT_MANAGER_H
17 #define RENDER_SERVICE_BASE_PROPERTY_RS_GLOBAL_LIGHT_MANAGER_H
18 
19 #include "common/rs_vector4.h"
20 #include "pipeline/rs_render_node.h"
21 #include "property/rs_properties_def.h"
22 #include "screen_manager/screen_types.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 class RSB_EXPORT RSPointLightManager {
27 public:
28     static RSPointLightManager* Instance();
29     void RegisterLightSource(const std::shared_ptr<RSRenderNode>& renderNode);
30     void RegisterIlluminated(const std::shared_ptr<RSRenderNode>& renderNode);
31     void UnRegisterLightSource(const std::shared_ptr<RSRenderNode>& renderNode);
32     void UnRegisterIlluminated(const std::shared_ptr<RSRenderNode>& renderNode);
33     void AddDirtyLightSource(std::weak_ptr<RSRenderNode> renderNode);
34     void AddDirtyIlluminated(std::weak_ptr<RSRenderNode> renderNode);
35     void PrepareLight();
36     Vector4f CalculateLightPosForIlluminated(const RSLightSource& lightSource,
37         const RectI& illuminatedAbsRect);
SetScreenRotation(ScreenRotation screenRotation)38     void SetScreenRotation(ScreenRotation screenRotation)
39     {
40         screenRotation_ = screenRotation;
41     }
GetScreenRotation()42     ScreenRotation GetScreenRotation() const
43     {
44         return screenRotation_;
45     }
46 
47 private:
48     RSPointLightManager() = default;
49     ~RSPointLightManager() = default;
50     RSPointLightManager(const RSPointLightManager&) = delete;
51     RSPointLightManager(const RSPointLightManager&&) = delete;
52     RSPointLightManager& operator=(const RSPointLightManager&) = delete;
53     RSPointLightManager& operator=(const RSPointLightManager&&) = delete;
54 
55     void ClearDirtyList();
56     void CheckIlluminated(
57         const std::shared_ptr<RSRenderNode>& lightSourceNode, const std::shared_ptr<RSRenderNode>& illuminatedNode);
58     void PrepareLight(std::unordered_map<NodeId, std::weak_ptr<RSRenderNode>>& map,
59         std::vector<std::weak_ptr<RSRenderNode>>& dirtyList, bool isLightSourceDirty);
60     std::unordered_map<NodeId, std::weak_ptr<RSRenderNode>> lightSourceNodeMap_;
61     std::unordered_map<NodeId, std::weak_ptr<RSRenderNode>> illuminatedNodeMap_;
62     std::vector<std::weak_ptr<RSRenderNode>> dirtyLightSourceList_;
63     std::vector<std::weak_ptr<RSRenderNode>> dirtyIlluminatedList_;
64     ScreenRotation screenRotation_ = ScreenRotation::INVALID_SCREEN_ROTATION;
65 };
66 } // namespace Rosen
67 } // namespace OHOS
68 
69 #endif // RENDER_SERVICE_BASE_PROPERTY_RS_GLOBAL_LIGHT_MANAGER_H