• 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 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 RegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
95     bool UnRegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
96 #ifndef ROSEN_ARKUI_X
97     void SetScreenActiveMode(ScreenId id, uint32_t modeId);
98 
99     MemoryGraphic GetMemoryGraphic(int pid);
100 
101     std::vector<MemoryGraphic> GetMemoryGraphics();
102 #endif // !ROSEN_ARKUI_X
103     bool GetTotalAppMemSize(float& cpuMemSize, float& gpuMemSize);
104 
105 #ifndef ROSEN_ARKUI_X
106     int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height);
107 #endif // !ROSEN_ARKUI_X
108 
109     bool SetVirtualMirrorScreenCanvasRotation(ScreenId id, bool canvasRotation);
110 
111     // set scale mode for virtual screen
112     bool SetVirtualMirrorScreenScaleMode(ScreenId id, ScreenScaleMode scaleMode);
113 
114     // WMS set dark color display mode to RS
115     bool SetGlobalDarkColorMode(bool isDark);
116 
117 #ifndef ROSEN_ARKUI_X
118     RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id);
119 
120     void MarkPowerOffNeedProcessOneFrame();
121 
122     void DisablePowerOffRenderControl(ScreenId id);
123 
124     void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status);
125 
126     RSScreenModeInfo GetScreenActiveMode(ScreenId id);
127 #endif // !ROSEN_ARKUI_X
128 
129     void SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate);
130 
131     void SetRefreshRateMode(int32_t refreshRateMode);
132 
133     void SyncFrameRateRange(FrameRateLinkerId id, const FrameRateRange& range, int32_t animatorExpectedFrameRate);
134 
135     uint32_t GetScreenCurrentRefreshRate(ScreenId id);
136 
137     int32_t GetCurrentRefreshRateMode();
138 
139     std::vector<int32_t> GetScreenSupportedRefreshRates(ScreenId id);
140 
141     bool GetShowRefreshRateEnabled();
142 
143     void SetShowRefreshRateEnabled(bool enable);
144 
145     std::string GetRefreshInfo(pid_t pid);
146 
147 #ifndef ROSEN_ARKUI_X
148     std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id);
149 
150     RSScreenCapability GetScreenCapability(ScreenId id);
151 
152     ScreenPowerStatus GetScreenPowerStatus(ScreenId id);
153 
154     RSScreenData GetScreenData(ScreenId id);
155 #endif // !ROSEN_ARKUI_X
156     int32_t GetScreenBacklight(ScreenId id);
157 
158     void SetScreenBacklight(ScreenId id, uint32_t level);
159 
160     int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode);
161 
162     int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys);
163 
164     int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode);
165 
166     int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx);
167 
168     int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode);
169 
170     int32_t SetScreenCorrection(ScreenId id, ScreenRotation screenRotation);
171 
172     int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode);
173 
174     int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability);
175 
176     int32_t GetPixelFormat(ScreenId id, GraphicPixelFormat& pixelFormat);
177 
178     int32_t SetPixelFormat(ScreenId id, GraphicPixelFormat pixelFormat);
179 
180     int32_t GetScreenSupportedHDRFormats(ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats);
181 
182     int32_t GetScreenHDRFormat(ScreenId id, ScreenHDRFormat& hdrFormat);
183 
184     int32_t SetScreenHDRFormat(ScreenId id, int32_t modeIdx);
185 
186     int32_t GetScreenSupportedColorSpaces(ScreenId id, std::vector<GraphicCM_ColorSpaceType>& colorSpaces);
187 
188     int32_t GetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType& colorSpace);
189 
190     int32_t SetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType colorSpace);
191 
192     int32_t GetScreenType(ScreenId id, RSScreenType& screenType);
193 
194     /* skipFrameInterval : decide how many frames apart to refresh a frame,
195        DEFAULT_SKIP_FRAME_INTERVAL means refresh each frame,
196        change screen refresh rate finally */
197     int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval);
198 
199     std::shared_ptr<VSyncReceiver> CreateVSyncReceiver(
200         const std::string& name,
201         const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr);
202 
203     std::shared_ptr<VSyncReceiver> CreateVSyncReceiver(
204         const std::string& name,
205         uint64_t id,
206         const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr,
207         NodeId windowNodeId = 0);
208 
209     std::shared_ptr<Media::PixelMap> CreatePixelMapFromSurfaceId(uint64_t surfaceId, const Rect &srcRect);
210 
211     int32_t RegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback);
212 
213     int32_t RegisterSurfaceOcclusionChangeCallback(
214         NodeId id, const SurfaceOcclusionChangeCallback& callback, std::vector<float>& partitionPoints);
215 
216     int32_t UnRegisterSurfaceOcclusionChangeCallback(NodeId id);
217 
218     int32_t RegisterHgmConfigChangeCallback(const HgmConfigChangeCallback& callback);
219 
220     int32_t RegisterHgmRefreshRateModeChangeCallback(const HgmRefreshRateModeChangeCallback& callback);
221 
222     int32_t RegisterHgmRefreshRateUpdateCallback(const HgmRefreshRateUpdateCallback& callback);
223 
224     int32_t UnRegisterHgmRefreshRateUpdateCallback();
225 
226     void SetAppWindowNum(uint32_t num);
227 
228     // Set the system overload Animated Scenes to RS for special load shedding
229     bool SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedScenes);
230 
231     void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow);
232 
233     int32_t ResizeVirtualScreen(ScreenId id, uint32_t width, uint32_t height);
234 
235     void ReportJankStats();
236 
237     void NotifyLightFactorStatus(bool isSafe);
238 
239     void NotifyPackageEvent(uint32_t listSize, const std::vector<std::string>& packageList);
240 
241     void NotifyRefreshRateEvent(const EventInfo& eventInfo);
242 
243     void NotifyTouchEvent(int32_t touchStatus, int32_t touchCnt);
244 
245     void NotifyDynamicModeEvent(bool enableDynamicMode);
246 
247     void ReportEventResponse(DataBaseRs info);
248 
249     void ReportEventComplete(DataBaseRs info);
250 
251     void ReportEventJankFrame(DataBaseRs info);
252 
253     void ReportGameStateData(GameStateData info);
254 
255     void SetDefaultDeviceRotationOffset(uint32_t offset);
256 
257     void EnableCacheForRotation();
258 
259     void DisableCacheForRotation();
260 
261     void SetOnRemoteDiedCallback(const OnRemoteDiedCallback& callback);
262 
263     void SetCurtainScreenUsingStatus(bool isCurtainScreenOn);
264 
265     std::vector<ActiveDirtyRegionInfo> GetActiveDirtyRegionInfo() const;
266 
267     GlobalDirtyRegionInfo GetGlobalDirtyRegionInfo() const;
268 
269     LayerComposeInfo GetLayerComposeInfo() const;
270 
271     HwcDisabledReasonInfos GetHwcDisabledReasonInfo() const;
272 
273     void SetVmaCacheStatus(bool flag);
274 
275 #ifdef TP_FEATURE_ENABLE
276     void SetTpFeatureConfig(int32_t feature, const char* config);
277 #endif
278     void SetVirtualScreenUsingStatus(bool isVirtualScreenUsingStatus);
279 
280     int32_t RegisterUIExtensionCallback(uint64_t userId, const UIExtensionCallback& callback);
281 
282     bool SetAncoForceDoDirect(bool direct);
283 
284     bool RegisterSurfaceBufferCallback(pid_t pid, uint64_t uid,
285         std::shared_ptr<SurfaceBufferCallback> callback);
286 
287     bool UnregisterSurfaceBufferCallback(pid_t pid, uint64_t uid);
288 
289     // Make this node(nodeIdStr) should do DSS composition and set the layer to top. otherwise do GPU composition.
290     void SetLayerTop(const std::string &nodeIdStr, bool isTop);
291 private:
292     RSInterfaces();
293     ~RSInterfaces() noexcept;
294 
295     bool TakeSurfaceCaptureForUIWithoutUni(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback,
296         float scaleX, float scaleY);
297 
298     std::unique_ptr<RSRenderServiceClient> renderServiceClient_;
299 };
300 } // namespace Rosen
301 } // namespace OHOS
302 
303 #endif // RENDER_SERVICE_CLIENT_CORE_TRANSACTION_RS_INTERFACES_H
304