• 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 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     std::vector<ScreenId> GetAllScreenIds();
50 
51     // mirrorId: decide which screen id to mirror, INVALID_SCREEN_ID means do not mirror any screen.
52 #ifndef ROSEN_CROSS_PLATFORM
53     ScreenId CreateVirtualScreen(
54         const std::string &name,
55         uint32_t width,
56         uint32_t height,
57         sptr<Surface> surface,
58         ScreenId mirrorId = 0,
59         int flags = 0);
60 
61     int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface);
62 #endif
63 
64     void RemoveVirtualScreen(ScreenId id);
65 
66     int32_t SetScreenChangeCallback(const ScreenChangeCallback &callback);
67 
68     bool TakeSurfaceCapture(std::shared_ptr<RSSurfaceNode> node,
69         std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX = 1.0f, float scaleY = 1.0f);
70 
71     bool TakeSurfaceCapture(std::shared_ptr<RSDisplayNode> node,
72         std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX = 1.0f, float scaleY = 1.0f);
73 
74     bool TakeSurfaceCapture(NodeId id,
75         std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX = 1.0f, float scaleY = 1.0f);
76 
77     bool TakeSurfaceCaptureForUI(std::shared_ptr<RSNode> node,
78         std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX = 1.f, float scaleY = 1.f);
79 
80     void SetScreenActiveMode(ScreenId id, uint32_t modeId);
81 
82     MemoryGraphic GetMemoryGraphic(int pid);
83 
84     std::vector<MemoryGraphic> GetMemoryGraphics();
85 
86     int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height);
87 
88     RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id);
89 
90     void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status);
91 
92     RSScreenModeInfo GetScreenActiveMode(ScreenId id);
93 
94     void SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate);
95 
96     void SetRefreshRateMode(int32_t refreshRateMode);
97 
98     uint32_t GetScreenCurrentRefreshRate(ScreenId id);
99 
100     std::vector<uint32_t> GetScreenSupportedRefreshRates(ScreenId id);
101 
102     std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id);
103 
104     RSScreenCapability GetScreenCapability(ScreenId id);
105 
106     ScreenPowerStatus GetScreenPowerStatus(ScreenId id);
107 
108     RSScreenData GetScreenData(ScreenId id);
109 
110     int32_t GetScreenBacklight(ScreenId id);
111 
112     void SetScreenBacklight(ScreenId id, uint32_t level);
113 
114     int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode);
115 
116     int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys);
117 
118     int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode);
119 
120     int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx);
121 
122     int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode);
123 
124     int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode);
125 
126     int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability);
127 
128     int32_t GetScreenType(ScreenId id, RSScreenType& screenType);
129 
130     /* skipFrameInterval : decide how many frames apart to refresh a frame,
131        DEFAULT_SKIP_FRAME_INTERVAL means refresh each frame,
132        change screen refresh rate finally */
133     int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval);
134 
135     std::shared_ptr<VSyncReceiver> CreateVSyncReceiver(
136         const std::string& name,
137         const std::shared_ptr<OHOS::AppExecFwk::EventHandler> &looper = nullptr);
138 
139     int32_t RegisterOcclusionChangeCallback(const OcclusionChangeCallback& callback);
140 
141     void SetAppWindowNum(uint32_t num);
142 
143     void ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow);
144 
145     void ReportJankStats();
146 
147     void ReportEventResponse(DataBaseRs info);
148 
149     void ReportEventComplete(DataBaseRs info);
150 
151     void ReportEventJankFrame(DataBaseRs info);
152 private:
153     RSInterfaces();
154     ~RSInterfaces() noexcept;
155 
156     bool TakeSurfaceCaptureForUIWithoutUni(NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback,
157         float scaleX, float scaleY);
158 
159     std::unique_ptr<RSRenderServiceClient> renderServiceClient_;
160     std::mutex offscreenRenderMutex_;
161     int offscreenRenderNum_ = 0;
162 };
163 } // namespace Rosen
164 } // namespace OHOS
165 
166 #endif // RENDER_SERVICE_CLIENT_CORE_TRANSACTION_RS_INTERFACES_H
167