• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H
17 #define RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H
18 
19 #include <mutex>
20 #include <unordered_set>
21 
22 #include "ipc_callbacks/buffer_available_callback.h"
23 #include "pipeline/rs_render_service.h"
24 #include "screen_manager/rs_screen_manager.h"
25 #include "transaction/rs_render_service_connection_stub.h"
26 #include "vsync_distributor.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 class RSRenderServiceConnection : public RSRenderServiceConnectionStub {
31 public:
32     RSRenderServiceConnection(
33         pid_t remotePid,
34         wptr<RSRenderService> renderService,
35         RSMainThread* mainThread,
36         sptr<RSScreenManager> screenManager,
37         sptr<IRemoteObject> token,
38         sptr<VSyncDistributor> distributor);
39     ~RSRenderServiceConnection() noexcept;
40     RSRenderServiceConnection(const RSRenderServiceConnection&) = delete;
41     RSRenderServiceConnection& operator=(const RSRenderServiceConnection&) = delete;
42 
GetToken()43     sptr<IRemoteObject> GetToken() const
44     {
45         return token_;
46     }
47 
48 private:
49     void CleanVirtualScreens() noexcept;
50     void CleanRenderNodes() noexcept;
51     void CleanAll(bool toDelete = false) noexcept;
52 
53     // IPC RSIRenderServiceConnection Interfaces
54     void CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData) override;
55     void ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task) override;
56 
57     int32_t SetRenderModeChangeCallback(sptr<RSIRenderModeChangeCallback> callback) override;
58     void UpdateRenderMode(bool isUniRender) override;
59     bool GetUniRenderEnabled() override;
60     bool QueryIfRTNeedRender() override;
61 
62     bool CreateNode(const RSSurfaceRenderNodeConfig& config) override;
63     sptr<Surface> CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config) override;
64 
65     sptr<IVSyncConnection> CreateVSyncConnection(const std::string& name) override;
66 
67     int32_t SetFocusAppInfo(
68         int32_t pid, int32_t uid, const std::string &bundleName, const std::string &abilityName) override;
69 
70     ScreenId GetDefaultScreenId() override;
71 
72     std::vector<ScreenId> GetAllScreenIds() override;
73 
74     ScreenId CreateVirtualScreen(
75         const std::string &name,
76         uint32_t width,
77         uint32_t height,
78         sptr<Surface> surface,
79         ScreenId mirrorId = 0,
80         int32_t flags = 0) override;
81 
82     int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface) override;
83 
84     void RemoveVirtualScreen(ScreenId id) override;
85 
86     int32_t SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback) override;
87 
88     void SetScreenActiveMode(ScreenId id, uint32_t modeId) override;
89 
90     int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height) override;
91 
92     void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status) override;
93 
94     void TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback, float scaleX, float scaleY) override;
95 
96     void RegisterApplicationAgent(uint32_t pid, sptr<IApplicationAgent> app) override;
97 
98     void UnRegisterApplicationAgent(sptr<IApplicationAgent> app);
99 
100     RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id) override;
101 
102     RSScreenModeInfo GetScreenActiveMode(ScreenId id) override;
103 
104     std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id) override;
105 
106     RSScreenCapability GetScreenCapability(ScreenId id) override;
107 
108     ScreenPowerStatus GetScreenPowerStatus(ScreenId id) override;
109 
110     RSScreenData GetScreenData(ScreenId id) override;
111 
112     int32_t GetScreenBacklight(ScreenId id) override;
113 
114     void SetScreenBacklight(ScreenId id, uint32_t level) override;
115 
116     void RegisterBufferAvailableListener(
117         NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread) override;
118 
119     int32_t GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode) override;
120 
121     int32_t GetScreenSupportedMetaDataKeys(ScreenId id, std::vector<ScreenHDRMetadataKey>& keys) override;
122 
123     int32_t GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode) override;
124 
125     int32_t SetScreenColorGamut(ScreenId id, int32_t modeIdx) override;
126 
127     int32_t SetScreenGamutMap(ScreenId id, ScreenGamutMap mode) override;
128 
129     int32_t GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode) override;
130 
131     int32_t GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability) override;
132 
133     int32_t GetScreenType(ScreenId id, RSScreenType& screenType) override;
134 
135     int32_t SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval) override;
136 
137     int32_t RegisterOcclusionChangeCallback(sptr<RSIOcclusionChangeCallback> callback) override;
138 
139     int32_t UnRegisterOcclusionChangeCallback(sptr<RSIOcclusionChangeCallback> callback) override;
140 
141     void SetAppWindowNum(uint32_t num) override;
142 
143     pid_t remotePid_;
144     wptr<RSRenderService> renderService_;
145     RSMainThread* mainThread_ = nullptr;
146     sptr<RSScreenManager> screenManager_;
147     sptr<IRemoteObject> token_;
148 
149     class RSConnectionDeathRecipient : public IRemoteObject::DeathRecipient {
150     public:
151         explicit RSConnectionDeathRecipient(wptr<RSRenderServiceConnection> conn);
152         virtual ~RSConnectionDeathRecipient() = default;
153 
154         void OnRemoteDied(const wptr<IRemoteObject>& token) override;
155 
156     private:
157         wptr<RSRenderServiceConnection> conn_;
158     };
159     friend class RSConnectionDeathRecipient;
160     sptr<RSConnectionDeathRecipient> connDeathRecipient_;
161 
162     class RSApplicationRenderThreadDeathRecipient : public IRemoteObject::DeathRecipient {
163     public:
164         explicit RSApplicationRenderThreadDeathRecipient(wptr<RSRenderServiceConnection> conn);
165         virtual ~RSApplicationRenderThreadDeathRecipient() = default;
166 
167         void OnRemoteDied(const wptr<IRemoteObject>& token) override;
168 
169     private:
170         wptr<RSRenderServiceConnection> conn_;
171     };
172     friend class RSApplicationRenderThreadDeathRecipient;
173     sptr<RSApplicationRenderThreadDeathRecipient> ApplicationDeathRecipient_;
174 
175     mutable std::mutex mutex_;
176     bool cleanDone_ = false;
177 
178     // save all virtual screenIds created by this connection.
179     std::unordered_set<ScreenId> virtualScreenIds_;
180     sptr<RSIScreenChangeCallback> screenChangeCallback_;
181     sptr<VSyncDistributor> appVSyncDistributor_;
182     std::vector<sptr<VSyncConnection>> vsyncConnections_;
183 };
184 } // namespace Rosen
185 } // namespace OHOS
186 
187 #endif // RENDER_SERVICE_PIPELINE_RS_RENDER_SERVICE_CONNECTION_H
188