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> filteredAppVector = {}); 64 65 int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface); 66 #endif 67 68 void RemoveVirtualScreen(ScreenId id); 69 70 int32_t SetScreenChangeCallback(const ScreenChangeCallback &callback); 71 72 bool TakeSurfaceCapture(std::shared_ptr<RSSurfaceNode> node, 73 std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX = 1.0f, float scaleY = 1.0f); 74 75 bool TakeSurfaceCapture(std::shared_ptr<RSDisplayNode> node, 76 std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX = 1.0f, float scaleY = 1.0f); 77 78 bool TakeSurfaceCapture(NodeId id, 79 std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX = 1.0f, float scaleY = 1.0f); 80 81 bool TakeSurfaceCaptureForUI(std::shared_ptr<RSNode> node, 82 std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX = 1.f, float scaleY = 1.f); 83 84 #ifndef ROSEN_ARKUI_X 85 void SetScreenActiveMode(ScreenId id, uint32_t modeId); 86 87 MemoryGraphic GetMemoryGraphic(int pid); 88 89 std::vector<MemoryGraphic> GetMemoryGraphics(); 90 #endif // !ROSEN_ARKUI_X 91 bool GetTotalAppMemSize(float& cpuMemSize, float& gpuMemSize); 92 93 #ifndef ROSEN_ARKUI_X 94 int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height); 95 #endif // !ROSEN_ARKUI_X 96 97 bool SetVirtualMirrorScreenCanvasRotation(ScreenId id, bool canvasRotation); 98 #ifndef ROSEN_ARKUI_X 99 RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id); 100 101 void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status); 102 103 RSScreenModeInfo GetScreenActiveMode(ScreenId id); 104 #endif // !ROSEN_ARKUI_X 105 106 void SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate); 107 108 void SetRefreshRateMode(int32_t refreshRateMode); 109 110 void SyncFrameRateRange(const FrameRateRange& range); 111 112 uint32_t GetScreenCurrentRefreshRate(ScreenId id); 113 114 int32_t GetCurrentRefreshRateMode(); 115 116 std::vector<int32_t> GetScreenSupportedRefreshRates(ScreenId id); 117 118 bool GetShowRefreshRateEnabled(); 119 120 void SetShowRefreshRateEnabled(bool enable); 121 122 #ifndef ROSEN_ARKUI_X 123 std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id); 124 125 RSScreenCapability GetScreenCapability(ScreenId id); 126 127 ScreenPowerStatus GetScreenPowerStatus(ScreenId id); 128 129 RSScreenData GetScreenData(ScreenId id); 130 #endif // !ROSEN_ARKUI_X 131 int32_t GetScreenBacklight(ScreenId id); 132 133 void SetScreenBacklight(ScreenId id, uint32_t level); 134 135 int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode); 136 137 int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys); 138 139 int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode); 140 141 int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx); 142 143 int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode); 144 145 int32_t SetScreenCorrection(ScreenId id, ScreenRotation screenRotation); 146 147 int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode); 148 149 int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability); 150 151 int32_t GetPixelFormat(ScreenId id, GraphicPixelFormat& pixelFormat); 152 153 int32_t SetPixelFormat(ScreenId id, GraphicPixelFormat pixelFormat); 154 155 int32_t GetScreenSupportedHDRFormats(ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats); 156 157 int32_t GetScreenHDRFormat(ScreenId id, ScreenHDRFormat& hdrFormat); 158 159 int32_t SetScreenHDRFormat(ScreenId id, int32_t modeIdx); 160 161 int32_t GetScreenSupportedColorSpaces(ScreenId id, std::vector<GraphicCM_ColorSpaceType>& colorSpaces); 162 163 int32_t GetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType& colorSpace); 164 165 int32_t SetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType colorSpace); 166 167 int32_t GetScreenType(ScreenId id, RSScreenType& screenType); 168 169 /* skipFrameInterval : decide how many frames apart to refresh a frame, 170 DEFAULT_SKIP_FRAME_INTERVAL means refresh each frame, 171 change screen refresh rate finally */ 172 int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval); 173 174 std::shared_ptr<VSyncReceiver> CreateVSyncReceiver( 175 const std::string& name, 176 const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr); 177 178 std::shared_ptr<VSyncReceiver> CreateVSyncReceiver( 179 const std::string& name, 180 uint64_t id, 181 const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr); 182 183 int32_t RegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback); 184 185 int32_t RegisterSurfaceOcclusionChangeCallback( 186 NodeId id, const SurfaceOcclusionChangeCallback& callback, std::vector<float>& partitionPoints); 187 188 int32_t UnRegisterSurfaceOcclusionChangeCallback(NodeId id); 189 190 int32_t RegisterHgmConfigChangeCallback(const HgmConfigChangeCallback& callback); 191 192 int32_t RegisterHgmRefreshRateModeChangeCallback(const HgmRefreshRateModeChangeCallback& callback); 193 194 void SetAppWindowNum(uint32_t num); 195 196 // Set the system overload Animated Scenes to RS for special load shedding 197 bool SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedScenes); 198 199 void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow); 200 201 int32_t ResizeVirtualScreen(ScreenId id, uint32_t width, uint32_t height); 202 203 void ReportJankStats(); 204 205 void NotifyLightFactorStatus(bool isSafe); 206 207 void NotifyPackageEvent(uint32_t listSize, const std::vector<std::string>& packageList); 208 209 void NotifyRefreshRateEvent(const EventInfo& eventInfo); 210 211 void NotifyTouchEvent(int32_t touchStatus); 212 213 void ReportEventResponse(DataBaseRs info); 214 215 void ReportEventComplete(DataBaseRs info); 216 217 void ReportEventJankFrame(DataBaseRs info); 218 219 void ReportGameStateData(GameStateData info); 220 221 void EnableCacheForRotation(); 222 223 void DisableCacheForRotation(); 224 225 void SetOnRemoteDiedCallback(const OnRemoteDiedCallback& callback); 226 227 #ifdef TP_FEATURE_ENABLE 228 void SetTpFeatureConfig(int32_t feature, const char* config); 229 #endif 230 void SetVirtualScreenUsingStatus(bool isVirtualScreenUsingStatus); 231 private: 232 RSInterfaces(); 233 ~RSInterfaces() noexcept; 234 235 bool TakeSurfaceCaptureForUIWithoutUni(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback, 236 float scaleX, float scaleY); 237 238 std::unique_ptr<RSRenderServiceClient> renderServiceClient_; 239 }; 240 } // namespace Rosen 241 } // namespace OHOS 242 243 #endif // RENDER_SERVICE_CLIENT_CORE_TRANSACTION_RS_INTERFACES_H 244