1 /*
2  * Copyright (c) 2021-2022 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_PIPELINE_RS_RENDER_SERVICE_H
17 #define RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_H
18 #include <map>
19 #include <unordered_set>
20 
21 #include "screen_manager/rs_screen_manager.h"
22 #include "transaction/rs_render_service_stub.h"
23 #include "vsync_controller.h"
24 #include "vsync_distributor.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 class RSMainThread;
29 class RSRenderServiceConnection;
30 
31 class RSRenderService : public RSRenderServiceStub {
32 public:
33     RSRenderService();
34     ~RSRenderService() noexcept;
35 
36     RSRenderService(const RSRenderService&) = delete;
37     RSRenderService& operator=(const RSRenderService&) = delete;
38 
39     bool Init();
40     void Run();
41 
42 private:
43     int Dump(int fd, const std::vector<std::u16string>& args) override;
44     void DoDump(std::unordered_set<std::u16string>& argSets, std::string& dumpString) const;
45     void DumpNodesNotOnTheTree(std::string& dumpString) const;
46     void DumpAllNodesMemSize(std::string& dumpString) const;
47     void DumpHelpInfo(std::string& dumpString) const;
48     void DumpGpuInfo(std::string& dumpString) const;
49     void DumpRSEvenParam(std::string& dumpString) const;
50     void DumpRenderServiceTree(std::string& dumpString, bool forceDumpSingleFrame = true) const;
51     void DumpRefreshRateCounts(std::string& dumpString) const;
52     void DumpClearRefreshRateCounts(std::string& dumpString) const;
53     void DumpJankStatsRs(std::string& dumpString) const;
54 #ifdef RS_ENABLE_VK
55     void DumpVkTextureLimit(std::string& dumpString) const;
56 #endif
57     void DumpSurfaceNode(std::string& dumpString, NodeId id) const;
58     void WindowHitchsDump(std::unordered_set<std::u16string>& argSets, std::string& dumpString,
59         const std::u16string& arg) const;
60     void DumpMem(std::unordered_set<std::u16string>& argSets, std::string& dumpString) const;
61     void FPSDUMPProcess(std::unordered_set<std::u16string>& argSets, std::string& dumpString,
62         const std::u16string& arg) const;
63     void FPSDUMPClearProcess(std::unordered_set<std::u16string>& argSets,
64         std::string& dumpString, const std::u16string& arg) const;
65 
66     sptr<RSIRenderServiceConnection> CreateConnection(const sptr<RSIConnectionToken>& token) override;
67     void RemoveConnection(sptr<IRemoteObject> token);
68     void RegisterRcdMsg();
69 
70     RSMainThread* mainThread_ = nullptr;
71     sptr<RSScreenManager> screenManager_;
72 
73     friend class RSRenderServiceConnection;
74     mutable std::mutex mutex_;
75     std::map<sptr<IRemoteObject>, sptr<RSIRenderServiceConnection>> connections_;
76 
77     sptr<VSyncController> rsVSyncController_;
78     sptr<VSyncController> appVSyncController_;
79 
80     sptr<VSyncDistributor> rsVSyncDistributor_;
81     sptr<VSyncDistributor> appVSyncDistributor_;
82 
83     bool isRcdServiceRegister_ = false;
84 #ifdef RS_PROFILER_ENABLED
85     friend class RSProfiler;
86 #endif
87 };
88 } // Rosen
89 } // OHOS
90 
91 #endif // RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_H
92