• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
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 #include <cstdarg>
16 #include <cerrno>
17 #include "hifb_adapter.h"
18 #include "display_adapter_interface.h"
19 
DisplayOpenDevice(const char * path,int flags,mode_t mode)20 static int32_t DisplayOpenDevice(const char *path, int flags, mode_t mode)
21 {
22     return OSAL_OPEN(path, flags, mode);
23 }
24 
DisplayCloseDevice(int32_t devFd)25 static int32_t DisplayCloseDevice(int32_t devFd)
26 {
27     return OSAL_CLOSE(devFd);
28 }
29 
DisplayIoctl(int32_t devFd,uint32_t cmd,void * args)30 static int32_t DisplayIoctl(int32_t devFd, uint32_t cmd, void *args)
31 {
32     return OSAL_IOCTL(devFd, cmd, args);
33 }
34 
DisplayFbGetDmaBuffer(int32_t devFd)35 static int32_t DisplayFbGetDmaBuffer(int32_t devFd)
36 {
37     struct hifb_membuf_info fbMemBuf;
38     fbMemBuf.fd = -1;
39     int32_t ret = OSAL_IOCTL(devFd, HIFB_GET_MEMBUF, &fbMemBuf);
40     if (ret < 0) {
41         return -1;
42     }
43     return fbMemBuf.fd;
44 }
45 
DisplayFbFresh(int32_t devFd,DisplayFrameInfo * frame)46 static int32_t DisplayFbFresh(int32_t devFd, DisplayFrameInfo *frame)
47 {
48     if (frame == nullptr) {
49         return DISPLAY_NULL_PTR;
50     }
51 
52     struct hifb_frame_info fbFrameInfo;
53     fbFrameInfo.rect.x = frame->rect.x;
54     fbFrameInfo.rect.y = frame->rect.y;
55     fbFrameInfo.rect.w = frame->rect.w;
56     fbFrameInfo.rect.h = frame->rect.h;
57     fbFrameInfo.in_fence = frame->inFence;
58     fbFrameInfo.stride = frame->stride;
59     fbFrameInfo.bufaddr = frame->bufaddr;
60     fbFrameInfo.format = frame->format;
61     if (OSAL_IOCTL(devFd, HIFB_REFRESH_FRAMEINFO, &fbFrameInfo) != 0) {
62         return DISPLAY_FAILURE;
63     }
64     frame->outFence = fbFrameInfo.out_fence;
65     return DISPLAY_SUCCESS;
66 }
67 
68 extern "C"
69 {
DisplayAdapaterInitialize(DisplayAdapterFuncs ** funcs)70 int32_t DisplayAdapaterInitialize(DisplayAdapterFuncs **funcs)
71 {
72     DisplayAdapterFuncs *adapter = (DisplayAdapterFuncs *)calloc(1, sizeof(DisplayAdapterFuncs));
73     if (adapter == nullptr) {
74         return DISPLAY_FAILURE;
75     }
76     adapter->OpenDevice = DisplayOpenDevice;
77     adapter->CloseDevice = DisplayCloseDevice;
78     adapter->Ioctl = DisplayIoctl;
79     adapter->FbGetDmaBuffer = DisplayFbGetDmaBuffer;
80     adapter->FbFresh = DisplayFbFresh;
81     *funcs = adapter;
82     return DISPLAY_SUCCESS;
83 }
84 
DisplayAdapaterUninitialize(DisplayAdapterFuncs * funcs)85 int32_t DisplayAdapaterUninitialize(DisplayAdapterFuncs *funcs)
86 {
87     if (funcs != nullptr) {
88         free(funcs);
89     }
90     return DISPLAY_SUCCESS;
91 }
92 }