• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021–2022 Beijing OSWare Technology Co., Ltd
3  * This file contains confidential and proprietary information of
4  * OSWare Technology Co., Ltd
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include "fb_display.h"
20 #include <sys/ioctl.h>
21 #include <sys/mman.h>
22 #include <sys/ioctl.h>
23 #include <cerrno>
24 #include <securec.h>
25 #include <linux/fb.h>
26 #include "display_common.h"
27 #include "hdi_gfx_composition.h"
28 #include "fb_composition.h"
29 #include "vsync/sorft_vsync.h"
30 #include "hdi_gfx_composition.h"
31 #include "display_adapter.h"
32 
33 namespace OHOS {
34 namespace HDI {
35 namespace DISPLAY {
CreateHdiLayer(LayerType type)36 std::unique_ptr<HdiLayer> FbDisplay::CreateHdiLayer(LayerType type)
37 {
38     DISPLAY_LOGD();
39     auto layer = HdiDisplay::CreateHdiLayer(type);
40     layer->SetReleaseFence(-1); // the fd display will return the current buffer fence.
41     return layer;
42 }
43 
FbDisplay(std::vector<int> & fds)44 FbDisplay::FbDisplay(std::vector<int> &fds)
45 {
46     DISPLAY_LOGD();
47     deviceFds_ = fds;
48 }
49 
~FbDisplay()50 FbDisplay::~FbDisplay()
51 {
52     DISPLAY_LOGD();
53 }
54 
Init()55 int32_t FbDisplay::Init()
56 {
57     int ret;
58     int deviceFd = deviceFds_[0];
59     struct fb_var_screeninfo varInfo;
60     const uint32_t defaultFreshRate = 60 * 1000;
61     ret = HdiDisplay::Init();
62     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("init failed"));
63     ret = DisplayAdapter::GetInstance()->Ioctl(deviceFd, FBIOGET_VSCREENINFO, &varInfo);
64     DISPLAY_CHK_RETURN((ret < 0), DISPLAY_FAILURE, DISPLAY_LOGE("failed to get screen information"));
65     DisplayModeInfo mode;
66     mode.freshRate = defaultFreshRate;
67     mode.width = varInfo.xres;
68     mode.height = varInfo.yres;
69     mode.id = 0;
70     modes_.push_back(mode);
71     DISPLAY_LOGD("xres : %{public}d yres : %{public}d fps : %{public}d", varInfo.xres, varInfo.yres, mode.freshRate);
72 
73     displayCapability_.phyWidth = varInfo.xres;
74     displayCapability_.phyHeight = varInfo.yres;
75     displayCapability_.type = DISP_INTF_PANEL;
76     mActiveModeId = 0;
77     auto preComp = std::make_unique<HdiGfxComposition>();
78     DISPLAY_CHK_RETURN((preComp == nullptr), DISPLAY_FAILURE,
79         DISPLAY_LOGE("can not new HdiGfxComposition errno %{public}d", errno));
80     ret = preComp->Init();
81     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("can not init HdiGfxComposition"));
82 
83     auto postComp = std::make_unique<FbComposition>(deviceFds_);
84     DISPLAY_CHK_RETURN((postComp == nullptr), DISPLAY_FAILURE,
85         DISPLAY_LOGE("can not new HdiDrmComposition errno %{public}d", errno));
86     ret = postComp->Init();
87     DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("can not init HdiDrmComposition"));
88     mComposer = std::make_unique<HdiComposer>(std::move(preComp), std::move(postComp));
89     mClientLayer->SetReleaseFence(-1);
90     return DISPLAY_SUCCESS;
91 }
92 
GetDisplayCapability(DisplayCapability * info)93 int32_t FbDisplay::GetDisplayCapability(DisplayCapability *info)
94 {
95     DISPLAY_LOGD();
96     DISPLAY_CHK_RETURN((info == nullptr), DISPLAY_NULL_PTR, DISPLAY_LOGE("inof is nullptr"));
97     *info = displayCapability_;
98     return DISPLAY_SUCCESS;
99 }
100 
GetDisplaySupportedModes(uint32_t * num,DisplayModeInfo * modes)101 int32_t FbDisplay::GetDisplaySupportedModes(uint32_t *num, DisplayModeInfo *modes)
102 {
103     DISPLAY_LOGD();
104     DISPLAY_CHK_RETURN((num == NULL), DISPLAY_NULL_PTR, DISPLAY_LOGE("num and modes is nullptr"));
105     DISPLAY_CHK_RETURN((*num < 0), DISPLAY_FAILURE, DISPLAY_LOGE("the num is invalid"));
106     if (modes == NULL) {
107         *num = modes_.size();
108         return DISPLAY_SUCCESS;
109     }
110     if (*num > modes_.size()) {
111         *num = modes_.size();
112     }
113     memcpy_s(modes, sizeof(DisplayModeInfo) * (*num), modes_.data(), sizeof(DisplayModeInfo) * (*num));
114     return DISPLAY_SUCCESS;
115 }
116 
GetDisplayMode(uint32_t * modeId)117 int32_t FbDisplay::GetDisplayMode(uint32_t *modeId)
118 {
119     DISPLAY_LOGD();
120     *modeId = mActiveModeId;
121     if (mActiveModeId == static_cast<uint32_t>(INVALID_MODE_ID)) {
122         DISPLAY_LOGE("now has not active mode");
123         return DISPLAY_FAILURE;
124     }
125     return DISPLAY_SUCCESS;
126 }
127 
SetDisplayMode(uint32_t modeId)128 int32_t FbDisplay::SetDisplayMode(uint32_t modeId)
129 {
130     DISPLAY_LOGD();
131     if (modeId < modes_.size()) {
132         mActiveModeId = modeId;
133     } else {
134         DISPLAY_LOGE("the modeId is invalid");
135     }
136     return DISPLAY_SUCCESS;
137 }
138 
GetDisplayPowerStatus(DispPowerStatus * status)139 int32_t FbDisplay::GetDisplayPowerStatus(DispPowerStatus *status)
140 {
141     DISPLAY_LOGD();
142     DISPLAY_CHK_RETURN((status == nullptr), DISPLAY_NULL_PTR, DISPLAY_LOGE("the status is nullptr"));
143     *status = mPowerstatus;
144     return DISPLAY_SUCCESS;
145 }
146 
SetDisplayPowerStatus(DispPowerStatus status)147 int32_t FbDisplay::SetDisplayPowerStatus(DispPowerStatus status)
148 {
149     DISPLAY_LOGD();
150     mPowerstatus = status;
151     return DISPLAY_SUCCESS;
152 }
153 
GetDisplayBacklight(uint32_t * value)154 int32_t FbDisplay::GetDisplayBacklight(uint32_t *value)
155 {
156     DISPLAY_LOGD();
157     return DISPLAY_NOT_SUPPORT;
158 }
159 
SetDisplayBacklight(uint32_t value)160 int32_t FbDisplay::SetDisplayBacklight(uint32_t value)
161 {
162     DISPLAY_LOGD();
163     return DISPLAY_NOT_SUPPORT;
164 }
165 
RegDisplayVBlankCallback(VBlankCallback cb,void * data)166 int32_t FbDisplay::RegDisplayVBlankCallback(VBlankCallback cb, void *data)
167 {
168     DISPLAY_LOGD("the VBlankCallback %{public}p ", cb);
169     std::shared_ptr<VsyncCallBack> vsyncCb = std::make_shared<VsyncCallBack>(cb, nullptr);
170     SorftVsync::GetInstance().ReqesterVBlankCb(vsyncCb);
171     return DISPLAY_SUCCESS;
172 }
173 
IsConnected()174 bool FbDisplay::IsConnected()
175 {
176     DISPLAY_LOGD();
177     return true;
178 }
179 
SetDisplayVsyncEnabled(bool enabled)180 int32_t FbDisplay::SetDisplayVsyncEnabled(bool enabled)
181 {
182     DISPLAY_LOGD("enable %{public}d", enabled);
183     SorftVsync::GetInstance().EnableVsync(enabled);
184     return DISPLAY_SUCCESS;
185 }
186 } // namespace OHOS
187 } // namespace HDI
188 } // namespace DISPLAY
189