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