1 /*
2 * Copyright (c) 2021 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 "video_layer_proxy.h"
17 #include <buffer_handle_parcel.h>
18 #include <hdf_base.h>
19 #include <hdf_log.h>
20 #include <iservmgr_hdi.h>
21 #include <message_parcel.h>
22
23 namespace OHOS {
24 namespace HDI {
25 namespace Display {
26 namespace V1_0 {
Get(const char * serviceName)27 sptr<IDisplayLayer> IDisplayLayer::Get(const char *serviceName)
28 {
29 do {
30 using namespace OHOS::HDI::ServiceManager::V1_0;
31 auto servMgr = IServiceManager::Get();
32 if (servMgr == nullptr) {
33 HDF_LOGE("%{public}s: IServiceManager failed", __func__);
34 break;
35 }
36
37 auto remote = servMgr->GetService(serviceName);
38 if (remote != nullptr) {
39 sptr<VideoLayerProxy> layerSptr = iface_cast<VideoLayerProxy>(remote);
40 return layerSptr;
41 }
42 HDF_LOGE("%{public}s: GetService failed! serviceName = %{public}s", __func__, serviceName);
43 } while (false);
44
45 return nullptr;
46 }
47
InitDisplay(unsigned int devId)48 DispErrCode VideoLayerProxy::InitDisplay(unsigned int devId)
49 {
50 MessageParcel data;
51 MessageParcel reply;
52 MessageOption option;
53
54 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
55 HDF_LOGE("%{public}s: write devId failed", __func__);
56 return DISPLAY_FAILURE;
57 }
58
59 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_INIT_DISPLAY, data, reply, option);
60 if (ret != HDF_SUCCESS) {
61 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
62 return DISPLAY_FAILURE;
63 }
64
65 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
66 if (retCode != DISPLAY_SUCCESS) {
67 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
68 }
69 return retCode;
70 }
71
DeinitDisplay(unsigned int devId)72 DispErrCode VideoLayerProxy::DeinitDisplay(unsigned int devId)
73 {
74 MessageParcel data;
75 MessageParcel reply;
76 MessageOption option;
77
78 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
79 HDF_LOGE("%{public}s: write devId failed", __func__);
80 return DISPLAY_FAILURE;
81 }
82
83 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_DEINIT_DISPLAY, data, reply, option);
84 if (ret != HDF_SUCCESS) {
85 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
86 return DISPLAY_FAILURE;
87 }
88
89 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
90 if (retCode != DISPLAY_SUCCESS) {
91 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
92 }
93 return retCode;
94 }
95
GetDisplayInfo(unsigned int devId,std::shared_ptr<DisplayInfo> & dispInfo)96 DispErrCode VideoLayerProxy::GetDisplayInfo(unsigned int devId, std::shared_ptr<DisplayInfo> &dispInfo)
97 {
98 MessageParcel data;
99 MessageParcel reply;
100 MessageOption option;
101
102 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
103 HDF_LOGE("%{public}s: write devId failed", __func__);
104 return DISPLAY_FAILURE;
105 }
106
107 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_GET_DISPLAY_INFO, data, reply, option);
108 if (ret != HDF_SUCCESS) {
109 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
110 return DISPLAY_FAILURE;
111 }
112
113 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
114 if (retCode != DISPLAY_SUCCESS) {
115 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
116 return retCode;
117 }
118
119 dispInfo = std::make_shared<DisplayInfo>();
120 if (dispInfo == nullptr) {
121 HDF_LOGE("%{public}s: dispInfo is nullptr", __func__);
122 return DISPLAY_FAILURE;
123 }
124 dispInfo->width = reply.ReadUint32();
125 dispInfo->height = reply.ReadUint32();
126 dispInfo->rotAngle = reply.ReadInt32();
127
128 return DISPLAY_SUCCESS;
129 }
130
CreateLayer(unsigned int devId,LayerInfo & layerInfo,unsigned int & layerId)131 DispErrCode VideoLayerProxy::CreateLayer(unsigned int devId, LayerInfo &layerInfo, unsigned int &layerId)
132 {
133 MessageParcel data;
134 MessageParcel reply;
135 MessageOption option;
136
137 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId)) {
138 HDF_LOGE("%{public}s: write devId failed", __func__);
139 return DISPLAY_FAILURE;
140 }
141
142 bool flag = data.WriteInt32(layerInfo.width);
143 flag |= data.WriteInt32(layerInfo.height);
144 flag |= data.WriteInt32(static_cast<int32_t>(layerInfo.type));
145 flag |= data.WriteInt32(layerInfo.bpp);
146 flag |= data.WriteInt32(static_cast<int32_t>(layerInfo.pixFormat));
147 if (!flag) {
148 HDF_LOGE("%s: write layer info failed", __func__);
149 return DISPLAY_FAILURE;
150 }
151
152 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_CREATE_LAYER, data, reply, option);
153 if (ret != HDF_SUCCESS) {
154 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
155 return DISPLAY_FAILURE;
156 }
157
158 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
159 if (retCode != DISPLAY_SUCCESS) {
160 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
161 return retCode;
162 }
163
164 layerId = reply.ReadUint32();
165 return DISPLAY_SUCCESS;
166 }
167
CloseLayer(unsigned int devId,unsigned int layerId)168 DispErrCode VideoLayerProxy::CloseLayer(unsigned int devId, unsigned int layerId)
169 {
170 MessageParcel data;
171 MessageParcel reply;
172 MessageOption option;
173
174 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId) ||
175 !data.WriteUint32(layerId)) {
176 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
177 return DISPLAY_FAILURE;
178 }
179
180 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_CLOSE_LAYER, data, reply, option);
181 if (ret != HDF_SUCCESS) {
182 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
183 return DISPLAY_FAILURE;
184 }
185
186 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
187 if (retCode != DISPLAY_SUCCESS) {
188 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
189 }
190 return retCode;
191 }
192
SetLayerVisible(unsigned int devId,unsigned int layerId,bool visible)193 DispErrCode VideoLayerProxy::SetLayerVisible(unsigned int devId, unsigned int layerId, bool visible)
194 {
195 MessageParcel data;
196 MessageParcel reply;
197 MessageOption option;
198
199 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId) ||
200 !data.WriteUint32(layerId)) {
201 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
202 return DISPLAY_FAILURE;
203 }
204
205 if (!data.WriteBool(visible)) {
206 HDF_LOGE("%{public}s: write visible failed", __func__);
207 return DISPLAY_FAILURE;
208 }
209
210 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_SET_LAYER_VISIBLE, data, reply, option);
211 if (ret != HDF_SUCCESS) {
212 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
213 return DISPLAY_FAILURE;
214 }
215
216 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
217 if (retCode != DISPLAY_SUCCESS) {
218 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
219 }
220 return retCode;
221 }
222
GetLayerVisibleState(unsigned int devId,unsigned int layerId,bool & visible)223 DispErrCode VideoLayerProxy::GetLayerVisibleState(unsigned int devId, unsigned int layerId, bool &visible)
224 {
225 MessageParcel data;
226 MessageParcel reply;
227 MessageOption option;
228
229 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId) ||
230 !data.WriteUint32(layerId)) {
231 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
232 return DISPLAY_FAILURE;
233 }
234
235 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_GET_LAYER_VISIBLE_STATE, data, reply, option);
236 if (ret != HDF_SUCCESS) {
237 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
238 return DISPLAY_FAILURE;
239 }
240
241 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
242 if (retCode != DISPLAY_SUCCESS) {
243 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
244 return retCode;
245 }
246
247 visible = reply.ReadBool();
248 return DISPLAY_SUCCESS;
249 }
250
SetLayerRect(unsigned int devId,unsigned int layerId,IRect & rect)251 DispErrCode VideoLayerProxy::SetLayerRect(unsigned int devId, unsigned int layerId, IRect &rect)
252 {
253 MessageParcel data;
254 MessageParcel reply;
255 MessageOption option;
256
257 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId) ||
258 !data.WriteUint32(layerId)) {
259 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
260 return DISPLAY_FAILURE;
261 }
262
263 bool flag = data.WriteInt32(rect.x);
264 flag |= data.WriteInt32(rect.y);
265 flag |= data.WriteInt32(rect.w);
266 flag |= data.WriteInt32(rect.h);
267 if (!flag) {
268 HDF_LOGE("%s: write rect failed", __func__);
269 return DISPLAY_FAILURE;
270 }
271
272 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_SET_LAYER_RECT, data, reply, option);
273 if (ret != HDF_SUCCESS) {
274 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
275 return DISPLAY_FAILURE;
276 }
277
278 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
279 if (retCode != DISPLAY_SUCCESS) {
280 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
281 }
282 return retCode;
283 }
284
GetLayerRect(unsigned int devId,unsigned int layerId,std::shared_ptr<IRect> & rect)285 DispErrCode VideoLayerProxy::GetLayerRect(unsigned int devId, unsigned int layerId, std::shared_ptr<IRect> &rect)
286 {
287 MessageParcel data;
288 MessageParcel reply;
289 MessageOption option;
290
291 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId) ||
292 !data.WriteUint32(layerId)) {
293 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
294 return DISPLAY_FAILURE;
295 }
296
297 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_GET_LAYER_RECT, data, reply, option);
298 if (ret != HDF_SUCCESS) {
299 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
300 return DISPLAY_FAILURE;
301 }
302
303 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
304 if (retCode != DISPLAY_SUCCESS) {
305 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
306 return retCode;
307 }
308
309 rect = std::make_shared<IRect>();
310 if (rect == nullptr) {
311 HDF_LOGE("%{public}s: rect is nullptr", __func__);
312 return DISPLAY_FAILURE;
313 }
314 rect->x = reply.ReadInt32();
315 rect->y = reply.ReadInt32();
316 rect->w = reply.ReadInt32();
317 rect->h = reply.ReadInt32();
318 return DISPLAY_SUCCESS;
319 }
320
SetLayerZorder(unsigned int devId,unsigned int layerId,unsigned int zorder)321 DispErrCode VideoLayerProxy::SetLayerZorder(unsigned int devId, unsigned int layerId, unsigned int zorder)
322 {
323 MessageParcel data;
324 MessageParcel reply;
325 MessageOption option;
326
327 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId) ||
328 !data.WriteUint32(layerId)) {
329 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
330 return DISPLAY_FAILURE;
331 }
332
333 if (!data.WriteUint32(zorder)) {
334 HDF_LOGE("%{public}s: write zorder failed!", __func__);
335 return DISPLAY_FAILURE;
336 }
337
338 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_SET_LAYER_ZORDER, data, reply, option);
339 if (ret != HDF_SUCCESS) {
340 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
341 return DISPLAY_FAILURE;
342 }
343
344 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
345 if (retCode != DISPLAY_SUCCESS) {
346 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
347 }
348 return retCode;
349 }
350
GetLayerZorder(unsigned int devId,unsigned int layerId,unsigned int & zorder)351 DispErrCode VideoLayerProxy::GetLayerZorder(unsigned int devId, unsigned int layerId, unsigned int &zorder)
352 {
353 MessageParcel data;
354 MessageParcel reply;
355 MessageOption option;
356
357 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId) ||
358 !data.WriteUint32(layerId)) {
359 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
360 return DISPLAY_FAILURE;
361 }
362
363 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_GET_LAYER_ZORDER, data, reply, option);
364 if (ret != HDF_SUCCESS) {
365 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
366 return DISPLAY_FAILURE;
367 }
368
369 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
370 if (retCode != DISPLAY_SUCCESS) {
371 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
372 return retCode;
373 }
374 zorder = reply.ReadUint32();
375 return DISPLAY_SUCCESS;
376 }
377
SetTransformMode(unsigned int devId,unsigned int layerId,TransformType & type)378 DispErrCode VideoLayerProxy::SetTransformMode(unsigned int devId, unsigned int layerId, TransformType &type)
379 {
380 MessageParcel data;
381 MessageParcel reply;
382 MessageOption option;
383
384 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId) ||
385 !data.WriteUint32(layerId)) {
386 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
387 return DISPLAY_FAILURE;
388 }
389
390 if (!data.WriteUint32(static_cast<unsigned int>(type))) {
391 HDF_LOGE("%{public}s: write transmode failed!", __func__);
392 return DISPLAY_FAILURE;
393 }
394
395 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_SET_TRANSFORM_MODE, data, reply, option);
396 if (ret != HDF_SUCCESS) {
397 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
398 return DISPLAY_FAILURE;
399 }
400
401 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
402 if (retCode != DISPLAY_SUCCESS) {
403 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
404 }
405 return retCode;
406 }
407
SetLayerBuffer(unsigned int devId,unsigned int layerId,const BufferHandle & buffer,int fence)408 DispErrCode VideoLayerProxy::SetLayerBuffer(unsigned int devId, unsigned int layerId,
409 const BufferHandle &buffer, int fence)
410 {
411 MessageParcel data;
412 MessageParcel reply;
413 MessageOption option;
414 (void)fence;
415
416 if (!data.WriteInterfaceToken(VideoLayerProxy::GetDescriptor()) || !data.WriteUint32(devId) ||
417 !data.WriteUint32(layerId)) {
418 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
419 return DISPLAY_FAILURE;
420 }
421
422 if (!OHOS::WriteBufferHandle(data, buffer)) {
423 HDF_LOGE("%{public}s: write bufferHandle failed", __func__);
424 return DISPLAY_FAILURE;
425 }
426
427 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_SET_LAYER_BUFFER, data, reply, option);
428 if (ret != HDF_SUCCESS) {
429 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
430 return DISPLAY_FAILURE;
431 }
432
433 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
434 if (retCode != DISPLAY_SUCCESS) {
435 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
436 }
437 return retCode;
438 }
439 } // namespace V1_0
440 } // namespace Display
441 } // namespace HDI
442 } // namespace OHOS