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