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_CLIENT_H 17 #define ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CLIENT_H 18 19 #include <functional> 20 #include <map> 21 #include <memory> 22 #include <mutex> 23 #include <refbase.h> 24 #ifndef ROSEN_CROSS_PLATFORM 25 #include <surface.h> 26 #endif 27 28 #include "ipc_callbacks/buffer_available_callback.h" 29 #include "ipc_callbacks/iapplication_agent.h" 30 #include "ipc_callbacks/screen_change_callback.h" 31 #include "ipc_callbacks/surface_capture_callback.h" 32 #include "memory/rs_memory_graphic.h" 33 #ifdef NEW_RENDER_CONTEXT 34 #include "render_backend/rs_render_surface.h" 35 #else 36 #include "platform/drawing/rs_surface.h" 37 #endif 38 #include "rs_irender_client.h" 39 #include "screen_manager/rs_screen_capability.h" 40 #include "screen_manager/rs_screen_data.h" 41 #include "screen_manager/rs_screen_hdr_capability.h" 42 #include "screen_manager/rs_screen_mode_info.h" 43 #include "screen_manager/screen_types.h" 44 #include "screen_manager/rs_virtual_screen_resolution.h" 45 #include "vsync_receiver.h" 46 #include "ipc_callbacks/rs_iocclusion_change_callback.h" 47 #include "rs_occlusion_data.h" 48 49 namespace OHOS { 50 namespace Rosen { 51 // normal callback functor for client users. 52 using ScreenChangeCallback = std::function<void(ScreenId, ScreenEvent)>; 53 using BufferAvailableCallback = std::function<void()>; 54 using BufferClearCallback = std::function<void()>; 55 using OcclusionChangeCallback = std::function<void(std::shared_ptr<RSOcclusionData>)>; 56 57 struct DataBaseRs { 58 int32_t appPid = -1; 59 int32_t eventType = -1; 60 int32_t versionCode = -1; 61 int64_t uniqueId = 0; 62 int64_t inputTime = 0; 63 int64_t beginVsyncTime = 0; 64 int64_t endVsyncTime = 0; 65 std::string sceneId; 66 std::string versionName; 67 std::string bundleName; 68 std::string processName; 69 std::string abilityName; 70 std::string pageUrl; 71 std::string sourceType; 72 std::string note; 73 }; 74 75 class SurfaceCaptureCallback { 76 public: SurfaceCaptureCallback()77 SurfaceCaptureCallback() {} ~SurfaceCaptureCallback()78 virtual ~SurfaceCaptureCallback() {} 79 virtual void OnSurfaceCapture(std::shared_ptr<Media::PixelMap> pixelmap) = 0; 80 }; 81 82 class RSB_EXPORT RSRenderServiceClient : public RSIRenderClient { 83 public: 84 RSRenderServiceClient() = default; 85 virtual ~RSRenderServiceClient() = default; 86 87 RSRenderServiceClient(const RSRenderServiceClient&) = delete; 88 void operator=(const RSRenderServiceClient&) = delete; 89 90 void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override; 91 void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override; 92 93 bool GetUniRenderEnabled(); 94 95 bool CreateNode(const RSSurfaceRenderNodeConfig& config); 96 #ifdef NEW_RENDER_CONTEXT 97 std::shared_ptr<RSRenderSurface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config); 98 #else 99 std::shared_ptr<RSSurface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config); 100 #endif 101 std::shared_ptr<VSyncReceiver> CreateVSyncReceiver( 102 const std::string& name, 103 const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr); 104 105 bool TakeSurfaceCapture(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX, float scaleY); 106 107 int32_t SetFocusAppInfo(int32_t pid, int32_t uid, const std::string &bundleName, const std::string &abilityName, 108 uint64_t focusNodeId); 109 110 ScreenId GetDefaultScreenId(); 111 112 std::vector<ScreenId> GetAllScreenIds(); 113 114 #ifndef ROSEN_CROSS_PLATFORM 115 #if defined(NEW_RENDER_CONTEXT) 116 std::shared_ptr<RSRenderSurface> CreateRSSurface(const sptr<Surface> &surface); 117 #else 118 std::shared_ptr<RSSurface> CreateRSSurface(const sptr<Surface> &surface); 119 #endif 120 ScreenId CreateVirtualScreen(const std::string& name, uint32_t width, uint32_t height, sptr<Surface> surface, 121 ScreenId mirrorId, int32_t flags); 122 123 int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface); 124 #endif 125 126 void RemoveVirtualScreen(ScreenId id); 127 128 int32_t SetScreenChangeCallback(const ScreenChangeCallback& callback); 129 130 void SetScreenActiveMode(ScreenId id, uint32_t modeId); 131 132 void SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate); 133 134 void SetRefreshRateMode(int32_t refreshRateMode); 135 136 uint32_t GetScreenCurrentRefreshRate(ScreenId id); 137 138 std::vector<uint32_t> GetScreenSupportedRefreshRates(ScreenId id); 139 140 int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height); 141 142 RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id); 143 144 void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status); 145 146 RSScreenModeInfo GetScreenActiveMode(ScreenId id); 147 148 std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id); 149 150 RSScreenCapability GetScreenCapability(ScreenId id); 151 152 ScreenPowerStatus GetScreenPowerStatus(ScreenId id); 153 154 RSScreenData GetScreenData(ScreenId id); 155 156 MemoryGraphic GetMemoryGraphic(int pid); 157 std::vector<MemoryGraphic> GetMemoryGraphics(); 158 159 int32_t GetScreenBacklight(ScreenId id); 160 161 void SetScreenBacklight(ScreenId id, uint32_t level); 162 163 bool RegisterBufferAvailableListener( 164 NodeId id, const BufferAvailableCallback &callback, bool isFromRenderThread = false); 165 166 bool RegisterBufferClearListener( 167 NodeId id, const BufferClearCallback &callback); 168 169 bool UnregisterBufferAvailableListener(NodeId id); 170 171 int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode); 172 173 int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys); 174 175 int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode); 176 177 int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx); 178 179 int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode); 180 181 int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode); 182 183 int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability); 184 185 int32_t GetScreenType(ScreenId id, RSScreenType& screenType); 186 187 #ifndef USE_ROSEN_DRAWING 188 bool GetBitmap(NodeId id, SkBitmap& bitmap); 189 bool GetPixelmap(NodeId id, const std::shared_ptr<Media::PixelMap> pixelmap, const SkRect* rect); 190 #else 191 bool GetBitmap(NodeId id, Drawing::Bitmap& bitmap); 192 #endif 193 194 int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval); 195 196 int32_t RegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback); 197 198 void SetAppWindowNum(uint32_t num); 199 200 void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow); 201 202 void ReportJankStats(); 203 204 void ReportEventResponse(DataBaseRs info); 205 206 void ReportEventComplete(DataBaseRs info); 207 208 void ReportEventJankFrame(DataBaseRs info); 209 210 void SetHardwareEnabled(NodeId id, bool isEnabled); 211 private: 212 void TriggerSurfaceCaptureCallback(NodeId id, Media::PixelMap* pixelmap); 213 std::mutex mutex_; 214 std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbRTMap_; 215 std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbUIMap_; 216 sptr<RSIScreenChangeCallback> screenChangeCb_; 217 sptr<RSISurfaceCaptureCallback> surfaceCaptureCbDirector_; 218 std::map<NodeId, std::vector<std::shared_ptr<SurfaceCaptureCallback>>> surfaceCaptureCbMap_; 219 220 friend class SurfaceCaptureCallbackDirector; 221 }; 222 } // namespace Rosen 223 } // namespace OHOS 224 225 #endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CLIENT_H 226