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_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H 17 #define RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H 18 19 #include <mutex> 20 #include <unordered_set> 21 22 #include "hgm_config_callback_manager.h" 23 #include "ipc_callbacks/buffer_available_callback.h" 24 #include "ipc_callbacks/buffer_clear_callback.h" 25 #include "pipeline/hardware_thread/rs_hardware_thread.h" 26 #include "pipeline/render_thread/rs_uni_render_thread.h" 27 #include "pipeline/main_thread/rs_render_service.h" 28 #include "screen_manager/rs_screen_manager.h" 29 #include "transaction/rs_render_service_connection_stub.h" 30 #include "vsync_distributor.h" 31 32 namespace OHOS { 33 namespace Rosen { 34 class HgmFrameRateManager; 35 class RSRenderServiceConnection : public RSRenderServiceConnectionStub { 36 public: 37 RSRenderServiceConnection( 38 pid_t remotePid, 39 wptr<RSRenderService> renderService, 40 RSMainThread* mainThread, 41 sptr<RSScreenManager> screenManager, 42 sptr<IRemoteObject> token, 43 sptr<VSyncDistributor> distributor); 44 ~RSRenderServiceConnection() noexcept; 45 RSRenderServiceConnection(const RSRenderServiceConnection&) = delete; 46 RSRenderServiceConnection& operator=(const RSRenderServiceConnection&) = delete; 47 GetToken()48 sptr<IRemoteObject> GetToken() const 49 { 50 return token_; 51 } 52 53 private: 54 void CleanVirtualScreens() noexcept; 55 void CleanRenderNodes() noexcept; 56 void CleanFrameRateLinkers() noexcept; 57 void CleanFrameRateLinkerExpectedFpsCallbacks() noexcept; 58 void CleanAll(bool toDelete = false) noexcept; 59 60 // IPC RSIRenderServiceConnection Interfaces 61 ErrCode CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override; 62 ErrCode ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override; 63 ErrCode GetMemoryGraphic(int pid, MemoryGraphic& memoryGraphic) override; 64 ErrCode GetMemoryGraphics(std::vector<MemoryGraphic>& memoryGraphics) override; 65 ErrCode GetTotalAppMemSize(float& cpuMemSize, float& gpuMemSize, bool& success) override; 66 ErrCode GetUniRenderEnabled(bool& enable) override; 67 68 ErrCode CreateNode(const RSSurfaceRenderNodeConfig& config, bool& success) override; 69 ErrCode CreateNode(const RSDisplayNodeConfig& displayNodeConfig, NodeId nodeId, bool& success) override; 70 ErrCode CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config, sptr<Surface>& sfc, 71 bool unobscured = false) override; 72 73 sptr<IVSyncConnection> CreateVSyncConnection(const std::string& name, 74 const sptr<VSyncIConnectionToken>& token, 75 uint64_t id, 76 NodeId windowNodeId = 0, 77 bool fromXcomponent = false) override; 78 79 ErrCode GetPixelMapByProcessId(std::vector<PixelMapInfo>& pixelMapInfoVector, pid_t pid, int32_t& repCode) override; 80 81 ErrCode CreatePixelMapFromSurface(sptr<Surface> surface, 82 const Rect &srcRect, std::shared_ptr<Media::PixelMap> &pixelMap) override; 83 84 int32_t SetFocusAppInfo( 85 int32_t pid, int32_t uid, const std::string &bundleName, const std::string &abilityName, 86 uint64_t focusNodeId) override; 87 88 ScreenId GetDefaultScreenId() override; 89 90 ScreenId GetActiveScreenId() override; 91 92 std::vector<ScreenId> GetAllScreenIds() override; 93 94 ScreenId CreateVirtualScreen( 95 const std::string &name, 96 uint32_t width, 97 uint32_t height, 98 sptr<Surface> surface, 99 ScreenId mirrorId = 0, 100 int32_t flags = 0, 101 std::vector<NodeId> whiteList = {}) override; 102 103 int32_t SetVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector) override; 104 105 ErrCode AddVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector, int32_t& repCode) override; 106 107 ErrCode RemoveVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector, int32_t& repCode) override; 108 109 int32_t SetVirtualScreenSecurityExemptionList( 110 ScreenId id, const std::vector<NodeId>& securityExemptionList) override; 111 112 int32_t SetScreenSecurityMask(ScreenId id, 113 std::shared_ptr<Media::PixelMap> securityMask) override; 114 115 int32_t SetMirrorScreenVisibleRect(ScreenId id, const Rect& mainScreenRect, bool supportRotation = false) override; 116 117 int32_t SetCastScreenEnableSkipWindow(ScreenId id, bool enable) override; 118 119 int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface) override; 120 121 void RemoveVirtualScreen(ScreenId id) override; 122 123 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR 124 int32_t SetPointerColorInversionConfig(float darkBuffer, float brightBuffer, 125 int64_t interval, int32_t rangeSize) override; 126 127 int32_t SetPointerColorInversionEnabled(bool enable) override; 128 129 int32_t RegisterPointerLuminanceChangeCallback(sptr<RSIPointerLuminanceChangeCallback> callback) override; 130 131 int32_t UnRegisterPointerLuminanceChangeCallback() override; 132 #endif 133 134 int32_t SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback) override; 135 136 void SetScreenActiveMode(ScreenId id, uint32_t modeId) override; 137 138 void SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate) override; 139 140 void SetRefreshRateMode(int32_t refreshRateMode) override; 141 142 void SyncFrameRateRange(FrameRateLinkerId id, const FrameRateRange& range, 143 int32_t animatorExpectedFrameRate) override; 144 145 void UnregisterFrameRateLinker(FrameRateLinkerId id) override; 146 147 uint32_t GetScreenCurrentRefreshRate(ScreenId id) override; 148 149 int32_t GetCurrentRefreshRateMode() override; 150 151 std::vector<int32_t> GetScreenSupportedRefreshRates(ScreenId id) override; 152 153 bool GetShowRefreshRateEnabled() override; 154 155 void SetShowRefreshRateEnabled(bool enabled, int32_t type) override; 156 157 uint32_t GetRealtimeRefreshRate(ScreenId screenId) override; 158 159 ErrCode GetRefreshInfo(pid_t pid, std::string& enable) override; 160 161 int32_t SetPhysicalScreenResolution(ScreenId id, uint32_t width, uint32_t height) override; 162 163 int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height) override; 164 165 void MarkPowerOffNeedProcessOneFrame() override; 166 167 ErrCode RepaintEverything() override; 168 169 void ForceRefreshOneFrameWithNextVSync() override; 170 171 void DisablePowerOffRenderControl(ScreenId id) override; 172 173 void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status) override; 174 175 void TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback, 176 const RSSurfaceCaptureConfig& captureConfig, const RSSurfaceCaptureBlurParam& blurParam, 177 const Drawing::Rect& specifiedAreaRect = Drawing::Rect(0.f, 0.f, 0.f, 0.f), 178 RSSurfaceCapturePermissions permissions = RSSurfaceCapturePermissions()) override; 179 180 void TakeSelfSurfaceCapture( 181 NodeId id, sptr<RSISurfaceCaptureCallback> callback, const RSSurfaceCaptureConfig& captureConfig) override; 182 183 ErrCode SetWindowFreezeImmediately(NodeId id, bool isFreeze, sptr<RSISurfaceCaptureCallback> callback, 184 const RSSurfaceCaptureConfig& captureConfig, const RSSurfaceCaptureBlurParam& blurParam) override; 185 186 void SetHwcNodeBounds(int64_t rsNodeId, float positionX, float positionY, 187 float positionZ, float positionW) override; 188 189 ErrCode RegisterApplicationAgent(uint32_t pid, sptr<IApplicationAgent> app) override; 190 191 void UnRegisterApplicationAgent(sptr<IApplicationAgent> app); 192 193 RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id) override; 194 195 RSScreenModeInfo GetScreenActiveMode(ScreenId id) override; 196 197 std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id) override; 198 199 RSScreenCapability GetScreenCapability(ScreenId id) override; 200 201 ScreenPowerStatus GetScreenPowerStatus(ScreenId id) override; 202 203 RSScreenData GetScreenData(ScreenId id) override; 204 205 int32_t GetScreenBacklight(ScreenId id) override; 206 207 void SetScreenBacklight(ScreenId id, uint32_t level) override; 208 209 ErrCode RegisterBufferAvailableListener( 210 NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread) override; 211 212 ErrCode RegisterBufferClearListener( 213 NodeId id, sptr<RSIBufferClearCallback> callback) override; 214 215 int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode) override; 216 217 int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys) override; 218 219 int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode) override; 220 221 int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx) override; 222 223 int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode) override; 224 225 int32_t SetScreenCorrection(ScreenId id, ScreenRotation screenRotation) override; 226 227 bool SetVirtualMirrorScreenCanvasRotation(ScreenId id, bool canvasRotation) override; 228 229 bool SetVirtualMirrorScreenScaleMode(ScreenId id, ScreenScaleMode scaleMode) override; 230 231 bool SetGlobalDarkColorMode(bool isDark) override; 232 233 int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode) override; 234 235 int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability) override; 236 237 ErrCode GetPixelFormat(ScreenId id, GraphicPixelFormat& pixelFormat, int32_t& resCode) override; 238 239 ErrCode SetPixelFormat(ScreenId id, GraphicPixelFormat pixelFormat, int32_t& resCode) override; 240 241 ErrCode GetScreenSupportedHDRFormats( 242 ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats, int32_t& resCode) override; 243 244 ErrCode GetScreenHDRFormat(ScreenId id, ScreenHDRFormat& hdrFormat, int32_t& resCode) override; 245 246 ErrCode SetScreenHDRFormat(ScreenId id, int32_t modeIdx, int32_t& resCode) override; 247 248 ErrCode GetScreenSupportedColorSpaces( 249 ScreenId id, std::vector<GraphicCM_ColorSpaceType>& colorSpaces, int32_t& resCode) override; 250 251 ErrCode GetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType& colorSpace, int32_t& resCode) override; 252 253 ErrCode SetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType colorSpace, int32_t& resCode) override; 254 255 int32_t GetScreenType(ScreenId id, RSScreenType& screenType) override; 256 257 ErrCode GetBitmap(NodeId id, Drawing::Bitmap& bitmap, bool& success) override; 258 ErrCode GetPixelmap(NodeId id, std::shared_ptr<Media::PixelMap> pixelmap, 259 const Drawing::Rect* rect, std::shared_ptr<Drawing::DrawCmdList> drawCmdList, bool& success) override; 260 bool RegisterTypeface(uint64_t globalUniqueId, std::shared_ptr<Drawing::Typeface>& typeface) override; 261 bool UnRegisterTypeface(uint64_t globalUniqueId) override; 262 263 int32_t GetDisplayIdentificationData(ScreenId id, uint8_t& outPort, std::vector<uint8_t>& edidData) override; 264 265 int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval) override; 266 267 int32_t SetVirtualScreenRefreshRate(ScreenId id, uint32_t maxRefreshRate, uint32_t& actualRefreshRate) override; 268 269 uint32_t SetScreenActiveRect(ScreenId id, const Rect& activeRect) override; 270 271 int32_t RegisterOcclusionChangeCallback(sptr<RSIOcclusionChangeCallback> callback) override; 272 273 int32_t RegisterSurfaceOcclusionChangeCallback( 274 NodeId id, sptr<RSISurfaceOcclusionChangeCallback> callback, std::vector<float>& partitionPoints) override; 275 276 int32_t UnRegisterSurfaceOcclusionChangeCallback(NodeId id) override; 277 278 int32_t RegisterHgmConfigChangeCallback(sptr<RSIHgmConfigChangeCallback> callback) override; 279 280 int32_t RegisterHgmRefreshRateModeChangeCallback(sptr<RSIHgmConfigChangeCallback> callback) override; 281 282 int32_t RegisterHgmRefreshRateUpdateCallback(sptr<RSIHgmConfigChangeCallback> callback) override; 283 284 int32_t RegisterFrameRateLinkerExpectedFpsUpdateCallback(int32_t dstPid, 285 sptr<RSIFrameRateLinkerExpectedFpsUpdateCallback> callback) override; 286 287 ErrCode SetAppWindowNum(uint32_t num) override; 288 289 bool SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedScenes, bool isRegularAnimation) override; 290 291 void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow) override; 292 293 ErrCode SetWatermark(const std::string& name, std::shared_ptr<Media::PixelMap> watermark, bool& success) override; 294 295 int32_t ResizeVirtualScreen(ScreenId id, uint32_t width, uint32_t height) override; 296 297 ErrCode ReportJankStats() override; 298 299 ErrCode ReportEventResponse(DataBaseRs info) override; 300 301 ErrCode ReportEventComplete(DataBaseRs info) override; 302 303 ErrCode ReportEventJankFrame(DataBaseRs info) override; 304 305 void ReportRsSceneJankStart(AppInfo info) override; 306 307 void ReportRsSceneJankEnd(AppInfo info) override; 308 309 void ReportGameStateData(GameStateData info) override; 310 311 ErrCode SetHardwareEnabled(NodeId id, bool isEnabled, SelfDrawingNodeType selfDrawingType, 312 bool dynamicHardwareEnable) override; 313 314 ErrCode SetHidePrivacyContent(NodeId id, bool needHidePrivacyContent, uint32_t& resCode) override; 315 316 ErrCode NotifyLightFactorStatus(int32_t lightFactorStatus) override; 317 318 void NotifyPackageEvent(uint32_t listSize, const std::vector<std::string>& packageList) override; 319 320 void NotifyAppStrategyConfigChangeEvent(const std::string& pkgName, uint32_t listSize, 321 const std::vector<std::pair<std::string, std::string>>& newConfig) override; 322 323 void NotifyRefreshRateEvent(const EventInfo& eventInfo) override; 324 325 ErrCode NotifySoftVsyncEvent(uint32_t pid, uint32_t rateDiscount) override; 326 327 void NotifyTouchEvent(int32_t touchStatus, int32_t touchCnt) override; 328 329 void NotifyDynamicModeEvent(bool enableDynamicModeEvent) override; 330 331 ErrCode NotifyHgmConfigEvent(const std::string &eventName, bool state) override; 332 333 ErrCode SetCacheEnabledForRotation(bool isEnabled) override; 334 335 bool SetVirtualScreenStatus(ScreenId id, VirtualScreenStatus screenStatus) override; 336 337 std::vector<ActiveDirtyRegionInfo> GetActiveDirtyRegionInfo() override; 338 339 GlobalDirtyRegionInfo GetGlobalDirtyRegionInfo() override; 340 341 LayerComposeInfo GetLayerComposeInfo() override; 342 343 HwcDisabledReasonInfos GetHwcDisabledReasonInfo() override; 344 345 ErrCode GetHdrOnDuration(int64_t& hdrOnDuration) override; 346 347 ErrCode SetVmaCacheStatus(bool flag) override; 348 349 int32_t RegisterUIExtensionCallback(uint64_t userId, sptr<RSIUIExtensionCallback> callback, 350 bool unobscured = false) override; 351 352 #ifdef TP_FEATURE_ENABLE 353 void SetTpFeatureConfig(int32_t feature, const char* config, TpFeatureConfigType tpFeatureConfigType) override; 354 #endif 355 356 void SetVirtualScreenUsingStatus(bool isVirtualScreenUsingStatus) override; 357 ErrCode SetCurtainScreenUsingStatus(bool isCurtainScreenOn) override; 358 359 void DropFrameByPid(const std::vector<int32_t> pidList) override; 360 361 ErrCode SetAncoForceDoDirect(bool direct, bool& res) override; 362 363 void SetFreeMultiWindowStatus(bool enable) override; 364 365 void SetLayerTop(const std::string &nodeIdStr, bool isTop) override; 366 367 ErrCode RegisterSurfaceBufferCallback(pid_t pid, uint64_t uid, 368 sptr<RSISurfaceBufferCallback> callback) override; 369 ErrCode UnregisterSurfaceBufferCallback(pid_t pid, uint64_t uid) override; 370 371 void NotifyScreenSwitched() override; 372 373 ErrCode SetWindowContainer(NodeId nodeId, bool value) override; 374 375 int32_t RegisterSelfDrawingNodeRectChangeCallback(sptr<RSISelfDrawingNodeRectChangeCallback> callback) override; 376 377 #ifdef RS_ENABLE_OVERLAY_DISPLAY 378 ErrCode SetOverlayDisplayMode(int32_t mode) override; 379 #endif 380 381 void NotifyPageName(const std::string &packageName, const std::string &pageName, bool isEnter) override; 382 TestLoadFileSubTreeToNode(NodeId nodeId,const std::string & filePath)383 void TestLoadFileSubTreeToNode(NodeId nodeId, const std::string &filePath) override {}; 384 385 pid_t remotePid_; 386 wptr<RSRenderService> renderService_; 387 RSMainThread* mainThread_ = nullptr; 388 #ifdef RS_ENABLE_GPU 389 RSUniRenderThread& renderThread_; 390 #endif 391 sptr<RSScreenManager> screenManager_; 392 sptr<IRemoteObject> token_; 393 394 class RSConnectionDeathRecipient : public IRemoteObject::DeathRecipient { 395 public: 396 explicit RSConnectionDeathRecipient(wptr<RSRenderServiceConnection> conn); 397 virtual ~RSConnectionDeathRecipient() = default; 398 399 void OnRemoteDied(const wptr<IRemoteObject>& token) override; 400 401 private: 402 wptr<RSRenderServiceConnection> conn_; 403 }; 404 friend class RSConnectionDeathRecipient; 405 sptr<RSConnectionDeathRecipient> connDeathRecipient_; 406 407 class RSApplicationRenderThreadDeathRecipient : public IRemoteObject::DeathRecipient { 408 public: 409 explicit RSApplicationRenderThreadDeathRecipient(wptr<RSRenderServiceConnection> conn); 410 virtual ~RSApplicationRenderThreadDeathRecipient() = default; 411 412 void OnRemoteDied(const wptr<IRemoteObject>& token) override; 413 414 private: 415 wptr<RSRenderServiceConnection> conn_; 416 }; 417 friend class RSApplicationRenderThreadDeathRecipient; 418 sptr<RSApplicationRenderThreadDeathRecipient> applicationDeathRecipient_ = nullptr; 419 420 mutable std::mutex mutex_; 421 bool cleanDone_ = false; 422 const std::string VOTER_SCENE_BLUR = "VOTER_SCENE_BLUR"; 423 424 // save all virtual screenIds created by this connection. 425 std::unordered_set<ScreenId> virtualScreenIds_; 426 sptr<RSIScreenChangeCallback> screenChangeCallback_; 427 sptr<VSyncDistributor> appVSyncDistributor_; 428 429 #ifdef RS_PROFILER_ENABLED 430 friend class RSProfiler; 431 #endif 432 }; 433 } // namespace Rosen 434 } // namespace OHOS 435 436 #endif // RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H 437