• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_UI_DIRECTOR_H
16 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_UI_DIRECTOR_H
17 
18 #include <atomic>
19 #include <functional>
20 #include <mutex>
21 
22 #include "command/rs_animation_command.h"
23 #include "common/rs_common_def.h"
24 
25 namespace OHOS {
26 class Surface;
27 namespace Rosen {
28 class RSSurfaceNode;
29 class RSTransactionData;
30 using TaskRunner = std::function<void(const std::function<void()>&)>;
31 
32 class RSC_EXPORT RSUIDirector final {
33 public:
34     static std::shared_ptr<RSUIDirector> Create();
35 
36     ~RSUIDirector();
37     void GoBackground();
38     void GoForeground();
39     void Init(bool shouldCreateRenderThread = true);
40     void Destroy();
41     void SetRSSurfaceNode(std::shared_ptr<RSSurfaceNode> surfaceNode);
42     void SetAbilityBGAlpha(uint8_t alpha);
43     /**
44      * @brief Set rt render status and keep it till set again
45      *
46      * @param isRenderForced if true, rt will reject partial render and be forced to render all frames
47      */
48     void SetRTRenderForced(bool isRenderForced);
49     void SetContainerWindow(bool hasContainerWindow, float density);
50 
51     void SetRoot(NodeId root);
52     void SetUITaskRunner(const TaskRunner& uiTaskRunner);
53     void SendMessages(); // post messages to render thread
54 
55     void SetTimeStamp(uint64_t timeStamp, const std::string& abilityName);
56     void SetCacheDir(const std::string& cacheFilePath);
57 
58     bool RunningCustomAnimation(uint64_t timeStamp);
59 
60     void SetAppFreeze(bool isAppFreeze);
61 
62 private:
63     void AttachSurface();
64     static void RecvMessages();
65     static void RecvMessages(std::shared_ptr<RSTransactionData> cmds);
66     static void ProcessMessages(std::shared_ptr<RSTransactionData> cmds); // receive message
67     static void AnimationCallbackProcessor(NodeId nodeId, AnimationId animId, AnimationCallbackEvent event);
68     static void PostTask(const std::function<void()>& task);
69 
70     RSUIDirector() = default;
71     RSUIDirector(const RSUIDirector&) = delete;
72     RSUIDirector(const RSUIDirector&&) = delete;
73     RSUIDirector& operator=(const RSUIDirector&) = delete;
74     RSUIDirector& operator=(const RSUIDirector&&) = delete;
75 
76     std::mutex mutex_;
77     NodeId root_ = 0;
78 
79     bool isActive_ = false;
80     bool isUniRenderEnabled_ = false;
81     uint64_t refreshPeriod_ = 16666667;
82     uint64_t timeStamp_ = 0;
83     std::string abilityName_;
84     std::weak_ptr<RSSurfaceNode> surfaceNode_;
85     int surfaceWidth_ = 0;
86     int surfaceHeight_ = 0;
87     std::string cacheDir_;
88 
89     friend class RSApplicationAgentImpl;
90     friend class RSRenderThread;
91     friend class RSImplicitAnimator;
92 };
93 } // namespace Rosen
94 } // namespace OHOS
95 
96 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_UI_DIRECTOR_H
97