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_CLIENT_CORE_TRANSACTION_RS_INTERFACES_H
17 #define RENDER_SERVICE_CLIENT_CORE_TRANSACTION_RS_INTERFACES_H
18 
19 #include <memory>
20 #include <mutex>
21 
22 #include "memory/rs_memory_graphic.h"
23 #include "transaction/rs_render_service_client.h"
24 #include "ui/rs_display_node.h"
25 #include "ui/rs_surface_node.h"
26 #include "ipc_callbacks/rs_iocclusion_change_callback.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 
31 struct FocusAppInfo {
32     int32_t pid = -1;
33     int32_t uid = -1;
34     std::string bundleName;
35     std::string abilityName;
36     uint64_t focusNodeId;
37 };
38 
39 class RSC_EXPORT RSInterfaces {
40 public:
41     static RSInterfaces &GetInstance();
42     RSInterfaces(const RSInterfaces &) = delete;
43     void operator=(const RSInterfaces &) = delete;
44 
45     int32_t SetFocusAppInfo(FocusAppInfo& info);
46 
47     ScreenId GetDefaultScreenId();
48 
49     // for bootAnimation only
50     ScreenId GetActiveScreenId();
51 
52     std::vector<ScreenId> GetAllScreenIds();
53 
54     // mirrorId: decide which screen id to mirror, INVALID_SCREEN_ID means do not mirror any screen.
55 #ifndef ROSEN_CROSS_PLATFORM
56     ScreenId CreateVirtualScreen(
57         const std::string &name,
58         uint32_t width,
59         uint32_t height,
60         sptr<Surface> surface,
61         ScreenId mirrorId = 0,
62         int flags = 0,
63         std::vector<NodeId> whiteList = {});
64 
65     int32_t SetVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector);
66 
67     int32_t AddVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector);
68 
69     int32_t RemoveVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector);
70 
71     int32_t SetVirtualScreenSecurityExemptionList(ScreenId id, const std::vector<NodeId>& securityExemptionList);
72 
73     int32_t SetCastScreenEnableSkipWindow(ScreenId id, bool enable);
74 
75     int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface);
76 #endif
77 
78     void RemoveVirtualScreen(ScreenId id);
79 
80     int32_t SetScreenChangeCallback(const ScreenChangeCallback &callback);
81 
82     bool TakeSurfaceCapture(std::shared_ptr<RSSurfaceNode> node, std::shared_ptr<SurfaceCaptureCallback> callback,
83         RSSurfaceCaptureConfig captureConfig = {});
84 
85     bool TakeSurfaceCapture(std::shared_ptr<RSDisplayNode> node, std::shared_ptr<SurfaceCaptureCallback> callback,
86         RSSurfaceCaptureConfig captureConfig = {});
87 
88     bool TakeSurfaceCapture(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback,
89         RSSurfaceCaptureConfig captureConfig = {});
90 
91     bool TakeSurfaceCaptureForUI(std::shared_ptr<RSNode> node,
92         std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX = 1.f, float scaleY = 1.f, bool isSync = false);
93 
94     bool SetWindowFreezeImmediately(std::shared_ptr<RSSurfaceNode> node, bool isFreeze,
95         std::shared_ptr<SurfaceCaptureCallback> callback, RSSurfaceCaptureConfig captureConfig = {});
96 
97     bool RegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
98     bool UnRegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
99 #ifndef ROSEN_ARKUI_X
100     void SetScreenActiveMode(ScreenId id, uint32_t modeId);
101 
102     MemoryGraphic GetMemoryGraphic(int pid);
103 
104     std::vector<MemoryGraphic> GetMemoryGraphics();
105 #endif // !ROSEN_ARKUI_X
106     bool GetTotalAppMemSize(float& cpuMemSize, float& gpuMemSize);
107 
108 #ifndef ROSEN_ARKUI_X
109     int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height);
110 #endif // !ROSEN_ARKUI_X
111 
112     bool SetVirtualMirrorScreenCanvasRotation(ScreenId id, bool canvasRotation);
113 
114     // set scale mode for virtual screen
115     bool SetVirtualMirrorScreenScaleMode(ScreenId id, ScreenScaleMode scaleMode);
116 
117     // WMS set dark color display mode to RS
118     bool SetGlobalDarkColorMode(bool isDark);
119 
120 #ifndef ROSEN_ARKUI_X
121     RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id);
122 
123     void MarkPowerOffNeedProcessOneFrame();
124 
125     void DisablePowerOffRenderControl(ScreenId id);
126 
127     void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status);
128 
129     RSScreenModeInfo GetScreenActiveMode(ScreenId id);
130 #endif // !ROSEN_ARKUI_X
131 
132     void SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate);
133 
134     void SetRefreshRateMode(int32_t refreshRateMode);
135 
136     void SyncFrameRateRange(FrameRateLinkerId id, const FrameRateRange& range, int32_t animatorExpectedFrameRate);
137 
138     uint32_t GetScreenCurrentRefreshRate(ScreenId id);
139 
140     int32_t GetCurrentRefreshRateMode();
141 
142     std::vector<int32_t> GetScreenSupportedRefreshRates(ScreenId id);
143 
144     bool GetShowRefreshRateEnabled();
145 
146     void SetShowRefreshRateEnabled(bool enable);
147 
148     std::string GetRefreshInfo(pid_t pid);
149 
150 #ifndef ROSEN_ARKUI_X
151     std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id);
152 
153     RSScreenCapability GetScreenCapability(ScreenId id);
154 
155     ScreenPowerStatus GetScreenPowerStatus(ScreenId id);
156 
157     RSScreenData GetScreenData(ScreenId id);
158 #endif // !ROSEN_ARKUI_X
159     int32_t GetScreenBacklight(ScreenId id);
160 
161     void SetScreenBacklight(ScreenId id, uint32_t level);
162 
163     int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode);
164 
165     int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys);
166 
167     int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode);
168 
169     int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx);
170 
171     int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode);
172 
173     int32_t SetScreenCorrection(ScreenId id, ScreenRotation screenRotation);
174 
175     int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode);
176 
177     int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability);
178 
179     int32_t GetPixelFormat(ScreenId id, GraphicPixelFormat& pixelFormat);
180 
181     int32_t SetPixelFormat(ScreenId id, GraphicPixelFormat pixelFormat);
182 
183     int32_t GetScreenSupportedHDRFormats(ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats);
184 
185     int32_t GetScreenHDRFormat(ScreenId id, ScreenHDRFormat& hdrFormat);
186 
187     int32_t SetScreenHDRFormat(ScreenId id, int32_t modeIdx);
188 
189     int32_t GetScreenSupportedColorSpaces(ScreenId id, std::vector<GraphicCM_ColorSpaceType>& colorSpaces);
190 
191     int32_t GetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType& colorSpace);
192 
193     int32_t SetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType colorSpace);
194 
195     int32_t GetScreenType(ScreenId id, RSScreenType& screenType);
196 
197     /* skipFrameInterval : decide how many frames apart to refresh a frame,
198        DEFAULT_SKIP_FRAME_INTERVAL means refresh each frame,
199        change screen refresh rate finally */
200     int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval);
201 
202     int32_t SetVirtualScreenRefreshRate(ScreenId id, uint32_t maxRefreshRate, uint32_t& actualRefreshRate);
203 
204     std::shared_ptr<VSyncReceiver> CreateVSyncReceiver(
205         const std::string& name,
206         const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr);
207 
208     std::shared_ptr<VSyncReceiver> CreateVSyncReceiver(
209         const std::string& name,
210         uint64_t id,
211         const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr,
212         NodeId windowNodeId = 0,
213         bool fromXcomponent = false);
214 
215     std::shared_ptr<Media::PixelMap> CreatePixelMapFromSurfaceId(uint64_t surfaceId, const Rect &srcRect);
216 
217     int32_t RegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback);
218 
219     int32_t RegisterSurfaceOcclusionChangeCallback(
220         NodeId id, const SurfaceOcclusionChangeCallback& callback, std::vector<float>& partitionPoints);
221 
222     int32_t UnRegisterSurfaceOcclusionChangeCallback(NodeId id);
223 
224     int32_t RegisterHgmConfigChangeCallback(const HgmConfigChangeCallback& callback);
225 
226     int32_t RegisterHgmRefreshRateModeChangeCallback(const HgmRefreshRateModeChangeCallback& callback);
227 
228     int32_t RegisterHgmRefreshRateUpdateCallback(const HgmRefreshRateUpdateCallback& callback);
229 
230     int32_t UnRegisterHgmRefreshRateUpdateCallback();
231 
232     int32_t RegisterFrameRateLinkerExpectedFpsUpdateCallback(int32_t dstPid,
233         const FrameRateLinkerExpectedFpsUpdateCallback& callback);
234 
235     int32_t UnRegisterFrameRateLinkerExpectedFpsUpdateCallback(int32_t dstPid);
236 
237     void SetAppWindowNum(uint32_t num);
238 
239     // Set the system overload Animated Scenes to RS for special load shedding
240     bool SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedScenes);
241 
242     void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow);
243 
244     int32_t ResizeVirtualScreen(ScreenId id, uint32_t width, uint32_t height);
245 
246     void ReportJankStats();
247 
248     void NotifyLightFactorStatus(bool isSafe);
249 
250     void NotifyPackageEvent(uint32_t listSize, const std::vector<std::string>& packageList);
251 
252     void NotifyRefreshRateEvent(const EventInfo& eventInfo);
253 
254     void NotifyTouchEvent(int32_t touchStatus, int32_t touchCnt);
255 
256     void NotifyDynamicModeEvent(bool enableDynamicMode);
257 
258     void ReportEventResponse(DataBaseRs info);
259 
260     void ReportEventComplete(DataBaseRs info);
261 
262     void ReportEventJankFrame(DataBaseRs info);
263 
264     void ReportGameStateData(GameStateData info);
265 
266     void EnableCacheForRotation();
267 
268     void DisableCacheForRotation();
269 
270     void SetOnRemoteDiedCallback(const OnRemoteDiedCallback& callback);
271 
272     void SetCurtainScreenUsingStatus(bool isCurtainScreenOn);
273 
274     void DropFrameByPid(const std::vector<int32_t> pidList);
275 
276     std::vector<ActiveDirtyRegionInfo> GetActiveDirtyRegionInfo() const;
277 
278     GlobalDirtyRegionInfo GetGlobalDirtyRegionInfo() const;
279 
280     LayerComposeInfo GetLayerComposeInfo() const;
281 
282     HwcDisabledReasonInfos GetHwcDisabledReasonInfo() const;
283 
284     void SetVmaCacheStatus(bool flag);
285 
286 #ifdef TP_FEATURE_ENABLE
287     void SetTpFeatureConfig(int32_t feature, const char* config,
288         TpFeatureConfigType tpFeatureConfigType = TpFeatureConfigType::DEFAULT_TP_FEATURE);
289 #endif
290     void SetVirtualScreenUsingStatus(bool isVirtualScreenUsingStatus);
291 
292     int32_t RegisterUIExtensionCallback(uint64_t userId, const UIExtensionCallback& callback);
293 
294     bool SetAncoForceDoDirect(bool direct);
295 
296     bool RegisterSurfaceBufferCallback(pid_t pid, uint64_t uid,
297         std::shared_ptr<SurfaceBufferCallback> callback);
298 
299     bool UnregisterSurfaceBufferCallback(pid_t pid, uint64_t uid);
300 
301     // Make this node(nodeIdStr) should do DSS composition and set the layer to top. otherwise do GPU composition.
302     void SetLayerTop(const std::string &nodeIdStr, bool isTop);
303 private:
304     RSInterfaces();
305     ~RSInterfaces() noexcept;
306 
307     bool TakeSurfaceCaptureForUIWithoutUni(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback,
308         float scaleX, float scaleY);
309 
310     std::unique_ptr<RSRenderServiceClient> renderServiceClient_;
311 };
312 } // namespace Rosen
313 } // namespace OHOS
314 
315 #endif // RENDER_SERVICE_CLIENT_CORE_TRANSACTION_RS_INTERFACES_H
316