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 "display_layer_proxy.h"
17 #include <buffer_handle_parcel.h>
18 #include <hdf_base.h>
19 #include <hdf_log.h>
20 #include <message_parcel.h>
21
22 namespace OHOS {
23 namespace HDI {
24 namespace Display {
25 namespace V1_0 {
26
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<DisplayLayerProxy> layerSptr = iface_cast<DisplayLayerProxy>(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 DisplayLayerProxy::InitDisplay(unsigned int devId)
49 {
50 MessageParcel data;
51 MessageParcel reply;
52 MessageOption option;
53
54 if (!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 DisplayLayerProxy::DeinitDisplay(unsigned int devId)
73 {
74 MessageParcel data;
75 MessageParcel reply;
76 MessageOption option;
77
78 if (!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 DisplayLayerProxy::GetDisplayInfo(unsigned int devId, std::shared_ptr<DisplayInfo> &dispInfo)
97 {
98 MessageParcel data;
99 MessageParcel reply;
100 MessageOption option;
101
102 if (!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 DisplayLayerProxy::CreateLayer(unsigned int devId, LayerInfo &layerInfo, unsigned int &layerId)
132 {
133 MessageParcel data;
134 MessageParcel reply;
135 MessageOption option;
136
137 if (!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 DisplayLayerProxy::CloseLayer(unsigned int devId, unsigned int layerId)
169 {
170 MessageParcel data;
171 MessageParcel reply;
172 MessageOption option;
173
174 if (!data.WriteUint32(devId) || !data.WriteUint32(layerId)) {
175 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
176 return DISPLAY_FAILURE;
177 }
178
179 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_CLOSE_LAYER, data, reply, option);
180 if (ret != HDF_SUCCESS) {
181 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
182 return DISPLAY_FAILURE;
183 }
184
185 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
186 if (retCode != DISPLAY_SUCCESS) {
187 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
188 }
189 return retCode;
190 }
191
SetLayerVisible(unsigned int devId,unsigned int layerId,bool visible)192 DispErrCode DisplayLayerProxy::SetLayerVisible(unsigned int devId, unsigned int layerId, bool visible)
193 {
194 MessageParcel data;
195 MessageParcel reply;
196 MessageOption option;
197
198 if (!data.WriteUint32(devId) || !data.WriteUint32(layerId)) {
199 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
200 return DISPLAY_FAILURE;
201 }
202
203 if (!data.WriteBool(visible)) {
204 HDF_LOGE("%{public}s: write visible failed", __func__);
205 return DISPLAY_FAILURE;
206 }
207
208 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_SET_LAYER_VISIBLE, data, reply, option);
209 if (ret != HDF_SUCCESS) {
210 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
211 return DISPLAY_FAILURE;
212 }
213
214 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
215 if (retCode != DISPLAY_SUCCESS) {
216 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
217 }
218 return retCode;
219 }
220
GetLayerVisibleState(unsigned int devId,unsigned int layerId,bool & visible)221 DispErrCode DisplayLayerProxy::GetLayerVisibleState(unsigned int devId, unsigned int layerId, bool &visible)
222 {
223 MessageParcel data;
224 MessageParcel reply;
225 MessageOption option;
226
227 if (!data.WriteUint32(devId) || !data.WriteUint32(layerId)) {
228 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
229 return DISPLAY_FAILURE;
230 }
231
232 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_GET_LAYER_VISIBLE_STATE, data, reply, option);
233 if (ret != HDF_SUCCESS) {
234 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
235 return DISPLAY_FAILURE;
236 }
237
238 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
239 if (retCode != DISPLAY_SUCCESS) {
240 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
241 return retCode;
242 }
243
244 visible = reply.ReadBool();
245 return DISPLAY_SUCCESS;
246 }
247
SetLayerRect(unsigned int devId,unsigned int layerId,IRect & rect)248 DispErrCode DisplayLayerProxy::SetLayerRect(unsigned int devId, unsigned int layerId, IRect &rect)
249 {
250 MessageParcel data;
251 MessageParcel reply;
252 MessageOption option;
253
254 if (!data.WriteUint32(devId) || !data.WriteUint32(layerId)) {
255 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
256 return DISPLAY_FAILURE;
257 }
258
259 bool flag = data.WriteInt32(rect.x);
260 flag |= data.WriteInt32(rect.y);
261 flag |= data.WriteInt32(rect.w);
262 flag |= data.WriteInt32(rect.h);
263 if (!flag) {
264 HDF_LOGE("%s: write rect failed", __func__);
265 return DISPLAY_FAILURE;
266 }
267
268 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_SET_LAYER_RECT, data, reply, option);
269 if (ret != HDF_SUCCESS) {
270 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
271 return DISPLAY_FAILURE;
272 }
273
274 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
275 if (retCode != DISPLAY_SUCCESS) {
276 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
277 }
278 return retCode;
279 }
280
GetLayerRect(unsigned int devId,unsigned int layerId,std::shared_ptr<IRect> & rect)281 DispErrCode DisplayLayerProxy::GetLayerRect(unsigned int devId, unsigned int layerId, std::shared_ptr<IRect> &rect)
282 {
283 MessageParcel data;
284 MessageParcel reply;
285 MessageOption option;
286
287 if (!data.WriteUint32(devId) || !data.WriteUint32(layerId)) {
288 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
289 return DISPLAY_FAILURE;
290 }
291
292 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_GET_LAYER_RECT, data, reply, option);
293 if (ret != HDF_SUCCESS) {
294 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
295 return DISPLAY_FAILURE;
296 }
297
298 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
299 if (retCode != DISPLAY_SUCCESS) {
300 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
301 return retCode;
302 }
303
304 rect = std::make_shared<IRect>();
305 if (rect == nullptr) {
306 HDF_LOGE("%{public}s: rect is nullptr", __func__);
307 return DISPLAY_FAILURE;
308 }
309 rect->x = reply.ReadInt32();
310 rect->y = reply.ReadInt32();
311 rect->w = reply.ReadInt32();
312 rect->h = reply.ReadInt32();
313 return DISPLAY_SUCCESS;
314 }
315
SetLayerZorder(unsigned int devId,unsigned int layerId,unsigned int zorder)316 DispErrCode DisplayLayerProxy::SetLayerZorder(unsigned int devId, unsigned int layerId, unsigned int zorder)
317 {
318 MessageParcel data;
319 MessageParcel reply;
320 MessageOption option;
321
322 if (!data.WriteUint32(devId) || !data.WriteUint32(layerId)) {
323 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
324 return DISPLAY_FAILURE;
325 }
326
327 if (!data.WriteUint32(zorder)) {
328 HDF_LOGE("%{public}s: write zorder failed!", __func__);
329 return DISPLAY_FAILURE;
330 }
331
332 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_SET_LAYER_ZORDER, data, reply, option);
333 if (ret != HDF_SUCCESS) {
334 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
335 return DISPLAY_FAILURE;
336 }
337
338 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
339 if (retCode != DISPLAY_SUCCESS) {
340 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
341 }
342 return retCode;
343 }
344
GetLayerZorder(unsigned int devId,unsigned int layerId,unsigned int & zorder)345 DispErrCode DisplayLayerProxy::GetLayerZorder(unsigned int devId, unsigned int layerId, unsigned int &zorder)
346 {
347 MessageParcel data;
348 MessageParcel reply;
349 MessageOption option;
350
351 if (!data.WriteUint32(devId) || !data.WriteUint32(layerId)) {
352 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
353 return DISPLAY_FAILURE;
354 }
355
356 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_GET_LAYER_ZORDER, data, reply, option);
357 if (ret != HDF_SUCCESS) {
358 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
359 return DISPLAY_FAILURE;
360 }
361
362 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
363 if (retCode != DISPLAY_SUCCESS) {
364 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
365 return retCode;
366 }
367 zorder = reply.ReadUint32();
368 return DISPLAY_SUCCESS;
369 }
370
SetTransformMode(unsigned int devId,unsigned int layerId,TransformType & type)371 DispErrCode DisplayLayerProxy::SetTransformMode(unsigned int devId, unsigned int layerId, TransformType &type)
372 {
373 MessageParcel data;
374 MessageParcel reply;
375 MessageOption option;
376
377 if (!data.WriteUint32(devId) || !data.WriteUint32(layerId)) {
378 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
379 return DISPLAY_FAILURE;
380 }
381
382 if (!data.WriteUint32(static_cast<unsigned int>(type))) {
383 HDF_LOGE("%{public}s: write transmode failed!", __func__);
384 return DISPLAY_FAILURE;
385 }
386
387 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_SET_TRANSFORM_MODE, data, reply, option);
388 if (ret != HDF_SUCCESS) {
389 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
390 return DISPLAY_FAILURE;
391 }
392
393 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
394 if (retCode != DISPLAY_SUCCESS) {
395 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
396 }
397 return retCode;
398 }
399
SetLayerBuffer(unsigned int devId,unsigned int layerId,const BufferHandle & buffer,int fence)400 DispErrCode DisplayLayerProxy::SetLayerBuffer(unsigned int devId, unsigned int layerId,
401 const BufferHandle &buffer, int fence)
402 {
403 MessageParcel data;
404 MessageParcel reply;
405 MessageOption option;
406
407 if (!data.WriteUint32(devId) || !data.WriteUint32(layerId)) {
408 HDF_LOGE("%{public}s: write devId or layerId failed", __func__);
409 return DISPLAY_FAILURE;
410 }
411
412 if (!OHOS::WriteBufferHandle(data, buffer)) {
413 HDF_LOGE("%{public}s: write bufferHandle failed", __func__);
414 return DISPLAY_FAILURE;
415 }
416
417 int32_t ret = Remote()->SendRequest(CMD_DISPLAY_LAYER_REMOTE_SET_LAYER_BUFFER, data, reply, option);
418 if (ret != HDF_SUCCESS) {
419 HDF_LOGE("%{public}s: SendRequest failed, error code is %{public}d", __func__, ret);
420 return DISPLAY_FAILURE;
421 }
422
423 DispErrCode retCode = static_cast<DispErrCode>(reply.ReadInt32());
424 if (retCode != DISPLAY_SUCCESS) {
425 HDF_LOGE("%{public}s: failed retCode is %{public}d", __func__, retCode);
426 }
427 return retCode;
428 }
429
430 } // namespace V1_0
431 } // namespace Display
432 } // namespace HDI
433 } // namespace OHOS