1 /*
2 * Copyright (c) 2022 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 "fb_composition.h"
17 #include <vector>
18 #include <memory>
19 #include <cerrno>
20 #include "hitrace_meter.h"
21 #include "display_adapter.h"
22 namespace OHOS {
23 namespace HDI {
24 namespace DISPLAY {
FbFresh(int fd,HdiLayer & clientlayer,int & fence)25 int32_t FbComposition::FbFresh(int fd, HdiLayer &clientlayer, int &fence)
26 {
27 DISPLAY_LOGD();
28 DisplayFrameInfo fbFrameInfo;
29 fbFrameInfo.rect.x = 0;
30 fbFrameInfo.rect.y = 0;
31 fbFrameInfo.rect.w = clientlayer.GetCurrentBuffer()->GetWidth();
32 fbFrameInfo.rect.h = clientlayer.GetCurrentBuffer()->GetHeight();
33 fbFrameInfo.inFence = clientlayer.GetAcquireFenceFd();
34 fbFrameInfo.stride = clientlayer.GetCurrentBuffer()->GetStride();
35 fbFrameInfo.bufaddr = clientlayer.GetCurrentBuffer()->GetMemHandle();
36 fbFrameInfo.format = PIXEL_FMT_RGBA_8888;
37 HitraceScoped trace(HITRACE_TAG_GRAPHIC_AGP, "fbfresh");
38 if (DisplayAdapter::GetInstance()->FbFresh(fd, fbFrameInfo) != 0) {
39 DISPLAY_LOGE(" HIFB_REFRESH_FRAMEINFO Error! %{public}d", errno);
40 }
41 fence = fbFrameInfo.outFence;
42 return DISPLAY_SUCCESS;
43 }
44
FbComposition(const std::vector<int> & fbs)45 FbComposition::FbComposition(const std::vector<int> &fbs)
46 {
47 DISPLAY_LOGD();
48 fds_ = fbs;
49 }
50
~FbComposition()51 FbComposition::~FbComposition()
52 {
53 DISPLAY_LOGD();
54 }
55
Init()56 int32_t FbComposition::Init()
57 {
58 DISPLAY_LOGD();
59 return HdiComposition::Init();
60 }
61
SetLayers(std::vector<HdiLayer * > & layers,HdiLayer & clientLayer)62 int32_t FbComposition::SetLayers(std::vector<HdiLayer*> &layers, HdiLayer &clientLayer)
63 {
64 DISPLAY_LOGD();
65 mCompLayers.clear();
66 mCompLayers.push_back(&clientLayer);
67 return DISPLAY_SUCCESS;
68 }
69
Apply(bool modeSet)70 int32_t FbComposition::Apply(bool modeSet)
71 {
72 (void)modeSet;
73 DISPLAY_LOGD("mCompLayers size %{public}zu", mCompLayers.size());
74 for (uint32_t i = 0; i < mCompLayers.size(); i++) {
75 int fence = -1;
76 HdiLayer *layer = mCompLayers[i];
77 HitraceScoped trace(HITRACE_TAG_GRAPHIC_AGP, "fb apply");
78 int ret = FbFresh(fds_[i], *layer, fence);
79 layer->SetReleaseFence(fence);
80 DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("fb fresh failed"));
81 }
82 return DISPLAY_SUCCESS;
83 }
84 } // OHOS
85 } // HDI
86 } // DISPLAY
87