1 /*
2  * Copyright (c) 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 "display_device_proxy.h"
17 #include "display_device_common.h"
18 
19 #undef HDF_LOG_TAG
20 #define HDF_LOG_TAG DisplayHostProxy
21 
22 using OHOS::Display::Device::IDisplayDevice;
23 using OHOS::Display::Device::Client::DisplayDeviceProxy;
24 using std::map;
25 using std::move;
26 using std::pair;
27 using std::unique_ptr;
28 
29 static constexpr uint32_t MAX_DEVID = 4;
30 static const std::string serverName = "display_device_service";
31 static OHOS::sptr<IDisplayDevice> g_instance;
32 
Initialize(void)33 void IDisplayDevice::Initialize(void)
34 {
35     DISPLAY_START;
36     if (g_instance != nullptr) {
37         DISPLAY_LOG("initialize was already");
38         DISPLAY_END;
39         return;
40     }
41     do {
42         using OHOS::sptr;
43         using OHOS::HDI::ServiceManager::V1_0::IServiceManager;
44         auto servMgr = IServiceManager::Get();
45         if (servMgr == nullptr) {
46             DISPLAY_LOG("IServiceManager failed!");
47             break;
48         }
49         sptr<IRemoteObject> remote = servMgr->GetService(serverName.c_str());
50         if (remote == nullptr) {
51             DISPLAY_LOG("IServiceManager IDisplayDevice(%{public}s) failed!", serverName.c_str());
52             break;
53         }
54         g_instance = iface_cast<IDisplayDevice>(remote);
55         if (g_instance == nullptr) {
56             DISPLAY_LOG("failed to iface cast IDisplayDevice");
57             break;
58         }
59         g_instance->m_hotPlugObject_ = new DisplayRegisterCallbackFramework();
60         if (g_instance->m_hotPlugObject_ == nullptr) {
61             DISPLAY_LOG("create DisplayRegisterCallbackFramework failed!");
62             break;
63         }
64         DISPLAY_END;
65         return;
66     } while (0);
67     return;
68 }
69 
GetInstance(void)70 OHOS::sptr<IDisplayDevice> DisplayDeviceProxy::GetInstance(void)
71 {
72     DISPLAY_START;
73     DISPLAY_END;
74     if (g_instance == nullptr) {
75         Initialize();
76     }
77     return g_instance;
78 }
79 
ReleaseInstance(void)80 void DisplayDeviceProxy::ReleaseInstance(void)
81 {
82     DISPLAY_START;
83     DISPLAY_END;
84     g_instance = nullptr;
85 }
86 
RegHotPlugCallback(HotPlugCallback callback,void * callBackdata)87 int32_t DisplayDeviceProxy::RegHotPlugCallback(HotPlugCallback callback, void *callBackdata)
88 {
89     DISPLAY_LOG("interface start");
90     if (callback == nullptr || callBackdata == nullptr) {
91         DISPLAY_LOG("callback %{public}s nullptr, data %{public}s nullptr", callback == nullptr ? "is" : "is not",
92             callBackdata == nullptr ? "is" : "is not");
93         return DISPLAY_PARAM_ERR;
94     }
95 
96     m_hotPlugObject_->SetHotplugInData(callback, callBackdata);
97     SetProxyRemoteCallback(m_hotPlugObject_);
98 
99     MessageParcel data;
100     MessageParcel reply;
101     MessageOption option;
102     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor())) {
103         return HDF_FAILURE;
104     }
105     int32_t ret = Remote()->SendRequest(DSP_CMD_REGHOTPLUGCALLBACK, data, reply, option);
106     if (ret != 0) {
107         DISPLAY_LOG("error: failed %{public}d", ret);
108     }
109 
110     DISPLAY_LOG("interface end");
111     return ret;
112 }
113 
RegDisplayVBlankCallback(uint32_t devId,VBlankCallback callback,void * callbackData)114 int32_t DisplayDeviceProxy::RegDisplayVBlankCallback(uint32_t devId, VBlankCallback callback, void *callbackData)
115 {
116     DISPLAY_LOG("interface start");
117     if (callback == nullptr || (devId > MAX_DEVID)) {
118         DISPLAY_LOG("callback %{public}s nullptr, data %{public}s nullptr", callback == nullptr ? "is" : "is not",
119             callbackData == nullptr ? "is" : "is not");
120         return DISPLAY_PARAM_ERR;
121     }
122 
123     m_hotPlugObject_->SetVBlankData(callback, callbackData);
124 
125     MessageParcel data;
126     MessageParcel reply;
127     MessageOption option;
128     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
129         DISPLAY_LOG("error: write devId into parcel failed");
130         return false;
131     }
132 
133     int32_t ret = Remote()->SendRequest(DSP_CMD_REGDISPLAYVBLANKCALLBACK, data, reply, option);
134     if (ret != 0) {
135         DISPLAY_LOG("error: failed %{public}d", ret);
136     }
137 
138     DISPLAY_LOG("interface end");
139     return ret;
140 }
141 
RegDisplayRefreshCallback(uint32_t devId,RefreshCallback callback,void * callBackdata)142 int32_t DisplayDeviceProxy::RegDisplayRefreshCallback(uint32_t devId, RefreshCallback callback, void *callBackdata)
143 {
144     DISPLAY_LOG("interface start");
145     if (callback == nullptr || (devId > MAX_DEVID)) {
146         DISPLAY_LOG("callback %{public}s nullptr, data %{public}s nullptr", callback == nullptr ? "is" : "is not",
147             callBackdata == nullptr ? "is" : "is not");
148         return DISPLAY_PARAM_ERR;
149     }
150 
151     m_hotPlugObject_->SetRefreshData(callback, callBackdata);
152 
153     MessageParcel data;
154     MessageParcel reply;
155     MessageOption option;
156 
157     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
158         DISPLAY_LOG("error: write devId into data failed");
159         return DISPLAY_FAILURE;
160     }
161 
162     int32_t ret = Remote()->SendRequest(DSP_CMD_REGDISPLAYREFRESHCALLBACK, data, reply, option);
163     if (ret != 0) {
164         DISPLAY_LOG("error: failed %{public}d", ret);
165     }
166     DISPLAY_LOG("interface end");
167     return ret;
168 }
169 
GetDisplayCapability(uint32_t devId,DisplayCapability & info)170 int32_t DisplayDeviceProxy::GetDisplayCapability(uint32_t devId, DisplayCapability &info)
171 {
172     DISPLAY_LOG("interface start");
173     printf("DisplayDeviceProxy:%s %d", __func__, __LINE__);
174     if (devId > MAX_DEVID) {
175         return DISPLAY_PARAM_ERR;
176     }
177 
178     MessageParcel data;
179     MessageParcel reply;
180     MessageOption option;
181     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
182         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
183         return DISPLAY_FAILURE;
184     }
185     int32_t ret = Remote()->SendRequest(DSP_CMD_GETDISPLAYCAPABILITY, data, reply, option);
186     if (ret != 0) {
187         DISPLAY_LOG("error: failed %{public}d", ret);
188         return ret;
189     }
190 
191     if (!DisplayDeviceReadData(&info, &reply)) {
192         DISPLAY_LOG("error: %{public}s failed %{public}d", __func__, ret);
193         ret = DISPLAY_FAILURE;
194     }
195     DISPLAY_LOG("interface end");
196     return ret;
197 }
198 
GetDisplaySupportedModes(uint32_t devId,uint32_t & num,DisplayModeInfo * modes)199 int32_t DisplayDeviceProxy::GetDisplaySupportedModes(uint32_t devId, uint32_t &num, DisplayModeInfo *modes)
200 {
201     DISPLAY_LOG("interface start");
202     if (devId > MAX_DEVID) {
203         return DISPLAY_PARAM_ERR;
204     }
205 
206     MessageParcel data;
207     MessageParcel reply;
208     MessageOption option;
209     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
210         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
211         return DISPLAY_FAILURE;
212     }
213     if (!data.WriteInt32(num)) {
214         DISPLAY_LOG("error: %{public}s write num into data failed", __func__);
215         return DISPLAY_FAILURE;
216     }
217 
218     int32_t ret = Remote()->SendRequest(DSP_CMD_GETDISPLAYSUPPORTEDMODES, data, reply, option);
219     if (ret != 0) {
220         DISPLAY_LOG("error: failed %{public}d", ret);
221         return ret;
222     }
223     num = reply.ReadInt32();
224     if (num > 0 && modes != nullptr && !DisplayDeviceReadData(modes, &reply, num)) {
225         DISPLAY_LOG("error: %{public}s read reply failed", __func__);
226         ret = DISPLAY_FAILURE;
227     }
228 
229     DISPLAY_LOG("interface end");
230     return ret;
231 }
232 
GetDisplayMode(uint32_t devId,uint32_t & modeId)233 int32_t DisplayDeviceProxy::GetDisplayMode(uint32_t devId, uint32_t &modeId)
234 {
235     DISPLAY_LOG("interface start");
236     if (devId > MAX_DEVID) {
237         return DISPLAY_PARAM_ERR;
238     }
239 
240     MessageParcel data;
241     MessageParcel reply;
242     MessageOption option;
243     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
244         DISPLAY_LOG("error: write devId into data failed");
245         return DISPLAY_FAILURE;
246     }
247     int32_t ret = Remote()->SendRequest(DSP_CMD_GETDISPLAYMODE, data, reply, option);
248     if (ret != 0) {
249         DISPLAY_LOG("error: failed %{public}d", ret);
250         return ret;
251     }
252     modeId = reply.ReadUint32();
253     DISPLAY_LOG("interface end");
254     return ret;
255 }
256 
SetDisplayMode(uint32_t devId,uint32_t modeId)257 int32_t DisplayDeviceProxy::SetDisplayMode(uint32_t devId, uint32_t modeId)
258 {
259     DISPLAY_LOG("interface start");
260     if (devId > MAX_DEVID) {
261         DISPLAY_LOG("modeId is nullptr");
262         return DISPLAY_PARAM_ERR;
263     }
264 
265     MessageParcel data;
266     MessageParcel reply;
267     MessageOption option;
268     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
269         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
270         return DISPLAY_FAILURE;
271     }
272     if (!data.WriteUint32(modeId)) {
273         DISPLAY_LOG("error: %{public}s write modeId into data failed", __func__);
274         return DISPLAY_FAILURE;
275     }
276     int32_t ret = Remote()->SendRequest(DSP_CMD_SETDISPLAYMODE, data, reply, option);
277     if (ret != 0) {
278         DISPLAY_LOG("error: failed %{public}d", ret);
279         return ret;
280     }
281 
282     DISPLAY_LOG("interface end");
283     return ret;
284 }
285 
GetDisplayPowerStatus(uint32_t devId,DispPowerStatus & status)286 int32_t DisplayDeviceProxy::GetDisplayPowerStatus(uint32_t devId, DispPowerStatus &status)
287 {
288     DISPLAY_LOG("interface start");
289     if (devId > MAX_DEVID) {
290         DISPLAY_LOG("status is nullptr");
291         return DISPLAY_PARAM_ERR;
292     }
293     MessageParcel data;
294     MessageParcel reply;
295     MessageOption option;
296     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
297         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
298         return DISPLAY_FAILURE;
299     }
300     int32_t ret = Remote()->SendRequest(DSP_CMD_GETDISPLAYPOWERSTATUS, data, reply, option);
301     if (ret != 0) {
302         DISPLAY_LOG("error: failed %{public}d", ret);
303         return ret;
304     }
305     status = static_cast<DispPowerStatus>(reply.ReadInt32());
306     DISPLAY_LOG("interface end");
307     return ret;
308 }
309 
SetDisplayPowerStatus(uint32_t devId,DispPowerStatus status)310 int32_t DisplayDeviceProxy::SetDisplayPowerStatus(uint32_t devId, DispPowerStatus status)
311 {
312     DISPLAY_LOG("interface start");
313     if (devId > MAX_DEVID) {
314         DISPLAY_LOG("status is nullptr");
315         return DISPLAY_PARAM_ERR;
316     }
317     MessageParcel data;
318     MessageParcel reply;
319     MessageOption option;
320     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
321         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
322         return DISPLAY_FAILURE;
323     }
324     if (!data.WriteUint32(status)) {
325         DISPLAY_LOG("error: %{public}s write status into data failed", __func__);
326         return DISPLAY_FAILURE;
327     }
328 
329     int32_t ret = Remote()->SendRequest(DSP_CMD_SETDISPLAYPOWERSTATUS, data, reply, option);
330     if (ret != 0) {
331         DISPLAY_LOG("error: failed %{public}d", ret);
332         return ret;
333     }
334     DISPLAY_LOG("interface end");
335     return ret;
336 }
337 
GetDisplayBacklight(uint32_t devId,uint32_t & level)338 int32_t DisplayDeviceProxy::GetDisplayBacklight(uint32_t devId, uint32_t &level)
339 {
340     DISPLAY_LOG("interface start");
341     if (devId > MAX_DEVID) {
342         DISPLAY_LOG("param error");
343         return DISPLAY_PARAM_ERR;
344     }
345 
346     MessageParcel data;
347     MessageParcel reply;
348     MessageOption option;
349     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
350         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
351         return DISPLAY_FAILURE;
352     }
353     int32_t ret = Remote()->SendRequest(DSP_CMD_GETDISPLAYBACKLIGHT, data, reply, option);
354     if (ret != 0) {
355         DISPLAY_LOG("error: failed %{public}d", ret);
356         return ret;
357     }
358     level = reply.ReadUint32();
359     DISPLAY_LOG("interface end");
360     return ret;
361 }
362 
SetDisplayBacklight(uint32_t devId,uint32_t level)363 int32_t DisplayDeviceProxy::SetDisplayBacklight(uint32_t devId, uint32_t level)
364 {
365     DISPLAY_LOG("interface start");
366     if (devId > MAX_DEVID) {
367         DISPLAY_LOG("param error");
368         return DISPLAY_PARAM_ERR;
369     }
370 
371     MessageParcel data;
372     MessageParcel reply;
373     MessageOption option;
374     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
375         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
376         return DISPLAY_FAILURE;
377     }
378     if (!data.WriteUint32(level)) {
379         DISPLAY_LOG("error: %{public}s write status into data failed", __func__);
380         return DISPLAY_FAILURE;
381     }
382     int32_t ret = Remote()->SendRequest(DSP_CMD_SETDISPLAYBACKLIGHT, data, reply, option);
383     if (ret != 0) {
384         DISPLAY_LOG("error: failed %{public}d", ret);
385         return ret;
386     }
387 
388     DISPLAY_LOG("interface end");
389     return ret;
390 }
391 
GetDisplayProperty(uint32_t devId,uint32_t propertyId,uint64_t & value)392 int32_t DisplayDeviceProxy::GetDisplayProperty(uint32_t devId, uint32_t propertyId, uint64_t &value)
393 {
394     DISPLAY_LOG("interface start");
395     if (devId > MAX_DEVID) {
396         DISPLAY_LOG("param error");
397         return DISPLAY_PARAM_ERR;
398     }
399 
400     MessageParcel data;
401     MessageParcel reply;
402     MessageOption option;
403     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
404         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
405         return DISPLAY_FAILURE;
406     }
407     if (!data.WriteUint32(propertyId)) {
408         DISPLAY_LOG("error: %{public}s write status into data failed", __func__);
409         return DISPLAY_FAILURE;
410     }
411     int32_t ret = Remote()->SendRequest(DSP_CMD_GETDISPLAYPROPERTY, data, reply, option);
412     if (ret != 0) {
413         DISPLAY_LOG("error: failed %{public}d", ret);
414         return ret;
415     }
416     value = reply.ReadUint64();
417     DISPLAY_LOG("interface end");
418     return ret;
419 }
420 
SetDisplayProperty(uint32_t devId,uint32_t propertyId,uint64_t value)421 int32_t DisplayDeviceProxy::SetDisplayProperty(uint32_t devId, uint32_t propertyId, uint64_t value)
422 {
423     DISPLAY_LOG("interface start");
424     if (devId > MAX_DEVID) {
425         DISPLAY_LOG("param error");
426         return DISPLAY_PARAM_ERR;
427     }
428 
429     MessageParcel data;
430     MessageParcel reply;
431     MessageOption option;
432     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
433         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
434         return DISPLAY_FAILURE;
435     }
436     if (!data.WriteUint32(propertyId)) {
437         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
438         return DISPLAY_FAILURE;
439     }
440     if (!data.WriteUint32(value)) {
441         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
442         return DISPLAY_FAILURE;
443     }
444     int32_t ret = Remote()->SendRequest(DSP_CMD_SETDISPLAYPROPERTY, data, reply, option);
445     if (ret != 0) {
446         DISPLAY_LOG("error: failed %{public}d", ret);
447         return ret;
448     }
449 
450     DISPLAY_LOG("interface end");
451     return ret;
452 }
453 
PrepareDisplayLayers(uint32_t devId,bool & needFlushFb)454 int32_t DisplayDeviceProxy::PrepareDisplayLayers(uint32_t devId, bool &needFlushFb)
455 {
456     DISPLAY_LOG("interface start");
457     if (devId > MAX_DEVID) {
458         DISPLAY_LOG("param error");
459         return DISPLAY_PARAM_ERR;
460     }
461 
462     MessageParcel data;
463     MessageParcel reply;
464     MessageOption option;
465     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
466         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
467         return DISPLAY_FAILURE;
468     }
469     if (!data.WriteUint32(needFlushFb)) {
470         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
471         return DISPLAY_FAILURE;
472     }
473 
474     int32_t ret = Remote()->SendRequest(DSP_CMD_PREPAREDISPLAYLAYERS, data, reply, option);
475     if (ret != 0) {
476         DISPLAY_LOG("error: failed %{public}d", ret);
477         return ret;
478     }
479     needFlushFb = reply.ReadBool();
480     DISPLAY_LOG("interface end");
481     return ret;
482 }
483 
GetDisplayCompChange(uint32_t devId,uint32_t & num,uint32_t * layers,int32_t * type)484 int32_t DisplayDeviceProxy::GetDisplayCompChange(uint32_t devId, uint32_t &num, uint32_t *layers, int32_t *type)
485 {
486     DISPLAY_LOG("interface start");
487     if (devId > MAX_DEVID) {
488         DISPLAY_LOG("param error");
489         return DISPLAY_PARAM_ERR;
490     }
491 
492     MessageParcel data;
493     MessageParcel reply;
494     MessageOption option;
495     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
496         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
497         return DISPLAY_FAILURE;
498     }
499     int32_t ret = Remote()->SendRequest(DSP_CMD_GETDISPLAYCOMPCHANGE, data, reply, option);
500     if (ret != 0) {
501         DISPLAY_LOG("error: failed %{public}d", ret);
502         return ret;
503     }
504 
505     num = reply.ReadUint32();
506     if (num == 0) {
507         return ret;
508     }
509 
510     if (layers != nullptr && !DisplayDeviceReadData(layers, &reply, num)) {
511         DISPLAY_LOG("error: %{public}s read reply layers failed", __func__);
512         ret = DISPLAY_FAILURE;
513     }
514     if (type != nullptr && !DisplayDeviceReadData(type, &reply, num)) {
515         DISPLAY_LOG("error: %{public}s read reply layers failed", __func__);
516         ret = DISPLAY_FAILURE;
517     }
518     DISPLAY_LOG("interface end");
519     return ret;
520 }
521 
SetDisplayClientCrop(uint32_t devId,const IRect * rect)522 int32_t DisplayDeviceProxy::SetDisplayClientCrop(uint32_t devId, const IRect *rect)
523 {
524     DISPLAY_LOG("interface start");
525     if (rect == nullptr) {
526         DISPLAY_LOG("rect is nullptr");
527         return DISPLAY_PARAM_ERR;
528     }
529     if (devId > MAX_DEVID) {
530         DISPLAY_LOG("param error");
531         return DISPLAY_PARAM_ERR;
532     }
533 
534     MessageParcel data;
535     MessageParcel reply;
536     MessageOption option;
537     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
538         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
539         return DISPLAY_FAILURE;
540     }
541     if (!DisplayDeviceWriteData(&data, rect)) {
542         DISPLAY_LOG("error: write devId into data failed");
543         return DISPLAY_FAILURE;
544     }
545     int32_t ret = Remote()->SendRequest(DSP_CMD_SETDISPLAYCLIENTCROP, data, reply, option);
546     if (ret != 0) {
547         DISPLAY_LOG("error: failed %{public}d", ret);
548         return ret;
549     }
550     DISPLAY_LOG("interface end");
551     return ret;
552 }
553 
SetDisplayClientDestRect(uint32_t devId,const IRect & rect)554 int32_t DisplayDeviceProxy::SetDisplayClientDestRect(uint32_t devId, const IRect &rect)
555 {
556     DISPLAY_LOG("interface start");
557     if (devId > MAX_DEVID) {
558         DISPLAY_LOG("param error");
559         return DISPLAY_PARAM_ERR;
560     }
561 
562     MessageParcel data;
563     MessageParcel reply;
564     MessageOption option;
565     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
566         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
567         return DISPLAY_FAILURE;
568     }
569     if (!DisplayDeviceWriteData(&data, &rect)) {
570         DISPLAY_LOG("error: write devId into data failed");
571         return DISPLAY_FAILURE;
572     }
573 
574     int32_t ret = Remote()->SendRequest(DSP_CMD_SETDISPLAYCLIENTDESTRECT, data, reply, option);
575     if (ret != 0) {
576         DISPLAY_LOG("error: failed %{public}d", ret);
577         return ret;
578     }
579     DISPLAY_LOG("interface end");
580     return ret;
581 }
582 
SetDisplayClientBuffer(uint32_t devId,const BufferHandle & bufhandle,int32_t fence)583 int32_t DisplayDeviceProxy::SetDisplayClientBuffer(uint32_t devId, const BufferHandle &bufhandle, int32_t fence)
584 {
585     DISPLAY_LOG("interface start");
586     if (devId > MAX_DEVID) {
587         return DISPLAY_PARAM_ERR;
588     }
589 
590     MessageParcel data;
591     MessageParcel reply;
592     MessageOption option;
593     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
594         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
595         return DISPLAY_FAILURE;
596     }
597     if (!DisplayDeviceWriteBufHdl(&data, &bufhandle)) {
598         DISPLAY_LOG("error: write bufferhandle into data failed");
599         return DISPLAY_FAILURE;
600     }
601     if (!DisplayDeviceWriteFileDescriptor(&data, fence)) {
602         DISPLAY_LOG("error: write size into data failed");
603         return DISPLAY_FAILURE;
604     }
605 
606     int32_t ret = Remote()->SendRequest(DSP_CMD_SETDISPLAYCLIENTBUFFER, data, reply, option);
607     if (ret != 0) {
608         DISPLAY_LOG("error: failed %{public}d", ret);
609         return ret;
610     }
611     DISPLAY_LOG("interface end");
612     return ret;
613 }
614 
SetDisplayClientDamage(uint32_t devId,uint32_t num,const IRect & rect)615 int32_t DisplayDeviceProxy::SetDisplayClientDamage(uint32_t devId, uint32_t num, const IRect &rect)
616 {
617     DISPLAY_LOG("interface start");
618     if (num == 0) {
619         return DISPLAY_PARAM_ERR;
620     }
621 
622     if (devId > MAX_DEVID) {
623         DISPLAY_LOG("param error");
624         return DISPLAY_PARAM_ERR;
625     }
626 
627     MessageParcel data;
628     MessageParcel reply;
629     MessageOption option;
630     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
631         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
632         return DISPLAY_FAILURE;
633     }
634     if (!data.WriteUint32(num)) {
635         DISPLAY_LOG("error: %{public}s write num into data failed", __func__);
636         return DISPLAY_FAILURE;
637     }
638     if (!DisplayDeviceWriteData(&data, &rect, num)) {
639         DISPLAY_LOG("error: write rect into data failed");
640         return DISPLAY_FAILURE;
641     }
642 
643     int32_t ret = Remote()->SendRequest(DSP_CMD_SETDISPLAYCLIENTDAMAGE, data, reply, option);
644     if (ret != 0) {
645         DISPLAY_LOG("error: failed %{public}d", ret);
646         return ret;
647     }
648     DISPLAY_LOG("interface end");
649     return ret;
650 }
651 
SetDisplayVsyncEnabled(uint32_t devId,bool enabled)652 int32_t DisplayDeviceProxy::SetDisplayVsyncEnabled(uint32_t devId, bool enabled)
653 {
654     DISPLAY_LOG("interface start");
655     if (devId > MAX_DEVID) {
656         DISPLAY_LOG("param error");
657         return DISPLAY_PARAM_ERR;
658     }
659     MessageParcel data;
660     MessageParcel reply;
661     MessageOption option;
662     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
663         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
664         return DISPLAY_FAILURE;
665     }
666     if (!data.WriteBool(enabled)) {
667         DISPLAY_LOG("error: write enabled into data failed");
668         return DISPLAY_FAILURE;
669     }
670 
671     int32_t ret = Remote()->SendRequest(DSP_CMD_SETDISPLAYVSYNCENABLED, data, reply, option);
672     if (ret != 0) {
673         DISPLAY_LOG("error: failed %{public}d", ret);
674         return ret;
675     }
676     DISPLAY_LOG("interface end");
677     return ret;
678 }
679 
GetDisplayReleaseFence(uint32_t devId,uint32_t * num,uint32_t * layers,int32_t * fences)680 int32_t DisplayDeviceProxy::GetDisplayReleaseFence(uint32_t devId, uint32_t *num, uint32_t *layers, int32_t *fences)
681 {
682     DISPLAY_LOG("interface start");
683     if (num == nullptr) {
684         DISPLAY_LOG("num %{public}s nullptr, layers %{public}s nullptr, fences %{public}s nullptr",
685             (num == nullptr) ? "is" : "is not", (layers == nullptr) ? "is" : "is not",
686             (fences == nullptr) ? "is" : "is not");
687         return DISPLAY_PARAM_ERR;
688     }
689     if (devId > MAX_DEVID) {
690         DISPLAY_LOG("param error");
691         return DISPLAY_PARAM_ERR;
692     }
693 
694     MessageParcel data;
695     MessageParcel reply;
696     MessageOption option;
697     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
698         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
699         return DISPLAY_FAILURE;
700     }
701     int32_t ret = Remote()->SendRequest(DSP_CMD_GETDISPLAYRELEASEFENCE, data, reply, option);
702     if (ret != 0) {
703         DISPLAY_LOG("error: failed %{public}d", ret);
704         return ret;
705     }
706     uint32_t numRet = reply.ReadUint32();
707     DISPLAY_LOG("numRet = %{public}d", numRet);
708     if (numRet > *num && (layers != nullptr || fences != nullptr)) {
709         DISPLAY_LOG("error: failed out buffer to small %{public}u vs %{public}u", numRet, *num);
710         return DISPLAY_PARAM_ERR;
711     }
712     *num = numRet;
713     if (layers != nullptr && !DisplayDeviceReadData(layers, &reply, numRet)) {
714         DISPLAY_LOG("error: %{public}s read reply layers failed", __func__);
715         ret = DISPLAY_FAILURE;
716     }
717     if (fences != nullptr && !DisplayDeviceReadFileDescriptorArray(fences, &reply, numRet)) {
718         DISPLAY_LOG("error: %{public}s read reply fences failed", __func__);
719         ret = DISPLAY_FAILURE;
720     }
721     DISPLAY_LOG("interface end");
722     return ret;
723 }
724 
Commit(uint32_t devId,int32_t & fence)725 int32_t DisplayDeviceProxy::Commit(uint32_t devId, int32_t &fence)
726 {
727     DISPLAY_LOG("interface start");
728     if (devId > MAX_DEVID) {
729         DISPLAY_LOG("param error");
730         return DISPLAY_PARAM_ERR;
731     }
732 
733     MessageParcel data;
734     MessageParcel reply;
735     MessageOption option;
736     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
737         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
738         return DISPLAY_FAILURE;
739     }
740     int32_t ret = Remote()->SendRequest(DSP_CMD_COMMIT, data, reply, option);
741     if (ret != 0) {
742         DISPLAY_LOG("error: failed %{public}d", ret);
743         return ret;
744     }
745     if (!DisplayDeviceReadFileDescriptor(&fence, &reply)) {
746         DISPLAY_LOG("error: read reply failed");
747         return DISPLAY_FAILURE;
748     }
749     DISPLAY_LOG("interface end");
750     return ret;
751 }
752 
InvokeDisplayCmd(uint32_t devId,...)753 int32_t DisplayDeviceProxy::InvokeDisplayCmd(uint32_t devId, ...)
754 {
755     (void)devId;
756     return DISPLAY_NOT_SUPPORT;
757 }
758 
CreateVirtualDisplay(uint32_t width,uint32_t height,int32_t & format,uint32_t & devId)759 int32_t DisplayDeviceProxy::CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t &format, uint32_t &devId)
760 {
761     DISPLAY_LOG("interface start");
762     MessageParcel data;
763     MessageParcel reply;
764     MessageOption option;
765     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
766         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
767         return DISPLAY_FAILURE;
768     }
769     if (!data.WriteUint32(width)) {
770         DISPLAY_LOG("error: %{public}s write width into data failed", __func__);
771         return DISPLAY_FAILURE;
772     }
773     if (!data.WriteUint32(height)) {
774         DISPLAY_LOG("error: %{public}s write height into data failed", __func__);
775         return DISPLAY_FAILURE;
776     }
777 
778     int32_t ret = Remote()->SendRequest(DSP_CMD_CREATEVIRTUALDISPLAY, data, reply, option);
779     if (ret != 0) {
780         DISPLAY_LOG("error: failed %{public}d", ret);
781         return ret;
782     }
783     format = reply.ReadInt32();
784     devId = reply.ReadUint32();
785     DISPLAY_LOG("interface end");
786     return ret;
787 }
788 
DestroyVirtualDisplay(uint32_t devId)789 int32_t DisplayDeviceProxy::DestroyVirtualDisplay(uint32_t devId)
790 {
791     DISPLAY_LOG("interface start");
792     if (devId > MAX_DEVID) {
793         DISPLAY_LOG("param error");
794         return DISPLAY_PARAM_ERR;
795     }
796     MessageParcel data;
797     MessageParcel reply;
798     MessageOption option;
799     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
800         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
801         return DISPLAY_FAILURE;
802     }
803 
804     int32_t ret = Remote()->SendRequest(DSP_CMD_DESTROYVIRTUALDISPLAY, data, reply, option);
805     if (ret != 0) {
806         DISPLAY_LOG("error: failed %{public}d", ret);
807         return ret;
808     }
809 
810     DISPLAY_LOG("interface end");
811     return ret;
812 }
813 
SetVirtualDisplayBuffer(uint32_t devId,const BufferHandle * bufhandle,int32_t fence)814 int32_t DisplayDeviceProxy::SetVirtualDisplayBuffer(uint32_t devId, const BufferHandle *bufhandle, int32_t fence)
815 {
816     DISPLAY_LOG("interface start");
817     if (devId > MAX_DEVID) {
818         DISPLAY_LOG("param error");
819         return DISPLAY_PARAM_ERR;
820     }
821     if (bufhandle == nullptr) {
822         DISPLAY_LOG("bufhandle is nullptr");
823         return DISPLAY_PARAM_ERR;
824     }
825 
826     MessageParcel data;
827     MessageParcel reply;
828     MessageOption option;
829     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
830         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
831         return DISPLAY_FAILURE;
832     }
833     if (!DisplayDeviceWriteBufHdl(&data, bufhandle)) {
834         DISPLAY_LOG("error: write bufferhandle into data failed");
835         return DISPLAY_FAILURE;
836     }
837     if (!DisplayDeviceWriteFileDescriptor(&data, fence)) {
838         DISPLAY_LOG("error: write size into data failed");
839         return DISPLAY_FAILURE;
840     }
841 
842     int32_t ret = Remote()->SendRequest(DSP_CMD_SETVIRTUALDISPLAYBUFFER, data, reply, option);
843     if (ret != 0) {
844         DISPLAY_LOG("error: failed %{public}d", ret);
845         return ret;
846     }
847 
848     DISPLAY_LOG("interface end");
849     return ret;
850 }
851 
GetWriteBackFrame(uint32_t devId,BufferHandle & buffer,int32_t & fence)852 int32_t DisplayDeviceProxy::GetWriteBackFrame(uint32_t devId, BufferHandle &buffer, int32_t &fence)
853 {
854     DISPLAY_LOG("interface not support");
855     (void)devId;
856     (void)buffer;
857     (void)fence;
858     return DISPLAY_NOT_SUPPORT;
859 }
860 
CreateWriteBack(uint32_t & devId,uint32_t width,uint32_t height,int32_t & format)861 int32_t DisplayDeviceProxy::CreateWriteBack(uint32_t &devId, uint32_t width, uint32_t height, int32_t &format)
862 {
863     DISPLAY_LOG("interface start");
864     MessageParcel data;
865     MessageParcel reply;
866     MessageOption option;
867     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(width)) {
868         DISPLAY_LOG("error: %{public}s write width into data failed", __func__);
869         return DISPLAY_FAILURE;
870     }
871     if (!data.WriteUint32(height)) {
872         DISPLAY_LOG("error: %{public}s write height into data failed", __func__);
873         return DISPLAY_FAILURE;
874     }
875 
876     int32_t ret = Remote()->SendRequest(DSP_CMD_CREATEWRITEBACK, data, reply, option);
877     if (ret != 0) {
878         DISPLAY_LOG("error: failed %{public}d", ret);
879         return ret;
880     }
881     devId = reply.ReadUint32();
882     format = reply.ReadInt32();
883     DISPLAY_LOG("interface end");
884     return ret;
885 }
886 
DestroyWriteBack(uint32_t devId)887 int32_t DisplayDeviceProxy::DestroyWriteBack(uint32_t devId)
888 {
889     DISPLAY_LOG("interface start");
890     if (devId > MAX_DEVID) {
891         DISPLAY_LOG("param error");
892         return DISPLAY_PARAM_ERR;
893     }
894     MessageParcel data;
895     MessageParcel reply;
896     MessageOption option;
897     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
898         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
899         return DISPLAY_FAILURE;
900     }
901     int32_t ret = Remote()->SendRequest(DSP_CMD_DESTROYWRITEBACK, data, reply, option);
902     if (ret != 0) {
903         DISPLAY_LOG("error: failed %{public}d", ret);
904         return ret;
905     }
906     DISPLAY_LOG("interface end");
907     return ret;
908 }
909 
SetProxyRemoteCallback(const OHOS::sptr<DisplayRegisterCallbackBase> & callback)910 int32_t DisplayDeviceProxy::SetProxyRemoteCallback(const OHOS::sptr<DisplayRegisterCallbackBase> &callback)
911 {
912     DISPLAY_LOG("interface start");
913     MessageParcel data;
914     MessageParcel reply;
915     MessageOption option;
916     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) ||
917         !data.WriteRemoteObject(callback->AsObject())) {
918         DISPLAY_LOG("error: write callback into data failed");
919         return DISPLAY_FAILURE;
920     }
921 
922     int32_t ret = Remote()->SendRequest(DSP_CMD_SET_PROXY_REMOTE_CALLBACK, data, reply, option);
923     if (ret != 0) {
924         DISPLAY_LOG("error: failed %{public}d", ret);
925         return ret;
926     }
927     DISPLAY_LOG("interface end");
928     return ret;
929 }
930 
InitDisplay(uint32_t devId)931 int32_t DisplayDeviceProxy::InitDisplay(uint32_t devId)
932 {
933     DISPLAY_LOG("interface start");
934     if (devId > MAX_DEVID) {
935         DISPLAY_LOG("param error");
936         return DISPLAY_PARAM_ERR;
937     }
938     MessageParcel data;
939     MessageParcel reply;
940     MessageOption option;
941     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
942         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
943         return DISPLAY_FAILURE;
944     }
945 
946     int32_t ret = Remote()->SendRequest(DSP_CMD_INITDISPLAY, data, reply, option);
947     if (ret != 0) {
948         DISPLAY_LOG("error: failed %{public}d", ret);
949         return ret;
950     }
951     DISPLAY_LOG("interface end");
952     return ret;
953 }
954 
DeinitDisplay(uint32_t devId)955 int32_t DisplayDeviceProxy::DeinitDisplay(uint32_t devId)
956 {
957     DISPLAY_LOG("interface start");
958     if (devId > MAX_DEVID) {
959         DISPLAY_LOG("param error");
960         return DISPLAY_PARAM_ERR;
961     }
962     MessageParcel data;
963     MessageParcel reply;
964     MessageOption option;
965     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
966         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
967         return DISPLAY_FAILURE;
968     }
969 
970     int32_t ret = Remote()->SendRequest(DSP_CMD_DEINITDISPLAY, data, reply, option);
971     if (ret != 0) {
972         DISPLAY_LOG("error: failed %{public}d", ret);
973         return ret;
974     }
975     DISPLAY_LOG("interface end");
976     return ret;
977 }
978 
GetDisplayInfo(uint32_t devId,DisplayInfo & dispInfo)979 int32_t DisplayDeviceProxy::GetDisplayInfo(uint32_t devId, DisplayInfo &dispInfo)
980 {
981     DISPLAY_LOG("interface start");
982     if (devId > MAX_DEVID) {
983         DISPLAY_LOG("param error");
984         return DISPLAY_PARAM_ERR;
985     }
986     MessageParcel data;
987     MessageParcel reply;
988     MessageOption option;
989     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
990         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
991         return DISPLAY_FAILURE;
992     }
993     int32_t ret = Remote()->SendRequest(DSP_CMD_GETDISPLAYINFO, data, reply, option);
994     if (ret != 0) {
995         DISPLAY_LOG("error: failed %{public}d", ret);
996         return ret;
997     }
998     if (!DisplayDeviceReadData(&dispInfo, &reply)) {
999         DISPLAY_LOG("error: read reply failed");
1000         return DISPLAY_FAILURE;
1001     }
1002     DISPLAY_LOG("interface end");
1003     return ret;
1004 }
1005 
CreateLayer(uint32_t devId,const LayerInfo & layerInfo,uint32_t & layerId)1006 int32_t DisplayDeviceProxy::CreateLayer(uint32_t devId, const LayerInfo &layerInfo, uint32_t &layerId)
1007 {
1008     DISPLAY_LOG("interface start");
1009     if (devId > MAX_DEVID) {
1010         DISPLAY_LOG("param error");
1011         return DISPLAY_PARAM_ERR;
1012     }
1013     MessageParcel data;
1014     MessageParcel reply;
1015     MessageOption option;
1016     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1017         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1018         return DISPLAY_FAILURE;
1019     }
1020     if (!DisplayDeviceWriteData(&data, &layerInfo)) {
1021         DISPLAY_LOG("error: write rect into data failed");
1022         return DISPLAY_FAILURE;
1023     }
1024 
1025     int32_t ret = Remote()->SendRequest(DSP_CMD_CREATELAYER, data, reply, option);
1026     if (ret != 0) {
1027         DISPLAY_LOG("error: failed %{public}d", ret);
1028         return ret;
1029     }
1030     layerId = reply.ReadUint32();
1031     DISPLAY_LOG("interface end");
1032     return ret;
1033 }
1034 
CloseLayer(uint32_t devId,uint32_t layerId)1035 int32_t DisplayDeviceProxy::CloseLayer(uint32_t devId, uint32_t layerId)
1036 {
1037     DISPLAY_LOG("interface start");
1038     if (devId > MAX_DEVID) {
1039         DISPLAY_LOG("param error");
1040         return DISPLAY_PARAM_ERR;
1041     }
1042     MessageParcel data;
1043     MessageParcel reply;
1044     MessageOption option;
1045     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1046         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1047         return DISPLAY_FAILURE;
1048     }
1049     if (!data.WriteUint32(layerId)) {
1050         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1051         return DISPLAY_FAILURE;
1052     }
1053 
1054     int32_t ret = Remote()->SendRequest(DSP_CMD_CLOSELAYER, data, reply, option);
1055     if (ret != 0) {
1056         DISPLAY_LOG("error: failed %{public}d", ret);
1057         return ret;
1058     }
1059     DISPLAY_LOG("interface end");
1060     return ret;
1061 }
1062 
SetLayerVisible(uint32_t devId,uint32_t layerId,bool visible)1063 int32_t DisplayDeviceProxy::SetLayerVisible(uint32_t devId, uint32_t layerId, bool visible)
1064 {
1065     DISPLAY_LOG("interface start");
1066     if (devId > MAX_DEVID) {
1067         DISPLAY_LOG("param error");
1068         return DISPLAY_PARAM_ERR;
1069     }
1070     MessageParcel data;
1071     MessageParcel reply;
1072     MessageOption option;
1073     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1074         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1075         return DISPLAY_FAILURE;
1076     }
1077     if (!data.WriteUint32(layerId)) {
1078         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1079         return DISPLAY_FAILURE;
1080     }
1081     if (!data.WriteBool(visible)) {
1082         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1083         return DISPLAY_FAILURE;
1084     }
1085     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERVISIBLE, data, reply, option);
1086     if (ret != 0) {
1087         DISPLAY_LOG("error: failed %{public}d", ret);
1088         return ret;
1089     }
1090 
1091     DISPLAY_LOG("interface end");
1092     return ret;
1093 }
1094 
GetLayerVisibleState(uint32_t devId,uint32_t layerId,bool & visible)1095 int32_t DisplayDeviceProxy::GetLayerVisibleState(uint32_t devId, uint32_t layerId, bool &visible)
1096 {
1097     DISPLAY_LOG("interface start");
1098     if (devId > MAX_DEVID) {
1099         DISPLAY_LOG("param error");
1100         return DISPLAY_PARAM_ERR;
1101     }
1102     MessageParcel data;
1103     MessageParcel reply;
1104     MessageOption option;
1105     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1106         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1107         return DISPLAY_FAILURE;
1108     }
1109     if (!data.WriteUint32(layerId)) {
1110         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1111         return DISPLAY_FAILURE;
1112     }
1113     int32_t ret = Remote()->SendRequest(DSP_CMD_GETLAYERVISIBLESTATE, data, reply, option);
1114     if (ret != 0) {
1115         DISPLAY_LOG("error: failed %{public}d", ret);
1116         return ret;
1117     }
1118     visible = reply.ReadBool();
1119     DISPLAY_LOG("interface end");
1120     return ret;
1121 }
1122 
SetLayerSize(uint32_t devId,uint32_t layerId,const IRect * rect)1123 int32_t DisplayDeviceProxy::SetLayerSize(uint32_t devId, uint32_t layerId, const IRect *rect)
1124 {
1125     DISPLAY_LOG("interface start");
1126     if (rect == nullptr) {
1127         DISPLAY_LOG("rect is nullptr");
1128         return DISPLAY_PARAM_ERR;
1129     }
1130     if (devId > MAX_DEVID) {
1131         DISPLAY_LOG("param error");
1132         return DISPLAY_PARAM_ERR;
1133     }
1134     MessageParcel data;
1135     MessageParcel reply;
1136     MessageOption option;
1137     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1138         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1139         return DISPLAY_FAILURE;
1140     }
1141     if (!data.WriteUint32(layerId)) {
1142         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1143         return DISPLAY_FAILURE;
1144     }
1145     if (!DisplayDeviceWriteData(&data, rect)) {
1146         DISPLAY_LOG("error: write rect into data failed");
1147         return DISPLAY_FAILURE;
1148     }
1149     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERSIZE, data, reply, option);
1150     if (ret != 0) {
1151         DISPLAY_LOG("error: failed %{public}d", ret);
1152         return ret;
1153     }
1154 
1155     DISPLAY_LOG("interface end");
1156     return ret;
1157 }
1158 
GetLayerSize(uint32_t devId,uint32_t layerId,IRect & rect)1159 int32_t DisplayDeviceProxy::GetLayerSize(uint32_t devId, uint32_t layerId, IRect &rect)
1160 {
1161     DISPLAY_LOG("interface start");
1162     if (devId > MAX_DEVID) {
1163         DISPLAY_LOG("param error");
1164         return DISPLAY_PARAM_ERR;
1165     }
1166     MessageParcel data;
1167     MessageParcel reply;
1168     MessageOption option;
1169     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1170         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1171         return DISPLAY_FAILURE;
1172     }
1173     if (!data.WriteUint32(layerId)) {
1174         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1175         return DISPLAY_FAILURE;
1176     }
1177     int32_t ret = Remote()->SendRequest(DSP_CMD_GETLAYERSIZE, data, reply, option);
1178     if (ret != 0) {
1179         DISPLAY_LOG("error: failed %{public}d", ret);
1180         return ret;
1181     }
1182     if (!DisplayDeviceReadData(&rect, &data)) {
1183         DISPLAY_LOG("error: read rect into data failed");
1184         return DISPLAY_FAILURE;
1185     }
1186     DISPLAY_LOG("interface end");
1187     return ret;
1188 }
1189 
SetLayerCrop(uint32_t devId,uint32_t layerId,const IRect * rect)1190 int32_t DisplayDeviceProxy::SetLayerCrop(uint32_t devId, uint32_t layerId, const IRect *rect)
1191 {
1192     DISPLAY_LOG("interface start");
1193     if (rect == nullptr) {
1194         DISPLAY_LOG("rect is nullptr");
1195         return DISPLAY_PARAM_ERR;
1196     }
1197 
1198     if (devId > MAX_DEVID) {
1199         DISPLAY_LOG("param error");
1200         return DISPLAY_PARAM_ERR;
1201     }
1202     MessageParcel data;
1203     MessageParcel reply;
1204     MessageOption option;
1205     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1206         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1207         return DISPLAY_FAILURE;
1208     }
1209     if (!data.WriteUint32(layerId)) {
1210         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1211         return DISPLAY_FAILURE;
1212     }
1213     if (!DisplayDeviceWriteData(&data, rect)) {
1214         DISPLAY_LOG("error: write rect into data failed");
1215         return DISPLAY_FAILURE;
1216     }
1217     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERCROP, data, reply, option);
1218     if (ret != 0) {
1219         DISPLAY_LOG("error: failed %{public}d", ret);
1220         return ret;
1221     }
1222 
1223     DISPLAY_LOG("interface end");
1224     return ret;
1225 }
1226 
SetLayerZorder(uint32_t devId,uint32_t layerId,uint32_t zorder)1227 int32_t DisplayDeviceProxy::SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder)
1228 {
1229     DISPLAY_LOG("interface start");
1230     if (devId > MAX_DEVID) {
1231         DISPLAY_LOG("param error");
1232         return DISPLAY_PARAM_ERR;
1233     }
1234     MessageParcel data;
1235     MessageParcel reply;
1236     MessageOption option;
1237     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1238         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1239         return DISPLAY_FAILURE;
1240     }
1241     if (!data.WriteUint32(layerId)) {
1242         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1243         return DISPLAY_FAILURE;
1244     }
1245     if (!data.WriteUint32(zorder)) {
1246         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1247         return DISPLAY_FAILURE;
1248     }
1249     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERZORDER, data, reply, option);
1250     if (ret != 0) {
1251         DISPLAY_LOG("error: failed %{public}d", ret);
1252         return ret;
1253     }
1254 
1255     DISPLAY_LOG("interface end");
1256     return ret;
1257 }
1258 
GetLayerZorder(uint32_t devId,uint32_t layerId,uint32_t & zorder)1259 int32_t DisplayDeviceProxy::GetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t &zorder)
1260 {
1261     DISPLAY_LOG("interface start");
1262     if (devId > MAX_DEVID) {
1263         DISPLAY_LOG("param error");
1264         return DISPLAY_PARAM_ERR;
1265     }
1266     MessageParcel data;
1267     MessageParcel reply;
1268     MessageOption option;
1269     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1270         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1271         return DISPLAY_FAILURE;
1272     }
1273     if (!data.WriteUint32(layerId)) {
1274         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1275         return DISPLAY_FAILURE;
1276     }
1277 
1278     int32_t ret = Remote()->SendRequest(DSP_CMD_GETLAYERZORDER, data, reply, option);
1279     if (ret != 0) {
1280         DISPLAY_LOG("error: failed %{public}d", ret);
1281         return ret;
1282     }
1283     zorder = reply.ReadUint32();
1284     DISPLAY_LOG("interface end");
1285     return ret;
1286 }
1287 
SetLayerPreMulti(uint32_t devId,uint32_t layerId,bool preMul)1288 int32_t DisplayDeviceProxy::SetLayerPreMulti(uint32_t devId, uint32_t layerId, bool preMul)
1289 {
1290     DISPLAY_LOG("interface start");
1291     if (devId > MAX_DEVID) {
1292         DISPLAY_LOG("param error");
1293         return DISPLAY_PARAM_ERR;
1294     }
1295     MessageParcel data;
1296     MessageParcel reply;
1297     MessageOption option;
1298     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1299         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1300         return DISPLAY_FAILURE;
1301     }
1302     if (!data.WriteUint32(layerId)) {
1303         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1304         return DISPLAY_FAILURE;
1305     }
1306     if (!data.WriteBool(preMul)) {
1307         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1308         return DISPLAY_FAILURE;
1309     }
1310     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERPREMULTI, data, reply, option);
1311     if (ret != 0) {
1312         DISPLAY_LOG("error: failed %{public}d", ret);
1313         return ret;
1314     }
1315 
1316     DISPLAY_LOG("interface end");
1317     return ret;
1318 }
1319 
GetLayerPreMulti(uint32_t devId,uint32_t layerId,bool & preMul)1320 int32_t DisplayDeviceProxy::GetLayerPreMulti(uint32_t devId, uint32_t layerId, bool &preMul)
1321 {
1322     DISPLAY_LOG("interface start");
1323     if (devId > MAX_DEVID) {
1324         DISPLAY_LOG("param error");
1325         return DISPLAY_PARAM_ERR;
1326     }
1327     MessageParcel data;
1328     MessageParcel reply;
1329     MessageOption option;
1330     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1331         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1332         return DISPLAY_FAILURE;
1333     }
1334     if (!data.WriteUint32(layerId)) {
1335         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1336         return DISPLAY_FAILURE;
1337     }
1338     int32_t ret = Remote()->SendRequest(DSP_CMD_GETLAYERPREMULTI, data, reply, option);
1339     if (ret != 0) {
1340         DISPLAY_LOG("error: failed %{public}d", ret);
1341         return ret;
1342     }
1343     preMul = reply.ReadBool();
1344     DISPLAY_LOG("interface end");
1345     return ret;
1346 }
1347 
SetLayerAlpha(uint32_t devId,uint32_t layerId,const LayerAlpha & alpha)1348 int32_t DisplayDeviceProxy::SetLayerAlpha(uint32_t devId, uint32_t layerId, const LayerAlpha &alpha)
1349 {
1350     DISPLAY_LOG("interface start");
1351     if (devId > MAX_DEVID) {
1352         DISPLAY_LOG("param error");
1353         return DISPLAY_PARAM_ERR;
1354     }
1355     MessageParcel data;
1356     MessageParcel reply;
1357     MessageOption option;
1358     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1359         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1360         return DISPLAY_FAILURE;
1361     }
1362     if (!data.WriteUint32(layerId)) {
1363         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1364         return DISPLAY_FAILURE;
1365     }
1366     if (!DisplayDeviceWriteData(&data, &alpha)) {
1367         DISPLAY_LOG("error: write alpha into data failed");
1368         return DISPLAY_FAILURE;
1369     }
1370     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERALPHA, data, reply, option);
1371     if (ret != 0) {
1372         DISPLAY_LOG("error: failed %{public}d", ret);
1373         return ret;
1374     }
1375     DISPLAY_LOG("interface end");
1376     return ret;
1377 }
1378 
GetLayerAlpha(uint32_t devId,uint32_t layerId,LayerAlpha & alpha)1379 int32_t DisplayDeviceProxy::GetLayerAlpha(uint32_t devId, uint32_t layerId, LayerAlpha &alpha)
1380 {
1381     DISPLAY_LOG("interface start");
1382     if (devId > MAX_DEVID) {
1383         DISPLAY_LOG("param error");
1384         return DISPLAY_PARAM_ERR;
1385     }
1386     MessageParcel data;
1387     MessageParcel reply;
1388     MessageOption option;
1389     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1390         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1391         return DISPLAY_FAILURE;
1392     }
1393     if (!data.WriteUint32(layerId)) {
1394         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1395         return DISPLAY_FAILURE;
1396     }
1397 
1398     int32_t ret = Remote()->SendRequest(DSP_CMD_GETLAYERALPHA, data, reply, option);
1399     if (ret != 0) {
1400         DISPLAY_LOG("error: failed %{public}d", ret);
1401         return ret;
1402     }
1403     if (!DisplayDeviceReadData(&alpha, &reply)) {
1404         DISPLAY_LOG("error: read alpha failed");
1405         return DISPLAY_FAILURE;
1406     }
1407     DISPLAY_LOG("interface end");
1408     return ret;
1409 }
1410 
SetLayerColorKey(uint32_t devId,uint32_t layerId,bool enable,uint32_t key)1411 int32_t DisplayDeviceProxy::SetLayerColorKey(uint32_t devId, uint32_t layerId, bool enable, uint32_t key)
1412 {
1413     DISPLAY_LOG("interface start");
1414     if (devId > MAX_DEVID) {
1415         DISPLAY_LOG("param error");
1416         return DISPLAY_PARAM_ERR;
1417     }
1418     MessageParcel data;
1419     MessageParcel reply;
1420     MessageOption option;
1421     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1422         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1423         return DISPLAY_FAILURE;
1424     }
1425     if (!data.WriteUint32(layerId)) {
1426         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1427         return DISPLAY_FAILURE;
1428     }
1429     if (!data.WriteBool(enable)) {
1430         DISPLAY_LOG("error: %{public}s write enable into data failed", __func__);
1431         return DISPLAY_FAILURE;
1432     }
1433     if (!data.WriteUint32(key)) {
1434         DISPLAY_LOG("error: %{public}s write key into data failed", __func__);
1435         return DISPLAY_FAILURE;
1436     }
1437     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERCOLORKEY, data, reply, option);
1438     if (ret != 0) {
1439         DISPLAY_LOG("error: failed %{public}d", ret);
1440         return ret;
1441     }
1442     DISPLAY_LOG("interface end");
1443     return ret;
1444 }
1445 
GetLayerColorKey(uint32_t devId,uint32_t layerId,bool * enable,uint32_t * key)1446 int32_t DisplayDeviceProxy::GetLayerColorKey(uint32_t devId, uint32_t layerId, bool *enable, uint32_t *key)
1447 {
1448     DISPLAY_LOG("interface start");
1449     if (devId > MAX_DEVID) {
1450         DISPLAY_LOG("param error");
1451         return DISPLAY_PARAM_ERR;
1452     }
1453     MessageParcel data;
1454     MessageParcel reply;
1455     MessageOption option;
1456     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1457         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1458         return DISPLAY_FAILURE;
1459     }
1460     if (!data.WriteUint32(layerId)) {
1461         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1462         return DISPLAY_FAILURE;
1463     }
1464     int32_t ret = Remote()->SendRequest(DSP_CMD_GETLAYERCOLORKEY, data, reply, option);
1465     if (ret != 0) {
1466         DISPLAY_LOG("error: failed %{public}d", ret);
1467         return ret;
1468     }
1469 
1470     *enable = reply.ReadBool();
1471     *key = reply.ReadUint32();
1472     DISPLAY_LOG("interface end");
1473     return ret;
1474 }
1475 
SetLayerPalette(uint32_t devId,uint32_t layerId,const uint32_t * palette,uint32_t len)1476 int32_t DisplayDeviceProxy::SetLayerPalette(uint32_t devId, uint32_t layerId, const uint32_t *palette, uint32_t len)
1477 {
1478     DISPLAY_LOG("interface start");
1479     if (palette == nullptr) {
1480         DISPLAY_LOG("palette is nullptr");
1481         return DISPLAY_PARAM_ERR;
1482     }
1483 
1484     if (devId > MAX_DEVID) {
1485         DISPLAY_LOG("param error");
1486         return DISPLAY_PARAM_ERR;
1487     }
1488     MessageParcel data;
1489     MessageParcel reply;
1490     MessageOption option;
1491     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1492         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1493         return DISPLAY_FAILURE;
1494     }
1495     if (!data.WriteUint32(layerId)) {
1496         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1497         return DISPLAY_FAILURE;
1498     }
1499     if (!data.WriteUint32(len)) {
1500         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1501         return DISPLAY_FAILURE;
1502     }
1503     if (!DisplayDeviceWriteData(&data, &palette[0], len)) {
1504         DISPLAY_LOG("error: write enable into data failed");
1505         return DISPLAY_FAILURE;
1506     }
1507     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERPALETTE, data, reply, option);
1508     if (ret != 0) {
1509         DISPLAY_LOG("error: failed %{public}d", ret);
1510         return ret;
1511     }
1512     DISPLAY_LOG("interface end");
1513     return ret;
1514 }
1515 
GetLayerPalette(uint32_t devId,uint32_t layerId,uint32_t & palette,uint32_t len)1516 int32_t DisplayDeviceProxy::GetLayerPalette(uint32_t devId, uint32_t layerId, uint32_t &palette, uint32_t len)
1517 {
1518     DISPLAY_LOG("interface start");
1519     if (devId > MAX_DEVID) {
1520         DISPLAY_LOG("param error");
1521         return DISPLAY_PARAM_ERR;
1522     }
1523     MessageParcel data;
1524     MessageParcel reply;
1525     MessageOption option;
1526     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1527         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1528         return DISPLAY_FAILURE;
1529     }
1530     if (!data.WriteUint32(layerId)) {
1531         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1532         return DISPLAY_FAILURE;
1533     }
1534 
1535     int32_t ret = Remote()->SendRequest(DSP_CMD_GETLAYERPALETTE, data, reply, option);
1536     if (ret != 0) {
1537         DISPLAY_LOG("error: failed %{public}d", ret);
1538         return ret;
1539     }
1540     len = reply.ReadInt32();
1541     if (!DisplayDeviceReadData(&palette, &reply, len)) {
1542         DISPLAY_LOG("error: read reply failed");
1543         return DISPLAY_FAILURE;
1544     }
1545     DISPLAY_LOG("interface end");
1546     return ret;
1547 }
1548 
SetTransformMode(uint32_t devId,uint32_t layerId,TransformType type)1549 int32_t DisplayDeviceProxy::SetTransformMode(uint32_t devId, uint32_t layerId, TransformType type)
1550 {
1551     DISPLAY_LOG("interface start");
1552     if (devId > MAX_DEVID) {
1553         DISPLAY_LOG("param error");
1554         return DISPLAY_PARAM_ERR;
1555     }
1556     MessageParcel data;
1557     MessageParcel reply;
1558     MessageOption option;
1559     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1560         DISPLAY_LOG("error: %{public}s write devId into data failed", __func__);
1561         return DISPLAY_FAILURE;
1562     }
1563     if (!data.WriteUint32(layerId)) {
1564         DISPLAY_LOG("error: %{public}s write layerId into data failed", __func__);
1565         return DISPLAY_FAILURE;
1566     }
1567     if (!data.WriteInt32(type)) {
1568         DISPLAY_LOG("error: write type into data failed");
1569         return DISPLAY_FAILURE;
1570     }
1571     int32_t ret = Remote()->SendRequest(DSP_CMD_SETTRANSFORMMODE, data, reply, option);
1572     if (ret != 0) {
1573         DISPLAY_LOG("error: failed %{public}d", ret);
1574         return ret;
1575     }
1576     DISPLAY_LOG("interface end");
1577     return ret;
1578 }
1579 
SetLayerCompression(uint32_t devId,uint32_t layerId,int32_t compType)1580 int32_t DisplayDeviceProxy::SetLayerCompression(uint32_t devId, uint32_t layerId, int32_t compType)
1581 {
1582     DISPLAY_LOG("interface start");
1583     if (devId > MAX_DEVID) {
1584         DISPLAY_LOG("param error");
1585         return DISPLAY_PARAM_ERR;
1586     }
1587     MessageParcel data;
1588     MessageParcel reply;
1589     MessageOption option;
1590     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1591         DISPLAY_LOG("error: write devId into data failed");
1592         return DISPLAY_FAILURE;
1593     }
1594     if (!data.WriteUint32(layerId)) {
1595         DISPLAY_LOG("error: write layerId into data failed");
1596         return DISPLAY_FAILURE;
1597     }
1598     if (!data.WriteInt32(compType)) {
1599         DISPLAY_LOG("error: write compType into data failed");
1600         return DISPLAY_FAILURE;
1601     }
1602     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERCOMPRESSION, data, reply, option);
1603     if (ret != 0) {
1604         DISPLAY_LOG("error: failed %{public}d", ret);
1605         return ret;
1606     }
1607     DISPLAY_LOG("interface end");
1608     return ret;
1609 }
1610 
GetLayerCompression(uint32_t devId,uint32_t layerId,int32_t & compType)1611 int32_t DisplayDeviceProxy::GetLayerCompression(uint32_t devId, uint32_t layerId, int32_t &compType)
1612 {
1613     DISPLAY_LOG("interface start");
1614     if (devId > MAX_DEVID) {
1615         DISPLAY_LOG("param error");
1616         return DISPLAY_PARAM_ERR;
1617     }
1618     MessageParcel data;
1619     MessageParcel reply;
1620     MessageOption option;
1621     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1622         DISPLAY_LOG("error: write devId into data failed");
1623         return DISPLAY_FAILURE;
1624     }
1625     if (!data.WriteUint32(layerId)) {
1626         DISPLAY_LOG("error: write layerId into data failed");
1627         return DISPLAY_FAILURE;
1628     }
1629     int32_t ret = Remote()->SendRequest(DSP_CMD_GETLAYERCOMPRESSION, data, reply, option);
1630     if (ret != 0) {
1631         DISPLAY_LOG("error: failed %{public}d", ret);
1632         return ret;
1633     }
1634     compType = reply.ReadInt32();
1635     DISPLAY_LOG("interface end");
1636     return ret;
1637 }
1638 
SetLayerDirtyRegion(uint32_t devId,uint32_t layerId,uint32_t num,const IRect & region)1639 int32_t DisplayDeviceProxy::SetLayerDirtyRegion(uint32_t devId, uint32_t layerId, uint32_t num, const IRect &region)
1640 {
1641     DISPLAY_LOG("interface start");
1642     if (devId > MAX_DEVID) {
1643         DISPLAY_LOG("param error");
1644         return DISPLAY_PARAM_ERR;
1645     }
1646     MessageParcel data;
1647     MessageParcel reply;
1648     MessageOption option;
1649     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1650         DISPLAY_LOG("error: write devId into data failed");
1651         return DISPLAY_FAILURE;
1652     }
1653     if (!data.WriteUint32(layerId)) {
1654         DISPLAY_LOG("error: write layerId into data failed");
1655         return DISPLAY_FAILURE;
1656     }
1657     if (!data.WriteUint32(num)) {
1658         DISPLAY_LOG("error: write layerId into data failed");
1659         return DISPLAY_FAILURE;
1660     }
1661     if (!DisplayDeviceWriteData(&data, &region, num)) {
1662         DISPLAY_LOG("error: write layerId into data failed");
1663         return DISPLAY_FAILURE;
1664     }
1665     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERDIRTYREGION, data, reply, option);
1666     if (ret != 0) {
1667         DISPLAY_LOG("error: failed %{public}d", ret);
1668         return ret;
1669     }
1670 
1671     DISPLAY_LOG("interface end");
1672     return ret;
1673 }
1674 
GetLayerBuffer(uint32_t devId,uint32_t layerId,LayerBuffer * buffer)1675 int32_t DisplayDeviceProxy::GetLayerBuffer(uint32_t devId, uint32_t layerId, LayerBuffer *buffer)
1676 {
1677     DISPLAY_LOG("interface start");
1678     if (buffer == nullptr) {
1679         DISPLAY_LOG("buffer is nullptr");
1680         return DISPLAY_PARAM_ERR;
1681     }
1682 
1683     if (devId > MAX_DEVID) {
1684         DISPLAY_LOG("param error");
1685         return DISPLAY_PARAM_ERR;
1686     }
1687 
1688     MessageParcel data;
1689     MessageParcel reply;
1690     MessageOption option;
1691     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1692         DISPLAY_LOG("error: write devId into data failed");
1693         return DISPLAY_FAILURE;
1694     }
1695     if (!data.WriteUint32(layerId)) {
1696         DISPLAY_LOG("error: write layerId into data failed");
1697         return DISPLAY_FAILURE;
1698     }
1699     int32_t ret = Remote()->SendRequest(DSP_CMD_GETLAYERBUFFER, data, reply, option);
1700     if (ret != 0) {
1701         DISPLAY_LOG("error: failed %{public}d", ret);
1702         return ret;
1703     }
1704     if (!DisplayDeviceReadData(buffer, &reply)) {
1705         DISPLAY_LOG("error: read reply failed");
1706         return DISPLAY_FAILURE;
1707     }
1708     if (!DisplayDeviceReadBufHdl(buffer->hdl, &reply)) {
1709         DISPLAY_LOG("error: read BufferHandle reply failed");
1710         return DISPLAY_FAILURE;
1711     }
1712     DISPLAY_LOG("interface end");
1713     return ret;
1714 }
1715 
Flush(uint32_t devId,uint32_t layerId,LayerBuffer & buffer)1716 int32_t DisplayDeviceProxy::Flush(uint32_t devId, uint32_t layerId, LayerBuffer &buffer)
1717 {
1718     DISPLAY_LOG("interface start");
1719     if (devId > MAX_DEVID) {
1720         DISPLAY_LOG("param error");
1721         return DISPLAY_PARAM_ERR;
1722     }
1723     MessageParcel data;
1724     MessageParcel reply;
1725     MessageOption option;
1726     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1727         DISPLAY_LOG("error: write devId into data failed");
1728         return DISPLAY_FAILURE;
1729     }
1730     if (!data.WriteUint32(layerId)) {
1731         DISPLAY_LOG("error: write layerId into data failed");
1732         return DISPLAY_FAILURE;
1733     }
1734     if (!DisplayDeviceWriteData(&data, &buffer)) {
1735         DISPLAY_LOG("error: write layerId into data failed");
1736         return DISPLAY_FAILURE;
1737     }
1738     if (!DisplayDeviceWriteBufHdl(&data, buffer.hdl)) {
1739         DISPLAY_LOG("error: server write buffer handle into data failed");
1740         return DISPLAY_FAILURE;
1741     }
1742     int32_t ret = Remote()->SendRequest(DSP_CMD_FLUSH, data, reply, option);
1743     if (ret != 0) {
1744         DISPLAY_LOG("error: failed %{public}d", ret);
1745         return ret;
1746     }
1747     DISPLAY_LOG("interface end");
1748     return ret;
1749 }
1750 
WaitForVBlank(uint32_t devId,uint32_t layerId,int32_t timeOut)1751 int32_t DisplayDeviceProxy::WaitForVBlank(uint32_t devId, uint32_t layerId, int32_t timeOut)
1752 {
1753     DISPLAY_LOG("interface start");
1754     if (devId > MAX_DEVID) {
1755         DISPLAY_LOG("param error");
1756         return DISPLAY_PARAM_ERR;
1757     }
1758     MessageParcel data;
1759     MessageParcel reply;
1760     MessageOption option;
1761     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1762         DISPLAY_LOG("error: write devId into data failed");
1763         return DISPLAY_FAILURE;
1764     }
1765     if (!data.WriteUint32(layerId)) {
1766         DISPLAY_LOG("error: write layerId into data failed");
1767         return DISPLAY_FAILURE;
1768     }
1769     if (!data.WriteInt32(timeOut)) {
1770         DISPLAY_LOG("error: write timeOut into data failed");
1771         return DISPLAY_FAILURE;
1772     }
1773     int32_t ret = Remote()->SendRequest(DSP_CMD_WAITFORVBLANK, data, reply, option);
1774     if (ret != 0) {
1775         DISPLAY_LOG("error: failed %{public}d", ret);
1776         return ret;
1777     }
1778     DISPLAY_LOG("interface end");
1779     return ret;
1780 }
1781 
SnapShot(uint32_t devId,LayerBuffer & buffer)1782 int32_t DisplayDeviceProxy::SnapShot(uint32_t devId, LayerBuffer &buffer)
1783 {
1784     DISPLAY_LOG("interface start");
1785     if (devId > MAX_DEVID) {
1786         DISPLAY_LOG("param error");
1787         return DISPLAY_PARAM_ERR;
1788     }
1789     MessageParcel data;
1790     MessageParcel reply;
1791     MessageOption option;
1792     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1793         DISPLAY_LOG("error: write devId into data failed");
1794         return DISPLAY_FAILURE;
1795     }
1796     int32_t ret = Remote()->SendRequest(DSP_CMD_SNAPSHOT, data, reply, option);
1797     if (ret != 0) {
1798         DISPLAY_LOG("error: failed %{public}d", ret);
1799         return ret;
1800     }
1801     // LayerBuffer's member 'BufferHandle* hdl' may not fully transmitted
1802     if (!DisplayDeviceReadData(&buffer, &reply)) {
1803         DISPLAY_LOG("error: read reply failed");
1804         return DISPLAY_FAILURE;
1805     }
1806     if (!DisplayDeviceReadBufHdl(buffer.hdl, &reply)) {
1807         DISPLAY_LOG("error: server write buffer handle into data failed");
1808         return DISPLAY_FAILURE;
1809     }
1810 
1811     DISPLAY_LOG("interface end");
1812     return ret;
1813 }
1814 
SetLayerVisibleRegion(uint32_t devId,uint32_t layerId,uint32_t num,const IRect & rect)1815 int32_t DisplayDeviceProxy::SetLayerVisibleRegion(uint32_t devId, uint32_t layerId, uint32_t num, const IRect &rect)
1816 {
1817     DISPLAY_LOG("interface start");
1818     if (devId > MAX_DEVID) {
1819         DISPLAY_LOG("param error");
1820         return DISPLAY_PARAM_ERR;
1821     }
1822     MessageParcel data;
1823     MessageParcel reply;
1824     MessageOption option;
1825     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1826         DISPLAY_LOG("error: write devId into data failed");
1827         return DISPLAY_FAILURE;
1828     }
1829     if (!data.WriteUint32(layerId)) {
1830         DISPLAY_LOG("error: write layerId into data failed");
1831         return DISPLAY_FAILURE;
1832     }
1833     if (!data.WriteUint32(num)) {
1834         DISPLAY_LOG("error: write num into data failed");
1835         return DISPLAY_FAILURE;
1836     }
1837     if (!DisplayDeviceWriteData(&data, &rect, num)) {
1838         DISPLAY_LOG("error: write rect into data failed");
1839         return DISPLAY_FAILURE;
1840     }
1841     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERVISIBLEREGION, data, reply, option);
1842     if (ret != 0) {
1843         DISPLAY_LOG("error: failed %{public}d", ret);
1844         return ret;
1845     }
1846     DISPLAY_LOG("interface end");
1847     return ret;
1848 }
1849 
SetLayerBuffer(uint32_t devId,uint32_t layerId,const BufferHandle & buffer,int32_t fence)1850 int32_t DisplayDeviceProxy::SetLayerBuffer(uint32_t devId, uint32_t layerId, const BufferHandle &buffer, int32_t fence)
1851 {
1852     DISPLAY_LOG("interface start");
1853     if (devId > MAX_DEVID) {
1854         DISPLAY_LOG("param error");
1855         return DISPLAY_PARAM_ERR;
1856     }
1857     MessageParcel data;
1858     MessageParcel reply;
1859     MessageOption option;
1860     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1861         DISPLAY_LOG("error: write devId into data failed");
1862         return DISPLAY_FAILURE;
1863     }
1864     if (!data.WriteUint32(layerId)) {
1865         DISPLAY_LOG("error: write layerId into data failed");
1866         return DISPLAY_FAILURE;
1867     }
1868     if (!DisplayDeviceWriteBufHdl(&data, &buffer)) {
1869         DISPLAY_LOG("error: write layerId into data failed");
1870         return DISPLAY_FAILURE;
1871     }
1872     if (!DisplayDeviceWriteFileDescriptor(&data, fence)) {
1873         DISPLAY_LOG("error: write layerId into data failed");
1874         return DISPLAY_FAILURE;
1875     }
1876     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERBUFFER, data, reply, option);
1877     if (ret != 0) {
1878         DISPLAY_LOG("error: failed %{public}d", ret);
1879         return ret;
1880     }
1881     DISPLAY_LOG("interface end");
1882     return ret;
1883 }
1884 
InvokeLayerCmd(uint32_t devId,uint32_t layerId,uint32_t cmd,...)1885 int32_t DisplayDeviceProxy::InvokeLayerCmd(uint32_t devId, uint32_t layerId, uint32_t cmd, ...)
1886 {
1887     DISPLAY_LOG("interface not support");
1888     (void)devId;
1889     (void)layerId;
1890     (void)cmd;
1891     return DISPLAY_NOT_SUPPORT;
1892 }
1893 
SetLayerCompositionType(uint32_t devId,uint32_t layerId,CompositionType type)1894 int32_t DisplayDeviceProxy::SetLayerCompositionType(uint32_t devId, uint32_t layerId, CompositionType type)
1895 {
1896     DISPLAY_LOG("interface start");
1897     if (devId > MAX_DEVID) {
1898         DISPLAY_LOG("param error");
1899         return DISPLAY_PARAM_ERR;
1900     }
1901     MessageParcel data;
1902     MessageParcel reply;
1903     MessageOption option;
1904     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1905         DISPLAY_LOG("error: write devId into data failed");
1906         return DISPLAY_FAILURE;
1907     }
1908     if (!data.WriteUint32(layerId)) {
1909         DISPLAY_LOG("error: write layerId into data failed");
1910         return DISPLAY_FAILURE;
1911     }
1912     if (!data.WriteInt32(type)) {
1913         DISPLAY_LOG("error: write type into data failed");
1914         return DISPLAY_FAILURE;
1915     }
1916     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERCOMPOSITIONTYPE, data, reply, option);
1917     if (ret != 0) {
1918         DISPLAY_LOG("error: failed %{public}d", ret);
1919         return ret;
1920     }
1921     DISPLAY_LOG("interface end");
1922     return ret;
1923 }
1924 
SetLayerBlendType(uint32_t devId,uint32_t layerId,BlendType type)1925 int32_t DisplayDeviceProxy::SetLayerBlendType(uint32_t devId, uint32_t layerId, BlendType type)
1926 {
1927     DISPLAY_LOG("interface start");
1928     if (devId > MAX_DEVID) {
1929         DISPLAY_LOG("param error");
1930         return DISPLAY_PARAM_ERR;
1931     }
1932     MessageParcel data;
1933     MessageParcel reply;
1934     MessageOption option;
1935     if (!data.WriteInterfaceToken(DisplayDeviceProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
1936         DISPLAY_LOG("error: write devId into data failed");
1937         return DISPLAY_FAILURE;
1938     }
1939     if (!data.WriteUint32(layerId)) {
1940         DISPLAY_LOG("error: write layerId into data failed");
1941         return DISPLAY_FAILURE;
1942     }
1943     if (!data.WriteInt32(type)) {
1944         DISPLAY_LOG("error: write type into data failed");
1945         return DISPLAY_FAILURE;
1946     }
1947     int32_t ret = Remote()->SendRequest(DSP_CMD_SETLAYERBLENDTYPE, data, reply, option);
1948     if (ret != 0) {
1949         DISPLAY_LOG("error: failed %{public}d", ret);
1950         return ret;
1951     }
1952     DISPLAY_LOG("interface end");
1953     return ret;
1954 }
1955