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/rs_render_service.h" 26 #include "pipeline/rs_hardware_thread.h" 27 #include "pipeline/rs_uni_render_thread.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 void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override; 62 void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override; 63 MemoryGraphic GetMemoryGraphic(int pid) override; 64 std::vector<MemoryGraphic> GetMemoryGraphics() override; 65 bool GetTotalAppMemSize(float& cpuMemSize, float& gpuMemSize) override; 66 bool GetUniRenderEnabled() override; 67 68 bool CreateNode(const RSSurfaceRenderNodeConfig& config) override; 69 bool CreateNode(const RSDisplayNodeConfig& displayNodeConfig, NodeId nodeId) override; 70 sptr<Surface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config, bool unobscured = false) override; 71 72 sptr<IVSyncConnection> CreateVSyncConnection(const std::string& name, 73 const sptr<VSyncIConnectionToken>& token, 74 uint64_t id, 75 NodeId windowNodeId = 0, 76 bool fromXcomponent = false) override; 77 78 std::shared_ptr<Media::PixelMap> CreatePixelMapFromSurface(sptr<Surface> surface, const Rect &srcRect) override; 79 80 int32_t SetFocusAppInfo( 81 int32_t pid, int32_t uid, const std::string &bundleName, const std::string &abilityName, 82 uint64_t focusNodeId) override; 83 84 ScreenId GetDefaultScreenId() override; 85 86 ScreenId GetActiveScreenId() override; 87 88 std::vector<ScreenId> GetAllScreenIds() override; 89 90 ScreenId CreateVirtualScreen( 91 const std::string &name, 92 uint32_t width, 93 uint32_t height, 94 sptr<Surface> surface, 95 ScreenId mirrorId = 0, 96 int32_t flags = 0, 97 std::vector<NodeId> whiteList = {}) override; 98 99 int32_t SetVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector) override; 100 101 int32_t AddVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector) override; 102 103 int32_t RemoveVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector) override; 104 105 int32_t SetVirtualScreenSecurityExemptionList( 106 ScreenId id, const std::vector<NodeId>& securityExemptionList) override; 107 108 int32_t SetCastScreenEnableSkipWindow(ScreenId id, bool enable) override; 109 110 int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface) override; 111 112 void RemoveVirtualScreen(ScreenId id) override; 113 114 int32_t SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback) override; 115 116 void SetScreenActiveMode(ScreenId id, uint32_t modeId) override; 117 118 void SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate) override; 119 120 void SetRefreshRateMode(int32_t refreshRateMode) override; 121 122 void SyncFrameRateRange(FrameRateLinkerId id, const FrameRateRange& range, 123 int32_t animatorExpectedFrameRate) override; 124 125 void UnregisterFrameRateLinker(FrameRateLinkerId id) override; 126 127 uint32_t GetScreenCurrentRefreshRate(ScreenId id) override; 128 129 int32_t GetCurrentRefreshRateMode() override; 130 131 std::vector<int32_t> GetScreenSupportedRefreshRates(ScreenId id) override; 132 133 bool GetShowRefreshRateEnabled() override; 134 135 void SetShowRefreshRateEnabled(bool enable) override; 136 137 std::string GetRefreshInfo(pid_t pid) override; 138 139 int32_t SetPhysicalScreenResolution(ScreenId id, uint32_t width, uint32_t height) override; 140 141 int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height) override; 142 143 void MarkPowerOffNeedProcessOneFrame() override; 144 145 void DisablePowerOffRenderControl(ScreenId id) override; 146 147 void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status) override; 148 149 void TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback, 150 const RSSurfaceCaptureConfig& captureConfig, 151 const Drawing::Rect& specifiedAreaRect = Drawing::Rect(0.f, 0.f, 0.f, 0.f), 152 RSSurfaceCapturePermissions permissions = RSSurfaceCapturePermissions()) override; 153 154 void SetWindowFreezeImmediately(NodeId id, bool isFreeze, sptr<RSISurfaceCaptureCallback> callback, 155 const RSSurfaceCaptureConfig& captureConfig) override; 156 157 void RegisterApplicationAgent(uint32_t pid, sptr<IApplicationAgent> app) override; 158 159 void UnRegisterApplicationAgent(sptr<IApplicationAgent> app); 160 161 RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id) override; 162 163 RSScreenModeInfo GetScreenActiveMode(ScreenId id) override; 164 165 std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id) override; 166 167 RSScreenCapability GetScreenCapability(ScreenId id) override; 168 169 ScreenPowerStatus GetScreenPowerStatus(ScreenId id) override; 170 171 RSScreenData GetScreenData(ScreenId id) override; 172 173 int32_t GetScreenBacklight(ScreenId id) override; 174 175 void SetScreenBacklight(ScreenId id, uint32_t level) override; 176 177 void RegisterBufferAvailableListener( 178 NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread) override; 179 180 void RegisterBufferClearListener( 181 NodeId id, sptr<RSIBufferClearCallback> callback) override; 182 183 int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode) override; 184 185 int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys) override; 186 187 int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode) override; 188 189 int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx) override; 190 191 int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode) override; 192 193 int32_t SetScreenCorrection(ScreenId id, ScreenRotation screenRotation) override; 194 195 bool SetVirtualMirrorScreenCanvasRotation(ScreenId id, bool canvasRotation) override; 196 197 bool SetVirtualMirrorScreenScaleMode(ScreenId id, ScreenScaleMode scaleMode) override; 198 199 bool SetGlobalDarkColorMode(bool isDark) override; 200 201 int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode) override; 202 203 int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability) override; 204 205 int32_t GetPixelFormat(ScreenId id, GraphicPixelFormat& pixelFormat) override; 206 207 int32_t SetPixelFormat(ScreenId id, GraphicPixelFormat pixelFormat) override; 208 209 int32_t GetScreenSupportedHDRFormats(ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats) override; 210 211 int32_t GetScreenHDRFormat(ScreenId id, ScreenHDRFormat& hdrFormat) override; 212 213 int32_t SetScreenHDRFormat(ScreenId id, int32_t modeIdx) override; 214 215 int32_t GetScreenSupportedColorSpaces(ScreenId id, std::vector<GraphicCM_ColorSpaceType>& colorSpaces) override; 216 217 int32_t GetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType& colorSpace) override; 218 219 int32_t SetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType colorSpace) override; 220 221 int32_t GetScreenType(ScreenId id, RSScreenType& screenType) override; 222 223 bool GetBitmap(NodeId id, Drawing::Bitmap& bitmap) override; 224 bool GetPixelmap(NodeId id, std::shared_ptr<Media::PixelMap> pixelmap, 225 const Drawing::Rect* rect, std::shared_ptr<Drawing::DrawCmdList> drawCmdList) override; 226 bool RegisterTypeface(uint64_t globalUniqueId, std::shared_ptr<Drawing::Typeface>& typeface) override; 227 bool UnRegisterTypeface(uint64_t globalUniqueId) override; 228 229 int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval) override; 230 231 int32_t SetVirtualScreenRefreshRate(ScreenId id, uint32_t maxRefreshRate, uint32_t& actualRefreshRate) override; 232 233 uint32_t SetScreenActiveRect(ScreenId id, const Rect& activeRect) override; 234 235 int32_t RegisterOcclusionChangeCallback(sptr<RSIOcclusionChangeCallback> callback) override; 236 237 int32_t RegisterSurfaceOcclusionChangeCallback( 238 NodeId id, sptr<RSISurfaceOcclusionChangeCallback> callback, std::vector<float>& partitionPoints) override; 239 240 int32_t UnRegisterSurfaceOcclusionChangeCallback(NodeId id) override; 241 242 int32_t RegisterHgmConfigChangeCallback(sptr<RSIHgmConfigChangeCallback> callback) override; 243 244 int32_t RegisterHgmRefreshRateModeChangeCallback(sptr<RSIHgmConfigChangeCallback> callback) override; 245 246 int32_t RegisterHgmRefreshRateUpdateCallback(sptr<RSIHgmConfigChangeCallback> callback) override; 247 248 int32_t RegisterFrameRateLinkerExpectedFpsUpdateCallback(int32_t dstPid, 249 sptr<RSIFrameRateLinkerExpectedFpsUpdateCallback> callback) override; 250 251 void SetAppWindowNum(uint32_t num) override; 252 253 bool SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedScenes) override; 254 255 void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow) override; 256 257 int32_t ResizeVirtualScreen(ScreenId id, uint32_t width, uint32_t height) override; 258 259 void ReportJankStats() override; 260 261 void ReportEventResponse(DataBaseRs info) override; 262 263 void ReportEventComplete(DataBaseRs info) override; 264 265 void ReportEventJankFrame(DataBaseRs info) override; 266 267 void ReportGameStateData(GameStateData info) override; 268 269 void SetHardwareEnabled(NodeId id, bool isEnabled, SelfDrawingNodeType selfDrawingType, 270 bool dynamicHardwareEnable) override; 271 272 uint32_t SetHidePrivacyContent(NodeId id, bool needHidePrivacyContent) override; 273 274 void NotifyLightFactorStatus(bool isSafe) override; 275 276 void NotifyPackageEvent(uint32_t listSize, const std::vector<std::string>& packageList) override; 277 278 void NotifyRefreshRateEvent(const EventInfo& eventInfo) override; 279 280 void NotifyTouchEvent(int32_t touchStatus, int32_t touchCnt) override; 281 282 void NotifyDynamicModeEvent(bool enableDynamicModeEvent) override; 283 284 void SetCacheEnabledForRotation(bool isEnabled) override; 285 286 std::vector<ActiveDirtyRegionInfo> GetActiveDirtyRegionInfo() override; 287 288 GlobalDirtyRegionInfo GetGlobalDirtyRegionInfo() override; 289 290 LayerComposeInfo GetLayerComposeInfo() override; 291 292 HwcDisabledReasonInfos GetHwcDisabledReasonInfo() override; 293 294 void SetVmaCacheStatus(bool flag) override; 295 296 int32_t RegisterUIExtensionCallback(uint64_t userId, sptr<RSIUIExtensionCallback> callback, 297 bool unobscured = false) override; 298 299 #ifdef TP_FEATURE_ENABLE 300 void SetTpFeatureConfig(int32_t feature, const char* config, TpFeatureConfigType tpFeatureConfigType) override; 301 #endif 302 303 void SetVirtualScreenUsingStatus(bool isVirtualScreenUsingStatus) override; 304 void SetCurtainScreenUsingStatus(bool isCurtainScreenOn) override; 305 306 void DropFrameByPid(const std::vector<int32_t> pidList) override; 307 308 bool SetAncoForceDoDirect(bool direct) override; 309 310 void RegisterSurfaceBufferCallback(pid_t pid, uint64_t uid, 311 sptr<RSISurfaceBufferCallback> callback) override; 312 void UnregisterSurfaceBufferCallback(pid_t pid, uint64_t uid) override; 313 void SetLayerTop(const std::string &nodeIdStr, bool isTop) override; 314 315 void NotifyScreenSwitched() override; 316 317 void SetWindowContainer(NodeId nodeId, bool value) override; 318 319 pid_t remotePid_; 320 wptr<RSRenderService> renderService_; 321 RSMainThread* mainThread_ = nullptr; 322 RSUniRenderThread& renderThread_; 323 sptr<RSScreenManager> screenManager_; 324 sptr<IRemoteObject> token_; 325 326 class RSConnectionDeathRecipient : public IRemoteObject::DeathRecipient { 327 public: 328 explicit RSConnectionDeathRecipient(wptr<RSRenderServiceConnection> conn); 329 virtual ~RSConnectionDeathRecipient() = default; 330 331 void OnRemoteDied(const wptr<IRemoteObject>& token) override; 332 333 private: 334 wptr<RSRenderServiceConnection> conn_; 335 }; 336 friend class RSConnectionDeathRecipient; 337 sptr<RSConnectionDeathRecipient> connDeathRecipient_; 338 339 class RSApplicationRenderThreadDeathRecipient : public IRemoteObject::DeathRecipient { 340 public: 341 explicit RSApplicationRenderThreadDeathRecipient(wptr<RSRenderServiceConnection> conn); 342 virtual ~RSApplicationRenderThreadDeathRecipient() = default; 343 344 void OnRemoteDied(const wptr<IRemoteObject>& token) override; 345 346 private: 347 wptr<RSRenderServiceConnection> conn_; 348 }; 349 friend class RSApplicationRenderThreadDeathRecipient; 350 sptr<RSApplicationRenderThreadDeathRecipient> ApplicationDeathRecipient_; 351 352 mutable std::mutex mutex_; 353 bool cleanDone_ = false; 354 355 // save all virtual screenIds created by this connection. 356 std::unordered_set<ScreenId> virtualScreenIds_; 357 sptr<RSIScreenChangeCallback> screenChangeCallback_; 358 sptr<VSyncDistributor> appVSyncDistributor_; 359 360 #ifdef RS_PROFILER_ENABLED 361 friend class RSProfiler; 362 #endif 363 }; 364 } // namespace Rosen 365 } // namespace OHOS 366 367 #endif // RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H 368