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