1 /* 2 * Copyright (c) 2021 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 <mutex> 20 21 #include "common/rs_common_def.h" 22 23 namespace OHOS { 24 class Surface; 25 namespace Rosen { 26 class RSSurfaceNode; 27 class RSTransactionData; 28 using TaskRunner = std::function<void(const std::function<void()>&)>; 29 30 class RS_EXPORT RSUIDirector final { 31 public: 32 static std::shared_ptr<RSUIDirector> Create(); 33 34 ~RSUIDirector(); 35 void GoBackground(); 36 void GoForeground(); 37 void Init(); 38 void SetRSSurfaceNode(std::shared_ptr<RSSurfaceNode> surfaceNode); 39 40 void SetRoot(NodeId root); 41 void SetUITaskRunner(const TaskRunner& uiTaskRunner); 42 void SendMessages(); // post messages to render thread 43 44 void SetTimeStamp(uint64_t timeStamp); 45 46 private: 47 void Destory(); 48 void AttachSurface(); 49 static void RecvMessages(); 50 static void RecvMessages(std::shared_ptr<RSTransactionData> cmds); 51 static void ProcessMessages(std::shared_ptr<RSTransactionData> cmds); // receive message 52 static void AnimationCallbackProcessor(NodeId nodeId, AnimationId animId); 53 54 RSUIDirector() = default; 55 RSUIDirector(const RSUIDirector&) = delete; 56 RSUIDirector(const RSUIDirector&&) = delete; 57 RSUIDirector& operator=(const RSUIDirector&) = delete; 58 RSUIDirector& operator=(const RSUIDirector&&) = delete; 59 60 std::mutex mutex_; 61 NodeId root_ = 0; 62 63 bool isActive_ = false; 64 uint64_t refreshPeriod_ = 16666667; 65 uint64_t timeStamp_ = 0; 66 std::shared_ptr<RSSurfaceNode> surfaceNode_ = nullptr; 67 int surfaceWidth_ = 0; 68 int surfaceHeight_ = 0; 69 70 friend class RSRenderThread; 71 }; 72 } // namespace Rosen 73 } // namespace OHOS 74 75 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_UI_DIRECTOR_H