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