• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <shared_mutex>
24 #include <refbase.h>
25 #include <surface_type.h>
26 #ifndef ROSEN_CROSS_PLATFORM
27 #include <surface.h>
28 #endif
29 
30 #include "ipc_callbacks/buffer_available_callback.h"
31 #include "ipc_callbacks/iapplication_agent.h"
32 #include "ipc_callbacks/rs_surface_buffer_callback.h"
33 #include "ipc_callbacks/screen_change_callback.h"
34 #include "ipc_callbacks/surface_capture_callback.h"
35 #include "memory/rs_memory_graphic.h"
36 #ifdef NEW_RENDER_CONTEXT
37 #include "render_backend/rs_render_surface.h"
38 #else
39 #include "platform/drawing/rs_surface.h"
40 #endif
41 #include "rs_irender_client.h"
42 #include "variable_frame_rate/rs_variable_frame_rate.h"
43 #include "screen_manager/rs_screen_capability.h"
44 #include "screen_manager/rs_screen_data.h"
45 #include "screen_manager/rs_screen_hdr_capability.h"
46 #include "screen_manager/rs_screen_mode_info.h"
47 #include "screen_manager/screen_types.h"
48 #include "screen_manager/rs_virtual_screen_resolution.h"
49 #include "vsync_receiver.h"
50 #include "ipc_callbacks/rs_iocclusion_change_callback.h"
51 #include "rs_hgm_config_data.h"
52 #include "rs_occlusion_data.h"
53 #include "rs_uiextension_data.h"
54 #include "info_collection/rs_gpu_dirty_region_collection.h"
55 #include "info_collection/rs_hardware_compose_disabled_reason_collection.h"
56 #include "info_collection/rs_layer_compose_collection.h"
57 
58 namespace OHOS {
59 namespace Rosen {
60 // normal callback functor for client users.
61 using ScreenChangeCallback = std::function<void(ScreenId, ScreenEvent)>;
62 using BufferAvailableCallback = std::function<void()>;
63 using BufferClearCallback = std::function<void()>;
64 using OcclusionChangeCallback = std::function<void(std::shared_ptr<RSOcclusionData>)>;
65 using SurfaceOcclusionChangeCallback = std::function<void(float)>;
66 using HgmConfigChangeCallback = std::function<void(std::shared_ptr<RSHgmConfigData>)>;
67 using OnRemoteDiedCallback = std::function<void()>;
68 using HgmRefreshRateModeChangeCallback = std::function<void(int32_t)>;
69 using HgmRefreshRateUpdateCallback = std::function<void(int32_t)>;
70 using FrameRateLinkerExpectedFpsUpdateCallback = std::function<void(int32_t, int32_t)>;
71 using UIExtensionCallback = std::function<void(std::shared_ptr<RSUIExtensionData>, uint64_t)>;
72 struct DataBaseRs {
73     int32_t appPid = -1;
74     int32_t eventType = -1;
75     int32_t versionCode = -1;
76     int64_t uniqueId = 0;
77     int64_t inputTime = 0;
78     int64_t beginVsyncTime = 0;
79     int64_t endVsyncTime = 0;
80     bool isDisplayAnimator = false;
81     std::string sceneId;
82     std::string versionName;
83     std::string bundleName;
84     std::string processName;
85     std::string abilityName;
86     std::string pageUrl;
87     std::string sourceType;
88     std::string note;
89 };
90 
91 struct GameStateData {
92     int32_t pid = -1;
93     int32_t uid = 0;
94     int32_t state = 0;
95     int32_t renderTid = -1;
96     std::string bundleName;
97 };
98 
99 class SurfaceCaptureCallback {
100 public:
SurfaceCaptureCallback()101     SurfaceCaptureCallback() {}
~SurfaceCaptureCallback()102     virtual ~SurfaceCaptureCallback() {}
103     virtual void OnSurfaceCapture(std::shared_ptr<Media::PixelMap> pixelmap) = 0;
104 };
105 
106 class SurfaceBufferCallback {
107 public:
108     SurfaceBufferCallback() = default;
109     virtual ~SurfaceBufferCallback() noexcept = default;
110     virtual void OnFinish(const FinishCallbackRet& ret) = 0;
111     virtual void OnAfterAcquireBuffer(const AfterAcquireBufferRet& ret) = 0;
112 };
113 
114 class RSB_EXPORT RSRenderServiceClient : public RSIRenderClient {
115 public:
116     RSRenderServiceClient() = default;
117     virtual ~RSRenderServiceClient() = default;
118 
119     RSRenderServiceClient(const RSRenderServiceClient&) = delete;
120     void operator=(const RSRenderServiceClient&) = delete;
121 
122     void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override;
123     void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override;
124 
125     bool GetUniRenderEnabled();
126 
127     bool CreateNode(const RSSurfaceRenderNodeConfig& config);
128     bool CreateNode(const RSDisplayNodeConfig& displayNodeConfig, NodeId nodeId);
129 #ifdef NEW_RENDER_CONTEXT
130     std::shared_ptr<RSRenderSurface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config,
131         bool unobscured = false);
132 #else
133     std::shared_ptr<RSSurface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config,
134         bool unobscured = false);
135 #endif
136     std::shared_ptr<VSyncReceiver> CreateVSyncReceiver(
137         const std::string& name,
138         const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr,
139         uint64_t id = 0,
140         NodeId windowNodeId = 0,
141         bool fromXcomponent = false);
142 
143     std::shared_ptr<Media::PixelMap> CreatePixelMapFromSurfaceId(uint64_t surfaceid, const Rect &srcRect);
144 
145     bool TakeSurfaceCapture(
146         NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback, const RSSurfaceCaptureConfig& captureConfig,
147         const Drawing::Rect& specifiedAreaRect = Drawing::Rect(0.f, 0.f, 0.f, 0.f));
148 
149     bool SetWindowFreezeImmediately(NodeId id, bool isFreeze, std::shared_ptr<SurfaceCaptureCallback> callback,
150         const RSSurfaceCaptureConfig& captureConfig);
151 
152     int32_t SetFocusAppInfo(int32_t pid, int32_t uid, const std::string &bundleName, const std::string &abilityName,
153         uint64_t focusNodeId);
154 
155     ScreenId GetDefaultScreenId();
156     ScreenId GetActiveScreenId();
157 
158     std::vector<ScreenId> GetAllScreenIds();
159 
160 #ifndef ROSEN_CROSS_PLATFORM
161 #if defined(NEW_RENDER_CONTEXT)
162     std::shared_ptr<RSRenderSurface> CreateRSSurface(const sptr<Surface> &surface);
163 #else
164     std::shared_ptr<RSSurface> CreateRSSurface(const sptr<Surface> &surface);
165 #endif
166     ScreenId CreateVirtualScreen(const std::string& name, uint32_t width, uint32_t height, sptr<Surface> surface,
167         ScreenId mirrorId, int32_t flags, std::vector<NodeId> whiteList = {});
168 
169     int32_t SetVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector);
170 
171     int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface);
172 
173     int32_t AddVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector);
174 
175     int32_t RemoveVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector);
176 #endif
177 
178     int32_t SetVirtualScreenSecurityExemptionList(ScreenId id, const std::vector<NodeId>& securityExemptionList);
179 
180     int32_t SetCastScreenEnableSkipWindow(ScreenId id, bool enable);
181 
182     void RemoveVirtualScreen(ScreenId id);
183 
184     int32_t SetScreenChangeCallback(const ScreenChangeCallback& callback);
185 
186 #ifndef ROSEN_ARKUI_X
187     void SetScreenActiveMode(ScreenId id, uint32_t modeId);
188 #endif // !ROSEN_ARKUI_X
189     void SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate);
190 
191     void SetRefreshRateMode(int32_t refreshRateMode);
192 
193     void SyncFrameRateRange(FrameRateLinkerId id, const FrameRateRange& range,
194         int32_t animatorExpectedFrameRate);
195 
196     void UnregisterFrameRateLinker(FrameRateLinkerId id);
197 
198     uint32_t GetScreenCurrentRefreshRate(ScreenId id);
199 
200     int32_t GetCurrentRefreshRateMode();
201 
202     std::vector<int32_t> GetScreenSupportedRefreshRates(ScreenId id);
203 
204     bool GetShowRefreshRateEnabled();
205 
206     void SetShowRefreshRateEnabled(bool enable);
207 
208     std::string GetRefreshInfo(pid_t pid);
209 
210 #ifndef ROSEN_ARKUI_X
211     int32_t SetPhysicalScreenResolution(ScreenId id, uint32_t width, uint32_t height);
212 
213     int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height);
214 
215     RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id);
216 
217     void MarkPowerOffNeedProcessOneFrame();
218 
219     void DisablePowerOffRenderControl(ScreenId id);
220 
221     void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status);
222 
223     RSScreenModeInfo GetScreenActiveMode(ScreenId id);
224 
225     std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id);
226 
227     RSScreenCapability GetScreenCapability(ScreenId id);
228 
229     ScreenPowerStatus GetScreenPowerStatus(ScreenId id);
230 
231     RSScreenData GetScreenData(ScreenId id);
232 
233     MemoryGraphic GetMemoryGraphic(int pid);
234 
235     std::vector<MemoryGraphic> GetMemoryGraphics();
236 #endif // !ROSEN_ARKUI_X
237     bool GetTotalAppMemSize(float& cpuMemSize, float& gpuMemSize);
238 
239     int32_t GetScreenBacklight(ScreenId id);
240 
241     void SetScreenBacklight(ScreenId id, uint32_t level);
242 
243     bool RegisterBufferAvailableListener(
244         NodeId id, const BufferAvailableCallback &callback, bool isFromRenderThread = false);
245 
246     bool RegisterBufferClearListener(
247         NodeId id, const BufferClearCallback &callback);
248 
249     bool UnregisterBufferAvailableListener(NodeId id);
250 
251     int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode);
252 
253     int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys);
254 
255     int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode);
256 
257     int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx);
258 
259     int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode);
260 
261     int32_t SetScreenCorrection(ScreenId id, ScreenRotation screenRotation);
262 
263     bool SetVirtualMirrorScreenCanvasRotation(ScreenId id, bool canvasRotation);
264 
265     bool SetVirtualMirrorScreenScaleMode(ScreenId id, ScreenScaleMode scaleMode);
266 
267     bool SetGlobalDarkColorMode(bool isDark);
268 
269     int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode);
270 
271     int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability);
272 
273     int32_t GetPixelFormat(ScreenId id, GraphicPixelFormat& pixelFormat);
274 
275     int32_t SetPixelFormat(ScreenId id, GraphicPixelFormat pixelFormat);
276 
277     int32_t GetScreenSupportedHDRFormats(ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats);
278 
279     int32_t GetScreenHDRFormat(ScreenId id, ScreenHDRFormat& hdrFormat);
280 
281     int32_t SetScreenHDRFormat(ScreenId id, int32_t modeIdx);
282 
283     int32_t GetScreenSupportedColorSpaces(ScreenId id, std::vector<GraphicCM_ColorSpaceType>& colorSpaces);
284 
285     int32_t GetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType& colorSpace);
286 
287     int32_t SetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType colorSpace);
288 
289     int32_t GetScreenType(ScreenId id, RSScreenType& screenType);
290 
291     bool GetBitmap(NodeId id, Drawing::Bitmap& bitmap);
292     bool GetPixelmap(NodeId id, std::shared_ptr<Media::PixelMap> pixelmap,
293         const Drawing::Rect* rect, std::shared_ptr<Drawing::DrawCmdList> drawCmdList);
294     bool RegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
295     bool UnRegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
296 
297     int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval);
298 
299     int32_t SetVirtualScreenRefreshRate(ScreenId id, uint32_t maxRefreshRate, uint32_t& actualRefreshRate);
300 
301     uint32_t SetScreenActiveRect(ScreenId id, const Rect& activeRect);
302 
303     int32_t RegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback);
304 
305     int32_t RegisterSurfaceOcclusionChangeCallback(
306         NodeId id, const SurfaceOcclusionChangeCallback& callback, std::vector<float>& partitionPoints);
307 
308     int32_t UnRegisterSurfaceOcclusionChangeCallback(NodeId id);
309 
310     int32_t RegisterHgmConfigChangeCallback(const HgmConfigChangeCallback& callback);
311 
312     int32_t RegisterHgmRefreshRateModeChangeCallback(const HgmRefreshRateModeChangeCallback& callback);
313 
314     int32_t RegisterHgmRefreshRateUpdateCallback(const HgmRefreshRateUpdateCallback& callback);
315 
316     int32_t RegisterFrameRateLinkerExpectedFpsUpdateCallback(int32_t dstPid,
317         const FrameRateLinkerExpectedFpsUpdateCallback& callback);
318 
319     void SetAppWindowNum(uint32_t num);
320 
321     bool SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedScenes);
322 
323     void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow);
324 
325     int32_t ResizeVirtualScreen(ScreenId id, uint32_t width, uint32_t height);
326 
327     void ReportJankStats();
328 
329     void NotifyLightFactorStatus(bool isSafe);
330 
331     void NotifyPackageEvent(uint32_t listSize, const std::vector<std::string>& packageList);
332 
333     void NotifyRefreshRateEvent(const EventInfo& eventInfo);
334 
335     void NotifyTouchEvent(int32_t touchStatus, int32_t touchCnt);
336 
337     void NotifyDynamicModeEvent(bool enableDynamicMode);
338 
339     void ReportEventResponse(DataBaseRs info);
340 
341     void ReportEventComplete(DataBaseRs info);
342 
343     void ReportEventJankFrame(DataBaseRs info);
344 
345     void ReportGameStateData(GameStateData info);
346 
347     void SetHardwareEnabled(NodeId id, bool isEnabled, SelfDrawingNodeType selfDrawingType, bool dynamicHardwareEnable);
348 
349     uint32_t SetHidePrivacyContent(NodeId id, bool needHidePrivacyContent);
350 
351     void SetCacheEnabledForRotation(bool isEnabled);
352 
353     void SetOnRemoteDiedCallback(const OnRemoteDiedCallback& callback);
354 
355     std::vector<ActiveDirtyRegionInfo> GetActiveDirtyRegionInfo();
356 
357     GlobalDirtyRegionInfo GetGlobalDirtyRegionInfo();
358 
359     LayerComposeInfo GetLayerComposeInfo();
360 
361     HwcDisabledReasonInfos GetHwcDisabledReasonInfo();
362 
363     void SetVmaCacheStatus(bool flag);
364 
365     int32_t RegisterUIExtensionCallback(uint64_t userId, const UIExtensionCallback& callback, bool unobscured = false);
366 
367     bool SetAncoForceDoDirect(bool direct);
368 
369     void SetLayerTop(const std::string &nodeIdStr, bool isTop);
370 #ifdef TP_FEATURE_ENABLE
371     void SetTpFeatureConfig(int32_t feature, const char* config,
372         TpFeatureConfigType tpFeatureConfigType = TpFeatureConfigType::DEFAULT_TP_FEATURE);
373 #endif
374     void SetVirtualScreenUsingStatus(bool isVirtualScreenUsingStatus);
375     void SetCurtainScreenUsingStatus(bool isCurtainScreenOn);
376 
377     void DropFrameByPid(const std::vector<int32_t> pidList);
378 
379     bool RegisterSurfaceBufferCallback(pid_t pid, uint64_t uid,
380         std::shared_ptr<SurfaceBufferCallback> callback);
381 
382     bool UnregisterSurfaceBufferCallback(pid_t pid, uint64_t uid);
383 
384     void NotifyScreenSwitched();
385 
386     void SetWindowContainer(NodeId nodeId, bool value);
387 private:
388     void TriggerSurfaceCaptureCallback(NodeId id, std::shared_ptr<Media::PixelMap> pixelmap);
389     void TriggerOnFinish(const FinishCallbackRet& ret) const;
390     void TriggerOnAfterAcquireBuffer(const AfterAcquireBufferRet& ret) const;
391 
392     std::mutex mutex_;
393     std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbRTMap_;
394     std::mutex mapMutex_;
395     std::map<NodeId, sptr<RSIBufferAvailableCallback>> bufferAvailableCbUIMap_;
396     sptr<RSIScreenChangeCallback> screenChangeCb_;
397     sptr<RSISurfaceCaptureCallback> surfaceCaptureCbDirector_;
398     std::map<NodeId, std::vector<std::shared_ptr<SurfaceCaptureCallback>>> surfaceCaptureCbMap_;
399 
400     sptr<RSISurfaceBufferCallback> surfaceBufferCbDirector_;
401     std::map<uint64_t, std::shared_ptr<SurfaceBufferCallback>> surfaceBufferCallbacks_;
402     mutable std::shared_mutex surfaceBufferCallbackMutex_;
403 
404     friend class SurfaceCaptureCallbackDirector;
405     friend class SurfaceBufferCallbackDirector;
406 };
407 } // namespace Rosen
408 } // namespace OHOS
409 
410 #endif // ROSEN_RENDER_SERVICE_BASE_TRANSACTION_RS_RENDER_SERVICE_CLIENT_H
411