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 ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECTION_PROXY_H 17 #define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECTION_PROXY_H 18 19 #include "command/rs_node_showing_command.h" 20 #include <iremote_proxy.h> 21 #include <memory> 22 #include <platform/ohos/rs_irender_service_connection.h> 23 #include <platform/ohos/rs_irender_service_connection_ipc_interface_code.h> 24 #include "sandbox_utils.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 class RSRenderServiceConnectionProxy : public IRemoteProxy<RSIRenderServiceConnection> { 29 public: 30 explicit RSRenderServiceConnectionProxy(const sptr<IRemoteObject>& impl); 31 virtual ~RSRenderServiceConnectionProxy() noexcept = default; 32 33 ErrCode CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override; 34 ErrCode ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override; 35 36 ErrCode GetMemoryGraphic(int pid, MemoryGraphic& memoryGraphic) override; 37 ErrCode GetMemoryGraphics(std::vector<MemoryGraphic>& memoryGraphics) override; 38 ErrCode GetTotalAppMemSize(float& cpuMemSize, float& gpuMemSize) override; 39 40 ErrCode GetUniRenderEnabled(bool& enable) override; 41 42 ErrCode CreateNode(const RSSurfaceRenderNodeConfig& configg, bool& success) override; 43 ErrCode CreateNode(const RSDisplayNodeConfig& displayNodeConfig, NodeId nodeIdg, bool& success) override; 44 ErrCode CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config, sptr<Surface>& sfc, 45 bool unobscured = false) override; 46 47 virtual ErrCode CreateVSyncConnection(sptr<IVSyncConnection>& vsyncConn, 48 const std::string& name, 49 const sptr<VSyncIConnectionToken>& token, 50 VSyncConnParam vsyncConnParam = {0, 0, false}) override; 51 52 ErrCode GetPixelMapByProcessId(std::vector<PixelMapInfo>& pixelMapInfoVector, pid_t pid, 53 int32_t& repCode) override; 54 55 ErrCode CreatePixelMapFromSurface(sptr<Surface> surface, const Rect &srcRect, 56 std::shared_ptr<Media::PixelMap> &pixelMap) override; 57 58 ErrCode SetFocusAppInfo(const FocusAppInfo& info, int32_t& repCode)override; 59 60 ErrCode GetDefaultScreenId(uint64_t& screenId) override; 61 ErrCode GetActiveScreenId(uint64_t& screenId) override; 62 63 std::vector<ScreenId> GetAllScreenIds() override; 64 65 // mirrorId: decide which screen id to mirror, INVALID_SCREEN_ID means do not mirror any screen. 66 ScreenId CreateVirtualScreen( 67 const std::string &name, 68 uint32_t width, 69 uint32_t height, 70 sptr<Surface> surface, 71 ScreenId mirrorId = 0, 72 int32_t flags = 0, 73 std::vector<NodeId> whiteList = {}) override; 74 75 int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface) override; 76 77 int32_t SetVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector) override; 78 79 ErrCode SetVirtualScreenTypeBlackList( 80 ScreenId id, std::vector<NodeType>& typeBlackListVector, int32_t& repCode) override; 81 82 ErrCode AddVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector, int32_t& repCode) override; 83 84 ErrCode RemoveVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector, int32_t& repCode) override; 85 86 ErrCode SetWatermark(const std::string& name, std::shared_ptr<Media::PixelMap> watermark, bool& success) override; 87 88 int32_t SetVirtualScreenSecurityExemptionList( 89 ScreenId id, const std::vector<NodeId>& securityExemptionList) override; 90 91 int32_t SetScreenSecurityMask(ScreenId id, std::shared_ptr<Media::PixelMap> securityMask) override; 92 93 int32_t SetMirrorScreenVisibleRect(ScreenId id, const Rect& mainScreenRect, bool supportRotation = false) override; 94 95 int32_t SetCastScreenEnableSkipWindow(ScreenId id, bool enable) override; 96 97 void RemoveVirtualScreen(ScreenId id) override; 98 99 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR 100 int32_t SetPointerColorInversionConfig(float darkBuffer, float brightBuffer, 101 int64_t interval, int32_t rangeSize) override; 102 103 int32_t SetPointerColorInversionEnabled(bool enable) override; 104 105 int32_t RegisterPointerLuminanceChangeCallback(sptr<RSIPointerLuminanceChangeCallback> callback) override; 106 107 int32_t UnRegisterPointerLuminanceChangeCallback() override; 108 #endif 109 110 int32_t SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback) override; 111 112 int32_t SetScreenSwitchingNotifyCallback(sptr<RSIScreenSwitchingNotifyCallback> 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 ErrCode GetShowRefreshRateEnabled(bool& enable) override; 132 133 void SetShowRefreshRateEnabled(bool enabled, int32_t type) override; 134 135 uint32_t GetRealtimeRefreshRate(ScreenId id) override; 136 137 ErrCode GetRefreshInfo(pid_t pid, std::string& enable) override; 138 ErrCode GetRefreshInfoToSP(NodeId id, std::string& enable) override; 139 140 int32_t SetPhysicalScreenResolution(ScreenId id, uint32_t width, uint32_t height) override; 141 142 int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height) override; 143 144 ErrCode MarkPowerOffNeedProcessOneFrame() override; 145 146 ErrCode RepaintEverything() override; 147 148 ErrCode ForceRefreshOneFrameWithNextVSync() override; 149 150 void DisablePowerOffRenderControl(ScreenId id) override; 151 152 void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status) override; 153 154 ErrCode RegisterApplicationAgent(uint32_t pid, sptr<IApplicationAgent> app) override; 155 156 void TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback, 157 const RSSurfaceCaptureConfig& captureConfig, const RSSurfaceCaptureBlurParam& blurParam, 158 const Drawing::Rect& specifiedAreaRect = Drawing::Rect(0.f, 0.f, 0.f, 0.f), 159 RSSurfaceCapturePermissions permissions = RSSurfaceCapturePermissions()) override; 160 161 std::vector<std::pair<NodeId, std::shared_ptr<Media::PixelMap>>> 162 TakeSurfaceCaptureSoloNode(NodeId id, const RSSurfaceCaptureConfig& captureConfig, 163 RSSurfaceCapturePermissions permissions = RSSurfaceCapturePermissions()) override; 164 165 void TakeSelfSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback, 166 const RSSurfaceCaptureConfig& captureConfig) override; 167 168 ErrCode SetWindowFreezeImmediately(NodeId id, bool isFreeze, sptr<RSISurfaceCaptureCallback> callback, 169 const RSSurfaceCaptureConfig& captureConfig, const RSSurfaceCaptureBlurParam& blurParam) override; 170 171 ErrCode TaskSurfaceCaptureWithAllWindows(NodeId id, sptr<RSISurfaceCaptureCallback> callback, 172 const RSSurfaceCaptureConfig& captureConfig, bool checkDrmAndSurfaceLock, 173 RSSurfaceCapturePermissions permissions = RSSurfaceCapturePermissions()) override; 174 175 ErrCode FreezeScreen(NodeId id, bool isFreeze) override; 176 177 void TakeUICaptureInRange( 178 NodeId id, sptr<RSISurfaceCaptureCallback> callback, const RSSurfaceCaptureConfig& captureConfig) override; 179 180 bool WriteSurfaceCaptureConfig(const RSSurfaceCaptureConfig& captureConfig, MessageParcel& data); 181 182 bool WriteSurfaceCaptureBlurParam(const RSSurfaceCaptureBlurParam& blurParam, MessageParcel& data); 183 184 bool WriteSurfaceCaptureAreaRect(const Drawing::Rect& specifiedAreaRect, MessageParcel& data); 185 186 ErrCode SetHwcNodeBounds(int64_t rsNodeId, float positionX, float positionY, 187 float positionZ, float positionW) override; 188 189 RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id) override; 190 191 ErrCode GetScreenActiveMode(uint64_t id, RSScreenModeInfo& screenModeInfo) override; 192 193 std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id) override; 194 195 RSScreenCapability GetScreenCapability(ScreenId id) override; 196 197 ErrCode GetScreenPowerStatus(uint64_t screenId, uint32_t& status) override; 198 199 RSScreenData GetScreenData(ScreenId id) override; 200 201 ErrCode GetScreenBacklight(uint64_t id, int32_t& level) override; 202 203 void SetScreenBacklight(ScreenId id, uint32_t level) override; 204 205 ErrCode RegisterBufferAvailableListener( 206 NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread) override; 207 208 ErrCode RegisterBufferClearListener( 209 NodeId id, sptr<RSIBufferClearCallback> callback) override; 210 211 int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode) override; 212 213 int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys) override; 214 215 int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode) override; 216 217 int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx) override; 218 219 int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode) override; 220 221 int32_t SetScreenCorrection(ScreenId id, ScreenRotation screenRotation) override; 222 223 bool SetVirtualMirrorScreenCanvasRotation(ScreenId id, bool canvasRotation) override; 224 225 int32_t SetVirtualScreenAutoRotation(ScreenId id, bool isAutoRotation) override; 226 227 bool SetVirtualMirrorScreenScaleMode(ScreenId id, ScreenScaleMode scaleMode) override; 228 229 ErrCode SetGlobalDarkColorMode(bool isDark) override; 230 231 int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode) override; 232 233 int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability) override; 234 235 ErrCode GetPixelFormat(ScreenId id, GraphicPixelFormat& pixelFormat, int32_t& resCode) override; 236 237 ErrCode SetPixelFormat(ScreenId id, GraphicPixelFormat pixelFormat, int32_t& resCode) override; 238 239 ErrCode GetScreenSupportedHDRFormats( 240 ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats, int32_t& resCode) override; 241 242 ErrCode GetScreenHDRFormat(ScreenId id, ScreenHDRFormat& hdrFormat, int32_t& resCode) override; 243 244 ErrCode SetScreenHDRFormat(ScreenId id, int32_t modeIdx, int32_t& resCode) override; 245 246 ErrCode GetScreenHDRStatus(ScreenId id, HdrStatus& hdrStatus, 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 ErrCode SetScreenSkipFrameInterval(uint64_t id, uint32_t skipFrameInterval, int32_t& resCode) override; 266 267 ErrCode SetVirtualScreenRefreshRate( 268 ScreenId id, uint32_t maxRefreshRate, uint32_t& actualRefreshRate, int32_t& retVal) override; 269 270 ErrCode SetScreenActiveRect(ScreenId id, const Rect& activeRect, uint32_t& repCode) override; 271 272 void SetScreenOffset(ScreenId id, int32_t offSetX, int32_t offSetY) override; 273 274 void SetScreenFrameGravity(ScreenId id, int32_t gravity) override; 275 276 ErrCode RegisterOcclusionChangeCallback(sptr<RSIOcclusionChangeCallback> callback, int32_t& repCode) override; 277 278 int32_t RegisterSurfaceOcclusionChangeCallback( 279 NodeId id, sptr<RSISurfaceOcclusionChangeCallback> callback, std::vector<float>& partitionPoints) override; 280 281 int32_t UnRegisterSurfaceOcclusionChangeCallback(NodeId id) override; 282 283 int32_t RegisterHgmConfigChangeCallback(sptr<RSIHgmConfigChangeCallback> callback) override; 284 285 int32_t RegisterHgmRefreshRateModeChangeCallback(sptr<RSIHgmConfigChangeCallback> callback) override; 286 287 int32_t RegisterHgmRefreshRateUpdateCallback(sptr<RSIHgmConfigChangeCallback> callback) override; 288 289 int32_t RegisterFirstFrameCommitCallback(sptr<RSIFirstFrameCommitCallback> callback) override; 290 291 ErrCode AvcodecVideoStart(uint64_t uniqueId, std::string& surfaceName, uint32_t fps, uint64_t reportTime) override; 292 293 ErrCode AvcodecVideoStop(uint64_t uniqueId, std::string& surfaceName, uint32_t fps) override; 294 295 int32_t RegisterFrameRateLinkerExpectedFpsUpdateCallback(int32_t dstPid, 296 sptr<RSIFrameRateLinkerExpectedFpsUpdateCallback> callback) override; 297 298 ErrCode SetAppWindowNum(uint32_t num) override; 299 300 ErrCode SetSystemAnimatedScenes( 301 SystemAnimatedScenes systemAnimatedScenes, bool isRegularAnimation, bool& success) override; 302 303 void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow) override; 304 305 int32_t ResizeVirtualScreen(ScreenId id, uint32_t width, uint32_t height) override; 306 307 ErrCode ReportJankStats() override; 308 309 ErrCode NotifyLightFactorStatus(int32_t lightFactorStatus) override; 310 311 void NotifyPackageEvent(uint32_t listSize, const std::vector<std::string>& packageList) override; 312 313 void NotifyAppStrategyConfigChangeEvent(const std::string& pkgName, uint32_t listSize, 314 const std::vector<std::pair<std::string, std::string>>& newConfig) override; 315 316 void NotifyRefreshRateEvent(const EventInfo& eventInfo) override; 317 318 void SetWindowExpectedRefreshRate(const std::unordered_map<uint64_t, EventInfo>& eventInfos) override; 319 320 void SetWindowExpectedRefreshRate(const std::unordered_map<std::string, EventInfo>& eventInfos) override; 321 322 ErrCode NotifySoftVsyncEvent(uint32_t pid, uint32_t rateDiscount) override; 323 324 bool NotifySoftVsyncRateDiscountEvent(uint32_t pid, const std::string &name, uint32_t rateDiscount) override; 325 326 ErrCode NotifyTouchEvent(int32_t touchStatus, int32_t touchCnt) override; 327 328 void NotifyDynamicModeEvent(bool enableDynamicMode) override; 329 330 ErrCode NotifyHgmConfigEvent(const std::string &eventName, bool state) override; 331 332 ErrCode NotifyXComponentExpectedFrameRate(const std::string& id, int32_t expectedFrameRate) override; 333 334 ErrCode ReportEventResponse(DataBaseRs info) override; 335 336 ErrCode ReportEventComplete(DataBaseRs info) override; 337 338 ErrCode ReportEventJankFrame(DataBaseRs info) override; 339 340 void ReportRsSceneJankStart(AppInfo info) override; 341 342 void ReportRsSceneJankEnd(AppInfo info) override; 343 344 ErrCode ReportGameStateData(GameStateData info) override; 345 346 ErrCode SetHardwareEnabled(NodeId id, bool isEnabled, SelfDrawingNodeType selfDrawingType, 347 bool dynamicHardwareEnable) override; 348 349 ErrCode SetHidePrivacyContent(NodeId id, bool needHidePrivacyContent, uint32_t& resCode) override; 350 351 ErrCode SetCacheEnabledForRotation(bool isEnabled) override; 352 353 void SetOnRemoteDiedCallback(const OnRemoteDiedCallback& callback) override; 354 355 void RunOnRemoteDiedCallback() override; 356 357 std::vector<ActiveDirtyRegionInfo> GetActiveDirtyRegionInfo() override; 358 359 GlobalDirtyRegionInfo GetGlobalDirtyRegionInfo() override; 360 361 LayerComposeInfo GetLayerComposeInfo() override; 362 363 HwcDisabledReasonInfos GetHwcDisabledReasonInfo() override; 364 365 ErrCode GetHdrOnDuration(int64_t& hdrOnDuration) override; 366 367 ErrCode SetVmaCacheStatus(bool flag) override; 368 369 int32_t RegisterUIExtensionCallback(uint64_t userId, sptr<RSIUIExtensionCallback> callback, 370 bool unobscured = false) override; 371 372 #ifdef TP_FEATURE_ENABLE 373 ErrCode SetTpFeatureConfig(int32_t feature, const char* config, 374 TpFeatureConfigType tpFeatureConfigType = TpFeatureConfigType::DEFAULT_TP_FEATURE) override; 375 #endif 376 void SetVirtualScreenUsingStatus(bool isVirtualScreenUsingStatus) override; 377 ErrCode SetCurtainScreenUsingStatus(bool isCurtainScreenOn) override; 378 379 ErrCode DropFrameByPid(const std::vector<int32_t> pidList) override; 380 381 ErrCode SetVirtualScreenStatus(ScreenId id, VirtualScreenStatus screenStatus, bool& success) override; 382 383 void SetFreeMultiWindowStatus(bool enable) override; 384 385 ErrCode RegisterSurfaceBufferCallback(pid_t pid, uint64_t uid, 386 sptr<RSISurfaceBufferCallback> callback) override; 387 388 ErrCode UnregisterSurfaceBufferCallback(pid_t pid, uint64_t uid) override; 389 390 void RegisterTransactionDataCallback(uint64_t token, 391 uint64_t timeStamp, sptr<RSITransactionDataCallback> callback) override; 392 393 ErrCode NotifyScreenSwitched() override; 394 395 ErrCode SetWindowContainer(NodeId nodeId, bool value) override; 396 397 int32_t RegisterSelfDrawingNodeRectChangeCallback( 398 const RectConstraint& constraint, sptr<RSISelfDrawingNodeRectChangeCallback> callback) override; 399 400 int32_t UnRegisterSelfDrawingNodeRectChangeCallback() override; 401 402 ErrCode NotifyPageName(const std::string &packageName, const std::string &pageName, bool isEnter) override; 403 404 bool GetHighContrastTextState() override; 405 406 ErrCode SetBehindWindowFilterEnabled(bool enabled) override; 407 408 ErrCode GetBehindWindowFilterEnabled(bool& enabled) override; 409 410 int32_t GetPidGpuMemoryInMB(pid_t pid, float &gpuMemInMB) override; 411 412 RetCodeHrpService ProfilerServiceOpenFile(const HrpServiceDirInfo& dirInfo, 413 const std::string& fileName, int32_t flags, int& outFd) override; 414 RetCodeHrpService ProfilerServicePopulateFiles(const HrpServiceDirInfo& dirInfo, 415 uint32_t firstFileIndex, std::vector<HrpServiceFileInfo>& outFiles) override; 416 bool ProfilerIsSecureScreen() override; 417 418 void ClearUifirstCache(NodeId id) override; 419 420 ErrCode SetGpuCrcDirtyEnabledPidList(const std::vector<int32_t> pidList) override; 421 422 ErrCode SetOptimizeCanvasDirtyPidList(const std::vector<int32_t>& pidList) override; 423 private: 424 bool FillParcelWithTransactionData( 425 std::unique_ptr<RSTransactionData>& transactionData, std::shared_ptr<MessageParcel>& data); 426 427 void ReportDataBaseRs(MessageParcel& data, MessageParcel& reply, MessageOption& option, DataBaseRs info); 428 429 void WriteAppInfo(MessageParcel& data, MessageParcel& reply, MessageOption& option, AppInfo info); 430 431 void ReportGameStateDataRs(MessageParcel& data, MessageParcel& reply, MessageOption& option, GameStateData info); 432 433 int32_t SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); 434 435 ErrCode SetAncoForceDoDirect(bool direct, bool& res) override; 436 437 ErrCode SetLayerTopForHWC(NodeId nodeId, bool isTop, uint32_t zOrder) override; 438 439 ErrCode SetLayerTop(const std::string &nodeIdStr, bool isTop) override; 440 441 ErrCode SetForceRefresh(const std::string &nodeIdStr, bool isForceRefresh) override; 442 443 void SetColorFollow(const std::string &nodeIdStr, bool isColorFollow) override; 444 445 #ifdef RS_ENABLE_OVERLAY_DISPLAY 446 ErrCode SetOverlayDisplayMode(int32_t mode) override; 447 #endif 448 449 static inline BrokerDelegator<RSRenderServiceConnectionProxy> delegator_; 450 451 pid_t pid_ = GetRealPid(); 452 uint32_t transactionDataIndex_ = 0; 453 OnRemoteDiedCallback OnRemoteDiedCallback_; 454 }; 455 } // namespace Rosen 456 } // namespace OHOS 457 458 #endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CONNECTION_PROXY_H 459