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