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_CORE_PIPELINE_PARALLEL_RENDER_RS_SUB_THREAD_MANAGER_H 17 #define RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_SUB_THREAD_MANAGER_H 18 19 #include "rs_sub_thread.h" 20 21 #include <condition_variable> 22 #include <cstdint> 23 #include <map> 24 #include <mutex> 25 #include "EGL/egl.h" 26 #include "pipeline/parallel_render/rs_render_task.h" 27 #include "pipeline/rs_base_render_node.h" 28 #include "render_context/render_context.h" 29 30 namespace OHOS::Rosen { 31 class RSSubThreadManager { 32 public: 33 static RSSubThreadManager *Instance(); 34 void Start(RenderContext *context); 35 void PostTask(const std::function<void()>& task, uint32_t threadIndex); 36 void WaitNodeTask(uint64_t nodeId); 37 void NodeTaskNotify(uint64_t nodeId); 38 void SubmitSubThreadTask(const std::shared_ptr<RSDisplayRenderNode>& node, 39 const std::list<std::shared_ptr<RSSurfaceRenderNode>>& subThreadNodes); 40 void ResetSubThreadGrContext(); 41 void DumpMem(DfxString& log); 42 private: 43 RSSubThreadManager() = default; 44 ~RSSubThreadManager() = default; 45 RSSubThreadManager(const RSSubThreadManager &) = delete; 46 RSSubThreadManager(const RSSubThreadManager &&) = delete; 47 RSSubThreadManager &operator = (const RSSubThreadManager &) = delete; 48 RSSubThreadManager &operator = (const RSSubThreadManager &&) = delete; 49 50 RenderContext* renderContext_ = nullptr; 51 uint32_t minLoadThreadIndex_ = 0; 52 std::mutex parallelRenderMutex_; 53 std::condition_variable cvParallelRender_; 54 std::map<uint64_t, uint8_t> nodeTaskState_; 55 std::vector<std::shared_ptr<RSSubThread>> threadList_; 56 bool needResetContext_ = false; 57 }; 58 } 59 #endif // RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_SUB_THREAD_MANAGER_H