1 /* 2 * Copyright (c) 2025 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_CONTEXT_MANAGER_H 16 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_UI_CONTEXT_MANAGER_H 17 18 #include "rs_ui_context.h" 19 20 #include "common/rs_macros.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 class RSC_EXPORT RSUIContextManager final { 25 public: 26 static const RSUIContextManager& Instance(); 27 static RSUIContextManager& MutableInstance(); 28 29 const std::shared_ptr<RSUIContext> GetRSUIContext(uint64_t token) const; 30 31 std::shared_ptr<RSUIContext> CreateRSUIContext(); 32 void DestroyContext(uint64_t token); 33 34 private: 35 RSUIContextManager(); 36 ~RSUIContextManager() noexcept; 37 RSUIContextManager(const RSUIContextManager&) = delete; 38 RSUIContextManager(const RSUIContextManager&&) = delete; 39 RSUIContextManager& operator=(const RSUIContextManager&) = delete; 40 RSUIContextManager& operator=(const RSUIContextManager&&) = delete; 41 42 uint64_t GenerateToken(int32_t tid); 43 std::shared_ptr<RSUIContext> GetRandomUITaskRunnerCtx() const; 44 45 mutable std::mutex mutex_; 46 std::unordered_map<uint64_t, std::shared_ptr<RSUIContext>> rsUIContextMap_; 47 uint32_t instanceIdCounter_ = 0; 48 bool isMultiInstanceOpen_ = false; 49 50 friend class RSUIDirector; 51 }; 52 } // namespace Rosen 53 } // namespace OHOS 54 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_UI_CONTEXT_MANAGER_H