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