• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "drawable/rs_surface_render_node_drawable.h"
27 #include "pipeline/rs_base_render_node.h"
28 #include "render_context/render_context.h"
29 
30 namespace OHOS::Rosen {
31 constexpr char TOPIC_RCD_DISPLAY_SIZE[] = "RCD_UPDATE_DISPLAY_SIZE";
32 constexpr char TOPIC_RCD_DISPLAY_ROTATION[] = "RCD_UPDATE_DISPLAY_ROTATION";
33 constexpr char TOPIC_RCD_DISPLAY_NOTCH[] = "RCD_UPDATE_DISPLAY_NOTCH";
34 constexpr char TOPIC_RCD_DISPLAY_HWRESOURCE[] = "RCD_UPDATE_DISPLAY_HWRESOURCE";
35 
36 class RSSubThreadManager {
37 public:
38     static RSSubThreadManager *Instance();
39     void Start(RenderContext *context);
40     void PostTask(const std::function<void()>& task, uint32_t threadIndex, bool isSyncTask = false);
41     void WaitNodeTask(uint64_t nodeId);
42     void NodeTaskNotify(uint64_t nodeId);
43     void SubmitSubThreadTask(const std::shared_ptr<RSDisplayRenderNode>& node,
44         const std::list<std::shared_ptr<RSSurfaceRenderNode>>& subThreadNodes);
45     void ResetSubThreadGrContext();
46     void CancelReleaseResourceTask();
47     void ReleaseTexture();
48     void TryReleaseTextureForIdleThread();
49     void CancelReleaseTextureTask();
50     void ForceReleaseResource();
51     void DumpMem(DfxString& log);
52     float GetAppGpuMemoryInMB();
53     void ReleaseSurface(uint32_t threadIndex) const;
54     void AddToReleaseQueue(std::shared_ptr<Drawing::Surface>&& surface, uint32_t threadIndex);
55     std::unordered_map<uint32_t, pid_t> GetReThreadIndexMap() const;
56     void ScheduleRenderNodeDrawable(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> nodeDrawable);
57     void ScheduleReleaseCacheSurfaceOnly(std::shared_ptr<DrawableV2::RSSurfaceRenderNodeDrawable> nodeDrawable);
58     std::shared_ptr<Drawing::GPUContext> GetGrContextFromSubThread(pid_t tid);
59 
60 private:
61     RSSubThreadManager() = default;
62     ~RSSubThreadManager() = default;
63     RSSubThreadManager(const RSSubThreadManager &) = delete;
64     RSSubThreadManager(const RSSubThreadManager &&) = delete;
65     RSSubThreadManager &operator = (const RSSubThreadManager &) = delete;
66     RSSubThreadManager &operator = (const RSSubThreadManager &&) = delete;
67 
68     uint32_t minLoadThreadIndex_ = 0;
69     uint32_t defaultThreadIndex_ = 0;
70     std::mutex parallelRenderMutex_;
71     std::condition_variable cvParallelRender_;
72     std::map<uint64_t, uint8_t> nodeTaskState_;
73     std::vector<std::shared_ptr<RSSubThread>> threadList_;
74     std::unordered_map<pid_t, uint32_t> threadIndexMap_;
75     std::unordered_map<uint32_t, pid_t> reThreadIndexMap_;
76     bool needResetContext_ = false;
77     bool needCancelTask_ = false;
78     bool needCancelReleaseTextureTask_ = false;
79 };
80 }
81 #endif // RENDER_SERVICE_CORE_PIPELINE_PARALLEL_RENDER_RS_SUB_THREAD_MANAGER_H