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 #include "rs_filter_sub_thread.h" 30 31 namespace OHOS::Rosen { 32 constexpr char TOPIC_RCD_DISPLAY_SIZE[] = "RCD_UPDATE_DISPLAY_SIZE"; 33 constexpr char TOPIC_RCD_DISPLAY_ROTATION[] = "RCD_UPDATE_DISPLAY_ROTATION"; 34 constexpr char TOPIC_RCD_DISPLAY_NOTCH[] = "RCD_UPDATE_DISPLAY_NOTCH"; 35 class RSSubThreadManager { 36 public: 37 static RSSubThreadManager *Instance(); 38 void Start(RenderContext *context); 39 void StartFilterThread(RenderContext* context); 40 void StartColorPickerThread(RenderContext* context); 41 void StartRCDThread(RenderContext* context); 42 void PostTask(const std::function<void()>& task, uint32_t threadIndex, bool isSyncTask = false); 43 void WaitNodeTask(uint64_t nodeId); 44 void NodeTaskNotify(uint64_t nodeId); 45 void SubmitFilterSubThreadTask(); 46 void SetFenceSubThread(sptr<SyncFence> fence); 47 void SubmitSubThreadTask(const std::shared_ptr<RSDisplayRenderNode>& node, 48 const std::list<std::shared_ptr<RSSurfaceRenderNode>>& subThreadNodes); 49 void ResetSubThreadGrContext(); 50 void CancelReleaseResourceTask(); 51 void DumpMem(DfxString& log); 52 float GetAppGpuMemoryInMB(); 53 std::vector<MemoryGraphic> CountSubMem(int pid); 54 void ReleaseSurface(uint32_t threadIndex) const; 55 #ifndef USE_ROSEN_DRAWING 56 void AddToReleaseQueue(sk_sp<SkSurface>&& surface, uint32_t threadIndex); 57 #else 58 void AddToReleaseQueue(std::shared_ptr<Drawing::Surface>&& surface, uint32_t threadIndex); 59 #endif 60 std::unordered_map<uint32_t, pid_t> GetReThreadIndexMap() const; 61 private: 62 RSSubThreadManager() = default; 63 ~RSSubThreadManager() = default; 64 RSSubThreadManager(const RSSubThreadManager &) = delete; 65 RSSubThreadManager(const RSSubThreadManager &&) = delete; 66 RSSubThreadManager &operator = (const RSSubThreadManager &) = delete; 67 RSSubThreadManager &operator = (const RSSubThreadManager &&) = delete; 68 69 RenderContext* renderContext_ = nullptr; 70 uint32_t minLoadThreadIndex_ = 0; 71 std::mutex parallelRenderMutex_; 72 std::condition_variable cvParallelRender_; 73 std::map<uint64_t, uint8_t> nodeTaskState_; 74 std::vector<std::shared_ptr<RSSubThread>> threadList_; 75 std::unordered_map<pid_t, uint32_t> threadIndexMap_; 76 std::unordered_map<uint32_t, pid_t> reThreadIndexMap_; 77 std::shared_ptr<RSFilterSubThread> filterThread = nullptr; 78 std::shared_ptr<RSFilterSubThread> colorPickerThread_ = nullptr; 79 bool needResetContext_ = false; 80 bool needCancelTask_ = false; 81 82 bool isRcdServiceRegister_ = false; 83 }; 84 } 85 #endif // RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_SUB_THREAD_MANAGER_H