• 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_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 SetScreenSecurityMask(ScreenId id, std::shared_ptr<Media::PixelMap> securityMask);
74 
75     int32_t SetMirrorScreenVisibleRect(ScreenId id, const Rect& mainScreenRect, bool supportRotation = false);
76 
77     int32_t SetCastScreenEnableSkipWindow(ScreenId id, bool enable);
78 
79     int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface);
80 #endif
81 
82     void RemoveVirtualScreen(ScreenId id);
83 
84 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
85     int32_t SetPointerColorInversionConfig(float darkBuffer, float brightBuffer, int64_t interval, int32_t rangeSize);
86 
87     int32_t SetPointerColorInversionEnabled(bool enable);
88 
89     int32_t RegisterPointerLuminanceChangeCallback(const PointerLuminanceChangeCallback &callback);
90 
91     int32_t UnRegisterPointerLuminanceChangeCallback();
92 #endif
93 
94     int32_t SetScreenChangeCallback(const ScreenChangeCallback &callback);
95 
96     // if return true, the setting is successful. otherwise failed. The function is setted watermark for SurfaceNode
97     bool SetWatermark(const std::string& name, std::shared_ptr<Media::PixelMap> watermark);
98 
99     int32_t GetPixelMapByProcessId(std::vector<PixelMapInfo>& pixelMapInfoVector, pid_t pid);
100 
101     bool TakeSurfaceCapture(std::shared_ptr<RSSurfaceNode> node, std::shared_ptr<SurfaceCaptureCallback> callback,
102         RSSurfaceCaptureConfig captureConfig = {});
103 
104     bool TakeSurfaceCaptureWithBlur(std::shared_ptr<RSSurfaceNode> node,
105         std::shared_ptr<SurfaceCaptureCallback> callback, RSSurfaceCaptureConfig captureConfig = {},
106         float blurRadius = 1E-6);
107 
108     bool TakeSurfaceCapture(std::shared_ptr<RSDisplayNode> node, std::shared_ptr<SurfaceCaptureCallback> callback,
109         RSSurfaceCaptureConfig captureConfig = {});
110 
111     bool TakeSurfaceCapture(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback,
112         RSSurfaceCaptureConfig captureConfig = {});
113 
114     bool TakeSurfaceCaptureForUI(std::shared_ptr<RSNode> node,
115         std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX = 1.f, float scaleY = 1.f,
116         bool isSync = false, const Drawing::Rect& specifiedAreaRect = Drawing::Rect(0.f, 0.f, 0.f, 0.f));
117 
118     bool TakeSelfSurfaceCapture(std::shared_ptr<RSSurfaceNode> node, std::shared_ptr<SurfaceCaptureCallback> callback,
119         RSSurfaceCaptureConfig captureConfig = {});
120 
121     bool SetWindowFreezeImmediately(std::shared_ptr<RSSurfaceNode> node, bool isFreeze,
122         std::shared_ptr<SurfaceCaptureCallback> callback, RSSurfaceCaptureConfig captureConfig = {},
123         float blurRadius = 1E-6);
124 
125     bool SetHwcNodeBounds(int64_t rsNodeId, float positionX, float positionY, float positionZ, float positionW);
126 
127     bool RegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
128     bool UnRegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
129 #ifndef ROSEN_ARKUI_X
130     void SetScreenActiveMode(ScreenId id, uint32_t modeId);
131 
132     MemoryGraphic GetMemoryGraphic(int pid);
133 
134     std::vector<MemoryGraphic> GetMemoryGraphics();
135 #endif // !ROSEN_ARKUI_X
136     bool GetTotalAppMemSize(float& cpuMemSize, float& gpuMemSize);
137 
138 #ifndef ROSEN_ARKUI_X
139     // width and height should be greater than physical width and height
140     int32_t SetPhysicalScreenResolution(ScreenId id, uint32_t width, uint32_t height);
141 
142     int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height);
143 #endif // !ROSEN_ARKUI_X
144 
145     bool SetVirtualMirrorScreenCanvasRotation(ScreenId id, bool canvasRotation);
146 
147     // set scale mode for virtual screen
148     bool SetVirtualMirrorScreenScaleMode(ScreenId id, ScreenScaleMode scaleMode);
149 
150     // WMS set dark color display mode to RS
151     bool SetGlobalDarkColorMode(bool isDark);
152 #ifndef ROSEN_ARKUI_X
153     RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id);
154 
155     void MarkPowerOffNeedProcessOneFrame();
156 
157     void RepaintEverything();
158 
159     void DisablePowerOffRenderControl(ScreenId id);
160 
161     void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status);
162 
163     RSScreenModeInfo GetScreenActiveMode(ScreenId id);
164 #endif // !ROSEN_ARKUI_X
165 
166     void SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate);
167 
168     void SetRefreshRateMode(int32_t refreshRateMode);
169 
170     void SyncFrameRateRange(FrameRateLinkerId id, const FrameRateRange& range, int32_t animatorExpectedFrameRate);
171 
172     uint32_t GetScreenCurrentRefreshRate(ScreenId id);
173 
174     int32_t GetCurrentRefreshRateMode();
175 
176     std::vector<int32_t> GetScreenSupportedRefreshRates(ScreenId id);
177 
178     bool GetShowRefreshRateEnabled();
179 
180     void SetShowRefreshRateEnabled(bool enabled, int32_t type = 1);
181 
182     uint32_t GetRealtimeRefreshRate(ScreenId id);
183 
184     std::string GetRefreshInfo(pid_t pid);
185 
186 #ifndef ROSEN_ARKUI_X
187     std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id);
188 
189     RSScreenCapability GetScreenCapability(ScreenId id);
190 
191     ScreenPowerStatus GetScreenPowerStatus(ScreenId id);
192 
193     RSScreenData GetScreenData(ScreenId id);
194 #endif // !ROSEN_ARKUI_X
195     int32_t GetScreenBacklight(ScreenId id);
196 
197     void SetScreenBacklight(ScreenId id, uint32_t level);
198 
199     int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode);
200 
201     int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys);
202 
203     int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode);
204 
205     int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx);
206 
207     int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode);
208 
209     int32_t SetScreenCorrection(ScreenId id, ScreenRotation screenRotation);
210 
211     int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode);
212 
213     int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability);
214 
215     int32_t GetPixelFormat(ScreenId id, GraphicPixelFormat& pixelFormat);
216 
217     int32_t SetPixelFormat(ScreenId id, GraphicPixelFormat pixelFormat);
218 
219     int32_t GetScreenSupportedHDRFormats(ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats);
220 
221     int32_t GetScreenHDRFormat(ScreenId id, ScreenHDRFormat& hdrFormat);
222 
223     int32_t SetScreenHDRFormat(ScreenId id, int32_t modeIdx);
224 
225     int32_t GetScreenSupportedColorSpaces(ScreenId id, std::vector<GraphicCM_ColorSpaceType>& colorSpaces);
226 
227     int32_t GetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType& colorSpace);
228 
229     int32_t SetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType colorSpace);
230 
231     int32_t GetScreenType(ScreenId id, RSScreenType& screenType);
232 
233     int32_t GetDisplayIdentificationData(ScreenId id, uint8_t& outPort, std::vector<uint8_t>& edidData);
234 
235     /* skipFrameInterval : decide how many frames apart to refresh a frame,
236        DEFAULT_SKIP_FRAME_INTERVAL means refresh each frame,
237        change screen refresh rate finally */
238     int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval);
239 
240     int32_t SetVirtualScreenRefreshRate(ScreenId id, uint32_t maxRefreshRate, uint32_t& actualRefreshRate);
241 
242     uint32_t SetScreenActiveRect(ScreenId id, const Rect& activeRect);
243 
244     std::shared_ptr<VSyncReceiver> CreateVSyncReceiver(
245         const std::string& name,
246         const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr);
247 
248     std::shared_ptr<VSyncReceiver> CreateVSyncReceiver(
249         const std::string& name,
250         uint64_t id,
251         const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr,
252         NodeId windowNodeId = 0,
253         bool fromXcomponent = false);
254 
255     std::shared_ptr<Media::PixelMap> CreatePixelMapFromSurfaceId(uint64_t surfaceId, const Rect &srcRect);
256 
257     int32_t RegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback);
258 
259     int32_t RegisterSurfaceOcclusionChangeCallback(
260         NodeId id, const SurfaceOcclusionChangeCallback& callback, std::vector<float>& partitionPoints);
261 
262     int32_t UnRegisterSurfaceOcclusionChangeCallback(NodeId id);
263 
264     int32_t RegisterHgmConfigChangeCallback(const HgmConfigChangeCallback& callback);
265 
266     int32_t RegisterHgmRefreshRateModeChangeCallback(const HgmRefreshRateModeChangeCallback& callback);
267 
268     int32_t RegisterHgmRefreshRateUpdateCallback(const HgmRefreshRateUpdateCallback& callback);
269 
270     int32_t UnRegisterHgmRefreshRateUpdateCallback();
271 
272     int32_t RegisterFrameRateLinkerExpectedFpsUpdateCallback(int32_t dstPid,
273         const FrameRateLinkerExpectedFpsUpdateCallback& callback);
274 
275     int32_t UnRegisterFrameRateLinkerExpectedFpsUpdateCallback(int32_t dstPid);
276 
277     void SetAppWindowNum(uint32_t num);
278 
279     /*
280     * @brief Set the system overload Animated Scenes to RS for special load shedding
281     * @param systemAnimatedScenes indicates the system animation scene
282     * @param isRegularAnimation indicates irregular windows in the animation scene
283     * @return true if succeed, otherwise false
284     */
285     bool SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedScenes, bool isRegularAnimation = false);
286 
287     void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow);
288 
289     int32_t ResizeVirtualScreen(ScreenId id, uint32_t width, uint32_t height);
290 
291     void ReportJankStats();
292 
293     void NotifyLightFactorStatus(int32_t lightFactorStatus);
294 
295     void NotifyPackageEvent(uint32_t listSize, const std::vector<std::string>& packageList);
296 
297     void NotifyAppStrategyConfigChangeEvent(const std::string& pkgName, uint32_t listSize,
298         const std::vector<std::pair<std::string, std::string>>& newConfig);
299 
300     void NotifyRefreshRateEvent(const EventInfo& eventInfo);
301 
302     void NotifyTouchEvent(int32_t touchStatus, int32_t touchCnt);
303 
304     void NotifyDynamicModeEvent(bool enableDynamicMode);
305 
306     void NotifyHgmConfigEvent(const std::string &eventName, bool state);
307 
308     void ReportEventResponse(DataBaseRs info);
309 
310     void ReportEventComplete(DataBaseRs info);
311 
312     void ReportEventJankFrame(DataBaseRs info);
313 
314     void ReportGameStateData(GameStateData info);
315 
316     void ReportRsSceneJankStart(AppInfo info);
317 
318     void ReportRsSceneJankEnd(AppInfo info);
319 
320     void EnableCacheForRotation();
321 
322     void DisableCacheForRotation();
323 
324     void SetOnRemoteDiedCallback(const OnRemoteDiedCallback& callback);
325 
326     void SetCurtainScreenUsingStatus(bool isCurtainScreenOn);
327 
328     void DropFrameByPid(const std::vector<int32_t> pidList);
329 
330     std::vector<ActiveDirtyRegionInfo> GetActiveDirtyRegionInfo() const;
331 
332     GlobalDirtyRegionInfo GetGlobalDirtyRegionInfo() const;
333 
334     LayerComposeInfo GetLayerComposeInfo() const;
335 
336     HwcDisabledReasonInfos GetHwcDisabledReasonInfo() const;
337 
338     int64_t GetHdrOnDuration() const;
339 
340     void SetVmaCacheStatus(bool flag);
341 
342 #ifdef TP_FEATURE_ENABLE
343     void SetTpFeatureConfig(int32_t feature, const char* config,
344         TpFeatureConfigType tpFeatureConfigType = TpFeatureConfigType::DEFAULT_TP_FEATURE);
345 #endif
346     void SetVirtualScreenUsingStatus(bool isVirtualScreenUsingStatus);
347 
348     int32_t RegisterUIExtensionCallback(uint64_t userId, const UIExtensionCallback& callback, bool unobscured = false);
349 
350     bool SetVirtualScreenStatus(ScreenId id, VirtualScreenStatus screenStatus);
351 
352     bool SetAncoForceDoDirect(bool direct);
353 
354     void SetFreeMultiWindowStatus(bool enable);
355 
356     bool RegisterSurfaceBufferCallback(pid_t pid, uint64_t uid,
357         std::shared_ptr<SurfaceBufferCallback> callback);
358 
359     bool UnregisterSurfaceBufferCallback(pid_t pid, uint64_t uid);
360 
361     // Make this node(nodeIdStr) should do DSS composition and set the layer to top. otherwise do GPU composition.
362     void SetLayerTop(const std::string &nodeIdStr, bool isTop);
363 
364     void NotifyScreenSwitched();
365 
366     void ForceRefreshOneFrameWithNextVSync();
367 
368     void SetWindowContainer(NodeId nodeId, bool value);
369 
370     int32_t RegisterSelfDrawingNodeRectChangeCallback(const SelfDrawingNodeRectChangeCallback& callback);
371 
372 #ifdef RS_ENABLE_OVERLAY_DISPLAY
373     int32_t SetOverlayDisplayMode(int32_t mode);
374 #endif
375 
376     void NotifyPageName(const std::string &packageName, const std::string &pageName, bool isEnter);
377 
378     void TestLoadFileSubTreeToNode(NodeId nodeId, const std::string &filePath);
379 private:
380     RSInterfaces();
381     ~RSInterfaces() noexcept;
382 
383     bool TakeSurfaceCaptureForUIWithoutUni(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback,
384         float scaleX, float scaleY);
385 
386     std::unique_ptr<RSRenderServiceClient> renderServiceClient_;
387 };
388 } // namespace Rosen
389 } // namespace OHOS
390 
391 #endif // RENDER_SERVICE_CLIENT_CORE_TRANSACTION_RS_INTERFACES_H
392