1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "rs_render_service_connection_proxy.h"
17
18 #include <message_option.h>
19 #include <message_parcel.h>
20 #include <vector>
21 #include "platform/common/rs_log.h"
22 #include "platform/common/rs_system_properties.h"
23 #include "transaction/rs_ashmem_helper.h"
24 #include "rs_trace.h"
25
26 namespace OHOS {
27 namespace Rosen {
28 namespace {
29 static constexpr size_t ASHMEM_SIZE_THRESHOLD = 400 * 1024; // cannot > 500K in TF_ASYNC mode
30 }
31
RSRenderServiceConnectionProxy(const sptr<IRemoteObject> & impl)32 RSRenderServiceConnectionProxy::RSRenderServiceConnectionProxy(const sptr<IRemoteObject>& impl)
33 : IRemoteProxy<RSIRenderServiceConnection>(impl)
34 {
35 }
36
CommitTransaction(std::unique_ptr<RSTransactionData> & transactionData)37 void RSRenderServiceConnectionProxy::CommitTransaction(std::unique_ptr<RSTransactionData>& transactionData)
38 {
39 if (!transactionData) {
40 ROSEN_LOGE("RSRenderServiceConnectionProxy::CommitTransaction transactionData nullptr!");
41 return;
42 }
43 bool isUniMode = RSSystemProperties::IsUniRenderMode();
44 transactionData->SetUniRender(isUniMode);
45 transactionData->SetSendingPid(pid_);
46
47 // split to several parcels if parcel size > PARCEL_SPLIT_THRESHOLD during marshalling
48 std::vector<std::shared_ptr<MessageParcel>> parcelVector;
49 while (transactionData->GetMarshallingIndex() < transactionData->GetCommandCount()) {
50 if (isUniMode) {
51 ++transactionDataIndex_;
52 }
53 transactionData->SetIndex(transactionDataIndex_);
54 std::shared_ptr<MessageParcel> parcel = std::make_shared<MessageParcel>();
55 if (!FillParcelWithTransactionData(transactionData, parcel)) {
56 ROSEN_LOGE("FillParcelWithTransactionData failed!");
57 return;
58 }
59 parcelVector.emplace_back(parcel);
60 }
61
62 MessageOption option;
63 option.SetFlags(MessageOption::TF_ASYNC);
64 for (auto& parcel : parcelVector) {
65 MessageParcel reply;
66 RS_ASYNC_TRACE_BEGIN("RSProxySendRequest", parcel->GetDataSize());
67 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::COMMIT_TRANSACTION, *parcel, reply, option);
68 if (err != NO_ERROR) {
69 ROSEN_LOGE("RSRenderServiceConnectionProxy::CommitTransaction SendRequest failed, err = %d", err);
70 return;
71 }
72 }
73 }
74
FillParcelWithTransactionData(std::unique_ptr<RSTransactionData> & transactionData,std::shared_ptr<MessageParcel> & data)75 bool RSRenderServiceConnectionProxy::FillParcelWithTransactionData(
76 std::unique_ptr<RSTransactionData>& transactionData, std::shared_ptr<MessageParcel>& data)
77 {
78 // write a flag at the begin of parcel to identify parcel type
79 // 0: indicate normal parcel
80 // 1: indicate ashmem parcel
81 data->WriteInt32(0);
82
83 // 1. marshalling RSTransactionData
84 RS_TRACE_BEGIN("Marsh RSTransactionData: cmd count:" + std::to_string(transactionData->GetCommandCount()) +
85 " transactionFlag:[" + std::to_string(pid_) + ", " + std::to_string(transactionData->GetIndex()) + "],isUni:" +
86 std::to_string(transactionData->GetUniRender()));
87 bool success = data->WriteParcelable(transactionData.get());
88 RS_TRACE_END();
89 if (!success) {
90 ROSEN_LOGE("FillParcelWithTransactionData data.WriteParcelable failed!");
91 return false;
92 }
93
94 // 2. convert data to new ashmem parcel if size over threshold
95 std::shared_ptr<MessageParcel> ashmemParcel = nullptr;
96 if (data->GetDataSize() > ASHMEM_SIZE_THRESHOLD) {
97 ashmemParcel = RSAshmemHelper::CreateAshmemParcel(data);
98 }
99 if (ashmemParcel != nullptr) {
100 data = ashmemParcel;
101 }
102 return true;
103 }
104
ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask> & task)105 void RSRenderServiceConnectionProxy::ExecuteSynchronousTask(const std::shared_ptr<RSSyncTask>& task)
106 {
107 MessageParcel data;
108 MessageParcel reply;
109 MessageOption option;
110
111 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
112 return;
113 }
114
115 if (!task->Marshalling(data)) {
116 return;
117 }
118
119 option.SetFlags(MessageOption::TF_SYNC);
120 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::EXECUTE_SYNCHRONOUS_TASK, data, reply, option);
121 if (err != NO_ERROR) {
122 return;
123 }
124
125 if (task->CheckHeader(reply)) {
126 task->ReadFromParcel(reply);
127 }
128 }
129
SetRenderModeChangeCallback(sptr<RSIRenderModeChangeCallback> callback)130 int32_t RSRenderServiceConnectionProxy::SetRenderModeChangeCallback(sptr<RSIRenderModeChangeCallback> callback)
131 {
132 if (callback == nullptr) {
133 ROSEN_LOGE("RSRenderServiceConnectionProxy::SetRenderModeChangeCallback: callback is nullptr.");
134 return INVALID_ARGUMENTS;
135 }
136
137 MessageParcel data;
138 MessageParcel reply;
139 MessageOption option;
140
141 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
142 return WRITE_PARCEL_ERR;
143 }
144
145 option.SetFlags(MessageOption::TF_ASYNC);
146 data.WriteRemoteObject(callback->AsObject());
147 int32_t err =
148 Remote()->SendRequest(RSIRenderServiceConnection::SET_RENDER_MODE_CHANGE_CALLBACK, data, reply, option);
149 if (err != NO_ERROR) {
150 ROSEN_LOGE("RSRenderServiceConnectionProxy::SetRenderModeChangeCallback: Send Request err.");
151 return RS_CONNECTION_ERROR;
152 }
153 int32_t result = reply.ReadInt32();
154 return result;
155 }
156
UpdateRenderMode(bool isUniRender)157 void RSRenderServiceConnectionProxy::UpdateRenderMode(bool isUniRender)
158 {
159 MessageParcel data;
160 MessageParcel reply;
161 MessageOption option;
162
163 if (!data.WriteBool(isUniRender)) {
164 ROSEN_LOGE("RSRenderServiceConnectionProxy::UpdateRenderMode WriteBool failed!");
165 return;
166 }
167 option.SetFlags(MessageOption::TF_ASYNC);
168 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::UPDATE_RENDER_MODE, data, reply, option);
169 if (err != NO_ERROR) {
170 ROSEN_LOGE("RSRenderServiceConnectionProxy::UpdateRenderMode SendRequest failed, err = %d", err);
171 return;
172 }
173 }
174
GetUniRenderEnabled()175 bool RSRenderServiceConnectionProxy::GetUniRenderEnabled()
176 {
177 MessageParcel data;
178 MessageParcel reply;
179 MessageOption option;
180
181 option.SetFlags(MessageOption::TF_SYNC);
182 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_UNI_RENDER_ENABLED, data, reply, option);
183 if (err != NO_ERROR) {
184 return false;
185 }
186 return reply.ReadBool();
187 }
188
QueryIfRTNeedRender()189 bool RSRenderServiceConnectionProxy::QueryIfRTNeedRender()
190 {
191 MessageParcel data;
192 MessageParcel reply;
193 MessageOption option;
194
195 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::QUERY_RT_NEED_RENDER, data, reply, option);
196 if (err != NO_ERROR) {
197 return true;
198 }
199 return reply.ReadBool();
200 }
201
CreateNode(const RSSurfaceRenderNodeConfig & config)202 bool RSRenderServiceConnectionProxy::CreateNode(const RSSurfaceRenderNodeConfig& config)
203 {
204 MessageParcel data;
205 MessageParcel reply;
206 MessageOption option;
207
208 if (!data.WriteUint64(config.id)) {
209 return false;
210 }
211 if (!data.WriteString(config.name)) {
212 return false;
213 }
214 option.SetFlags(MessageOption::TF_SYNC);
215 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::CREATE_NODE, data, reply, option);
216 if (err != NO_ERROR) {
217 return false;
218 }
219
220 return reply.ReadBool();
221 }
222
CreateNodeAndSurface(const RSSurfaceRenderNodeConfig & config)223 sptr<Surface> RSRenderServiceConnectionProxy::CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config)
224 {
225 MessageParcel data;
226 MessageParcel reply;
227 MessageOption option;
228
229 if (!data.WriteUint64(config.id)) {
230 return nullptr;
231 }
232 if (!data.WriteString(config.name)) {
233 return nullptr;
234 }
235 if (!data.WriteUint8(static_cast<uint8_t>(config.nodeType))) {
236 return nullptr;
237 }
238 option.SetFlags(MessageOption::TF_SYNC);
239 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::CREATE_NODE_AND_SURFACE, data, reply, option);
240 if (err != NO_ERROR) {
241 return nullptr;
242 }
243 sptr<IRemoteObject> surfaceObject = reply.ReadRemoteObject();
244 sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(surfaceObject);
245 sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
246 return surface;
247 }
248
CreateVSyncConnection(const std::string & name)249 sptr<IVSyncConnection> RSRenderServiceConnectionProxy::CreateVSyncConnection(const std::string& name)
250 {
251 MessageParcel data;
252 MessageParcel reply;
253 MessageOption option;
254
255 data.WriteString(name);
256 option.SetFlags(MessageOption::TF_SYNC);
257 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::CREATE_VSYNC_CONNECTION, data, reply, option);
258 if (err != NO_ERROR) {
259 return nullptr;
260 }
261
262 sptr<IRemoteObject> rObj = reply.ReadRemoteObject();
263 sptr<IVSyncConnection> conn = iface_cast<IVSyncConnection>(rObj);
264 return conn;
265 }
266
SetFocusAppInfo(int32_t pid,int32_t uid,const std::string & bundleName,const std::string & abilityName)267 int32_t RSRenderServiceConnectionProxy::SetFocusAppInfo(
268 int32_t pid, int32_t uid, const std::string &bundleName, const std::string &abilityName)
269 {
270 MessageParcel data;
271 MessageParcel reply;
272 MessageOption option;
273
274 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
275 return WRITE_PARCEL_ERR;
276 }
277
278 option.SetFlags(MessageOption::TF_ASYNC);
279 data.WriteInt32(pid);
280 data.WriteInt32(uid);
281 data.WriteString(bundleName);
282 data.WriteString(abilityName);
283 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_FOCUS_APP_INFO, data, reply, option);
284 if (err != NO_ERROR) {
285 ROSEN_LOGE("RSRenderServiceConnectionProxy::SetFocusAppInfo: Send Request err.");
286 return RS_CONNECTION_ERROR;
287 }
288 int32_t result = reply.ReadInt32();
289 return result;
290 }
291
GetDefaultScreenId()292 ScreenId RSRenderServiceConnectionProxy::GetDefaultScreenId()
293 {
294 MessageParcel data;
295 MessageParcel reply;
296 MessageOption option;
297
298 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
299 return INVALID_SCREEN_ID;
300 }
301
302 option.SetFlags(MessageOption::TF_SYNC);
303 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_DEFAULT_SCREEN_ID, data, reply, option);
304 if (err != NO_ERROR) {
305 return INVALID_SCREEN_ID;
306 }
307
308 ScreenId id = reply.ReadUint64();
309 return id;
310 }
311
GetAllScreenIds()312 std::vector<ScreenId> RSRenderServiceConnectionProxy::GetAllScreenIds()
313 {
314 MessageParcel data;
315 MessageParcel reply;
316 MessageOption option;
317 std::vector<ScreenId> screenIds;
318
319 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
320 return std::vector<ScreenId>();
321 }
322
323 option.SetFlags(MessageOption::TF_SYNC);
324 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_ALL_SCREEN_IDS, data, reply, option);
325 if (err != NO_ERROR) {
326 return std::vector<ScreenId>();
327 }
328
329 uint32_t size = reply.ReadUint32();
330 for (uint32_t i = 0; i < size; i++) {
331 screenIds.emplace_back(reply.ReadUint64());
332 }
333
334 return screenIds;
335 }
336
CreateVirtualScreen(const std::string & name,uint32_t width,uint32_t height,sptr<Surface> surface,ScreenId mirrorId,int32_t flags)337 ScreenId RSRenderServiceConnectionProxy::CreateVirtualScreen(
338 const std::string &name,
339 uint32_t width,
340 uint32_t height,
341 sptr<Surface> surface,
342 ScreenId mirrorId,
343 int32_t flags)
344 {
345 MessageParcel data;
346 MessageParcel reply;
347 MessageOption option;
348
349 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
350 return INVALID_SCREEN_ID;
351 }
352
353 option.SetFlags(MessageOption::TF_SYNC);
354 data.WriteString(name);
355 data.WriteUint32(width);
356 data.WriteUint32(height);
357
358 if (surface==nullptr) {
359 data.WriteRemoteObject(nullptr);
360 } else {
361 auto producer = surface->GetProducer();
362 data.WriteRemoteObject(producer->AsObject());
363 }
364
365 data.WriteUint64(mirrorId);
366 data.WriteInt32(flags);
367 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::CREATE_VIRTUAL_SCREEN, data, reply, option);
368 if (err != NO_ERROR) {
369 return INVALID_SCREEN_ID;
370 }
371
372 ScreenId id = reply.ReadUint64();
373 return id;
374 }
375
SetVirtualScreenSurface(ScreenId id,sptr<Surface> surface)376 int32_t RSRenderServiceConnectionProxy::SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface)
377 {
378 if (surface == nullptr) {
379 ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVirtualScreenSurface: Send surface is nullptr!");
380 return INVALID_ARGUMENTS;
381 }
382
383 MessageParcel data;
384 MessageParcel reply;
385 MessageOption option;
386
387 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
388 return WRITE_PARCEL_ERR;
389 }
390
391 option.SetFlags(MessageOption::TF_ASYNC);
392 data.WriteUint64(id);
393 auto producer = surface->GetProducer();
394 data.WriteRemoteObject(producer->AsObject());
395 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_VIRTUAL_SCREEN_SURFACE, data, reply, option);
396 if (err != NO_ERROR) {
397 ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVirtualScreenSurface: Send Request err.");
398 }
399
400 int32_t status = reply.ReadInt32();
401 return status;
402 }
403
RemoveVirtualScreen(ScreenId id)404 void RSRenderServiceConnectionProxy::RemoveVirtualScreen(ScreenId id)
405 {
406 MessageParcel data;
407 MessageParcel reply;
408 MessageOption option;
409
410 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
411 return;
412 }
413
414 option.SetFlags(MessageOption::TF_ASYNC);
415 data.WriteUint64(id);
416 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::REMOVE_VIRTUAL_SCREEN, data, reply, option);
417 if (err != NO_ERROR) {
418 ROSEN_LOGE("RSRenderServiceConnectionProxy::RemoveVirtualScreen: Send Request err.");
419 }
420 }
421
SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback)422 int32_t RSRenderServiceConnectionProxy::SetScreenChangeCallback(sptr<RSIScreenChangeCallback> callback)
423 {
424 if (callback == nullptr) {
425 ROSEN_LOGE("RSRenderServiceConnectionProxy::SetScreenChangeCallback: callback is nullptr.");
426 return INVALID_ARGUMENTS;
427 }
428
429 MessageParcel data;
430 MessageParcel reply;
431 MessageOption option;
432
433 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
434 return WRITE_PARCEL_ERR;
435 }
436
437 option.SetFlags(MessageOption::TF_ASYNC);
438 data.WriteRemoteObject(callback->AsObject());
439 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_SCREEN_CHANGE_CALLBACK, data, reply, option);
440 if (err != NO_ERROR) {
441 ROSEN_LOGE("RSRenderServiceConnectionProxy::SetScreenChangeCallback: Send Request err.");
442 return RS_CONNECTION_ERROR;
443 }
444 int32_t result = reply.ReadInt32();
445 return result;
446 }
447
SetScreenActiveMode(ScreenId id,uint32_t modeId)448 void RSRenderServiceConnectionProxy::SetScreenActiveMode(ScreenId id, uint32_t modeId)
449 {
450 MessageParcel data;
451 MessageParcel reply;
452 MessageOption option;
453
454 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
455 return;
456 }
457 option.SetFlags(MessageOption::TF_SYNC);
458 data.WriteUint64(id);
459 data.WriteUint32(modeId);
460 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_SCREEN_ACTIVE_MODE, data, reply, option);
461 if (err != NO_ERROR) {
462 return;
463 }
464 }
465
SetVirtualScreenResolution(ScreenId id,uint32_t width,uint32_t height)466 int32_t RSRenderServiceConnectionProxy::SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height)
467 {
468 MessageParcel data;
469 MessageParcel reply;
470 MessageOption option;
471
472 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
473 ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVirtualScreenResolution: WriteInterfaceToken err.");
474 return WRITE_PARCEL_ERR;
475 }
476 option.SetFlags(MessageOption::TF_SYNC);
477 data.WriteUint64(id);
478 data.WriteUint32(width);
479 data.WriteUint32(height);
480 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_VIRTUAL_SCREEN_RESOLUTION,
481 data, reply, option);
482 if (err != NO_ERROR) {
483 ROSEN_LOGE("RSRenderServiceConnectionProxy::SetVirtualScreenResolution: Send Request err.");
484 return RS_CONNECTION_ERROR;
485 }
486 int32_t status = reply.ReadInt32();
487 return status;
488 }
489
SetScreenPowerStatus(ScreenId id,ScreenPowerStatus status)490 void RSRenderServiceConnectionProxy::SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status)
491 {
492 MessageParcel data;
493 MessageParcel reply;
494 MessageOption option;
495
496 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
497 return;
498 }
499 option.SetFlags(MessageOption::TF_SYNC);
500 data.WriteUint64(id);
501 data.WriteUint32(static_cast<uint32_t>(status));
502 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_SCREEN_POWER_STATUS, data, reply, option);
503 if (err != NO_ERROR) {
504 return;
505 }
506 }
507
RegisterApplicationAgent(uint32_t pid,sptr<IApplicationAgent> app)508 void RSRenderServiceConnectionProxy::RegisterApplicationAgent(uint32_t pid, sptr<IApplicationAgent> app)
509 {
510 if (app == nullptr) {
511 ROSEN_LOGE("RSRenderServiceProxy: callback == nullptr\n");
512 return;
513 }
514
515 MessageParcel data;
516 MessageParcel reply;
517 MessageOption option;
518 option.SetFlags(MessageOption::TF_ASYNC);
519 data.WriteUint32(pid);
520 data.WriteRemoteObject(app->AsObject());
521 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::REGISTER_APPLICATION_AGENT, data, reply, option);
522 if (err != NO_ERROR) {
523 ROSEN_LOGE("RSRenderServiceProxy: Remote()->SendRequest() error.\n");
524 return;
525 }
526 }
527
TakeSurfaceCapture(NodeId id,sptr<RSISurfaceCaptureCallback> callback,float scaleX,float scaleY)528 void RSRenderServiceConnectionProxy::TakeSurfaceCapture(NodeId id, sptr<RSISurfaceCaptureCallback> callback,
529 float scaleX, float scaleY)
530 {
531 if (callback == nullptr) {
532 ROSEN_LOGE("RSRenderServiceProxy: callback == nullptr\n");
533 return;
534 }
535
536 MessageParcel data;
537 MessageParcel reply;
538 MessageOption option;
539 option.SetFlags(MessageOption::TF_ASYNC);
540 data.WriteUint64(id);
541 data.WriteRemoteObject(callback->AsObject());
542 data.WriteFloat(scaleX);
543 data.WriteFloat(scaleY);
544 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::TAKE_SURFACE_CAPTURE, data, reply, option);
545 if (err != NO_ERROR) {
546 ROSEN_LOGE("RSRenderServiceProxy: Remote()->SendRequest() error.\n");
547 return;
548 }
549 }
550
GetVirtualScreenResolution(ScreenId id)551 RSVirtualScreenResolution RSRenderServiceConnectionProxy::GetVirtualScreenResolution(ScreenId id)
552 {
553 MessageParcel data;
554 MessageParcel reply;
555 MessageOption option;
556 RSVirtualScreenResolution virtualScreenResolution;
557
558 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
559 return virtualScreenResolution;
560 }
561 option.SetFlags(MessageOption::TF_SYNC);
562 data.WriteUint64(id);
563 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_VIRTUAL_SCREEN_RESOLUTION,
564 data, reply, option);
565 if (err != NO_ERROR) {
566 return virtualScreenResolution;
567 }
568
569 sptr<RSVirtualScreenResolution> pVirtualScreenResolution(reply.ReadParcelable<RSVirtualScreenResolution>());
570 if (pVirtualScreenResolution == nullptr) {
571 return virtualScreenResolution;
572 }
573 virtualScreenResolution = *pVirtualScreenResolution;
574 return virtualScreenResolution;
575 }
576
GetScreenActiveMode(ScreenId id)577 RSScreenModeInfo RSRenderServiceConnectionProxy::GetScreenActiveMode(ScreenId id)
578 {
579 MessageParcel data;
580 MessageParcel reply;
581 MessageOption option;
582 RSScreenModeInfo screenModeInfo;
583
584 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
585 return screenModeInfo;
586 }
587 option.SetFlags(MessageOption::TF_SYNC);
588 data.WriteUint64(id);
589 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_ACTIVE_MODE, data, reply, option);
590 if (err != NO_ERROR) {
591 return screenModeInfo;
592 }
593
594 sptr<RSScreenModeInfo> pScreenModeInfo(reply.ReadParcelable<RSScreenModeInfo>());
595 if (pScreenModeInfo == nullptr) {
596 return screenModeInfo;
597 }
598 screenModeInfo = *pScreenModeInfo;
599 return screenModeInfo;
600 }
601
GetScreenSupportedModes(ScreenId id)602 std::vector<RSScreenModeInfo> RSRenderServiceConnectionProxy::GetScreenSupportedModes(ScreenId id)
603 {
604 MessageParcel data;
605 MessageParcel reply;
606 MessageOption option;
607 std::vector<RSScreenModeInfo> screenSupportedModes;
608
609 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
610 return screenSupportedModes;
611 }
612
613 option.SetFlags(MessageOption::TF_SYNC);
614 data.WriteUint64(id);
615 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_SUPPORTED_MODES, data, reply, option);
616 if (err != NO_ERROR) {
617 return screenSupportedModes;
618 }
619
620 uint64_t modeCount = reply.ReadUint64();
621 screenSupportedModes.resize(modeCount);
622 for (uint64_t modeIndex = 0; modeIndex < modeCount; modeIndex++) {
623 sptr<RSScreenModeInfo> itemScreenMode = reply.ReadParcelable<RSScreenModeInfo>();
624 if (itemScreenMode == nullptr) {
625 continue;
626 } else {
627 screenSupportedModes[modeIndex] = *itemScreenMode;
628 }
629 }
630 return screenSupportedModes;
631 }
632
GetScreenCapability(ScreenId id)633 RSScreenCapability RSRenderServiceConnectionProxy::GetScreenCapability(ScreenId id)
634 {
635 MessageParcel data;
636 MessageParcel reply;
637 MessageOption option;
638 RSScreenCapability screenCapability;
639 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
640 return screenCapability;
641 }
642 option.SetFlags(MessageOption::TF_SYNC);
643 data.WriteUint64(id);
644 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_CAPABILITY, data, reply, option);
645 if (err != NO_ERROR) {
646 return screenCapability;
647 }
648
649 sptr<RSScreenCapability> pScreenCapability(reply.ReadParcelable<RSScreenCapability>());
650 if (pScreenCapability == nullptr) {
651 return screenCapability;
652 }
653 screenCapability = *pScreenCapability;
654 return screenCapability;
655 }
656
GetScreenPowerStatus(ScreenId id)657 ScreenPowerStatus RSRenderServiceConnectionProxy::GetScreenPowerStatus(ScreenId id)
658 {
659 MessageParcel data;
660 MessageParcel reply;
661 MessageOption option;
662 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
663 return INVALID_POWER_STATUS;
664 }
665 option.SetFlags(MessageOption::TF_SYNC);
666 data.WriteUint64(id);
667 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_POWER_STATUS, data, reply, option);
668 if (err != NO_ERROR) {
669 return INVALID_POWER_STATUS;
670 }
671 return static_cast<ScreenPowerStatus>(reply.ReadUint32());
672 }
673
GetScreenData(ScreenId id)674 RSScreenData RSRenderServiceConnectionProxy::GetScreenData(ScreenId id)
675 {
676 MessageParcel data;
677 MessageParcel reply;
678 MessageOption option;
679 RSScreenData screenData;
680 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
681 return screenData;
682 }
683 option.SetFlags(MessageOption::TF_SYNC);
684 data.WriteUint64(id);
685 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_DATA, data, reply, option);
686 if (err != NO_ERROR) {
687 return screenData;
688 }
689 sptr<RSScreenData> pScreenData(reply.ReadParcelable<RSScreenData>());
690 if (pScreenData == nullptr) {
691 return screenData;
692 }
693 screenData = *pScreenData;
694 return screenData;
695 }
696
GetScreenBacklight(ScreenId id)697 int32_t RSRenderServiceConnectionProxy::GetScreenBacklight(ScreenId id)
698 {
699 MessageParcel data;
700 MessageParcel reply;
701 MessageOption option;
702 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
703 return INVALID_BACKLIGHT_VALUE;
704 }
705 option.SetFlags(MessageOption::TF_SYNC);
706 data.WriteUint64(id);
707 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_BACK_LIGHT, data, reply, option);
708 if (err != NO_ERROR) {
709 return INVALID_BACKLIGHT_VALUE;
710 }
711 int32_t level = reply.ReadInt32();
712 return level;
713 }
714
SetScreenBacklight(ScreenId id,uint32_t level)715 void RSRenderServiceConnectionProxy::SetScreenBacklight(ScreenId id, uint32_t level)
716 {
717 MessageParcel data;
718 MessageParcel reply;
719 MessageOption option;
720 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
721 return;
722 }
723 option.SetFlags(MessageOption::TF_SYNC);
724 data.WriteUint64(id);
725 data.WriteUint32(level);
726 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_SCREEN_BACK_LIGHT, data, reply, option);
727 if (err != NO_ERROR) {
728 return;
729 }
730 }
731
RegisterBufferAvailableListener(NodeId id,sptr<RSIBufferAvailableCallback> callback,bool isFromRenderThread)732 void RSRenderServiceConnectionProxy::RegisterBufferAvailableListener(
733 NodeId id, sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread)
734 {
735 if (callback == nullptr) {
736 ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterBufferAvailableListener: callback is nullptr.");
737 return;
738 }
739
740 MessageParcel data;
741 MessageParcel reply;
742 MessageOption option;
743
744 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
745 return;
746 }
747
748 option.SetFlags(MessageOption::TF_SYNC);
749 data.WriteUint64(id);
750 data.WriteRemoteObject(callback->AsObject());
751 data.WriteBool(isFromRenderThread);
752 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_BUFFER_AVAILABLE_LISTENER, data, reply, option);
753 if (err != NO_ERROR) {
754 ROSEN_LOGE("RSRenderServiceConnectionProxy::RegisterBufferAvailableListener: Send Request err.");
755 }
756 }
757
GetScreenSupportedColorGamuts(ScreenId id,std::vector<ScreenColorGamut> & mode)758 int32_t RSRenderServiceConnectionProxy::GetScreenSupportedColorGamuts(ScreenId id, std::vector<ScreenColorGamut>& mode)
759 {
760 MessageParcel data;
761 MessageParcel reply;
762 MessageOption option;
763 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
764 return RS_CONNECTION_ERROR;
765 }
766 option.SetFlags(MessageOption::TF_SYNC);
767 data.WriteUint64(id);
768 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_SUPPORTED_GAMUTS, data, reply, option);
769 if (err != NO_ERROR) {
770 return RS_CONNECTION_ERROR;
771 }
772 int32_t result = reply.ReadInt32();
773 if (result == SUCCESS) {
774 mode.clear();
775 std::vector<uint32_t> modeRecv;
776 reply.ReadUInt32Vector(&modeRecv);
777 for (auto i : modeRecv) {
778 mode.push_back(static_cast<ScreenColorGamut>(i));
779 }
780 }
781 return result;
782 }
783
GetScreenSupportedMetaDataKeys(ScreenId id,std::vector<ScreenHDRMetadataKey> & keys)784 int32_t RSRenderServiceConnectionProxy::GetScreenSupportedMetaDataKeys(
785 ScreenId id, std::vector<ScreenHDRMetadataKey>& keys)
786 {
787 MessageParcel data;
788 MessageParcel reply;
789 MessageOption option;
790 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
791 return RS_CONNECTION_ERROR;
792 }
793 option.SetFlags(MessageOption::TF_SYNC);
794 data.WriteUint64(id);
795 int32_t err = Remote()->SendRequest(
796 RSIRenderServiceConnection::GET_SCREEN_SUPPORTED_METADATAKEYS, data, reply, option);
797 if (err != NO_ERROR) {
798 return RS_CONNECTION_ERROR;
799 }
800 int32_t result = reply.ReadInt32();
801 if (result == SUCCESS) {
802 keys.clear();
803 std::vector<uint32_t> keyRecv;
804 reply.ReadUInt32Vector(&keyRecv);
805 for (auto i : keyRecv) {
806 keys.push_back(static_cast<ScreenHDRMetadataKey>(i));
807 }
808 }
809 return result;
810 }
811
GetScreenColorGamut(ScreenId id,ScreenColorGamut & mode)812 int32_t RSRenderServiceConnectionProxy::GetScreenColorGamut(ScreenId id, ScreenColorGamut& mode)
813 {
814 MessageParcel data;
815 MessageParcel reply;
816 MessageOption option;
817 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
818 return RS_CONNECTION_ERROR;
819 }
820 option.SetFlags(MessageOption::TF_SYNC);
821 data.WriteUint64(id);
822 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_GAMUT, data, reply, option);
823 if (err != NO_ERROR) {
824 return RS_CONNECTION_ERROR;
825 }
826 int32_t result = reply.ReadInt32();
827 if (result == SUCCESS) {
828 mode = static_cast<ScreenColorGamut>(reply.ReadUint32());
829 }
830 return result;
831 }
832
SetScreenColorGamut(ScreenId id,int32_t modeIdx)833 int32_t RSRenderServiceConnectionProxy::SetScreenColorGamut(ScreenId id, int32_t modeIdx)
834 {
835 MessageParcel data;
836 MessageParcel reply;
837 MessageOption option;
838 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
839 return RS_CONNECTION_ERROR;
840 }
841 option.SetFlags(MessageOption::TF_SYNC);
842 data.WriteUint64(id);
843 data.WriteInt32(modeIdx);
844 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_SCREEN_GAMUT, data, reply, option);
845 if (err != NO_ERROR) {
846 return RS_CONNECTION_ERROR;
847 }
848 int32_t result = reply.ReadInt32();
849 return result;
850 }
851
SetScreenGamutMap(ScreenId id,ScreenGamutMap mode)852 int32_t RSRenderServiceConnectionProxy::SetScreenGamutMap(ScreenId id, ScreenGamutMap mode)
853 {
854 MessageParcel data;
855 MessageParcel reply;
856 MessageOption option;
857 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
858 return RS_CONNECTION_ERROR;
859 }
860 option.SetFlags(MessageOption::TF_SYNC);
861 data.WriteUint64(id);
862 data.WriteUint32(mode);
863 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_SCREEN_GAMUT_MAP, data, reply, option);
864 if (err != NO_ERROR) {
865 return RS_CONNECTION_ERROR;
866 }
867 int32_t result = reply.ReadInt32();
868 return result;
869 }
870
GetScreenGamutMap(ScreenId id,ScreenGamutMap & mode)871 int32_t RSRenderServiceConnectionProxy::GetScreenGamutMap(ScreenId id, ScreenGamutMap& mode)
872 {
873 MessageParcel data;
874 MessageParcel reply;
875 MessageOption option;
876 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
877 return RS_CONNECTION_ERROR;
878 }
879 option.SetFlags(MessageOption::TF_SYNC);
880 data.WriteUint64(id);
881 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_GAMUT_MAP, data, reply, option);
882 if (err != NO_ERROR) {
883 return RS_CONNECTION_ERROR;
884 }
885 int32_t result = reply.ReadInt32();
886 if (result == SUCCESS) {
887 mode = static_cast<ScreenGamutMap>(reply.ReadUint32());
888 }
889 return result;
890 }
891
GetScreenHDRCapability(ScreenId id,RSScreenHDRCapability & screenHdrCapability)892 int32_t RSRenderServiceConnectionProxy::GetScreenHDRCapability(ScreenId id, RSScreenHDRCapability& screenHdrCapability)
893 {
894 MessageParcel data;
895 MessageParcel reply;
896 MessageOption option;
897 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
898 return RS_CONNECTION_ERROR;
899 }
900 option.SetFlags(MessageOption::TF_SYNC);
901 data.WriteUint64(id);
902 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_HDR_CAPABILITY, data, reply, option);
903 if (err != NO_ERROR) {
904 return RS_CONNECTION_ERROR;
905 }
906 int32_t result = reply.ReadInt32();
907 if (result != SUCCESS) {
908 return result;
909 }
910 sptr<RSScreenHDRCapability> pScreenCapability = reply.ReadParcelable<RSScreenHDRCapability>();
911 if (pScreenCapability == nullptr) {
912 return RS_CONNECTION_ERROR;
913 }
914 screenHdrCapability = *pScreenCapability;
915 return SUCCESS;
916 }
917
GetScreenType(ScreenId id,RSScreenType & screenType)918 int32_t RSRenderServiceConnectionProxy::GetScreenType(ScreenId id, RSScreenType& screenType)
919 {
920 MessageParcel data;
921 MessageParcel reply;
922 MessageOption option;
923 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
924 return RS_CONNECTION_ERROR;
925 }
926 option.SetFlags(MessageOption::TF_SYNC);
927 data.WriteUint64(id);
928 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::GET_SCREEN_TYPE, data, reply, option);
929 if (err != NO_ERROR) {
930 return RS_CONNECTION_ERROR;
931 }
932 int32_t result = reply.ReadInt32();
933 if (result == SUCCESS) {
934 screenType = static_cast<RSScreenType>(reply.ReadUint32());
935 }
936 return result;
937 }
938
SetScreenSkipFrameInterval(ScreenId id,uint32_t skipFrameInterval)939 int32_t RSRenderServiceConnectionProxy::SetScreenSkipFrameInterval(ScreenId id, uint32_t skipFrameInterval)
940 {
941 MessageParcel data;
942 MessageParcel reply;
943 MessageOption option;
944 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
945 return RS_CONNECTION_ERROR;
946 }
947 option.SetFlags(MessageOption::TF_SYNC);
948 data.WriteUint64(id);
949 data.WriteUint32(skipFrameInterval);
950 int32_t err = Remote()->SendRequest(RSIRenderServiceConnection::SET_SCREEN_SKIP_FRAME_INTERVAL,
951 data, reply, option);
952 if (err != NO_ERROR) {
953 return RS_CONNECTION_ERROR;
954 }
955 int32_t result = reply.ReadInt32();
956 return result;
957 }
958
RegisterOcclusionChangeCallback(sptr<RSIOcclusionChangeCallback> callback)959 int32_t RSRenderServiceConnectionProxy::RegisterOcclusionChangeCallback(sptr<RSIOcclusionChangeCallback> callback)
960 {
961 MessageParcel data;
962 MessageParcel reply;
963 MessageOption option;
964 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
965 return RS_CONNECTION_ERROR;
966 }
967 option.SetFlags(MessageOption::TF_SYNC);
968 data.WriteRemoteObject(callback->AsObject());
969 int32_t err = Remote()->SendRequest(
970 RSIRenderServiceConnection::REGISTER_OCCLUSION_CHANGE_CALLBACK, data, reply, option);
971 if (err != NO_ERROR) {
972 return RS_CONNECTION_ERROR;
973 }
974 int32_t result = reply.ReadInt32();
975 return result;
976 }
977
SetAppWindowNum(uint32_t num)978 void RSRenderServiceConnectionProxy::SetAppWindowNum(uint32_t num)
979 {
980 MessageParcel data;
981 MessageParcel reply;
982 MessageOption option;
983 if (!data.WriteInterfaceToken(RSIRenderServiceConnection::GetDescriptor())) {
984 return;
985 }
986 option.SetFlags(MessageOption::TF_ASYNC);
987 data.WriteUint32(num);
988 int32_t err = Remote()->SendRequest(
989 RSIRenderServiceConnection::SET_APP_WINDOW_NUM, data, reply, option);
990 if (err != NO_ERROR) {
991 ROSEN_LOGE("RSRenderServiceConnectionProxy::SetAppWindowNum: Send Request err.");
992 }
993 }
994 } // namespace Rosen
995 } // namespace OHOS
996