• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <hdf_base.h>
17 #include <hdf_device_desc.h>
18 #include <hdf_log.h>
19 #include <hdf_sbuf_ipc.h>
20 #include "v1_0/display_composer_stub.h"
21 
22 #undef LOG_TAG
23 #define LOG_TAG "COMPOSER_DRV"
24 #undef LOG_DOMAIN
25 #define LOG_DOMAIN 0xD002500
26 
27 using namespace OHOS::HDI::Display::Composer::V1_0;
28 
29 struct HdfDisplayComposerHost {
30     struct IDeviceIoService ioService;
31     OHOS::sptr<OHOS::IRemoteObject> stub;
32 };
33 
DisplayComposerDriverDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)34 static int32_t DisplayComposerDriverDispatch(
35     struct HdfDeviceIoClient* client, int cmdId, struct HdfSBuf* data, struct HdfSBuf* reply)
36 {
37     if ((client == nullptr) || (client->device == nullptr)) {
38         HDF_LOGE("%{public}s: param is nullptr", __func__);
39         return HDF_ERR_INVALID_PARAM;
40     }
41     auto* hdfDisplayComposerHost = CONTAINER_OF(client->device->service, struct HdfDisplayComposerHost, ioService);
42 
43     OHOS::MessageParcel* dataParcel = nullptr;
44     OHOS::MessageParcel* replyParcel = nullptr;
45     OHOS::MessageOption option;
46 
47     if (SbufToParcel(data, &dataParcel) != HDF_SUCCESS) {
48         HDF_LOGE("%{public}s:invalid data sbuf object to dispatch", __func__);
49         return HDF_ERR_INVALID_PARAM;
50     }
51     if (SbufToParcel(reply, &replyParcel) != HDF_SUCCESS) {
52         HDF_LOGE("%{public}s:invalid reply sbuf object to dispatch", __func__);
53         return HDF_ERR_INVALID_PARAM;
54     }
55 
56     return hdfDisplayComposerHost->stub->SendRequest(cmdId, *dataParcel, *replyParcel, option);
57 }
58 
HdfDisplayComposerDriverInit(struct HdfDeviceObject * deviceObject)59 static int HdfDisplayComposerDriverInit(struct HdfDeviceObject* deviceObject)
60 {
61     HDF_LOGI("%{public}s: enter", __func__);
62     return HDF_SUCCESS;
63 }
64 
HdfDisplayComposerDriverBind(struct HdfDeviceObject * deviceObject)65 static int HdfDisplayComposerDriverBind(struct HdfDeviceObject* deviceObject)
66 {
67     HDF_LOGI("%{public}s: enter", __func__);
68     auto* hdfDisplayComposerHost = new (std::nothrow) HdfDisplayComposerHost;
69     if (hdfDisplayComposerHost == nullptr) {
70         HDF_LOGE("%{public}s: failed to create HdfDisplayComposerHost object", __func__);
71         return HDF_FAILURE;
72     }
73 
74     hdfDisplayComposerHost->ioService.Dispatch = DisplayComposerDriverDispatch;
75     hdfDisplayComposerHost->ioService.Open = NULL;
76     hdfDisplayComposerHost->ioService.Release = NULL;
77 
78     auto serviceImpl = IDisplayComposer::Get(true);
79     if (serviceImpl == nullptr) {
80         HDF_LOGE("%{public}s: failed to get the implement of service", __func__);
81         delete hdfDisplayComposerHost;
82         return HDF_FAILURE;
83     }
84 
85     hdfDisplayComposerHost->stub =
86         OHOS::HDI::ObjectCollector::GetInstance().GetOrNewObject(serviceImpl, IDisplayComposer::GetDescriptor());
87     if (hdfDisplayComposerHost->stub == nullptr) {
88         HDF_LOGE("%{public}s: failed to get stub object", __func__);
89         delete hdfDisplayComposerHost;
90         return HDF_FAILURE;
91     }
92 
93     deviceObject->service = &hdfDisplayComposerHost->ioService;
94     return HDF_SUCCESS;
95 }
96 
HdfDisplayComposerDriverRelease(struct HdfDeviceObject * deviceObject)97 static void HdfDisplayComposerDriverRelease(struct HdfDeviceObject* deviceObject)
98 {
99     HDF_LOGI("%{public}s: enter", __func__);
100     if (deviceObject->service == nullptr) {
101         HDF_LOGE("%{public}s: service is nullptr", __func__);
102         return;
103     }
104 
105     auto* hdfDisplayComposerHost = CONTAINER_OF(deviceObject->service, struct HdfDisplayComposerHost, ioService);
106     delete hdfDisplayComposerHost;
107 }
108 
109 static struct HdfDriverEntry g_displaycomposerDriverEntry = {
110     .moduleVersion = 1,
111     .moduleName = "display_composer",
112     .Bind = HdfDisplayComposerDriverBind,
113     .Init = HdfDisplayComposerDriverInit,
114     .Release = HdfDisplayComposerDriverRelease,
115 };
116 
117 #ifdef __cplusplus
118 extern "C" {
119 #endif
120 HDF_INIT(g_displaycomposerDriverEntry);
121 #ifdef __cplusplus
122 }
123 #endif
124