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 "platform/drawing/rs_surface.h" 33 #include "rs_irender_client.h" 34 #include "screen_manager/rs_screen_capability.h" 35 #include "screen_manager/rs_screen_data.h" 36 #include "screen_manager/rs_screen_hdr_capability.h" 37 #include "screen_manager/rs_screen_mode_info.h" 38 #include "screen_manager/screen_types.h" 39 #include "screen_manager/rs_virtual_screen_resolution.h" 40 #include "vsync_receiver.h" 41 #include "ipc_callbacks/rs_iocclusion_change_callback.h" 42 #include "ipc_callbacks/rs_irender_mode_change_callback.h" 43 #include "rs_occlusion_data.h" 44 45 namespace OHOS { 46 namespace Rosen { 47 // normal callback functor for client users. 48 using ScreenChangeCallback = std::function<void(ScreenId, ScreenEvent)>; 49 using BufferAvailableCallback = std::function<void()>; 50 using OcclusionChangeCallback = std::function<void(std::shared_ptr<RSOcclusionData>)>; 51 using RenderModeChangeCallback = std::function<void(bool)>; 52 class SurfaceCaptureCallback { 53 public: SurfaceCaptureCallback()54 SurfaceCaptureCallback() {} ~SurfaceCaptureCallback()55 virtual ~SurfaceCaptureCallback() {} 56 virtual void OnSurfaceCapture(std::shared_ptr<Media::PixelMap> pixelmap) = 0; 57 }; 58 59 class RSB_EXPORT RSRenderServiceClient : public RSIRenderClient { 60 public: 61 RSRenderServiceClient() = default; 62 virtual ~RSRenderServiceClient() = default; 63 64 RSRenderServiceClient(const RSRenderServiceClient&) = delete; 65 void operator=(const RSRenderServiceClient&) = delete; 66 67 void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override; 68 void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override; 69 70 int32_t SetRenderModeChangeCallback(const RenderModeChangeCallback& callback); 71 void UpdateRenderMode(bool isUniRender); 72 bool GetUniRenderEnabled(); 73 bool QueryIfRTNeedRender(); 74 bool CreateNode(const RSSurfaceRenderNodeConfig& config); 75 std::shared_ptr<RSSurface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config); 76 77 std::shared_ptr<VSyncReceiver> CreateVSyncReceiver( 78 const std::string& name, 79 const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr); 80 81 bool TakeSurfaceCapture(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX, float scaleY); 82 83 int32_t SetFocusAppInfo(int32_t pid, int32_t uid, const std::string &bundleName, const std::string &abilityName); 84 85 ScreenId GetDefaultScreenId(); 86 87 std::vector<ScreenId> GetAllScreenIds(); 88 89 #ifndef ROSEN_CROSS_PLATFORM 90 std::shared_ptr<RSSurface> CreateRSSurface(const sptr<Surface> &surface); 91 92 ScreenId CreateVirtualScreen(const std::string& name, uint32_t width, uint32_t height, sptr<Surface> surface, 93 ScreenId mirrorId, int32_t flags); 94 95 int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface); 96 #endif 97 98 void RemoveVirtualScreen(ScreenId id); 99 100 int32_t SetScreenChangeCallback(const ScreenChangeCallback& callback); 101 102 void SetScreenActiveMode(ScreenId id, uint32_t modeId); 103 104 int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height); 105 106 RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id); 107 108 void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status); 109 110 RSScreenModeInfo GetScreenActiveMode(ScreenId id); 111 112 std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id); 113 114 RSScreenCapability GetScreenCapability(ScreenId id); 115 116 ScreenPowerStatus GetScreenPowerStatus(ScreenId id); 117 118 RSScreenData GetScreenData(ScreenId id); 119 120 int32_t GetScreenBacklight(ScreenId id); 121 122 void SetScreenBacklight(ScreenId id, uint32_t level); 123 124 bool RegisterBufferAvailableListener( 125 NodeId id, const BufferAvailableCallback &callback, bool isFromRenderThread = false); 126 bool UnregisterBufferAvailableListener(NodeId id); 127 128 int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode); 129 130 int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys); 131 132 int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode); 133 134 int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx); 135 136 int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode); 137 138 int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode); 139 140 int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability); 141 142 int32_t GetScreenType(ScreenId id, RSScreenType& screenType); 143 144 int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval); 145 146 int32_t RegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback); 147 148 int32_t UnRegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback); 149 150 void SetAppWindowNum(uint32_t num); 151 private: 152 void TriggerSurfaceCaptureCallback(NodeId id, Media::PixelMap* pixelmap); 153 std::mutex mutex_; 154 std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbRTMap_; 155 std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbUIMap_; 156 sptr<RSIRenderModeChangeCallback> renderModeChangeCb_; 157 sptr<RSIScreenChangeCallback> screenChangeCb_; 158 sptr<RSISurfaceCaptureCallback> surfaceCaptureCbDirector_; 159 std::map<NodeId, std::shared_ptr<SurfaceCaptureCallback>> surfaceCaptureCbMap_; 160 161 friend class SurfaceCaptureCallbackDirector; 162 }; 163 } // namespace Rosen 164 } // namespace OHOS 165 166 #endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CLIENT_H 167