• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H
17 #define RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H
18 
19 #include <mutex>
20 #include <unordered_set>
21 
22 #include "ipc_callbacks/buffer_available_callback.h"
23 #include "ipc_callbacks/buffer_clear_callback.h"
24 #include "pipeline/rs_render_service.h"
25 #include "pipeline/rs_hardware_thread.h"
26 #include "screen_manager/rs_screen_manager.h"
27 #include "transaction/rs_render_service_connection_stub.h"
28 #include "vsync_distributor.h"
29 
30 namespace OHOS {
31 namespace Rosen {
32 class RSRenderServiceConnection : public RSRenderServiceConnectionStub {
33 public:
34     RSRenderServiceConnection(
35         pid_t remotePid,
36         wptr<RSRenderService> renderService,
37         RSMainThread* mainThread,
38         sptr<RSScreenManager> screenManager,
39         sptr<IRemoteObject> token,
40         sptr<VSyncDistributor> distributor);
41     ~RSRenderServiceConnection() noexcept;
42     RSRenderServiceConnection(const RSRenderServiceConnection&) = delete;
43     RSRenderServiceConnection& operator=(const RSRenderServiceConnection&) = delete;
44 
GetToken()45     sptr<IRemoteObject> GetToken() const
46     {
47         return token_;
48     }
49 
50 private:
51     void CleanVirtualScreens() noexcept;
52     void CleanRenderNodes() noexcept;
53     void CleanAll(bool toDelete = false) noexcept;
54 
55     // IPC RSIRenderServiceConnection Interfaces
56     void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override;
57     void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override;
58     MemoryGraphic GetMemoryGraphic(int pid) override;
59     std::vector<MemoryGraphic> GetMemoryGraphics() override;
60     bool GetUniRenderEnabled() override;
61 
62     bool CreateNode(const RSSurfaceRenderNodeConfig& config) override;
63     sptr<Surface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config) override;
64 
65     sptr<IVSyncConnection> CreateVSyncConnection(const std::string& name,
66                                                  const sptr<VSyncIConnectionToken>& token) override;
67 
68     int32_t SetFocusAppInfo(
69         int32_t pid, int32_t uid, const std::string &bundleName, const std::string &abilityName,
70         uint64_t focusNodeId) override;
71 
72     ScreenId GetDefaultScreenId() override;
73 
74     std::vector<ScreenId> GetAllScreenIds() override;
75 
76     ScreenId CreateVirtualScreen(
77         const std::string &name,
78         uint32_t width,
79         uint32_t height,
80         sptr<Surface> surface,
81         ScreenId mirrorId = 0,
82         int32_t flags = 0) override;
83 
84     int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface) override;
85 
86     void RemoveVirtualScreen(ScreenId id) override;
87 
88     int32_t SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback) override;
89 
90     void SetScreenActiveMode(ScreenId id, uint32_t modeId) override;
91 
92     void SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate) override;
93 
94     void SetRefreshRateMode(int32_t refreshRateMode) override;
95 
96     uint32_t GetScreenCurrentRefreshRate(ScreenId id) override;
97 
98     std::vector<uint32_t> GetScreenSupportedRefreshRates(ScreenId id) override;
99 
100     int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height) override;
101 
102     void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status) override;
103 
104     void TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback, float scaleX, float scaleY) override;
105 
106     void TakeSurfaceCaptureForUIWithUni(
107         NodeId id, sptr<RSISurfaceCaptureCallback> callback, float scaleX, float scaleY);
108 
109     void RegisterApplicationAgent(uint32_t pid, sptr<IApplicationAgent> app) override;
110 
111     void UnRegisterApplicationAgent(sptr<IApplicationAgent> app);
112 
113     RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id) override;
114 
115     RSScreenModeInfo GetScreenActiveMode(ScreenId id) override;
116 
117     std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id) override;
118 
119     RSScreenCapability GetScreenCapability(ScreenId id) override;
120 
121     ScreenPowerStatus GetScreenPowerStatus(ScreenId id) override;
122 
123     RSScreenData GetScreenData(ScreenId id) override;
124 
125     int32_t GetScreenBacklight(ScreenId id) override;
126 
127     void SetScreenBacklight(ScreenId id, uint32_t level) override;
128 
129     void RegisterBufferAvailableListener(
130         NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread) override;
131 
132     void RegisterBufferClearListener(
133         NodeId id, sptr<RSIBufferClearCallback> callback) override;
134 
135     int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode) override;
136 
137     int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys) override;
138 
139     int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode) override;
140 
141     int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx) override;
142 
143     int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode) override;
144 
145     int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode) override;
146 
147     int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability) override;
148 
149     int32_t GetScreenType(ScreenId id, RSScreenType& screenType) override;
150 
151 #ifndef USE_ROSEN_DRAWING
152     bool GetBitmap(NodeId id, SkBitmap& bitmap) override;
153     bool GetPixelmap(NodeId id, const std::shared_ptr<Media::PixelMap> pixelmap, const SkRect* rect) override;
154 #else
155     bool GetBitmap(NodeId id, Drawing::Bitmap& bitmap) override;
156 #endif
157 
158     int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval) override;
159 
160     int32_t RegisterOcclusionChangeCallback(sptr<RSIOcclusionChangeCallback> callback) override;
161 
162     void SetAppWindowNum(uint32_t num) override;
163 
164     void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow) override;
165 
166     void ReportJankStats() override;
167 
168     void ReportEventResponse(DataBaseRs info) override;
169 
170     void ReportEventComplete(DataBaseRs info) override;
171 
172     void ReportEventJankFrame(DataBaseRs info) override;
173 
174     void SetHardwareEnabled(NodeId id, bool isEnabled) override;
175 
176     pid_t remotePid_;
177     wptr<RSRenderService> renderService_;
178     RSMainThread* mainThread_ = nullptr;
179     sptr<RSScreenManager> screenManager_;
180     sptr<IRemoteObject> token_;
181 
182     class RSConnectionDeathRecipient : public IRemoteObject::DeathRecipient {
183     public:
184         explicit RSConnectionDeathRecipient(wptr<RSRenderServiceConnection> conn);
185         virtual ~RSConnectionDeathRecipient() = default;
186 
187         void OnRemoteDied(const wptr<IRemoteObject>& token) override;
188 
189     private:
190         wptr<RSRenderServiceConnection> conn_;
191     };
192     friend class RSConnectionDeathRecipient;
193     sptr<RSConnectionDeathRecipient> connDeathRecipient_;
194 
195     class RSApplicationRenderThreadDeathRecipient : public IRemoteObject::DeathRecipient {
196     public:
197         explicit RSApplicationRenderThreadDeathRecipient(wptr<RSRenderServiceConnection> conn);
198         virtual ~RSApplicationRenderThreadDeathRecipient() = default;
199 
200         void OnRemoteDied(const wptr<IRemoteObject>& token) override;
201 
202     private:
203         wptr<RSRenderServiceConnection> conn_;
204     };
205     friend class RSApplicationRenderThreadDeathRecipient;
206     sptr<RSApplicationRenderThreadDeathRecipient> ApplicationDeathRecipient_;
207 
208     mutable std::mutex mutex_;
209     bool cleanDone_ = false;
210 
211     int offscreenRenderNum_ = 0;
212     std::mutex offscreenRenderMutex_;
213 
214     // save all virtual screenIds created by this connection.
215     std::unordered_set<ScreenId> virtualScreenIds_;
216     sptr<RSIScreenChangeCallback> screenChangeCallback_;
217     sptr<VSyncDistributor> appVSyncDistributor_;
218     std::vector<sptr<VSyncConnection>> vsyncConnections_;
219 };
220 } // namespace Rosen
221 } // namespace OHOS
222 
223 #endif // RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H
224