• 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 ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CLIENT_H
17 #define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CLIENT_H
18 
19 #include <functional>
20 #include <map>
21 #include <memory>
22 #include <mutex>
23 #include <shared_mutex>
24 #include <refbase.h>
25 #include <surface_type.h>
26 #ifndef ROSEN_CROSS_PLATFORM
27 #include <surface.h>
28 #endif
29 
30 #include "ipc_callbacks/buffer_available_callback.h"
31 #include "ipc_callbacks/iapplication_agent.h"
32 #include "ipc_callbacks/rs_surface_buffer_callback.h"
33 #include "ipc_callbacks/screen_change_callback.h"
34 #include "ipc_callbacks/surface_capture_callback.h"
35 #include "memory/rs_memory_graphic.h"
36 #ifdef NEW_RENDER_CONTEXT
37 #include "render_backend/rs_render_surface.h"
38 #else
39 #include "platform/drawing/rs_surface.h"
40 #endif
41 #include "rs_irender_client.h"
42 #include "variable_frame_rate/rs_variable_frame_rate.h"
43 #include "screen_manager/rs_screen_capability.h"
44 #include "screen_manager/rs_screen_data.h"
45 #include "screen_manager/rs_screen_hdr_capability.h"
46 #include "screen_manager/rs_screen_mode_info.h"
47 #include "screen_manager/screen_types.h"
48 #include "screen_manager/rs_virtual_screen_resolution.h"
49 #include "vsync_receiver.h"
50 #include "ipc_callbacks/rs_iocclusion_change_callback.h"
51 #include "rs_hgm_config_data.h"
52 #include "rs_occlusion_data.h"
53 #include "rs_uiextension_data.h"
54 #include "info_collection/rs_gpu_dirty_region_collection.h"
55 #include "info_collection/rs_hardware_compose_disabled_reason_collection.h"
56 #include "info_collection/rs_layer_compose_collection.h"
57 
58 namespace OHOS {
59 namespace Rosen {
60 // normal callback functor for client users.
61 using ScreenChangeCallback = std::function<void(ScreenId, ScreenEvent)>;
62 using BufferAvailableCallback = std::function<void()>;
63 using BufferClearCallback = std::function<void()>;
64 using OcclusionChangeCallback = std::function<void(std::shared_ptr<RSOcclusionData>)>;
65 using SurfaceOcclusionChangeCallback = std::function<void(float)>;
66 using HgmConfigChangeCallback = std::function<void(std::shared_ptr<RSHgmConfigData>)>;
67 using OnRemoteDiedCallback = std::function<void()>;
68 using HgmRefreshRateModeChangeCallback = std::function<void(int32_t)>;
69 using HgmRefreshRateUpdateCallback = std::function<void(int32_t)>;
70 using UIExtensionCallback = std::function<void(std::shared_ptr<RSUIExtensionData>, uint64_t)>;
71 struct DataBaseRs {
72     int32_t appPid = -1;
73     int32_t eventType = -1;
74     int32_t versionCode = -1;
75     int64_t uniqueId = 0;
76     int64_t inputTime = 0;
77     int64_t beginVsyncTime = 0;
78     int64_t endVsyncTime = 0;
79     bool isDisplayAnimator = false;
80     std::string sceneId;
81     std::string versionName;
82     std::string bundleName;
83     std::string processName;
84     std::string abilityName;
85     std::string pageUrl;
86     std::string sourceType;
87     std::string note;
88 };
89 
90 struct GameStateData {
91     int32_t pid = -1;
92     int32_t uid = 0;
93     int32_t state = 0;
94     int32_t renderTid = -1;
95     std::string bundleName;
96 };
97 
98 class SurfaceCaptureCallback {
99 public:
SurfaceCaptureCallback()100     SurfaceCaptureCallback() {}
~SurfaceCaptureCallback()101     virtual ~SurfaceCaptureCallback() {}
102     virtual void OnSurfaceCapture(std::shared_ptr<Media::PixelMap> pixelmap) = 0;
103 };
104 
105 class SurfaceBufferCallback {
106 public:
107     SurfaceBufferCallback() = default;
108     virtual ~SurfaceBufferCallback() noexcept = default;
109     virtual void OnFinish(uint64_t uid, const std::vector<uint32_t>& surfaceBufferIds) = 0;
110 };
111 
112 class RSB_EXPORT RSRenderServiceClient : public RSIRenderClient {
113 public:
114     RSRenderServiceClient() = default;
115     virtual ~RSRenderServiceClient() = default;
116 
117     RSRenderServiceClient(const RSRenderServiceClient&) = delete;
118     void operator=(const RSRenderServiceClient&) = delete;
119 
120     void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override;
121     void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override;
122 
123     bool GetUniRenderEnabled();
124 
125     bool CreateNode(const RSSurfaceRenderNodeConfig& config);
126     bool CreateNode(const RSDisplayNodeConfig& displayNodeConfig, NodeId nodeId);
127 #ifdef NEW_RENDER_CONTEXT
128     std::shared_ptr<RSRenderSurface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config);
129 #else
130     std::shared_ptr<RSSurface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config);
131 #endif
132     std::shared_ptr<VSyncReceiver> CreateVSyncReceiver(
133         const std::string& name,
134         const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr,
135         uint64_t id = 0,
136         NodeId windowNodeId = 0);
137 
138     std::shared_ptr<Media::PixelMap> CreatePixelMapFromSurfaceId(uint64_t surfaceid, const Rect &srcRect);
139 
140     bool TakeSurfaceCapture(
141         NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback, const RSSurfaceCaptureConfig& captureConfig);
142 
143     int32_t SetFocusAppInfo(int32_t pid, int32_t uid, const std::string &bundleName, const std::string &abilityName,
144         uint64_t focusNodeId);
145 
146     ScreenId GetDefaultScreenId();
147     ScreenId GetActiveScreenId();
148 
149     std::vector<ScreenId> GetAllScreenIds();
150 
151 #ifndef ROSEN_CROSS_PLATFORM
152 #if defined(NEW_RENDER_CONTEXT)
153     std::shared_ptr<RSRenderSurface> CreateRSSurface(const sptr<Surface> &surface);
154 #else
155     std::shared_ptr<RSSurface> CreateRSSurface(const sptr<Surface> &surface);
156 #endif
157     ScreenId CreateVirtualScreen(const std::string& name, uint32_t width, uint32_t height, sptr<Surface> surface,
158         ScreenId mirrorId, int32_t flags, std::vector<NodeId> whiteList = {});
159 
160     int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface);
161 
162     int32_t SetVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector);
163 
164     int32_t AddVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector);
165 
166     int32_t RemoveVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector);
167 #endif
168 
169     int32_t SetVirtualScreenSecurityExemptionList(ScreenId id, const std::vector<NodeId>& securityExemptionList);
170 
171     int32_t SetCastScreenEnableSkipWindow(ScreenId id, bool enable);
172 
173     void RemoveVirtualScreen(ScreenId id);
174 
175     int32_t SetScreenChangeCallback(const ScreenChangeCallback& callback);
176 
177 #ifndef ROSEN_ARKUI_X
178     void SetScreenActiveMode(ScreenId id, uint32_t modeId);
179 #endif // !ROSEN_ARKUI_X
180     void SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate);
181 
182     void SetRefreshRateMode(int32_t refreshRateMode);
183 
184     void SyncFrameRateRange(FrameRateLinkerId id, const FrameRateRange& range,
185         int32_t animatorExpectedFrameRate);
186 
187     void UnregisterFrameRateLinker(FrameRateLinkerId id);
188 
189     uint32_t GetScreenCurrentRefreshRate(ScreenId id);
190 
191     int32_t GetCurrentRefreshRateMode();
192 
193     std::vector<int32_t> GetScreenSupportedRefreshRates(ScreenId id);
194 
195     bool GetShowRefreshRateEnabled();
196 
197     void SetShowRefreshRateEnabled(bool enable);
198 
199     std::string GetRefreshInfo(pid_t pid);
200 
201 #ifndef ROSEN_ARKUI_X
202     int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height);
203 
204     RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id);
205 
206     void MarkPowerOffNeedProcessOneFrame();
207 
208     void DisablePowerOffRenderControl(ScreenId id);
209 
210     void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status);
211 
212     RSScreenModeInfo GetScreenActiveMode(ScreenId id);
213 
214     std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id);
215 
216     RSScreenCapability GetScreenCapability(ScreenId id);
217 
218     ScreenPowerStatus GetScreenPowerStatus(ScreenId id);
219 
220     RSScreenData GetScreenData(ScreenId id);
221 
222     MemoryGraphic GetMemoryGraphic(int pid);
223 
224     std::vector<MemoryGraphic> GetMemoryGraphics();
225 #endif // !ROSEN_ARKUI_X
226     bool GetTotalAppMemSize(float& cpuMemSize, float& gpuMemSize);
227 
228     int32_t GetScreenBacklight(ScreenId id);
229 
230     void SetScreenBacklight(ScreenId id, uint32_t level);
231 
232     bool RegisterBufferAvailableListener(
233         NodeId id, const BufferAvailableCallback &callback, bool isFromRenderThread = false);
234 
235     bool RegisterBufferClearListener(
236         NodeId id, const BufferClearCallback &callback);
237 
238     bool UnregisterBufferAvailableListener(NodeId id);
239 
240     int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode);
241 
242     int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys);
243 
244     int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode);
245 
246     int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx);
247 
248     int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode);
249 
250     int32_t SetScreenCorrection(ScreenId id, ScreenRotation screenRotation);
251 
252     bool SetVirtualMirrorScreenCanvasRotation(ScreenId id, bool canvasRotation);
253 
254     bool SetVirtualMirrorScreenScaleMode(ScreenId id, ScreenScaleMode scaleMode);
255 
256     bool SetGlobalDarkColorMode(bool isDark);
257 
258     int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode);
259 
260     int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability);
261 
262     int32_t GetPixelFormat(ScreenId id, GraphicPixelFormat& pixelFormat);
263 
264     int32_t SetPixelFormat(ScreenId id, GraphicPixelFormat pixelFormat);
265 
266     int32_t GetScreenSupportedHDRFormats(ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats);
267 
268     int32_t GetScreenHDRFormat(ScreenId id, ScreenHDRFormat& hdrFormat);
269 
270     int32_t SetScreenHDRFormat(ScreenId id, int32_t modeIdx);
271 
272     int32_t GetScreenSupportedColorSpaces(ScreenId id, std::vector<GraphicCM_ColorSpaceType>& colorSpaces);
273 
274     int32_t GetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType& colorSpace);
275 
276     int32_t SetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType colorSpace);
277 
278     int32_t GetScreenType(ScreenId id, RSScreenType& screenType);
279 
280     bool GetBitmap(NodeId id, Drawing::Bitmap& bitmap);
281     bool GetPixelmap(NodeId id, std::shared_ptr<Media::PixelMap> pixelmap,
282         const Drawing::Rect* rect, std::shared_ptr<Drawing::DrawCmdList> drawCmdList);
283     bool RegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
284     bool UnRegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
285 
286     int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval);
287 
288     int32_t RegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback);
289 
290     int32_t RegisterSurfaceOcclusionChangeCallback(
291         NodeId id, const SurfaceOcclusionChangeCallback& callback, std::vector<float>& partitionPoints);
292 
293     int32_t UnRegisterSurfaceOcclusionChangeCallback(NodeId id);
294 
295     int32_t RegisterHgmConfigChangeCallback(const HgmConfigChangeCallback& callback);
296 
297     int32_t RegisterHgmRefreshRateModeChangeCallback(const HgmRefreshRateModeChangeCallback& callback);
298 
299     int32_t RegisterHgmRefreshRateUpdateCallback(const HgmRefreshRateUpdateCallback& callback);
300 
301     void SetAppWindowNum(uint32_t num);
302 
303     bool SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedScenes);
304 
305     void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow);
306 
307     int32_t ResizeVirtualScreen(ScreenId id, uint32_t width, uint32_t height);
308 
309     void ReportJankStats();
310 
311     void NotifyLightFactorStatus(bool isSafe);
312 
313     void NotifyPackageEvent(uint32_t listSize, const std::vector<std::string>& packageList);
314 
315     void NotifyRefreshRateEvent(const EventInfo& eventInfo);
316 
317     void NotifyTouchEvent(int32_t touchStatus, int32_t touchCnt);
318 
319     void NotifyDynamicModeEvent(bool enableDynamicMode);
320 
321     void ReportEventResponse(DataBaseRs info);
322 
323     void ReportEventComplete(DataBaseRs info);
324 
325     void ReportEventJankFrame(DataBaseRs info);
326 
327     void ReportGameStateData(GameStateData info);
328 
329     void SetHardwareEnabled(NodeId id, bool isEnabled, SelfDrawingNodeType selfDrawingType, bool dynamicHardwareEnable);
330 
331     uint32_t SetHidePrivacyContent(NodeId id, bool needHidePrivacyContent);
332 
333     void SetCacheEnabledForRotation(bool isEnabled);
334 
335     void SetDefaultDeviceRotationOffset(uint32_t offset);
336 
337     void SetOnRemoteDiedCallback(const OnRemoteDiedCallback& callback);
338 
339     std::vector<ActiveDirtyRegionInfo> GetActiveDirtyRegionInfo();
340 
341     GlobalDirtyRegionInfo GetGlobalDirtyRegionInfo();
342 
343     LayerComposeInfo GetLayerComposeInfo();
344 
345     HwcDisabledReasonInfos GetHwcDisabledReasonInfo();
346 
347     void SetVmaCacheStatus(bool flag);
348 
349     int32_t RegisterUIExtensionCallback(uint64_t userId, const UIExtensionCallback& callback);
350 
351     bool SetAncoForceDoDirect(bool direct);
352 
353     void SetLayerTop(const std::string &nodeIdStr, bool isTop);
354 #ifdef TP_FEATURE_ENABLE
355     void SetTpFeatureConfig(int32_t feature, const char* config);
356 #endif
357     void SetVirtualScreenUsingStatus(bool isVirtualScreenUsingStatus);
358     void SetCurtainScreenUsingStatus(bool isCurtainScreenOn);
359 
360     bool RegisterSurfaceBufferCallback(pid_t pid, uint64_t uid,
361         std::shared_ptr<SurfaceBufferCallback> callback);
362 
363     bool UnregisterSurfaceBufferCallback(pid_t pid, uint64_t uid);
364 private:
365     void TriggerSurfaceCaptureCallback(NodeId id, std::shared_ptr<Media::PixelMap> pixelmap);
366     void TriggerSurfaceBufferCallback(uint64_t uid, const std::vector<uint32_t>& surfaceBufferIds) const;
367     std::mutex mutex_;
368     std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbRTMap_;
369     std::mutex mapMutex_;
370     std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbUIMap_;
371     sptr<RSIScreenChangeCallback> screenChangeCb_;
372     sptr<RSISurfaceCaptureCallback> surfaceCaptureCbDirector_;
373     std::map<NodeId, std::vector<std::shared_ptr<SurfaceCaptureCallback>>> surfaceCaptureCbMap_;
374 
375     sptr<RSISurfaceBufferCallback> surfaceBufferCbDirector_;
376     std::map<uint64_t, std::shared_ptr<SurfaceBufferCallback>> surfaceBufferCallbacks_;
377     mutable std::shared_mutex surfaceBufferCallbackMutex_;
378 
379     friend class SurfaceCaptureCallbackDirector;
380     friend class SurfaceBufferCallbackDirector;
381 };
382 } // namespace Rosen
383 } // namespace OHOS
384 
385 #endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CLIENT_H
386