• 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 #include "rs_render_service_connection_proxy.h"
17 
18 #include <algorithm>
19 #include <cstdint>
20 #include <message_option.h>
21 #include <message_parcel.h>
22 #include <vector>
23 #include "platform/common/rs_log.h"
24 #include "platform/common/rs_system_properties.h"
25 #include "transaction/rs_ashmem_helper.h"
26 #include "transaction/rs_marshalling_helper.h"
27 #include "rs_trace.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace {
32 static constexpr size_t ASHMEM_SIZE_THRESHOLD = 400 * 1024; // cannot > 500K in TF_ASYNC mode
33 }
34 
RSRenderServiceConnectionProxy(const sptr<IRemoteObject> & impl)35 RSRenderServiceConnectionProxy::RSRenderServiceConnectionProxy(const sptr<IRemoteObject>& impl)
36     : IRemoteProxy<RSIRenderServiceConnection>(impl)
37 {
38 }
39 
CommitTransaction(std::unique_ptr<RSTransactionData> & transactionData)40 void RSRenderServiceConnectionProxy::CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData)
41 {
42     if (!transactionData) {
43         ROSEN_LOGE("RSRenderServiceConnectionProxy::CommitTransaction transactionData nullptr!");
44         return;
45     }
46     bool isUniMode = RSSystemProperties::GetUniRenderEnabled();
47     transactionData->SetSendingPid(pid_);
48 
49     // split to several parcels if parcel size > PARCEL_SPLIT_THRESHOLD during marshalling
50     std::vector<std::shared_ptr<MessageParcel>> parcelVector;
51     auto func = [isUniMode, &parcelVector, &transactionData, this]() -> bool {
52         if (isUniMode) {
53             ++transactionDataIndex_;
54         }
55         transactionData->SetIndex(transactionDataIndex_);
56         std::shared_ptr<MessageParcel> parcel = std::make_shared<MessageParcel>();
57         if (!FillParcelWithTransactionData(transactionData, parcel)) {
58             ROSEN_LOGE("FillParcelWithTransactionData failed!");
59             return false;
60         }
61         parcelVector.emplace_back(parcel);
62         return true;
63     };
64     if (transactionData->IsNeedSync() && transactionData->IsEmpty()) {
65         RS_TRACE_NAME("Commit empty syncTransaction");
66         func();
67     } else {
68         while (transactionData->GetMarshallingIndex() < transactionData->GetCommandCount()) {
69             if (!func()) {
70                 return;
71             }
72         }
73     }
74 
75     MessageOption option;
76     option.SetFlags(MessageOption::TF_ASYNC);
77     for (const auto& parcel : parcelVector) {
78         MessageParcel reply;
79         uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::COMMIT_TRANSACTION);
80         int32_t err = Remote()->SendRequest(code, *parcel, reply, option);
81         if (err != NO_ERROR) {
82             ROSEN_LOGE("RSRenderServiceConnectionProxy::CommitTransaction SendRequest failed, err = %{public}d", err);
83             return;
84         }
85     }
86 }
87 
ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask> & task)88 void RSRenderServiceConnectionProxy::ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task)
89 {
90     if (task == nullptr) {
91         return;
92     }
93 
94     MessageParcel data;
95     MessageParcel reply;
96     MessageOption option;
97     if (!data.WriteInterfaceToken(RSRenderServiceConnectionProxy::GetDescriptor())) {
98         return;
99     }
100     if (!task->Marshalling(data)) {
101         return;
102     }
103     option.SetFlags(MessageOption::TF_SYNC);
104     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::EXECUTE_SYNCHRONOUS_TASK);
105     int32_t err = Remote()->SendRequest(code, data, reply, option);
106     if (err != NO_ERROR) {
107         return;
108     }
109 
110     if (task->CheckHeader(reply)) {
111         task->ReadFromParcel(reply);
112     }
113 }
114 
FillParcelWithTransactionData(std::unique_ptr<RSTransactionData> & transactionData,std::shared_ptr<MessageParcel> & data)115 bool RSRenderServiceConnectionProxy::FillParcelWithTransactionData(
116     std::unique_ptr<RSTransactionData>& transactionData, std::shared_ptr<MessageParcel>& data)
117 {
118     // write a flag at the begin of parcel to identify parcel type
119     // 0: indicate normal parcel
120     // 1: indicate ashmem parcel
121     if (!data->WriteInt32(0)) {
122         ROSEN_LOGE("FillParcelWithTransactionData WriteInt32 failed");
123         return false;
124     }
125 
126     // 1. marshalling RSTransactionData
127     RS_TRACE_BEGIN("MarshRSTransactionData cmdCount:" + std::to_string(transactionData->GetCommandCount()) +
128         " transactionFlag:[" + std::to_string(pid_) + "," + std::to_string(transactionData->GetIndex()) + "]");
129     bool success = data->WriteParcelable(transactionData.get());
130     RS_TRACE_END();
131     if (!success) {
132         ROSEN_LOGE("FillParcelWithTransactionData data.WriteParcelable failed!");
133         return false;
134     }
135 
136     // 2. convert data to new ashmem parcel if size over threshold
137     std::shared_ptr<MessageParcel> ashmemParcel = nullptr;
138     if (data->GetDataSize() > ASHMEM_SIZE_THRESHOLD) {
139         ashmemParcel = RSAshmemHelper::CreateAshmemParcel(data);
140     }
141     if (ashmemParcel != nullptr) {
142         data = ashmemParcel;
143     }
144     return true;
145 }
146 
GetUniRenderEnabled()147 bool RSRenderServiceConnectionProxy::GetUniRenderEnabled()
148 {
149     MessageParcel data;
150     MessageParcel reply;
151     MessageOption option;
152 
153     option.SetFlags(MessageOption::TF_SYNC);
154     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_UNI_RENDER_ENABLED);
155     int32_t err = Remote()->SendRequest(code, data, reply, option);
156     if (err != NO_ERROR) {
157         return false;
158     }
159     return reply.ReadBool();
160 }
161 
CreateNode(const RSDisplayNodeConfig & displayNodeConfig,NodeId nodeId)162 bool RSRenderServiceConnectionProxy::CreateNode(const RSDisplayNodeConfig& displayNodeConfig, NodeId nodeId)
163 {
164     MessageParcel data;
165     MessageParcel reply;
166     MessageOption option;
167 
168     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
169         ROSEN_LOGE("RSRenderServiceConnectionProxy::CreateNode: WriteInterfaceToken err.");
170         return false;
171     }
172     if (!data.WriteUint64(nodeId)) {
173         ROSEN_LOGE("RSRenderServiceConnectionProxy::CreateNode: WriteUint64 NodeId err.");
174         return false;
175     }
176     if (!data.WriteUint64(displayNodeConfig.mirrorNodeId)) {
177         ROSEN_LOGE("RSRenderServiceConnectionProxy::CreateNode: WriteUint64 Config.MirrorNodeId err.");
178         return false;
179     }
180     if (!data.WriteUint64(displayNodeConfig.screenId)) {
181         ROSEN_LOGE("RSRenderServiceConnectionProxy::CreateNode: WriteUint64 Config.ScreenId err.");
182         return false;
183     }
184     if (!data.WriteBool(displayNodeConfig.isMirrored)) {
185         ROSEN_LOGE("RSRenderServiceConnectionProxy::CreateNode: WriteBool Config.IsMirrored err.");
186         return false;
187     }
188     option.SetFlags(MessageOption::TF_SYNC);
189     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_DISPLAY_NODE);
190     int32_t err = Remote()->SendRequest(code, data, reply, option);
191     if (err != NO_ERROR) {
192         return false;
193     }
194 
195     return reply.ReadBool();
196 }
197 
CreateNode(const RSSurfaceRenderNodeConfig & config)198 bool RSRenderServiceConnectionProxy::CreateNode(const RSSurfaceRenderNodeConfig& config)
199 {
200     MessageParcel data;
201     MessageParcel reply;
202     MessageOption option;
203 
204     if (!data.WriteUint64(config.id)) {
205         return false;
206     }
207     if (!data.WriteString(config.name)) {
208         return false;
209     }
210     if (!data.WriteString(config.bundleName)) {
211         return false;
212     }
213     option.SetFlags(MessageOption::TF_SYNC);
214     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_NODE);
215     int32_t err = Remote()->SendRequest(code, data, reply, option);
216     if (err != NO_ERROR) {
217         return false;
218     }
219 
220     return reply.ReadBool();
221 }
222 
CreateNodeAndSurface(const RSSurfaceRenderNodeConfig & config)223 sptr<Surface> RSRenderServiceConnectionProxy::CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config)
224 {
225     MessageParcel data;
226     MessageParcel reply;
227     MessageOption option;
228 
229     if (!data.WriteUint64(config.id)) {
230         return nullptr;
231     }
232     if (!data.WriteString(config.name)) {
233         return nullptr;
234     }
235     if (!data.WriteUint8(static_cast<uint8_t>(config.nodeType))) {
236         return nullptr;
237     }
238     if (!data.WriteString(config.bundleName)) {
239         return nullptr;
240     }
241     if (!data.WriteBool(config.isTextureExportNode)) {
242         return nullptr;
243     }
244     if (!data.WriteBool(config.isSync)) {
245         return nullptr;
246     }
247     if (!data.WriteUint8(static_cast<uint8_t>(config.surfaceWindowType))) {
248         return nullptr;
249     }
250     option.SetFlags(MessageOption::TF_SYNC);
251     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_NODE_AND_SURFACE);
252     int32_t err = Remote()->SendRequest(code, data, reply, option);
253     if (err != NO_ERROR) {
254         return nullptr;
255     }
256     sptr<IRemoteObject> surfaceObject = reply.ReadRemoteObject();
257     sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(surfaceObject);
258     if (bp == nullptr) {
259         return nullptr;
260     }
261     sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
262     return surface;
263 }
264 
CreateVSyncConnection(const std::string & name,const sptr<VSyncIConnectionToken> & token,uint64_t id,NodeId windowNodeId)265 sptr<IVSyncConnection> RSRenderServiceConnectionProxy::CreateVSyncConnection(const std::string& name,
266                                                                              const sptr<VSyncIConnectionToken>& token,
267                                                                              uint64_t id,
268                                                                              NodeId windowNodeId)
269 {
270     if (token == nullptr) {
271         ROSEN_LOGE("RSRenderServiceConnectionProxy::CreateVSyncConnection: token is nullptr.");
272         return nullptr;
273     }
274     MessageParcel data;
275     MessageParcel reply;
276     MessageOption option;
277 
278     data.WriteString(name);
279     data.WriteRemoteObject(token->AsObject());
280     data.WriteUint64(id);
281     data.WriteUint64(windowNodeId);
282     option.SetFlags(MessageOption::TF_SYNC);
283     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_VSYNC_CONNECTION);
284     int32_t err = Remote()->SendRequest(code, data, reply, option);
285     if (err != NO_ERROR) {
286         return nullptr;
287     }
288 
289     sptr<IRemoteObject> rObj = reply.ReadRemoteObject();
290     if (rObj == nullptr) {
291         return nullptr;
292     }
293     sptr<IVSyncConnection> conn = iface_cast<IVSyncConnection>(rObj);
294     return conn;
295 }
296 
CreatePixelMapFromSurface(sptr<Surface> surface,const Rect & srcRect)297 std::shared_ptr<Media::PixelMap> RSRenderServiceConnectionProxy::CreatePixelMapFromSurface(sptr<Surface> surface,
298     const Rect &srcRect)
299 {
300     MessageParcel data;
301     MessageParcel reply;
302     MessageOption option;
303     if (surface == nullptr) {
304         return nullptr;
305     }
306 
307     auto producer = surface->GetProducer();
308     if (producer == nullptr) {
309         return nullptr;
310     }
311 
312     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
313         return nullptr;
314     }
315     data.WriteRemoteObject(producer->AsObject());
316     data.WriteInt32(srcRect.x);
317     data.WriteInt32(srcRect.y);
318     data.WriteInt32(srcRect.w);
319     data.WriteInt32(srcRect.h);
320     option.SetFlags(MessageOption::TF_SYNC);
321     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_PIXEL_MAP_FROM_SURFACE);
322     int32_t err = Remote()->SendRequest(code, data, reply, option);
323     if (err != NO_ERROR) {
324         ROSEN_LOGE("RSRenderServiceConnectionProxy::CreatePixelMapFromSurface: Send Request err.");
325         return nullptr;
326     }
327 
328     std::shared_ptr<Media::PixelMap> pixelMap = nullptr;
329     if (reply.ReadBool()) {
330         pixelMap.reset(Media::PixelMap::Unmarshalling(reply));
331     }
332     return pixelMap;
333 }
334 
SetFocusAppInfo(int32_t pid,int32_t uid,const std::string & bundleName,const std::string & abilityName,uint64_t focusNodeId)335 int32_t RSRenderServiceConnectionProxy::SetFocusAppInfo(
336     int32_t pid, int32_t uid, const std::string &bundleName, const std::string &abilityName, uint64_t focusNodeId)
337 {
338     MessageParcel data;
339     MessageParcel reply;
340     MessageOption option;
341 
342     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
343         return WRITE_PARCEL_ERR;
344     }
345 
346     option.SetFlags(MessageOption::TF_ASYNC);
347     data.WriteInt32(pid);
348     data.WriteInt32(uid);
349     data.WriteString(bundleName);
350     data.WriteString(abilityName);
351     data.WriteUint64(focusNodeId);
352     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_FOCUS_APP_INFO);
353     int32_t err = Remote()->SendRequest(code, data, reply, option);
354     if (err != NO_ERROR) {
355         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetFocusAppInfo: Send Request err.");
356         return RS_CONNECTION_ERROR;
357     }
358     int32_t result = reply.ReadInt32();
359     return result;
360 }
361 
GetDefaultScreenId()362 ScreenId RSRenderServiceConnectionProxy::GetDefaultScreenId()
363 {
364     MessageParcel data;
365     MessageParcel reply;
366     MessageOption option;
367 
368     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
369         return INVALID_SCREEN_ID;
370     }
371 
372     option.SetFlags(MessageOption::TF_SYNC);
373     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_DEFAULT_SCREEN_ID);
374     int32_t err = Remote()->SendRequest(code, data, reply, option);
375     if (err != NO_ERROR) {
376         return INVALID_SCREEN_ID;
377     }
378 
379     ScreenId id = reply.ReadUint64();
380     return id;
381 }
382 
GetActiveScreenId()383 ScreenId RSRenderServiceConnectionProxy::GetActiveScreenId()
384 {
385     MessageParcel data;
386     MessageParcel reply;
387     MessageOption option;
388 
389     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
390         return INVALID_SCREEN_ID;
391     }
392 
393     option.SetFlags(MessageOption::TF_SYNC);
394     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ACTIVE_SCREEN_ID);
395     int32_t err = Remote()->SendRequest(code, data, reply, option);
396     if (err != NO_ERROR) {
397         return INVALID_SCREEN_ID;
398     }
399 
400     ScreenId id = reply.ReadUint64();
401     return id;
402 }
403 
GetAllScreenIds()404 std::vector<ScreenId> RSRenderServiceConnectionProxy::GetAllScreenIds()
405 {
406     MessageParcel data;
407     MessageParcel reply;
408     MessageOption option;
409     std::vector<ScreenId> screenIds;
410 
411     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
412         return std::vector<ScreenId>();
413     }
414 
415     option.SetFlags(MessageOption::TF_SYNC);
416     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ALL_SCREEN_IDS);
417     int32_t err = Remote()->SendRequest(code, data, reply, option);
418     if (err != NO_ERROR) {
419         return std::vector<ScreenId>();
420     }
421 
422     uint32_t size = reply.ReadUint32();
423     size_t readableSize = reply.GetReadableBytes() / sizeof(ScreenId);
424     size_t len = static_cast<size_t>(size);
425     if (len > readableSize || len > screenIds.max_size()) {
426         RS_LOGE("RSRenderServiceConnectionProxy GetAllScreenIds Failed read vector, size:%{public}zu,"
427             " readableSize:%{public}zu", len, readableSize);
428         return screenIds;
429     }
430     for (uint32_t i = 0; i < size; i++) {
431         screenIds.emplace_back(reply.ReadUint64());
432     }
433 
434     return screenIds;
435 }
436 
CreateVirtualScreen(const std::string & name,uint32_t width,uint32_t height,sptr<Surface> surface,ScreenId mirrorId,int32_t flags,std::vector<NodeId> whiteList)437 ScreenId RSRenderServiceConnectionProxy::CreateVirtualScreen(
438     const std::string &name,
439     uint32_t width,
440     uint32_t height,
441     sptr<Surface> surface,
442     ScreenId mirrorId,
443     int32_t flags,
444     std::vector<NodeId> whiteList)
445 {
446     MessageParcel data;
447     MessageParcel reply;
448     MessageOption option;
449 
450     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
451         return INVALID_SCREEN_ID;
452     }
453 
454     option.SetFlags(MessageOption::TF_SYNC);
455     if (!data.WriteString(name)) {
456         return INVALID_SCREEN_ID;
457     }
458     if (!data.WriteUint32(width)) {
459         return INVALID_SCREEN_ID;
460     }
461     if (!data.WriteUint32(height)) {
462         return INVALID_SCREEN_ID;
463     }
464     if (surface != nullptr) {
465         auto producer = surface->GetProducer();
466         if (producer != nullptr) {
467             if (!data.WriteBool(true)) {
468                 return INVALID_SCREEN_ID;
469             }
470             if (!data.WriteRemoteObject(producer->AsObject())) {
471                 return INVALID_SCREEN_ID;
472             }
473         } else {
474             if (!data.WriteBool(false)) {
475                 return INVALID_SCREEN_ID;
476             }
477         }
478     } else {
479         if (!data.WriteBool(false)) {
480             return INVALID_SCREEN_ID;
481         }
482     }
483     if (!data.WriteUint64(mirrorId)) {
484         return INVALID_SCREEN_ID;
485     }
486     if (!data.WriteInt32(flags)) {
487         return INVALID_SCREEN_ID;
488     }
489     if (!data.WriteUInt64Vector(whiteList)) {
490         return INVALID_SCREEN_ID;
491     }
492     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_VIRTUAL_SCREEN);
493     int32_t err = Remote()->SendRequest(code, data, reply, option);
494     if (err != NO_ERROR) {
495         return INVALID_SCREEN_ID;
496     }
497 
498     ScreenId id = reply.ReadUint64();
499     return id;
500 }
501 
SetVirtualScreenBlackList(ScreenId id,std::vector<NodeId> & blackListVector)502 int32_t RSRenderServiceConnectionProxy::SetVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector)
503 {
504     MessageParcel data;
505     MessageParcel reply;
506     MessageOption option;
507 
508     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
509         return WRITE_PARCEL_ERR;
510     }
511 
512     option.SetFlags(MessageOption::TF_ASYNC);
513     data.WriteUint64(id);
514     data.WriteUInt64Vector(blackListVector);
515     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_BLACKLIST);
516     int32_t err = Remote()->SendRequest(code, data, reply, option);
517     if (err != NO_ERROR) {
518         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVirtualScreenBlackList: Send Request err.");
519         return RS_CONNECTION_ERROR;
520     }
521 
522     int32_t status = reply.ReadInt32();
523     return status;
524 }
525 
AddVirtualScreenBlackList(ScreenId id,std::vector<NodeId> & blackListVector)526 int32_t RSRenderServiceConnectionProxy::AddVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector)
527 {
528     MessageParcel data;
529     MessageParcel reply;
530     MessageOption option;
531 
532     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
533         return WRITE_PARCEL_ERR;
534     }
535 
536     option.SetFlags(MessageOption::TF_ASYNC);
537     if (!data.WriteUint64(id)) {
538         return WRITE_PARCEL_ERR;
539     }
540     if (!data.WriteUInt64Vector(blackListVector)) {
541         return WRITE_PARCEL_ERR;
542     }
543     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::ADD_VIRTUAL_SCREEN_BLACKLIST);
544     int32_t err = Remote()->SendRequest(code, data, reply, option);
545     if (err != NO_ERROR) {
546         ROSEN_LOGE("RSRenderServiceConnectionProxy::AddVirtualScreenBlackList: Send Request err.");
547         return RS_CONNECTION_ERROR;
548     }
549 
550     int32_t status = reply.ReadInt32();
551     return status;
552 }
553 
RemoveVirtualScreenBlackList(ScreenId id,std::vector<NodeId> & blackListVector)554 int32_t RSRenderServiceConnectionProxy::RemoveVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector)
555 {
556     MessageParcel data;
557     MessageParcel reply;
558     MessageOption option;
559 
560     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
561         return WRITE_PARCEL_ERR;
562     }
563 
564     option.SetFlags(MessageOption::TF_ASYNC);
565     if (!data.WriteUint64(id)) {
566         return WRITE_PARCEL_ERR;
567     }
568     if (!data.WriteUInt64Vector(blackListVector)) {
569         return WRITE_PARCEL_ERR;
570     }
571     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REMOVE_VIRTUAL_SCREEN_BLACKLIST);
572     int32_t err = Remote()->SendRequest(code, data, reply, option);
573     if (err != NO_ERROR) {
574         ROSEN_LOGE("RSRenderServiceConnectionProxy::RemoveVirtualScreenBlackList: Send Request err.");
575         return RS_CONNECTION_ERROR;
576     }
577 
578     int32_t status = reply.ReadInt32();
579     return status;
580 }
581 
SetVirtualScreenSecurityExemptionList(ScreenId id,const std::vector<NodeId> & securityExemptionList)582 int32_t RSRenderServiceConnectionProxy::SetVirtualScreenSecurityExemptionList(
583     ScreenId id,
584     const std::vector<NodeId>& securityExemptionList)
585 {
586     MessageParcel data;
587     MessageParcel reply;
588     MessageOption option;
589 
590     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
591         return WRITE_PARCEL_ERR;
592     }
593 
594     option.SetFlags(MessageOption::TF_SYNC);
595     if (!data.WriteUint64(id)) {
596         return WRITE_PARCEL_ERR;
597     }
598     if (!data.WriteUInt64Vector(securityExemptionList)) {
599         return WRITE_PARCEL_ERR;
600     }
601     uint32_t code = static_cast<uint32_t>(
602         RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_SECURITY_EXEMPTION_LIST);
603     int32_t err = Remote()->SendRequest(code, data, reply, option);
604     if (err != NO_ERROR) {
605         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVirtualScreenSecurityExemptionList: Send Request err.");
606         return RS_CONNECTION_ERROR;
607     }
608 
609     int32_t status = reply.ReadInt32();
610     return status;
611 }
612 
SetCastScreenEnableSkipWindow(ScreenId id,bool enable)613 int32_t RSRenderServiceConnectionProxy::SetCastScreenEnableSkipWindow(ScreenId id, bool enable)
614 {
615     MessageParcel data;
616     MessageParcel reply;
617     MessageOption option;
618 
619     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
620         return WRITE_PARCEL_ERR;
621     }
622 
623     option.SetFlags(MessageOption::TF_ASYNC);
624     data.WriteUint64(id);
625     data.WriteBool(enable);
626     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_CAST_SCREEN_ENABLE_SKIP_WINDOW);
627     int32_t err = Remote()->SendRequest(code, data, reply, option);
628     if (err != NO_ERROR) {
629         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetCastScreenEnableSkipWindow: Send Request err.");
630         return RS_CONNECTION_ERROR;
631     }
632     int32_t result = reply.ReadInt32();
633     return result;
634 }
635 
SetVirtualScreenSurface(ScreenId id,sptr<Surface> surface)636 int32_t RSRenderServiceConnectionProxy::SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface)
637 {
638     if (surface == nullptr) {
639         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVirtualScreenSurface: Send surface is nullptr!");
640         return INVALID_ARGUMENTS;
641     }
642 
643     MessageParcel data;
644     MessageParcel reply;
645     MessageOption option;
646 
647     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
648         return WRITE_PARCEL_ERR;
649     }
650 
651     option.SetFlags(MessageOption::TF_ASYNC);
652     data.WriteUint64(id);
653     auto producer = surface->GetProducer();
654     data.WriteRemoteObject(producer->AsObject());
655     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_SURFACE);
656     int32_t err = Remote()->SendRequest(code, data, reply, option);
657     if (err != NO_ERROR) {
658         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVirtualScreenSurface: Send Request err.");
659         return RS_CONNECTION_ERROR;
660     }
661 
662     int32_t status = reply.ReadInt32();
663     return status;
664 }
665 
RemoveVirtualScreen(ScreenId id)666 void RSRenderServiceConnectionProxy::RemoveVirtualScreen(ScreenId id)
667 {
668     MessageParcel data;
669     MessageParcel reply;
670     MessageOption option;
671     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
672         return;
673     }
674 
675     option.SetFlags(MessageOption::TF_ASYNC);
676     data.WriteUint64(id);
677     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REMOVE_VIRTUAL_SCREEN);
678     int32_t err = Remote()->SendRequest(code, data, reply, option);
679     if (err != NO_ERROR) {
680         ROSEN_LOGE("RSRenderServiceConnectionProxy::RemoveVirtualScreen: Send Request err.");
681         return;
682     }
683 }
684 
SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback)685 int32_t RSRenderServiceConnectionProxy::SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback)
686 {
687     if (callback == nullptr) {
688         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetScreenChangeCallback: callback is nullptr.");
689         return INVALID_ARGUMENTS;
690     }
691 
692     MessageParcel data;
693     MessageParcel reply;
694     MessageOption option;
695 
696     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
697         return WRITE_PARCEL_ERR;
698     }
699 
700     option.SetFlags(MessageOption::TF_ASYNC);
701     data.WriteRemoteObject(callback->AsObject());
702     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_CHANGE_CALLBACK);
703     int32_t err = Remote()->SendRequest(code, data, reply, option);
704     if (err != NO_ERROR) {
705         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetScreenChangeCallback: Send Request err.");
706         return RS_CONNECTION_ERROR;
707     }
708     int32_t result = reply.ReadInt32();
709     return result;
710 }
711 
SetScreenActiveMode(ScreenId id,uint32_t modeId)712 void RSRenderServiceConnectionProxy::SetScreenActiveMode(ScreenId id, uint32_t modeId)
713 {
714     MessageParcel data;
715     MessageParcel reply;
716     MessageOption option;
717 
718     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
719         return;
720     }
721     option.SetFlags(MessageOption::TF_SYNC);
722     data.WriteUint64(id);
723     data.WriteUint32(modeId);
724     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_ACTIVE_MODE);
725     int32_t err = Remote()->SendRequest(code, data, reply, option);
726     if (err != NO_ERROR) {
727         return;
728     }
729 }
730 
SetScreenRefreshRate(ScreenId id,int32_t sceneId,int32_t rate)731 void RSRenderServiceConnectionProxy::SetScreenRefreshRate(ScreenId id, int32_t sceneId, int32_t rate)
732 {
733     MessageParcel data;
734     MessageParcel reply;
735     MessageOption option;
736 
737     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
738         ROSEN_LOGE("RSRenderServiceProxy failed to get descriptor");
739         return;
740     }
741     option.SetFlags(MessageOption::TF_SYNC);
742     data.WriteUint64(id);
743     data.WriteInt32(sceneId);
744     data.WriteInt32(rate);
745     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_REFRESH_RATE);
746     int32_t err = Remote()->SendRequest(code, data, reply, option);
747     if (err != NO_ERROR) {
748         ROSEN_LOGE("RSRenderServiceProxy sendrequest error : %{public}d", err);
749         return;
750     }
751 }
752 
SetRefreshRateMode(int32_t refreshRateMode)753 void RSRenderServiceConnectionProxy::SetRefreshRateMode(int32_t refreshRateMode)
754 {
755     MessageParcel data;
756     MessageParcel reply;
757     MessageOption option;
758 
759     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
760         ROSEN_LOGE("RSRenderServiceProxy failed to get descriptor");
761         return;
762     }
763     option.SetFlags(MessageOption::TF_SYNC);
764     data.WriteInt32(refreshRateMode);
765     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_REFRESH_RATE_MODE);
766     int32_t err = Remote()->SendRequest(code, data, reply, option);
767     if (err != NO_ERROR) {
768         ROSEN_LOGE("RSRenderServiceProxy sendrequest error : %{public}d", err);
769         return;
770     }
771 }
772 
SyncFrameRateRange(FrameRateLinkerId id,const FrameRateRange & range,int32_t animatorExpectedFrameRate)773 void RSRenderServiceConnectionProxy::SyncFrameRateRange(FrameRateLinkerId id, const FrameRateRange& range,
774     int32_t animatorExpectedFrameRate)
775 {
776     MessageParcel data;
777     MessageParcel reply;
778     MessageOption option;
779 
780     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
781         ROSEN_LOGE("RSRenderServiceProxy failed to get descriptor");
782         return;
783     }
784 
785     option.SetFlags(MessageOption::TF_SYNC);
786     data.WriteUint64(id);
787     data.WriteUint32(range.min_);
788     data.WriteUint32(range.max_);
789     data.WriteUint32(range.preferred_);
790     data.WriteUint32(range.type_);
791     data.WriteInt32(animatorExpectedFrameRate);
792     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SYNC_FRAME_RATE_RANGE);
793     int32_t err = Remote()->SendRequest(code, data, reply, option);
794     if (err != NO_ERROR) {
795         ROSEN_LOGE("RSRenderServiceProxy sendrequest error : %{public}d", err);
796         return;
797     }
798 }
799 
UnregisterFrameRateLinker(FrameRateLinkerId id)800 void RSRenderServiceConnectionProxy::UnregisterFrameRateLinker(FrameRateLinkerId id)
801 {
802     MessageParcel data;
803     MessageParcel reply;
804     MessageOption option;
805 
806     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
807         ROSEN_LOGE("RSRenderServiceProxy failed to get descriptor");
808         return;
809     }
810 
811     option.SetFlags(MessageOption::TF_ASYNC);
812     data.WriteUint64(id);
813     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_FRAME_RATE_LINKER);
814     int32_t err = Remote()->SendRequest(code, data, reply, option);
815     if (err != NO_ERROR) {
816         ROSEN_LOGE("RSRenderServiceProxy sendrequest error : %{public}d", err);
817         return;
818     }
819 }
820 
GetScreenCurrentRefreshRate(ScreenId id)821 uint32_t RSRenderServiceConnectionProxy::GetScreenCurrentRefreshRate(ScreenId id)
822 {
823     MessageParcel data;
824     MessageParcel reply;
825     MessageOption option;
826 
827     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
828         ROSEN_LOGE("RSRenderServiceProxy failed to get descriptor");
829         return SUCCESS;
830     }
831     option.SetFlags(MessageOption::TF_SYNC);
832     data.WriteUint64(id);
833     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_CURRENT_REFRESH_RATE);
834     int32_t err = Remote()->SendRequest(code, data, reply, option);
835     if (err != NO_ERROR) {
836         ROSEN_LOGE("RSRenderServiceProxy sendrequest error : %{public}d", err);
837         return SUCCESS;
838     }
839     uint32_t rate = reply.ReadUint32();
840     return rate;
841 }
842 
GetCurrentRefreshRateMode()843 int32_t RSRenderServiceConnectionProxy::GetCurrentRefreshRateMode()
844 {
845     MessageParcel data;
846     MessageParcel reply;
847     MessageOption option;
848 
849     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
850         ROSEN_LOGE("RSRenderServiceProxy failed to get descriptor");
851         return SUCCESS;
852     }
853     option.SetFlags(MessageOption::TF_SYNC);
854     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_CURRENT_REFRESH_RATE_MODE);
855     int32_t err = Remote()->SendRequest(code, data, reply, option);
856     if (err != NO_ERROR) {
857         ROSEN_LOGE("RSRenderServiceProxy sendrequest error : %{public}d", err);
858         return SUCCESS;
859     }
860     int32_t refreshRateMode = reply.ReadInt32();
861     return refreshRateMode;
862 }
863 
GetScreenSupportedRefreshRates(ScreenId id)864 std::vector<int32_t> RSRenderServiceConnectionProxy::GetScreenSupportedRefreshRates(ScreenId id)
865 {
866     MessageParcel data;
867     MessageParcel reply;
868     MessageOption option;
869     std::vector<int32_t> screenSupportedRates;
870 
871     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
872         ROSEN_LOGE("RSRenderServiceProxy failed to get descriptor");
873         return screenSupportedRates;
874     }
875     option.SetFlags(MessageOption::TF_SYNC);
876     data.WriteUint64(id);
877     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_REFRESH_RATES);
878     int32_t err = Remote()->SendRequest(code, data, reply, option);
879     if (err != NO_ERROR) {
880         return screenSupportedRates;
881     }
882     uint64_t rateCount = reply.ReadUint64();
883     size_t readableSize = reply.GetReadableBytes();
884     size_t len = static_cast<size_t>(rateCount);
885     if (len > readableSize || len > screenSupportedRates.max_size()) {
886         RS_LOGE("RSRenderServiceConnectionProxy GetScreenSupportedRefreshRates "
887             "fail read vector, size : %{public}zu, readableSize : %{public}zu", len, readableSize);
888         return screenSupportedRates;
889     }
890     screenSupportedRates.resize(rateCount);
891     for (uint64_t rateIndex = 0; rateIndex < rateCount; rateIndex++) {
892         screenSupportedRates[rateIndex] = reply.ReadInt32();
893     }
894     return screenSupportedRates;
895 }
896 
GetShowRefreshRateEnabled()897 bool RSRenderServiceConnectionProxy::GetShowRefreshRateEnabled()
898 {
899     MessageParcel data;
900     MessageParcel reply;
901     MessageOption option;
902 
903     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
904         ROSEN_LOGE("RSRenderServiceProxy failed to get descriptor");
905         return SUCCESS;
906     }
907     option.SetFlags(MessageOption::TF_SYNC);
908     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SHOW_REFRESH_RATE_ENABLED);
909     int32_t err = Remote()->SendRequest(code, data, reply, option);
910     if (err != NO_ERROR) {
911         ROSEN_LOGE("RSRenderServiceProxy sendrequest error : %{public}d", err);
912         return SUCCESS;
913     }
914     bool enable = reply.ReadBool();
915     return enable;
916 }
917 
SetShowRefreshRateEnabled(bool enable)918 void RSRenderServiceConnectionProxy::SetShowRefreshRateEnabled(bool enable)
919 {
920     MessageParcel data;
921     MessageParcel reply;
922     MessageOption option;
923 
924     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
925         ROSEN_LOGE("RSRenderServiceProxy failed to get descriptor");
926         return;
927     }
928     option.SetFlags(MessageOption::TF_SYNC);
929     data.WriteBool(enable);
930     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SHOW_REFRESH_RATE_ENABLED);
931     int32_t err = Remote()->SendRequest(code, data, reply, option);
932     if (err != NO_ERROR) {
933         ROSEN_LOGE("RSRenderServiceProxy sendrequest error : %{public}d", err);
934         return;
935     }
936 }
937 
GetRefreshInfo(pid_t pid)938 std::string RSRenderServiceConnectionProxy::GetRefreshInfo(pid_t pid)
939 {
940     MessageParcel data;
941     MessageParcel reply;
942     MessageOption option;
943 
944     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
945         ROSEN_LOGE("RSRenderServiceProxy failed to get descriptor");
946         return "";
947     }
948     option.SetFlags(MessageOption::TF_SYNC);
949     data.WriteInt32(pid);
950     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_REFRESH_INFO);
951     int32_t err = Remote()->SendRequest(code, data, reply, option);
952     if (err != NO_ERROR) {
953         ROSEN_LOGE("RSRenderServiceProxy sendrequest error : %{public}d", err);
954         return "";
955     }
956     std::string enable = reply.ReadString();
957     return enable;
958 }
959 
SetVirtualScreenResolution(ScreenId id,uint32_t width,uint32_t height)960 int32_t RSRenderServiceConnectionProxy::SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height)
961 {
962     MessageParcel data;
963     MessageParcel reply;
964     MessageOption option;
965 
966     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
967         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVirtualScreenResolution: WriteInterfaceToken err.");
968         return WRITE_PARCEL_ERR;
969     }
970     option.SetFlags(MessageOption::TF_SYNC);
971     data.WriteUint64(id);
972     data.WriteUint32(width);
973     data.WriteUint32(height);
974     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_RESOLUTION);
975     int32_t err = Remote()->SendRequest(code, data, reply, option);
976     if (err != NO_ERROR) {
977         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVirtualScreenResolution: Send Request err.");
978         return RS_CONNECTION_ERROR;
979     }
980     int32_t status = reply.ReadInt32();
981     return status;
982 }
983 
MarkPowerOffNeedProcessOneFrame()984 void RSRenderServiceConnectionProxy::MarkPowerOffNeedProcessOneFrame()
985 {
986     MessageParcel data;
987     MessageParcel reply;
988     MessageOption option;
989 
990     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
991         ROSEN_LOGE("RSRenderServiceConnectionProxy::MarkPowerOffNeedProcessOneFrame: Send Request err.");
992         return;
993     }
994     option.SetFlags(MessageOption::TF_SYNC);
995     uint32_t code =
996         static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::MARK_POWER_OFF_NEED_PROCESS_ONE_FRAME);
997     int32_t err = Remote()->SendRequest(code, data, reply, option);
998     if (err != NO_ERROR) {
999         return;
1000     }
1001 }
1002 
DisablePowerOffRenderControl(ScreenId id)1003 void RSRenderServiceConnectionProxy::DisablePowerOffRenderControl(ScreenId id)
1004 {
1005     MessageParcel data;
1006     MessageParcel reply;
1007     MessageOption option;
1008 
1009     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1010         ROSEN_LOGE("RSRenderServiceConnectionProxy::DisablePowerOffRenderControl: Send Request err.");
1011         return;
1012     }
1013     option.SetFlags(MessageOption::TF_SYNC);
1014     data.WriteUint64(id);
1015     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::DISABLE_RENDER_CONTROL_SCREEN);
1016     int32_t err = Remote()->SendRequest(code, data, reply, option);
1017     if (err != NO_ERROR) {
1018         return;
1019     }
1020 }
1021 
SetScreenPowerStatus(ScreenId id,ScreenPowerStatus status)1022 void RSRenderServiceConnectionProxy::SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status)
1023 {
1024     MessageParcel data;
1025     MessageParcel reply;
1026     MessageOption option;
1027 
1028     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1029         return;
1030     }
1031     option.SetFlags(MessageOption::TF_SYNC);
1032     data.WriteUint64(id);
1033     data.WriteUint32(static_cast<uint32_t>(status));
1034     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_POWER_STATUS);
1035     int32_t err = Remote()->SendRequest(code, data, reply, option);
1036     if (err != NO_ERROR) {
1037         return;
1038     }
1039 }
1040 
RegisterApplicationAgent(uint32_t pid,sptr<IApplicationAgent> app)1041 void RSRenderServiceConnectionProxy::RegisterApplicationAgent(uint32_t pid, sptr<IApplicationAgent> app)
1042 {
1043     if (app == nullptr) {
1044         ROSEN_LOGE("RSRenderServiceProxy: callback == nullptr\n");
1045         return;
1046     }
1047 
1048     MessageParcel data;
1049     MessageParcel reply;
1050     MessageOption option;
1051     option.SetFlags(MessageOption::TF_ASYNC);
1052     data.WriteUint32(pid);
1053     data.WriteRemoteObject(app->AsObject());
1054     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_APPLICATION_AGENT);
1055     int32_t err = Remote()->SendRequest(code, data, reply, option);
1056     if (err != NO_ERROR) {
1057         ROSEN_LOGE("RSRenderServiceProxy: Remote()->SendRequest() error.\n");
1058         return;
1059     }
1060 }
1061 
TakeSurfaceCapture(NodeId id,sptr<RSISurfaceCaptureCallback> callback,const RSSurfaceCaptureConfig & captureConfig,RSSurfaceCapturePermissions)1062 void RSRenderServiceConnectionProxy::TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback,
1063     const RSSurfaceCaptureConfig& captureConfig, RSSurfaceCapturePermissions /* permissions */)
1064 {
1065     if (callback == nullptr) {
1066         ROSEN_LOGE("RSRenderServiceProxy: callback == nullptr\n");
1067         return;
1068     }
1069 
1070     MessageParcel data;
1071     MessageParcel reply;
1072     MessageOption option;
1073     option.SetFlags(MessageOption::TF_ASYNC);
1074     data.WriteUint64(id);
1075     data.WriteRemoteObject(callback->AsObject());
1076     data.WriteFloat(captureConfig.scaleX);
1077     data.WriteFloat(captureConfig.scaleY);
1078     data.WriteBool(captureConfig.useDma);
1079     data.WriteBool(captureConfig.useCurWindow);
1080     data.WriteUint8(static_cast<uint8_t>(captureConfig.captureType));
1081     data.WriteBool(captureConfig.isSync);
1082     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::TAKE_SURFACE_CAPTURE);
1083     int32_t err = Remote()->SendRequest(code, data, reply, option);
1084     if (err != NO_ERROR) {
1085         ROSEN_LOGE("RSRenderServiceProxy: Remote()->SendRequest() error.\n");
1086         return;
1087     }
1088 }
1089 
GetVirtualScreenResolution(ScreenId id)1090 RSVirtualScreenResolution RSRenderServiceConnectionProxy::GetVirtualScreenResolution(ScreenId id)
1091 {
1092     MessageParcel data;
1093     MessageParcel reply;
1094     MessageOption option;
1095     RSVirtualScreenResolution virtualScreenResolution;
1096 
1097     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1098         return virtualScreenResolution;
1099     }
1100     option.SetFlags(MessageOption::TF_SYNC);
1101     data.WriteUint64(id);
1102     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_VIRTUAL_SCREEN_RESOLUTION);
1103     int32_t err = Remote()->SendRequest(code, data, reply, option);
1104     if (err != NO_ERROR) {
1105         return virtualScreenResolution;
1106     }
1107 
1108     sptr<RSVirtualScreenResolution> pVirtualScreenResolution(reply.ReadParcelable<RSVirtualScreenResolution>());
1109     if (pVirtualScreenResolution == nullptr) {
1110         return virtualScreenResolution;
1111     }
1112     virtualScreenResolution = *pVirtualScreenResolution;
1113     return virtualScreenResolution;
1114 }
1115 
GetScreenActiveMode(ScreenId id)1116 RSScreenModeInfo RSRenderServiceConnectionProxy::GetScreenActiveMode(ScreenId id)
1117 {
1118     MessageParcel data;
1119     MessageParcel reply;
1120     MessageOption option;
1121     RSScreenModeInfo screenModeInfo;
1122 
1123     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1124         return screenModeInfo;
1125     }
1126     option.SetFlags(MessageOption::TF_SYNC);
1127     data.WriteUint64(id);
1128     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_ACTIVE_MODE);
1129     int32_t err = Remote()->SendRequest(code, data, reply, option);
1130     if (err != NO_ERROR) {
1131         return screenModeInfo;
1132     }
1133 
1134     sptr<RSScreenModeInfo> pScreenModeInfo(reply.ReadParcelable<RSScreenModeInfo>());
1135     if (pScreenModeInfo == nullptr) {
1136         return screenModeInfo;
1137     }
1138     screenModeInfo = *pScreenModeInfo;
1139     return screenModeInfo;
1140 }
1141 
GetScreenSupportedModes(ScreenId id)1142 std::vector<RSScreenModeInfo> RSRenderServiceConnectionProxy::GetScreenSupportedModes(ScreenId id)
1143 {
1144     MessageParcel data;
1145     MessageParcel reply;
1146     MessageOption option;
1147     std::vector<RSScreenModeInfo> screenSupportedModes;
1148 
1149     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1150         return screenSupportedModes;
1151     }
1152 
1153     option.SetFlags(MessageOption::TF_SYNC);
1154     data.WriteUint64(id);
1155     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_MODES);
1156     int32_t err = Remote()->SendRequest(code, data, reply, option);
1157     if (err != NO_ERROR) {
1158         return screenSupportedModes;
1159     }
1160 
1161     uint64_t modeCount = reply.ReadUint64();
1162     size_t readableSize = reply.GetReadableBytes();
1163     size_t len = static_cast<size_t>(modeCount);
1164     if (len > readableSize || len > screenSupportedModes.max_size()) {
1165         RS_LOGE("RSRenderServiceConnectionProxy GetScreenSupportedModes Fail read vector, size:%{public}zu,"
1166             "readableSize:%{public}zu", len, readableSize);
1167         return screenSupportedModes;
1168     }
1169     screenSupportedModes.resize(modeCount);
1170     for (uint64_t modeIndex = 0; modeIndex < modeCount; modeIndex++) {
1171         sptr<RSScreenModeInfo> itemScreenMode = reply.ReadParcelable<RSScreenModeInfo>();
1172         if (itemScreenMode == nullptr) {
1173             continue;
1174         } else {
1175             screenSupportedModes[modeIndex] = *itemScreenMode;
1176         }
1177     }
1178     return screenSupportedModes;
1179 }
1180 
GetMemoryGraphics()1181 std::vector<MemoryGraphic> RSRenderServiceConnectionProxy::GetMemoryGraphics()
1182 {
1183     MessageParcel data;
1184     MessageParcel reply;
1185     MessageOption option;
1186     std::vector<MemoryGraphic> memoryGraphics;
1187 
1188     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1189         return memoryGraphics;
1190     }
1191 
1192     option.SetFlags(MessageOption::TF_SYNC);
1193     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_MEMORY_GRAPHICS);
1194     int32_t err = Remote()->SendRequest(code, data, reply, option);
1195     if (err != NO_ERROR) {
1196         return memoryGraphics;
1197     }
1198 
1199     uint64_t count = reply.ReadUint64();
1200     size_t readableSize = reply.GetReadableBytes();
1201     size_t len = static_cast<size_t>(count);
1202     if (len > readableSize || len > memoryGraphics.max_size()) {
1203         RS_LOGE("RSRenderServiceConnectionProxy GetMemoryGraphics Failed to read vector, size:%{public}zu,"
1204             " readableSize:%{public}zu", len, readableSize);
1205         return memoryGraphics;
1206     }
1207     memoryGraphics.resize(count);
1208     for (uint64_t index = 0; index < count; index++) {
1209         sptr<MemoryGraphic> item = reply.ReadParcelable<MemoryGraphic>();
1210         if (item == nullptr) {
1211             continue;
1212         } else {
1213             memoryGraphics[index] = *item;
1214         }
1215     }
1216     return memoryGraphics;
1217 }
1218 
GetTotalAppMemSize(float & cpuMemSize,float & gpuMemSize)1219 bool RSRenderServiceConnectionProxy::GetTotalAppMemSize(float& cpuMemSize, float& gpuMemSize)
1220 {
1221     MessageParcel data;
1222     MessageParcel reply;
1223     MessageOption option;
1224     MemoryGraphic memoryGraphic;
1225     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1226         return false;
1227     }
1228 
1229     option.SetFlags(MessageOption::TF_SYNC);
1230     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_TOTAL_APP_MEM_SIZE);
1231     int32_t err = Remote()->SendRequest(code, data, reply, option);
1232     if (err != NO_ERROR) {
1233         return false;
1234     }
1235 
1236     cpuMemSize = reply.ReadFloat();
1237     gpuMemSize = reply.ReadFloat();
1238     return true;
1239 }
1240 
GetMemoryGraphic(int pid)1241 MemoryGraphic RSRenderServiceConnectionProxy::GetMemoryGraphic(int pid)
1242 {
1243     MessageParcel data;
1244     MessageParcel reply;
1245     MessageOption option;
1246     MemoryGraphic memoryGraphic;
1247     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1248         return memoryGraphic;
1249     }
1250 
1251     option.SetFlags(MessageOption::TF_SYNC);
1252     data.WriteInt32(pid);
1253     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_MEMORY_GRAPHIC);
1254     int32_t err = Remote()->SendRequest(code, data, reply, option);
1255     if (err != NO_ERROR) {
1256         return memoryGraphic;
1257     }
1258     sptr<MemoryGraphic> pMemoryGraphic(reply.ReadParcelable<MemoryGraphic>());
1259     if (pMemoryGraphic == nullptr) {
1260         return memoryGraphic;
1261     }
1262     memoryGraphic = *pMemoryGraphic;
1263     return memoryGraphic;
1264 }
1265 
GetScreenCapability(ScreenId id)1266 RSScreenCapability RSRenderServiceConnectionProxy::GetScreenCapability(ScreenId id)
1267 {
1268     MessageParcel data;
1269     MessageParcel reply;
1270     MessageOption option;
1271     RSScreenCapability screenCapability;
1272     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1273         return screenCapability;
1274     }
1275     option.SetFlags(MessageOption::TF_SYNC);
1276     data.WriteUint64(id);
1277     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_CAPABILITY);
1278     int32_t err = Remote()->SendRequest(code, data, reply, option);
1279     if (err != NO_ERROR) {
1280         return screenCapability;
1281     }
1282 
1283     sptr<RSScreenCapability> pScreenCapability(reply.ReadParcelable<RSScreenCapability>());
1284     if (pScreenCapability == nullptr) {
1285         return screenCapability;
1286     }
1287     screenCapability = *pScreenCapability;
1288     return screenCapability;
1289 }
1290 
GetScreenPowerStatus(ScreenId id)1291 ScreenPowerStatus RSRenderServiceConnectionProxy::GetScreenPowerStatus(ScreenId id)
1292 {
1293     MessageParcel data;
1294     MessageParcel reply;
1295     MessageOption option;
1296     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1297         return INVALID_POWER_STATUS;
1298     }
1299     option.SetFlags(MessageOption::TF_SYNC);
1300     data.WriteUint64(id);
1301     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_POWER_STATUS);
1302     int32_t err = Remote()->SendRequest(code, data, reply, option);
1303     if (err != NO_ERROR) {
1304         return INVALID_POWER_STATUS;
1305     }
1306     return static_cast<ScreenPowerStatus>(reply.ReadUint32());
1307 }
1308 
GetScreenData(ScreenId id)1309 RSScreenData RSRenderServiceConnectionProxy::GetScreenData(ScreenId id)
1310 {
1311     MessageParcel data;
1312     MessageParcel reply;
1313     MessageOption option;
1314     RSScreenData screenData;
1315     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1316         return screenData;
1317     }
1318     option.SetFlags(MessageOption::TF_SYNC);
1319     data.WriteUint64(id);
1320     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_DATA);
1321     int32_t err = Remote()->SendRequest(code, data, reply, option);
1322     if (err != NO_ERROR) {
1323         return screenData;
1324     }
1325     sptr<RSScreenData> pScreenData(reply.ReadParcelable<RSScreenData>());
1326     if (pScreenData == nullptr) {
1327         return screenData;
1328     }
1329     screenData = *pScreenData;
1330     return screenData;
1331 }
1332 
GetScreenBacklight(ScreenId id)1333 int32_t RSRenderServiceConnectionProxy::GetScreenBacklight(ScreenId id)
1334 {
1335     MessageParcel data;
1336     MessageParcel reply;
1337     MessageOption option;
1338     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1339         return INVALID_BACKLIGHT_VALUE;
1340     }
1341     option.SetFlags(MessageOption::TF_SYNC);
1342     data.WriteUint64(id);
1343     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_BACK_LIGHT);
1344     int32_t err = Remote()->SendRequest(code, data, reply, option);
1345     if (err != NO_ERROR) {
1346         return INVALID_BACKLIGHT_VALUE;
1347     }
1348     int32_t level = reply.ReadInt32();
1349     return level;
1350 }
1351 
SetScreenBacklight(ScreenId id,uint32_t level)1352 void RSRenderServiceConnectionProxy::SetScreenBacklight(ScreenId id, uint32_t level)
1353 {
1354     MessageParcel data;
1355     MessageParcel reply;
1356     MessageOption option;
1357     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1358         return;
1359     }
1360     option.SetFlags(MessageOption::TF_SYNC);
1361     data.WriteUint64(id);
1362     data.WriteUint32(level);
1363     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_BACK_LIGHT);
1364     int32_t err = Remote()->SendRequest(code, data, reply, option);
1365     if (err != NO_ERROR) {
1366         return;
1367     }
1368 }
1369 
RegisterBufferClearListener(NodeId id,sptr<RSIBufferClearCallback> callback)1370 void RSRenderServiceConnectionProxy::RegisterBufferClearListener(
1371     NodeId id, sptr<RSIBufferClearCallback> callback)
1372 {
1373     if (callback == nullptr) {
1374         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterBufferClearListener: callback is nullptr.");
1375         return;
1376     }
1377 
1378     MessageParcel data;
1379     MessageParcel reply;
1380     MessageOption option;
1381 
1382     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1383         return;
1384     }
1385     option.SetFlags(MessageOption::TF_SYNC);
1386     data.WriteUint64(id);
1387     data.WriteRemoteObject(callback->AsObject());
1388     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_CLEAR_LISTENER);
1389     int32_t err = Remote()->SendRequest(code, data, reply, option);
1390     if (err != NO_ERROR) {
1391         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterBufferClearListener: Send Request err.");
1392         return;
1393     }
1394 }
1395 
RegisterBufferAvailableListener(NodeId id,sptr<RSIBufferAvailableCallback> callback,bool isFromRenderThread)1396 void RSRenderServiceConnectionProxy::RegisterBufferAvailableListener(
1397     NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread)
1398 {
1399     if (callback == nullptr) {
1400         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterBufferAvailableListener: callback is nullptr.");
1401         return;
1402     }
1403 
1404     MessageParcel data;
1405     MessageParcel reply;
1406     MessageOption option;
1407 
1408     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1409         return;
1410     }
1411 
1412     option.SetFlags(MessageOption::TF_SYNC);
1413     data.WriteUint64(id);
1414     data.WriteRemoteObject(callback->AsObject());
1415     data.WriteBool(isFromRenderThread);
1416     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_AVAILABLE_LISTENER);
1417     int32_t err = Remote()->SendRequest(code, data, reply, option);
1418     if (err != NO_ERROR) {
1419         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterBufferAvailableListener: Send Request err.");
1420         return;
1421     }
1422 }
1423 
GetScreenSupportedColorGamuts(ScreenId id,std::vector<ScreenColorGamut> & mode)1424 int32_t RSRenderServiceConnectionProxy::GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode)
1425 {
1426     MessageParcel data;
1427     MessageParcel reply;
1428     MessageOption option;
1429     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1430         return RS_CONNECTION_ERROR;
1431     }
1432     option.SetFlags(MessageOption::TF_SYNC);
1433     data.WriteUint64(id);
1434     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_GAMUTS);
1435     int32_t err = Remote()->SendRequest(code, data, reply, option);
1436     if (err != NO_ERROR) {
1437         return RS_CONNECTION_ERROR;
1438     }
1439     int32_t result = reply.ReadInt32();
1440     if (result == SUCCESS) {
1441         mode.clear();
1442         std::vector<uint32_t> modeRecv;
1443         reply.ReadUInt32Vector(&modeRecv);
1444         for (auto i : modeRecv) {
1445             mode.push_back(static_cast<ScreenColorGamut>(i));
1446         }
1447     }
1448     return result;
1449 }
1450 
GetScreenSupportedMetaDataKeys(ScreenId id,std::vector<ScreenHDRMetadataKey> & keys)1451 int32_t RSRenderServiceConnectionProxy::GetScreenSupportedMetaDataKeys(
1452     ScreenId id, std::vector<ScreenHDRMetadataKey>& keys)
1453 {
1454     MessageParcel data;
1455     MessageParcel reply;
1456     MessageOption option;
1457     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1458         return RS_CONNECTION_ERROR;
1459     }
1460     option.SetFlags(MessageOption::TF_SYNC);
1461     data.WriteUint64(id);
1462     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_METADATAKEYS);
1463     int32_t err = Remote()->SendRequest(code, data, reply, option);
1464     if (err != NO_ERROR) {
1465         return RS_CONNECTION_ERROR;
1466     }
1467     int32_t result = reply.ReadInt32();
1468     if (result == SUCCESS) {
1469         keys.clear();
1470         std::vector<uint32_t> keyRecv;
1471         reply.ReadUInt32Vector(&keyRecv);
1472         for (auto i : keyRecv) {
1473             keys.push_back(static_cast<ScreenHDRMetadataKey>(i));
1474         }
1475     }
1476     return result;
1477 }
1478 
GetScreenColorGamut(ScreenId id,ScreenColorGamut & mode)1479 int32_t RSRenderServiceConnectionProxy::GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode)
1480 {
1481     MessageParcel data;
1482     MessageParcel reply;
1483     MessageOption option;
1484     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1485         return RS_CONNECTION_ERROR;
1486     }
1487     option.SetFlags(MessageOption::TF_SYNC);
1488     data.WriteUint64(id);
1489     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_GAMUT);
1490     int32_t err = Remote()->SendRequest(code, data, reply, option);
1491     if (err != NO_ERROR) {
1492         return RS_CONNECTION_ERROR;
1493     }
1494     int32_t result = reply.ReadInt32();
1495     if (result == SUCCESS) {
1496         mode = static_cast<ScreenColorGamut>(reply.ReadUint32());
1497     }
1498     return result;
1499 }
1500 
SetScreenColorGamut(ScreenId id,int32_t modeIdx)1501 int32_t RSRenderServiceConnectionProxy::SetScreenColorGamut(ScreenId id, int32_t modeIdx)
1502 {
1503     MessageParcel data;
1504     MessageParcel reply;
1505     MessageOption option;
1506     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1507         return RS_CONNECTION_ERROR;
1508     }
1509     option.SetFlags(MessageOption::TF_SYNC);
1510     data.WriteUint64(id);
1511     data.WriteInt32(modeIdx);
1512     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_GAMUT);
1513     int32_t err = Remote()->SendRequest(code, data, reply, option);
1514     if (err != NO_ERROR) {
1515         return RS_CONNECTION_ERROR;
1516     }
1517     int32_t result = reply.ReadInt32();
1518     return result;
1519 }
1520 
SetScreenGamutMap(ScreenId id,ScreenGamutMap mode)1521 int32_t RSRenderServiceConnectionProxy::SetScreenGamutMap(ScreenId id, ScreenGamutMap mode)
1522 {
1523     MessageParcel data;
1524     MessageParcel reply;
1525     MessageOption option;
1526     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1527         return RS_CONNECTION_ERROR;
1528     }
1529     option.SetFlags(MessageOption::TF_SYNC);
1530     data.WriteUint64(id);
1531     data.WriteUint32(mode);
1532     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_GAMUT_MAP);
1533     int32_t err = Remote()->SendRequest(code, data, reply, option);
1534     if (err != NO_ERROR) {
1535         return RS_CONNECTION_ERROR;
1536     }
1537     int32_t result = reply.ReadInt32();
1538     return result;
1539 }
1540 
SetScreenCorrection(ScreenId id,ScreenRotation screenRotation)1541 int32_t RSRenderServiceConnectionProxy::SetScreenCorrection(ScreenId id, ScreenRotation screenRotation)
1542 {
1543     MessageParcel data;
1544     MessageParcel reply;
1545     MessageOption option;
1546     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1547         return RS_CONNECTION_ERROR;
1548     }
1549     option.SetFlags(MessageOption::TF_SYNC);
1550     data.WriteUint64(id);
1551     data.WriteUint32(static_cast<uint32_t>(screenRotation));
1552     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_CORRECTION);
1553     int32_t err = Remote()->SendRequest(code, data, reply, option);
1554     if (err != NO_ERROR) {
1555         return RS_CONNECTION_ERROR;
1556     }
1557     int32_t result = reply.ReadInt32();
1558     return result;
1559 }
1560 
GetScreenGamutMap(ScreenId id,ScreenGamutMap & mode)1561 int32_t RSRenderServiceConnectionProxy::GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode)
1562 {
1563     MessageParcel data;
1564     MessageParcel reply;
1565     MessageOption option;
1566     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1567         return RS_CONNECTION_ERROR;
1568     }
1569     option.SetFlags(MessageOption::TF_SYNC);
1570     data.WriteUint64(id);
1571     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_GAMUT_MAP);
1572     int32_t err = Remote()->SendRequest(code, data, reply, option);
1573     if (err != NO_ERROR) {
1574         return RS_CONNECTION_ERROR;
1575     }
1576     int32_t result = reply.ReadInt32();
1577     if (result == SUCCESS) {
1578         mode = static_cast<ScreenGamutMap>(reply.ReadUint32());
1579     }
1580     return result;
1581 }
1582 
GetScreenHDRCapability(ScreenId id,RSScreenHDRCapability & screenHdrCapability)1583 int32_t RSRenderServiceConnectionProxy::GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability)
1584 {
1585     MessageParcel data;
1586     MessageParcel reply;
1587     MessageOption option;
1588     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1589         return RS_CONNECTION_ERROR;
1590     }
1591     option.SetFlags(MessageOption::TF_SYNC);
1592     data.WriteUint64(id);
1593     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_HDR_CAPABILITY);
1594     int32_t err = Remote()->SendRequest(code, data, reply, option);
1595     if (err != NO_ERROR) {
1596         return RS_CONNECTION_ERROR;
1597     }
1598     int32_t result = reply.ReadInt32();
1599     if (result != SUCCESS) {
1600         return result;
1601     }
1602     sptr<RSScreenHDRCapability> pScreenCapability = reply.ReadParcelable<RSScreenHDRCapability>();
1603     if (pScreenCapability == nullptr) {
1604         return RS_CONNECTION_ERROR;
1605     }
1606     screenHdrCapability = *pScreenCapability;
1607     return SUCCESS;
1608 }
1609 
GetPixelFormat(ScreenId id,GraphicPixelFormat & pixelFormat)1610 int32_t RSRenderServiceConnectionProxy::GetPixelFormat(ScreenId id, GraphicPixelFormat& pixelFormat)
1611 {
1612     MessageParcel data;
1613     MessageParcel reply;
1614     MessageOption option;
1615 
1616     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1617         return WRITE_PARCEL_ERR;
1618     }
1619     option.SetFlags(MessageOption::TF_SYNC);
1620     data.WriteUint64(id);
1621     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_PIXEL_FORMAT);
1622     int32_t err = Remote()->SendRequest(code, data, reply, option);
1623     if (err != NO_ERROR) {
1624         return RS_CONNECTION_ERROR;
1625     }
1626     int32_t result = reply.ReadInt32();
1627     if (result == SUCCESS) {
1628         pixelFormat = static_cast<GraphicPixelFormat>(reply.ReadUint32());
1629     }
1630     return result;
1631 }
1632 
SetPixelFormat(ScreenId id,GraphicPixelFormat pixelFormat)1633 int32_t RSRenderServiceConnectionProxy::SetPixelFormat(ScreenId id, GraphicPixelFormat pixelFormat)
1634 {
1635     MessageParcel data;
1636     MessageParcel reply;
1637     MessageOption option;
1638 
1639     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1640         return WRITE_PARCEL_ERR;
1641     }
1642     option.SetFlags(MessageOption::TF_SYNC);
1643     data.WriteUint64(id);
1644     data.WriteUint32(static_cast<uint32_t>(pixelFormat));
1645     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_PIXEL_FORMAT);
1646     int32_t err = Remote()->SendRequest(code, data, reply, option);
1647     if (err != NO_ERROR) {
1648         return RS_CONNECTION_ERROR;
1649     }
1650     int32_t result = reply.ReadInt32();
1651     return result;
1652 }
1653 
GetScreenSupportedHDRFormats(ScreenId id,std::vector<ScreenHDRFormat> & hdrFormats)1654 int32_t RSRenderServiceConnectionProxy::GetScreenSupportedHDRFormats(
1655     ScreenId id, std::vector<ScreenHDRFormat>& hdrFormats)
1656 {
1657     MessageParcel data;
1658     MessageParcel reply;
1659     MessageOption option;
1660     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1661         return RS_CONNECTION_ERROR;
1662     }
1663     option.SetFlags(MessageOption::TF_SYNC);
1664     data.WriteUint64(id);
1665     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_HDR_FORMATS);
1666     int32_t err = Remote()->SendRequest(code, data, reply, option);
1667     if (err != NO_ERROR) {
1668         return RS_CONNECTION_ERROR;
1669     }
1670     int32_t result = reply.ReadInt32();
1671     if (result == SUCCESS) {
1672         hdrFormats.clear();
1673         std::vector<uint32_t> hdrFormatsRecv;
1674         reply.ReadUInt32Vector(&hdrFormatsRecv);
1675         std::transform(hdrFormatsRecv.begin(), hdrFormatsRecv.end(), back_inserter(hdrFormats),
1676                        [](uint32_t i) -> ScreenHDRFormat {return static_cast<ScreenHDRFormat>(i);});
1677     }
1678     return result;
1679 }
1680 
GetScreenHDRFormat(ScreenId id,ScreenHDRFormat & hdrFormat)1681 int32_t RSRenderServiceConnectionProxy::GetScreenHDRFormat(ScreenId id, ScreenHDRFormat& hdrFormat)
1682 {
1683     MessageParcel data;
1684     MessageParcel reply;
1685     MessageOption option;
1686     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1687         return RS_CONNECTION_ERROR;
1688     }
1689     option.SetFlags(MessageOption::TF_SYNC);
1690     data.WriteUint64(id);
1691     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_HDR_FORMAT);
1692     int32_t err = Remote()->SendRequest(code, data, reply, option);
1693     if (err != NO_ERROR) {
1694         return RS_CONNECTION_ERROR;
1695     }
1696     int32_t result = reply.ReadInt32();
1697     if (result == SUCCESS) {
1698         hdrFormat = static_cast<ScreenHDRFormat>(reply.ReadUint32());
1699     }
1700     return result;
1701 }
1702 
SetScreenHDRFormat(ScreenId id,int32_t modeIdx)1703 int32_t RSRenderServiceConnectionProxy::SetScreenHDRFormat(ScreenId id, int32_t modeIdx)
1704 {
1705     MessageParcel data;
1706     MessageParcel reply;
1707     MessageOption option;
1708     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1709         return RS_CONNECTION_ERROR;
1710     }
1711     option.SetFlags(MessageOption::TF_SYNC);
1712     data.WriteUint64(id);
1713     data.WriteInt32(modeIdx);
1714     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_HDR_FORMAT);
1715     int32_t err = Remote()->SendRequest(code, data, reply, option);
1716     if (err != NO_ERROR) {
1717         return RS_CONNECTION_ERROR;
1718     }
1719     int32_t result = reply.ReadInt32();
1720     return result;
1721 }
1722 
GetScreenSupportedColorSpaces(ScreenId id,std::vector<GraphicCM_ColorSpaceType> & colorSpaces)1723 int32_t RSRenderServiceConnectionProxy::GetScreenSupportedColorSpaces(
1724     ScreenId id, std::vector<GraphicCM_ColorSpaceType>& colorSpaces)
1725 {
1726     MessageParcel data;
1727     MessageParcel reply;
1728     MessageOption option;
1729     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1730         return RS_CONNECTION_ERROR;
1731     }
1732     option.SetFlags(MessageOption::TF_SYNC);
1733     data.WriteUint64(id);
1734     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_COLORSPACES);
1735     int32_t err = Remote()->SendRequest(code, data, reply, option);
1736     if (err != NO_ERROR) {
1737         return RS_CONNECTION_ERROR;
1738     }
1739     int32_t result = reply.ReadInt32();
1740     if (result == SUCCESS) {
1741         colorSpaces.clear();
1742         std::vector<uint32_t> colorSpacesRecv;
1743         reply.ReadUInt32Vector(&colorSpacesRecv);
1744         std::transform(colorSpacesRecv.begin(), colorSpacesRecv.end(), back_inserter(colorSpaces),
1745                        [](uint32_t i) -> GraphicCM_ColorSpaceType {return static_cast<GraphicCM_ColorSpaceType>(i);});
1746     }
1747     return result;
1748 }
1749 
GetScreenColorSpace(ScreenId id,GraphicCM_ColorSpaceType & colorSpace)1750 int32_t RSRenderServiceConnectionProxy::GetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType& colorSpace)
1751 {
1752     MessageParcel data;
1753     MessageParcel reply;
1754     MessageOption option;
1755     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1756         return RS_CONNECTION_ERROR;
1757     }
1758     option.SetFlags(MessageOption::TF_SYNC);
1759     data.WriteUint64(id);
1760     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_COLORSPACE);
1761     int32_t err = Remote()->SendRequest(code, data, reply, option);
1762     if (err != NO_ERROR) {
1763         return RS_CONNECTION_ERROR;
1764     }
1765     int32_t result = reply.ReadInt32();
1766     if (result == SUCCESS) {
1767         colorSpace = static_cast<GraphicCM_ColorSpaceType>(reply.ReadUint32());
1768     }
1769     return result;
1770 }
1771 
SetScreenColorSpace(ScreenId id,GraphicCM_ColorSpaceType colorSpace)1772 int32_t RSRenderServiceConnectionProxy::SetScreenColorSpace(ScreenId id, GraphicCM_ColorSpaceType colorSpace)
1773 {
1774     MessageParcel data;
1775     MessageParcel reply;
1776     MessageOption option;
1777     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1778         return RS_CONNECTION_ERROR;
1779     }
1780     option.SetFlags(MessageOption::TF_SYNC);
1781     data.WriteUint64(id);
1782     data.WriteInt32(colorSpace);
1783     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_COLORSPACE);
1784     int32_t err = Remote()->SendRequest(code, data, reply, option);
1785     if (err != NO_ERROR) {
1786         return RS_CONNECTION_ERROR;
1787     }
1788     int32_t result = reply.ReadInt32();
1789     return result;
1790 }
1791 
GetScreenType(ScreenId id,RSScreenType & screenType)1792 int32_t RSRenderServiceConnectionProxy::GetScreenType(ScreenId id, RSScreenType& screenType)
1793 {
1794     MessageParcel data;
1795     MessageParcel reply;
1796     MessageOption option;
1797     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1798         return RS_CONNECTION_ERROR;
1799     }
1800     option.SetFlags(MessageOption::TF_SYNC);
1801     data.WriteUint64(id);
1802     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_TYPE);
1803     int32_t err = Remote()->SendRequest(code, data, reply, option);
1804     if (err != NO_ERROR) {
1805         return RS_CONNECTION_ERROR;
1806     }
1807     int32_t result = reply.ReadInt32();
1808     if (result == SUCCESS) {
1809         screenType = static_cast<RSScreenType>(reply.ReadUint32());
1810     }
1811     return result;
1812 }
1813 
GetBitmap(NodeId id,Drawing::Bitmap & bitmap)1814 bool RSRenderServiceConnectionProxy::GetBitmap(NodeId id, Drawing::Bitmap& bitmap)
1815 {
1816     MessageParcel data;
1817     MessageParcel reply;
1818     MessageOption option;
1819     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1820         return false;
1821     }
1822     option.SetFlags(MessageOption::TF_SYNC);
1823     data.WriteUint64(id);
1824     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_BITMAP);
1825     int32_t err = Remote()->SendRequest(code, data, reply, option);
1826     if (err != NO_ERROR) {
1827         return false;
1828     }
1829     bool result = reply.ReadBool();
1830     if (!result || !RSMarshallingHelper::Unmarshalling(reply, bitmap)) {
1831         RS_LOGE("RSRenderServiceConnectionProxy::GetBitmap: Unmarshalling failed");
1832         return false;
1833     }
1834     return true;
1835 }
1836 
SetVirtualMirrorScreenCanvasRotation(ScreenId id,bool canvasRotation)1837 bool RSRenderServiceConnectionProxy::SetVirtualMirrorScreenCanvasRotation(ScreenId id, bool canvasRotation)
1838 {
1839     MessageParcel data;
1840     MessageParcel reply;
1841     MessageOption option;
1842     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1843         return false;
1844     }
1845     option.SetFlags(MessageOption::TF_SYNC);
1846     data.WriteUint64(id);
1847     data.WriteBool(canvasRotation);
1848     uint32_t code = static_cast<uint32_t>(
1849         RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_MIRROR_SCREEN_CANVAS_ROTATION);
1850     int32_t err = Remote()->SendRequest(code, data, reply, option);
1851     if (err != NO_ERROR) {
1852         return false;
1853     }
1854     bool result = reply.ReadBool();
1855     return result;
1856 }
1857 
SetVirtualMirrorScreenScaleMode(ScreenId id,ScreenScaleMode scaleMode)1858 bool RSRenderServiceConnectionProxy::SetVirtualMirrorScreenScaleMode(ScreenId id, ScreenScaleMode scaleMode)
1859 {
1860     MessageParcel data;
1861     MessageParcel reply;
1862     MessageOption option;
1863     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1864         return false;
1865     }
1866     option.SetFlags(MessageOption::TF_SYNC);
1867     data.WriteUint64(id);
1868     data.WriteUint32(static_cast<uint32_t>(scaleMode));
1869     uint32_t code = static_cast<uint32_t>(
1870         RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_MIRROR_SCREEN_SCALE_MODE);
1871     int32_t err = Remote()->SendRequest(code, data, reply, option);
1872     if (err != NO_ERROR) {
1873         return false;
1874     }
1875     bool result = reply.ReadBool();
1876     return result;
1877 }
1878 
SetGlobalDarkColorMode(bool isDark)1879 bool RSRenderServiceConnectionProxy::SetGlobalDarkColorMode(bool isDark)
1880 {
1881     MessageParcel data;
1882     MessageParcel reply;
1883     MessageOption option;
1884     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1885         return false;
1886     }
1887     option.SetFlags(MessageOption::TF_ASYNC);
1888     if (!data.WriteBool(isDark)) {
1889         return false;
1890     }
1891     uint32_t code = static_cast<uint32_t>(
1892         RSIRenderServiceConnectionInterfaceCode::SET_GLOBAL_DARK_COLOR_MODE);
1893     int32_t err = Remote()->SendRequest(code, data, reply, option);
1894     if (err != NO_ERROR) {
1895         return false;
1896     }
1897     return true;
1898 }
1899 
GetPixelmap(NodeId id,std::shared_ptr<Media::PixelMap> pixelmap,const Drawing::Rect * rect,std::shared_ptr<Drawing::DrawCmdList> drawCmdList)1900 bool RSRenderServiceConnectionProxy::GetPixelmap(NodeId id, std::shared_ptr<Media::PixelMap> pixelmap,
1901     const Drawing::Rect* rect, std::shared_ptr<Drawing::DrawCmdList> drawCmdList)
1902 {
1903     MessageParcel data;
1904     MessageParcel reply;
1905     MessageOption option;
1906     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1907         return false;
1908     }
1909     option.SetFlags(MessageOption::TF_SYNC);
1910     data.WriteUint64(id);
1911     data.WriteParcelable(pixelmap.get());
1912     RSMarshallingHelper::Marshalling(data, *rect);
1913     RSMarshallingHelper::Marshalling(data, drawCmdList);
1914     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_PIXELMAP);
1915     int32_t err = Remote()->SendRequest(code, data, reply, option);
1916     if (err != NO_ERROR) {
1917         return false;
1918     }
1919     bool result = reply.ReadBool();
1920     if (!result || !RSMarshallingHelper::Unmarshalling(reply, pixelmap)) {
1921         RS_LOGD("RSRenderServiceConnectionProxy::GetPixelmap: GetPixelmap failed");
1922         return false;
1923     }
1924     return true;
1925 }
1926 
RegisterTypeface(uint64_t globalUniqueId,std::shared_ptr<Drawing::Typeface> & typeface)1927 bool RSRenderServiceConnectionProxy::RegisterTypeface(uint64_t globalUniqueId,
1928     std::shared_ptr<Drawing::Typeface>& typeface)
1929 {
1930     MessageParcel data;
1931     MessageParcel reply;
1932     MessageOption option;
1933     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1934         return false;
1935     }
1936     option.SetFlags(MessageOption::TF_SYNC);
1937     uint32_t hash = typeface->GetHash();
1938     data.WriteUint64(globalUniqueId);
1939     data.WriteUint32(hash);
1940 
1941     if (hash) { // if adapter does not provide hash, use old path
1942         MessageParcel reply2;
1943         uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NEED_REGISTER_TYPEFACE);
1944         int32_t err = Remote()->SendRequest(code, data, reply2, option);
1945         if (err != NO_ERROR) {
1946             RS_LOGW("Check if RegisterTypeface is needed failed, err:%{public}d", err);
1947             return false;
1948         }
1949         if (!reply2.ReadBool()) {
1950             return true; // the hash exists on server, no need to resend full data
1951         }
1952     }
1953 
1954     RSMarshallingHelper::Marshalling(data, typeface);
1955 
1956     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_TYPEFACE);
1957     int32_t err = Remote()->SendRequest(code, data, reply, option);
1958     if (err != NO_ERROR) {
1959         RS_LOGD("RSRenderServiceConnectionProxy::RegisterTypeface: RegisterTypeface failed");
1960         return false;
1961     }
1962     bool result = reply.ReadBool();
1963     return result;
1964 }
1965 
UnRegisterTypeface(uint64_t globalUniqueId)1966 bool RSRenderServiceConnectionProxy::UnRegisterTypeface(uint64_t globalUniqueId)
1967 {
1968     MessageParcel data;
1969     MessageParcel reply;
1970     MessageOption option;
1971     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1972         return false;
1973     }
1974     option.SetFlags(MessageOption::TF_ASYNC);
1975     data.WriteUint64(globalUniqueId);
1976     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_TYPEFACE);
1977     int32_t err = Remote()->SendRequest(code, data, reply, option);
1978     if (err != NO_ERROR) {
1979         RS_LOGD("RSRenderServiceConnectionProxy::UnRegisterTypeface: send request failed");
1980         return false;
1981     }
1982 
1983     return true;
1984 }
1985 
SetScreenSkipFrameInterval(ScreenId id,uint32_t skipFrameInterval)1986 int32_t RSRenderServiceConnectionProxy::SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval)
1987 {
1988     MessageParcel data;
1989     MessageParcel reply;
1990     MessageOption option;
1991     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
1992         return RS_CONNECTION_ERROR;
1993     }
1994     option.SetFlags(MessageOption::TF_SYNC);
1995     data.WriteUint64(id);
1996     data.WriteUint32(skipFrameInterval);
1997     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_SKIP_FRAME_INTERVAL);
1998     int32_t err = Remote()->SendRequest(code, data, reply, option);
1999     if (err != NO_ERROR) {
2000         return RS_CONNECTION_ERROR;
2001     }
2002     int32_t result = reply.ReadInt32();
2003     return result;
2004 }
2005 
RegisterOcclusionChangeCallback(sptr<RSIOcclusionChangeCallback> callback)2006 int32_t RSRenderServiceConnectionProxy::RegisterOcclusionChangeCallback(sptr<RSIOcclusionChangeCallback> callback)
2007 {
2008     if (callback == nullptr) {
2009         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterOcclusionChangeCallback: callback is nullptr.");
2010         return INVALID_ARGUMENTS;
2011     }
2012     MessageParcel data;
2013     MessageParcel reply;
2014     MessageOption option;
2015     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2016         return RS_CONNECTION_ERROR;
2017     }
2018     option.SetFlags(MessageOption::TF_ASYNC);
2019     data.WriteRemoteObject(callback->AsObject());
2020     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_OCCLUSION_CHANGE_CALLBACK);
2021     int32_t err = Remote()->SendRequest(code, data, reply, option);
2022     if (err != NO_ERROR) {
2023         return RS_CONNECTION_ERROR;
2024     } else {
2025         return SUCCESS;
2026     }
2027 }
2028 
RegisterSurfaceOcclusionChangeCallback(NodeId id,sptr<RSISurfaceOcclusionChangeCallback> callback,std::vector<float> & partitionPoints)2029 int32_t RSRenderServiceConnectionProxy::RegisterSurfaceOcclusionChangeCallback(
2030     NodeId id, sptr<RSISurfaceOcclusionChangeCallback> callback, std::vector<float>& partitionPoints)
2031 {
2032     if (callback == nullptr) {
2033         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterSurfaceOcclusionChangeCallback: callback is nullptr.");
2034         return INVALID_ARGUMENTS;
2035     }
2036 
2037     MessageParcel data;
2038     MessageParcel reply;
2039     MessageOption option;
2040     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2041         return RS_CONNECTION_ERROR;
2042     }
2043     option.SetFlags(MessageOption::TF_SYNC);
2044     data.WriteUint64(id);
2045     data.WriteRemoteObject(callback->AsObject());
2046     data.WriteFloatVector(partitionPoints);
2047 
2048     uint32_t code = static_cast<uint32_t>(
2049         RSIRenderServiceConnectionInterfaceCode::REGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK);
2050     int32_t err = Remote()->SendRequest(code, data, reply, option);
2051     if (err != NO_ERROR) {
2052         return RS_CONNECTION_ERROR;
2053     }
2054     int32_t result = reply.ReadInt32();
2055     return result;
2056 }
2057 
UnRegisterSurfaceOcclusionChangeCallback(NodeId id)2058 int32_t RSRenderServiceConnectionProxy::UnRegisterSurfaceOcclusionChangeCallback(NodeId id)
2059 {
2060     MessageParcel data;
2061     MessageParcel reply;
2062     MessageOption option;
2063     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2064         return RS_CONNECTION_ERROR;
2065     }
2066     option.SetFlags(MessageOption::TF_SYNC);
2067     data.WriteUint64(id);
2068 
2069     uint32_t code = static_cast<uint32_t>(
2070         RSIRenderServiceConnectionInterfaceCode::UNREGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK);
2071     int32_t err = Remote()->SendRequest(code, data, reply, option);
2072     if (err != NO_ERROR) {
2073         return RS_CONNECTION_ERROR;
2074     }
2075     int32_t result = reply.ReadInt32();
2076     return result;
2077 }
2078 
RegisterHgmConfigChangeCallback(sptr<RSIHgmConfigChangeCallback> callback)2079 int32_t RSRenderServiceConnectionProxy::RegisterHgmConfigChangeCallback(sptr<RSIHgmConfigChangeCallback> callback)
2080 {
2081     MessageParcel data;
2082     MessageParcel reply;
2083     MessageOption option;
2084     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2085         return RS_CONNECTION_ERROR;
2086     }
2087     option.SetFlags(MessageOption::TF_SYNC);
2088     data.WriteRemoteObject(callback->AsObject());
2089     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_HGM_CFG_CALLBACK);
2090     int32_t err = Remote()->SendRequest(code, data, reply, option);
2091     if (err != NO_ERROR) {
2092         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterHgmConfigChangeCallback: Send Request err.");
2093         return RS_CONNECTION_ERROR;
2094     }
2095     int32_t result = reply.ReadInt32();
2096     return result;
2097 }
2098 
RegisterHgmRefreshRateModeChangeCallback(sptr<RSIHgmConfigChangeCallback> callback)2099 int32_t RSRenderServiceConnectionProxy::RegisterHgmRefreshRateModeChangeCallback(
2100     sptr<RSIHgmConfigChangeCallback> callback)
2101 {
2102     MessageParcel data;
2103     MessageParcel reply;
2104     MessageOption option;
2105     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2106         return RS_CONNECTION_ERROR;
2107     }
2108     option.SetFlags(MessageOption::TF_SYNC);
2109     data.WriteRemoteObject(callback->AsObject());
2110     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REFRESH_RATE_MODE_CHANGE_CALLBACK);
2111     int32_t err = Remote()->SendRequest(code, data, reply, option);
2112     if (err != NO_ERROR) {
2113         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterHgmRefreshRateModeChangeCallback: Send Request err.");
2114         return RS_CONNECTION_ERROR;
2115     }
2116     int32_t result = reply.ReadInt32();
2117     return result;
2118 }
2119 
RegisterHgmRefreshRateUpdateCallback(sptr<RSIHgmConfigChangeCallback> callback)2120 int32_t RSRenderServiceConnectionProxy::RegisterHgmRefreshRateUpdateCallback(
2121     sptr<RSIHgmConfigChangeCallback> callback)
2122 {
2123     MessageParcel data;
2124     MessageParcel reply;
2125     MessageOption option;
2126     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2127         return RS_CONNECTION_ERROR;
2128     }
2129     option.SetFlags(MessageOption::TF_SYNC);
2130     if (callback) {
2131         if (!data.WriteBool(true)) {
2132             return WRITE_PARCEL_ERR;
2133         }
2134         if (!data.WriteRemoteObject(callback->AsObject())) {
2135             return WRITE_PARCEL_ERR;
2136         }
2137     } else {
2138         if (!data.WriteBool(false)) {
2139             return WRITE_PARCEL_ERR;
2140         }
2141     }
2142     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REFRESH_RATE_UPDATE_CALLBACK);
2143     int32_t err = Remote()->SendRequest(code, data, reply, option);
2144     if (err != NO_ERROR) {
2145         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterHgmRefreshRateModeChangeCallback: Send Request err.");
2146         return RS_CONNECTION_ERROR;
2147     }
2148     int32_t result = reply.ReadInt32();
2149     return result;
2150 }
2151 
SetAppWindowNum(uint32_t num)2152 void RSRenderServiceConnectionProxy::SetAppWindowNum(uint32_t num)
2153 {
2154     MessageParcel data;
2155     MessageParcel reply;
2156     MessageOption option;
2157     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2158         return;
2159     }
2160     option.SetFlags(MessageOption::TF_ASYNC);
2161     data.WriteUint32(num);
2162     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_APP_WINDOW_NUM);
2163     int32_t err = Remote()->SendRequest(code, data, reply, option);
2164     if (err != NO_ERROR) {
2165         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetAppWindowNum: Send Request err.");
2166         return;
2167     }
2168 }
2169 
SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedScenes)2170 bool RSRenderServiceConnectionProxy::SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedScenes)
2171 {
2172     MessageParcel data;
2173     MessageParcel reply;
2174     MessageOption option;
2175     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2176         return false;
2177     }
2178     option.SetFlags(MessageOption::TF_SYNC);
2179     data.WriteUint32(static_cast<uint32_t>(systemAnimatedScenes));
2180     uint32_t code = static_cast<uint32_t>(
2181         RSIRenderServiceConnectionInterfaceCode::SET_SYSTEM_ANIMATED_SCENES);
2182     int32_t err = Remote()->SendRequest(code, data, reply, option);
2183     if (err != NO_ERROR) {
2184         return false;
2185     }
2186     bool result = reply.ReadBool();
2187     return result;
2188 }
2189 
ShowWatermark(const std::shared_ptr<Media::PixelMap> & watermarkImg,bool isShow)2190 void RSRenderServiceConnectionProxy::ShowWatermark(const std::shared_ptr<Media::PixelMap> &watermarkImg, bool isShow)
2191 {
2192     if (watermarkImg == nullptr) {
2193         ROSEN_LOGE("RSRenderServiceConnectionProxy::ShowWatermark: watermarkImg is nullptr.");
2194         return;
2195     }
2196     MessageParcel data;
2197     MessageParcel reply;
2198     MessageOption option;
2199     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2200         return;
2201     }
2202     option.SetFlags(MessageOption::TF_ASYNC);
2203     data.WriteParcelable(watermarkImg.get());
2204     data.WriteBool(isShow);
2205     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SHOW_WATERMARK);
2206     int32_t err = Remote()->SendRequest(code, data, reply, option);
2207     if (err != NO_ERROR) {
2208         ROSEN_LOGE("RSRenderServiceConnectionProxy::ShowWatermark: Send Request err.");
2209         return;
2210     }
2211 }
2212 
ResizeVirtualScreen(ScreenId id,uint32_t width,uint32_t height)2213 int32_t RSRenderServiceConnectionProxy::ResizeVirtualScreen(ScreenId id, uint32_t width, uint32_t height)
2214 {
2215     MessageParcel data;
2216     MessageParcel reply;
2217     MessageOption option;
2218 
2219     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2220         ROSEN_LOGE("RSRenderServiceConnectionProxy::ResizeVirtualScreen: WriteInterfaceToken err.");
2221         return WRITE_PARCEL_ERR;
2222     }
2223     option.SetFlags(MessageOption::TF_SYNC);
2224     data.WriteUint64(id);
2225     data.WriteUint32(width);
2226     data.WriteUint32(height);
2227     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::RESIZE_VIRTUAL_SCREEN);
2228     int32_t err = Remote()->SendRequest(code, data, reply, option);
2229     if (err != NO_ERROR) {
2230         ROSEN_LOGE("RSRenderServiceConnectionProxy::ResizeVirtualScreen: Send Request err.");
2231         return RS_CONNECTION_ERROR;
2232     }
2233     int32_t status = reply.ReadInt32();
2234     return status;
2235 }
2236 
ReportJankStats()2237 void RSRenderServiceConnectionProxy::ReportJankStats()
2238 {
2239     MessageParcel data;
2240     MessageParcel reply;
2241     MessageOption option;
2242     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2243         return;
2244     }
2245     option.SetFlags(MessageOption::TF_ASYNC);
2246     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_JANK_STATS);
2247     int32_t err = Remote()->SendRequest(code, data, reply, option);
2248     if (err != NO_ERROR) {
2249         ROSEN_LOGE("RSRenderServiceConnectionProxy::ReportJankStats: Send Request err.");
2250         return;
2251     }
2252 }
2253 
ReportEventResponse(DataBaseRs info)2254 void RSRenderServiceConnectionProxy::ReportEventResponse(DataBaseRs info)
2255 {
2256     MessageParcel data;
2257     MessageParcel reply;
2258     MessageOption option;
2259     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2260         return;
2261     }
2262     ReportDataBaseRs(data, reply, option, info);
2263     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_RESPONSE);
2264     int32_t err = Remote()->SendRequest(code, data, reply, option);
2265     if (err != NO_ERROR) {
2266         ROSEN_LOGE("RSRenderServiceConnectionProxy::ReportEventResponse: Send Request err.");
2267         return;
2268     }
2269 }
2270 
ReportEventComplete(DataBaseRs info)2271 void RSRenderServiceConnectionProxy::ReportEventComplete(DataBaseRs info)
2272 {
2273     MessageParcel data;
2274     MessageParcel reply;
2275     MessageOption option;
2276     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2277         return;
2278     }
2279     ReportDataBaseRs(data, reply, option, info);
2280     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_COMPLETE);
2281     int32_t err = Remote()->SendRequest(code, data, reply, option);
2282     if (err != NO_ERROR) {
2283         ROSEN_LOGE("RSRenderServiceConnectionProxy::ReportEventComplete: Send Request err.");
2284         return;
2285     }
2286 }
2287 
ReportEventJankFrame(DataBaseRs info)2288 void RSRenderServiceConnectionProxy::ReportEventJankFrame(DataBaseRs info)
2289 {
2290     MessageParcel data;
2291     MessageParcel reply;
2292     MessageOption option;
2293     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2294         return;
2295     }
2296     ReportDataBaseRs(data, reply, option, info);
2297     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_JANK_FRAME);
2298     int32_t err = Remote()->SendRequest(code, data, reply, option);
2299     if (err != NO_ERROR) {
2300         ROSEN_LOGE("RSRenderServiceConnectionProxy::ReportEventJankFrame: Send Request err.");
2301         return;
2302     }
2303 }
2304 
ReportDataBaseRs(MessageParcel & data,MessageParcel & reply,MessageOption & option,DataBaseRs info)2305 void RSRenderServiceConnectionProxy::ReportDataBaseRs(
2306     MessageParcel& data, MessageParcel& reply, MessageOption& option, DataBaseRs info)
2307 {
2308     data.WriteInt32(info.appPid);
2309     data.WriteInt32(info.eventType);
2310     data.WriteInt32(info.versionCode);
2311     data.WriteInt64(info.uniqueId);
2312     data.WriteInt64(info.inputTime);
2313     data.WriteInt64(info.beginVsyncTime);
2314     data.WriteInt64(info.endVsyncTime);
2315     data.WriteBool(info.isDisplayAnimator);
2316     data.WriteString(info.sceneId);
2317     data.WriteString(info.versionName);
2318     data.WriteString(info.bundleName);
2319     data.WriteString(info.processName);
2320     data.WriteString(info.abilityName);
2321     data.WriteString(info.pageUrl);
2322     data.WriteString(info.sourceType);
2323     data.WriteString(info.note);
2324     option.SetFlags(MessageOption::TF_ASYNC);
2325 }
2326 
ReportGameStateDataRs(MessageParcel & data,MessageParcel & reply,MessageOption & option,GameStateData info)2327 void RSRenderServiceConnectionProxy::ReportGameStateDataRs(
2328     MessageParcel& data, MessageParcel& reply, MessageOption& option, GameStateData info)
2329 {
2330     data.WriteInt32(info.pid);
2331     data.WriteInt32(info.uid);
2332     data.WriteInt32(info.state);
2333     data.WriteInt32(info.renderTid);
2334     data.WriteString(info.bundleName);
2335     option.SetFlags(MessageOption::TF_ASYNC);
2336 }
2337 
ReportGameStateData(GameStateData info)2338 void RSRenderServiceConnectionProxy::ReportGameStateData(GameStateData info)
2339 {
2340     MessageParcel data;
2341     MessageParcel reply;
2342     MessageOption option;
2343     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2344         return;
2345     }
2346     ReportGameStateDataRs(data, reply, option, info);
2347     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_GAMESTATE);
2348     int32_t err = Remote()->SendRequest(code, data, reply, option);
2349     if (err != NO_ERROR) {
2350         ROSEN_LOGE("RSRenderServiceConnectionProxy::ReportGameStateData: Send Request err.");
2351         return;
2352     }
2353 }
2354 
SetHardwareEnabled(NodeId id,bool isEnabled,SelfDrawingNodeType selfDrawingType,bool dynamicHardwareEnable)2355 void RSRenderServiceConnectionProxy::SetHardwareEnabled(NodeId id, bool isEnabled, SelfDrawingNodeType selfDrawingType,
2356     bool dynamicHardwareEnable)
2357 {
2358     MessageParcel data;
2359     MessageParcel reply;
2360     MessageOption option;
2361     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2362         return;
2363     }
2364     if (!data.WriteUint64(id)) {
2365         return;
2366     }
2367     if (!data.WriteBool(isEnabled)) {
2368         return;
2369     }
2370     if (!data.WriteUint8(static_cast<uint8_t>(selfDrawingType))) {
2371         return;
2372     }
2373     if (!data.WriteBool(dynamicHardwareEnable)) {
2374         return;
2375     }
2376     option.SetFlags(MessageOption::TF_ASYNC);
2377     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_HARDWARE_ENABLED);
2378     int32_t err = Remote()->SendRequest(code, data, reply, option);
2379     if (err != NO_ERROR) {
2380         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetHardwareEnabled: Send Request err.");
2381         return;
2382     }
2383 }
2384 
SetHidePrivacyContent(NodeId id,bool needHidePrivacyContent)2385 uint32_t RSRenderServiceConnectionProxy::SetHidePrivacyContent(NodeId id, bool needHidePrivacyContent)
2386 {
2387     MessageParcel data;
2388     MessageParcel reply;
2389     MessageOption option;
2390     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2391         return static_cast<uint32_t>(RSInterfaceErrorCode::WRITE_PARCEL_ERROR);
2392     }
2393     if (!data.WriteUint64(id)) {
2394         return static_cast<uint32_t>(RSInterfaceErrorCode::WRITE_PARCEL_ERROR);
2395     }
2396     if (!data.WriteBool(needHidePrivacyContent)) {
2397         return static_cast<uint32_t>(RSInterfaceErrorCode::WRITE_PARCEL_ERROR);
2398     }
2399     option.SetFlags(MessageOption::TF_SYNC);
2400     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_HIDE_PRIVACY_CONTENT);
2401     int32_t err = Remote()->SendRequest(code, data, reply, option);
2402     if (err != NO_ERROR) {
2403         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetHidePrivacyContent: Send Request err.");
2404         return static_cast<uint32_t>(RSInterfaceErrorCode::UNKNOWN_ERROR);
2405     }
2406     return reply.ReadUint32();
2407 }
2408 
NotifyLightFactorStatus(bool isSafe)2409 void RSRenderServiceConnectionProxy::NotifyLightFactorStatus(bool isSafe)
2410 {
2411     MessageParcel data;
2412     MessageParcel reply;
2413     MessageOption option;
2414     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2415         return;
2416     }
2417     if (!data.WriteBool(isSafe)) {
2418         return;
2419     }
2420     option.SetFlags(MessageOption::TF_ASYNC);
2421     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_LIGHT_FACTOR_STATUS);
2422     int32_t err = Remote()->SendRequest(code, data, reply, option);
2423     if (err != NO_ERROR) {
2424         ROSEN_LOGE("RSRenderServiceConnectionProxy::NotifyLightFactorStatus: Send Request err.");
2425         return;
2426     }
2427 }
2428 
NotifyPackageEvent(uint32_t listSize,const std::vector<std::string> & packageList)2429 void RSRenderServiceConnectionProxy::NotifyPackageEvent(uint32_t listSize, const std::vector<std::string>& packageList)
2430 {
2431     MessageParcel data;
2432     MessageParcel reply;
2433     MessageOption option;
2434     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2435         return;
2436     }
2437     if (listSize != packageList.size()) {
2438         ROSEN_LOGE("input size doesn't match");
2439         return;
2440     }
2441     if (!data.WriteUint32(listSize)) {
2442         return;
2443     }
2444     for (auto pkg : packageList) {
2445         if (!data.WriteString(pkg)) {
2446             return;
2447         }
2448     }
2449     option.SetFlags(MessageOption::TF_ASYNC);
2450     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_PACKAGE_EVENT);
2451     int32_t err = Remote()->SendRequest(code, data, reply, option);
2452     if (err != NO_ERROR) {
2453         ROSEN_LOGE("RSRenderServiceConnectionProxy::NotifyPackageEvent: Send Request err.");
2454         return;
2455     }
2456 }
2457 
NotifyRefreshRateEvent(const EventInfo & eventInfo)2458 void RSRenderServiceConnectionProxy::NotifyRefreshRateEvent(const EventInfo& eventInfo)
2459 {
2460     MessageParcel data;
2461     MessageParcel reply;
2462     MessageOption option;
2463     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2464         return;
2465     }
2466     if (!data.WriteString(eventInfo.eventName)) {
2467         return;
2468     }
2469     if (!data.WriteBool(eventInfo.eventStatus)) {
2470         return;
2471     }
2472     if (!data.WriteUint32(eventInfo.minRefreshRate)) {
2473         return;
2474     }
2475     if (!data.WriteUint32(eventInfo.maxRefreshRate)) {
2476         return;
2477     }
2478     if (!data.WriteString(eventInfo.description)) {
2479         return;
2480     }
2481     option.SetFlags(MessageOption::TF_ASYNC);
2482     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_REFRESH_RATE_EVENT);
2483     int32_t err = Remote()->SendRequest(code, data, reply, option);
2484     if (err != NO_ERROR) {
2485         ROSEN_LOGE("RSRenderServiceConnectionProxy::NotifyRefreshRateEvent: Send Request err.");
2486         return;
2487     }
2488 }
2489 
NotifyTouchEvent(int32_t touchStatus,int32_t touchCnt)2490 void RSRenderServiceConnectionProxy::NotifyTouchEvent(int32_t touchStatus, int32_t touchCnt)
2491 {
2492     MessageParcel data;
2493     MessageParcel reply;
2494     MessageOption option;
2495     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2496         return;
2497     }
2498     if (!data.WriteInt32(touchStatus)) {
2499         return;
2500     }
2501     if (!data.WriteInt32(touchCnt)) {
2502         return;
2503     }
2504     option.SetFlags(MessageOption::TF_ASYNC);
2505     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_TOUCH_EVENT);
2506     int32_t err = Remote()->SendRequest(code, data, reply, option);
2507     if (err != NO_ERROR) {
2508         ROSEN_LOGE("RSRenderServiceConnectionProxy::NotifyTouchEvent: Send Request err.");
2509         return;
2510     }
2511 }
2512 
NotifyDynamicModeEvent(bool enableDynamicMode)2513 void RSRenderServiceConnectionProxy::NotifyDynamicModeEvent(bool enableDynamicMode)
2514 {
2515     MessageParcel data;
2516     MessageParcel reply;
2517     MessageOption option;
2518     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2519         return;
2520     }
2521     if (!data.WriteBool(enableDynamicMode)) {
2522         return;
2523     }
2524     option.SetFlags(MessageOption::TF_ASYNC);
2525     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_DYNAMIC_MODE_EVENT);
2526     int32_t err = Remote()->SendRequest(code, data, reply, option);
2527     if (err != NO_ERROR) {
2528         ROSEN_LOGE("RSRenderServiceConnectionProxy::NotifyDynamicModeEvent: Send Request err.");
2529         return;
2530     }
2531 }
2532 
SetCacheEnabledForRotation(bool isEnabled)2533 void RSRenderServiceConnectionProxy::SetCacheEnabledForRotation(bool isEnabled)
2534 {
2535     MessageParcel data;
2536     MessageParcel reply;
2537     MessageOption option;
2538     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2539         return;
2540     }
2541     if (!data.WriteBool(isEnabled)) {
2542         return;
2543     }
2544     option.SetFlags(MessageOption::TF_ASYNC);
2545     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_ROTATION_CACHE_ENABLED);
2546     int32_t err = Remote()->SendRequest(code, data, reply, option);
2547     if (err != NO_ERROR) {
2548         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetCacheEnabledForRotation: Send Request err.");
2549         return;
2550     }
2551 }
2552 
SetDefaultDeviceRotationOffset(uint32_t offset)2553 void RSRenderServiceConnectionProxy::SetDefaultDeviceRotationOffset(uint32_t offset)
2554 {
2555     MessageParcel data;
2556     MessageParcel reply;
2557     MessageOption option;
2558     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2559         return;
2560     }
2561     if (!data.WriteUint32(offset)) {
2562         return;
2563     }
2564     option.SetFlags(MessageOption::TF_ASYNC);
2565     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_DEFAULT_DEVICE_ROTATION_OFFSET);
2566     int32_t err = Remote()->SendRequest(code, data, reply, option);
2567     if (err != NO_ERROR) {
2568         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetDefaultDeviceRotationOffset: Send Request err.");
2569         return;
2570     }
2571 }
2572 
SetOnRemoteDiedCallback(const OnRemoteDiedCallback & callback)2573 void RSRenderServiceConnectionProxy::SetOnRemoteDiedCallback(const OnRemoteDiedCallback& callback)
2574 {
2575     OnRemoteDiedCallback_ = callback;
2576 }
2577 
RunOnRemoteDiedCallback()2578 void RSRenderServiceConnectionProxy::RunOnRemoteDiedCallback()
2579 {
2580     if (OnRemoteDiedCallback_) {
2581         OnRemoteDiedCallback_();
2582     }
2583 }
2584 
GetActiveDirtyRegionInfo()2585 std::vector<ActiveDirtyRegionInfo> RSRenderServiceConnectionProxy::GetActiveDirtyRegionInfo()
2586 {
2587     MessageParcel data;
2588     MessageParcel reply;
2589     MessageOption option;
2590     std::vector<ActiveDirtyRegionInfo> activeDirtyRegionInfos;
2591     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2592         return activeDirtyRegionInfos;
2593     }
2594     option.SetFlags(MessageOption::TF_SYNC);
2595     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ACTIVE_DIRTY_REGION_INFO);
2596     int32_t err = Remote()->SendRequest(code, data, reply, option);
2597     if (err != NO_ERROR) {
2598         ROSEN_LOGE("RSRenderServiceConnectionProxy::GetActiveDirtyRegionInfo: Send Request err.");
2599         return activeDirtyRegionInfos;
2600     }
2601     int32_t activeDirtyRegionInfosSize = reply.ReadInt32();
2602     while (activeDirtyRegionInfosSize--) {
2603         activeDirtyRegionInfos.emplace_back(ActiveDirtyRegionInfo(reply.ReadInt64(), reply.ReadInt32(),
2604             reply.ReadInt32(), reply.ReadString()));
2605     }
2606     return activeDirtyRegionInfos;
2607 }
2608 
GetGlobalDirtyRegionInfo()2609 GlobalDirtyRegionInfo RSRenderServiceConnectionProxy::GetGlobalDirtyRegionInfo()
2610 {
2611     MessageParcel data;
2612     MessageParcel reply;
2613     MessageOption option;
2614     GlobalDirtyRegionInfo globalDirtyRegionInfo;
2615     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2616         return globalDirtyRegionInfo;
2617     }
2618     option.SetFlags(MessageOption::TF_SYNC);
2619     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_GLOBAL_DIRTY_REGION_INFO);
2620     int32_t err = Remote()->SendRequest(code, data, reply, option);
2621     if (err != NO_ERROR) {
2622         ROSEN_LOGE("RSRenderServiceConnectionProxy::GetGlobalDirtyRegionInfo: Send Request err.");
2623         return globalDirtyRegionInfo;
2624     }
2625     return GlobalDirtyRegionInfo(reply.ReadInt64(), reply.ReadInt32(), reply.ReadInt32(), reply.ReadInt32());
2626 }
2627 
GetLayerComposeInfo()2628 LayerComposeInfo RSRenderServiceConnectionProxy::GetLayerComposeInfo()
2629 {
2630     MessageParcel data;
2631     MessageParcel reply;
2632     MessageOption option;
2633     LayerComposeInfo layerComposeInfo;
2634     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2635         return layerComposeInfo;
2636     }
2637     option.SetFlags(MessageOption::TF_SYNC);
2638     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_LAYER_COMPOSE_INFO);
2639     int32_t err = Remote()->SendRequest(code, data, reply, option);
2640     if (err != NO_ERROR) {
2641         ROSEN_LOGE("RSRenderServiceConnectionProxy::GetLayerComposeInfo: Send Request err.");
2642         return layerComposeInfo;
2643     }
2644     return LayerComposeInfo(reply.ReadInt32(), reply.ReadInt32(), reply.ReadInt32());
2645 }
2646 
GetHwcDisabledReasonInfo()2647 HwcDisabledReasonInfos RSRenderServiceConnectionProxy::GetHwcDisabledReasonInfo()
2648 {
2649     MessageParcel data;
2650     MessageParcel reply;
2651     MessageOption option;
2652     HwcDisabledReasonInfos hwcDisabledReasonInfos;
2653     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2654         return hwcDisabledReasonInfos;
2655     }
2656     option.SetFlags(MessageOption::TF_SYNC);
2657     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::
2658         GET_HARDWARE_COMPOSE_DISABLED_REASON_INFO);
2659     int32_t err = Remote()->SendRequest(code, data, reply, option);
2660     if (err != NO_ERROR) {
2661         ROSEN_LOGE("RSRenderServiceConnectionProxy::GetHwcDisabledReasonInfo: Send Request err.");
2662         return hwcDisabledReasonInfos;
2663     }
2664     int32_t size = reply.ReadInt32();
2665     size_t readableSize = reply.GetReadableBytes() / (sizeof(HwcDisabledReasonInfo) - HWC_DISABLED_REASON_INFO_OFFSET);
2666     size_t len = static_cast<size_t>(size);
2667     if (len > readableSize || len > hwcDisabledReasonInfos.max_size()) {
2668         RS_LOGE("RSRenderServiceConnectionProxy GetHwcDisabledReasonInfo Failed read vector, size:%{public}zu,"
2669             " readableSize:%{public}zu", len, readableSize);
2670         return hwcDisabledReasonInfos;
2671     }
2672 
2673     HwcDisabledReasonInfo hwcDisabledReasonInfo;
2674     while (size--) {
2675         for (int32_t pos = 0; pos < HwcDisabledReasons::DISABLED_REASON_LENGTH; pos++) {
2676             hwcDisabledReasonInfo.disabledReasonStatistics[pos] = reply.ReadInt32();
2677         }
2678         hwcDisabledReasonInfo.pidOfBelongsApp = reply.ReadInt32();
2679         hwcDisabledReasonInfo.nodeName = reply.ReadString();
2680         hwcDisabledReasonInfos.emplace_back(hwcDisabledReasonInfo);
2681     }
2682     return hwcDisabledReasonInfos;
2683 }
2684 
SetVmaCacheStatus(bool flag)2685 void RSRenderServiceConnectionProxy::SetVmaCacheStatus(bool flag)
2686 {
2687     MessageParcel data;
2688     MessageParcel reply;
2689     MessageOption option;
2690     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2691         return;
2692     }
2693     if (!data.WriteBool(flag)) {
2694         return;
2695     }
2696     option.SetFlags(MessageOption::TF_ASYNC);
2697     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VMA_CACHE_STATUS);
2698     int32_t err = Remote()->SendRequest(code, data, reply, option);
2699     if (err != NO_ERROR) {
2700         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVmaCacheStatus %d: Send Request err.", flag);
2701         return;
2702     }
2703 }
2704 
2705 #ifdef TP_FEATURE_ENABLE
SetTpFeatureConfig(int32_t feature,const char * config)2706 void RSRenderServiceConnectionProxy::SetTpFeatureConfig(int32_t feature, const char* config)
2707 {
2708     MessageParcel data;
2709     MessageParcel reply;
2710     MessageOption option;
2711 
2712     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2713         return;
2714     }
2715 
2716     if (!data.WriteInt32(feature)) {
2717         return;
2718     }
2719 
2720     if (!data.WriteCString(config)) {
2721         return;
2722     }
2723 
2724     option.SetFlags(MessageOption::TF_SYNC);
2725     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_TP_FEATURE_CONFIG);
2726     int32_t err = Remote()->SendRequest(code, data, reply, option);
2727     if (err != NO_ERROR) {
2728         return;
2729     }
2730 }
2731 #endif
SetVirtualScreenUsingStatus(bool isVirtualScreenUsingStatus)2732 void RSRenderServiceConnectionProxy::SetVirtualScreenUsingStatus(bool isVirtualScreenUsingStatus)
2733 {
2734     MessageParcel data;
2735     MessageParcel reply;
2736     MessageOption option;
2737     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2738         return;
2739     }
2740     if (!data.WriteBool(isVirtualScreenUsingStatus)) {
2741         return;
2742     }
2743     option.SetFlags(MessageOption::TF_ASYNC);
2744     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_USING_STATUS);
2745     int32_t err = Remote()->SendRequest(code, data, reply, option);
2746     if (err != NO_ERROR) {
2747         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVirtualScreenUsingStatus: Send Request err.");
2748         return;
2749     }
2750 }
2751 
SetCurtainScreenUsingStatus(bool isCurtainScreenOn)2752 void RSRenderServiceConnectionProxy::SetCurtainScreenUsingStatus(bool isCurtainScreenOn)
2753 {
2754     MessageParcel data;
2755     MessageParcel reply;
2756     MessageOption option;
2757     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2758         return;
2759     }
2760     if (!data.WriteBool(isCurtainScreenOn)) {
2761         return;
2762     }
2763     option.SetFlags(MessageOption::TF_ASYNC);
2764     uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_CURTAIN_SCREEN_USING_STATUS);
2765     int32_t err = Remote()->SendRequest(code, data, reply, option);
2766     if (err != NO_ERROR) {
2767         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetCurtainScreenUsingStatus: Send Request err.");
2768         return;
2769     }
2770 }
2771 
RegisterUIExtensionCallback(uint64_t userId,sptr<RSIUIExtensionCallback> callback)2772 int32_t RSRenderServiceConnectionProxy::RegisterUIExtensionCallback(
2773     uint64_t userId, sptr<RSIUIExtensionCallback> callback)
2774 {
2775     if (callback == nullptr) {
2776         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterUIExtensionCallback: callback is nullptr.");
2777         return INVALID_ARGUMENTS;
2778     }
2779     MessageParcel data;
2780     MessageParcel reply;
2781     MessageOption option;
2782     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2783         return RS_CONNECTION_ERROR;
2784     }
2785     option.SetFlags(MessageOption::TF_SYNC);
2786     if (data.WriteUint64(userId) && data.WriteRemoteObject(callback->AsObject())) {
2787         uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_UIEXTENSION_CALLBACK);
2788         int32_t err = Remote()->SendRequest(code, data, reply, option);
2789         if (err != NO_ERROR) {
2790             return RS_CONNECTION_ERROR;
2791         }
2792         int32_t result = reply.ReadInt32();
2793         return result;
2794     } else {
2795         return RS_CONNECTION_ERROR;
2796     }
2797 }
2798 
SetAncoForceDoDirect(bool direct)2799 bool RSRenderServiceConnectionProxy::SetAncoForceDoDirect(bool direct)
2800 {
2801     MessageParcel data;
2802     MessageParcel reply;
2803     MessageOption option;
2804     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2805         return false;
2806     }
2807     option.SetFlags(MessageOption::TF_SYNC);
2808     if (data.WriteBool(direct)) {
2809         uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_ANCO_FORCE_DO_DIRECT);
2810         int32_t err = Remote()->SendRequest(code, data, reply, option);
2811         if (err != NO_ERROR) {
2812             return false;
2813         }
2814         bool result = reply.ReadBool();
2815         return result;
2816     } else {
2817         return false;
2818     }
2819 }
2820 
RegisterSurfaceBufferCallback(pid_t pid,uint64_t uid,sptr<RSISurfaceBufferCallback> callback)2821 void RSRenderServiceConnectionProxy::RegisterSurfaceBufferCallback(
2822     pid_t pid, uint64_t uid, sptr<RSISurfaceBufferCallback> callback)
2823 {
2824     if (callback == nullptr) {
2825         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterSurfaceBufferCallback callback == nullptr");
2826         return;
2827     }
2828     MessageParcel data;
2829     MessageParcel reply;
2830     MessageOption option;
2831     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2832         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterSurfaceBufferCallback: write token err.");
2833         return;
2834     }
2835     option.SetFlags(MessageOption::TF_ASYNC);
2836     static_assert(std::is_same_v<int32_t, pid_t>, "pid_t is not int32_t on this platform.");
2837     if (!data.WriteInt32(pid)) {
2838         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterSurfaceBufferCallback: write Int32 val err.");
2839         return;
2840     }
2841     if (!data.WriteUint64(uid)) {
2842         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterSurfaceBufferCallback: write Uint64 val err.");
2843         return;
2844     }
2845     if (!data.WriteRemoteObject(callback->AsObject())) {
2846         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterSurfaceBufferCallback: write RemoteObject val err.");
2847         return;
2848     }
2849     uint32_t code = static_cast<uint32_t>(
2850         RSIRenderServiceConnectionInterfaceCode::REGISTER_SURFACE_BUFFER_CALLBACK);
2851     int32_t err = Remote()->SendRequest(code, data, reply, option);
2852     if (err != NO_ERROR) {
2853         ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterSurfaceBufferCallback: Send Request err.");
2854         return;
2855     }
2856 }
2857 
UnregisterSurfaceBufferCallback(pid_t pid,uint64_t uid)2858 void RSRenderServiceConnectionProxy::UnregisterSurfaceBufferCallback(pid_t pid, uint64_t uid)
2859 {
2860     MessageParcel data;
2861     MessageParcel reply;
2862     MessageOption option;
2863     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2864         ROSEN_LOGE("RSRenderServiceConnectionProxy::UnregisterSurfaceBufferCallback: write token err.");
2865         return;
2866     }
2867     option.SetFlags(MessageOption::TF_ASYNC);
2868     static_assert(std::is_same_v<int32_t, pid_t>, "pid_t is not int32_t on this platform.");
2869     if (!data.WriteInt32(pid)) {
2870         ROSEN_LOGE("RSRenderServiceConnectionProxy::UnregisterSurfaceBufferCallback: write Int32 val err.");
2871         return;
2872     }
2873     if (!data.WriteUint64(uid)) {
2874         ROSEN_LOGE("RSRenderServiceConnectionProxy::UnregisterSurfaceBufferCallback: write Uint64 val err.");
2875         return;
2876     }
2877     uint32_t code = static_cast<uint32_t>(
2878         RSIRenderServiceConnectionInterfaceCode::UNREGISTER_SURFACE_BUFFER_CALLBACK);
2879     int32_t err = Remote()->SendRequest(code, data, reply, option);
2880     if (err != NO_ERROR) {
2881         ROSEN_LOGE("RSRenderServiceConnectionProxy::UnregisterSurfaceBufferCallback: Send Request err.");
2882         return;
2883     }
2884 }
2885 
SetLayerTop(const std::string & nodeIdStr,bool isTop)2886 void RSRenderServiceConnectionProxy::SetLayerTop(const std::string &nodeIdStr, bool isTop)
2887 {
2888     MessageParcel data;
2889     MessageParcel reply;
2890     MessageOption option;
2891     if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
2892         ROSEN_LOGE("RSRenderServiceConnectionProxy::SetLayerTop: write token err.");
2893         return;
2894     }
2895     option.SetFlags(MessageOption::TF_ASYNC);
2896     if (data.WriteString(nodeIdStr) && data.WriteBool(isTop)) {
2897         uint32_t code = static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_LAYER_TOP);
2898         int32_t err = Remote()->SendRequest(code, data, reply, option);
2899         if (err != NO_ERROR) {
2900             ROSEN_LOGE("RSRenderServiceConnectionProxy::SetLayerTop: Send Request err.");
2901             return;
2902         }
2903     }
2904 }
2905 } // namespace Rosen
2906 } // namespace OHOS
2907