• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef OHOS_HDI_DISPLAY_V1_2_DISPLAY_COMPOSER_HDI_IMPL_H
17 #define OHOS_HDI_DISPLAY_V1_2_DISPLAY_COMPOSER_HDI_IMPL_H
18 
19 #include "v1_1/hdi_impl/display_composer_hdi_impl.h"
20 #include "v1_2/display_command/display_cmd_requester.h"
21 #include "v1_2/display_composer_type.h"
22 #include "v1_2/idisplay_composer.h"
23 #include "v1_2/include/idisplay_composer_interface.h"
24 #include <cinttypes>
25 
26 #undef LOG_TAG
27 #define LOG_TAG "DISP_HDI_COMP"
28 #undef LOG_DOMAIN
29 #define LOG_DOMAIN 0xD002515
30 
31 namespace OHOS {
32 namespace HDI {
33 namespace Display {
34 namespace Composer {
35 namespace V1_2 {
36 
37 template <typename Interface, typename CompHdi, typename CmdReq>
38 class DisplayComposerHdiImpl : public V1_1::DisplayComposerHdiImpl<Interface, CompHdi, CmdReq>,
39     public IVBlankIdleCallback {
40 public:
Create(bool needSMQ)41     static IDisplayComposerInterface* Create(bool needSMQ)
42     {
43         sptr<CompHdi> hdi;
44         std::shared_ptr<CmdReq> req = nullptr;
45         HDF_LOGI("%{public}s: hdi v1_2 start", __func__);
46         while ((hdi = CompHdi::Get()) == nullptr) {
47             // Waiting for display composer service ready
48             usleep(WAIT_TIME_INTERVAL);
49         }
50         HDF_LOGI("%{public}s: hdi v1_2 end", __func__);
51         if (needSMQ) {
52             req = CmdReq::Create(hdi);
53             if (req == nullptr) {
54                 HDF_LOGE("%{public}s: Create DisplayCmdRequester failed %{public}d", __func__, __LINE__);
55                 return nullptr;
56             }
57         }
58         return new DisplayComposerHdiImpl(hdi, req);
59     }
60 
DisplayComposerHdiImpl(sptr<CompHdi> hdi,std::shared_ptr<CmdReq> req)61     DisplayComposerHdiImpl(sptr<CompHdi> hdi, std::shared_ptr<CmdReq> req)
62         : BaseType1_1(hdi, req),
63         req_v1_2_(req),
64         hdi_v1_2_(hdi),
65         isSupportSkipValidate_(0),
66         VBlankIdleCb_(nullptr),
67         VBlankIdleCbData_(nullptr) {}
68 
~DisplayComposerHdiImpl()69     virtual ~DisplayComposerHdiImpl() {}
70 
CommitAndGetReleaseFence(uint32_t devId,int32_t & fence,int32_t & skipState,bool & needFlush,std::vector<uint32_t> & layers,std::vector<int32_t> & fences,bool isValidated)71     virtual int32_t CommitAndGetReleaseFence(uint32_t devId, int32_t& fence, int32_t& skipState, bool& needFlush,
72         std::vector<uint32_t>& layers, std::vector<int32_t>& fences, bool isValidated) override
73     {
74         COMPOSER_CHECK_NULLPTR_RETURN(req_v1_2_);
75         bool isSupportSkipValidate = (isSupportSkipValidate_ == 1) ? 1 : 0;
76         return ToDispErrCode(req_v1_2_->CommitAndGetReleaseFence(devId, fence,
77             isSupportSkipValidate, skipState, needFlush, layers, fences, isValidated));
78     }
79 
GetDisplayProperty(uint32_t devId,uint32_t id,uint64_t & value)80     virtual int32_t GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value) override
81     {
82         COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_);
83         value = 0;
84         int32_t ret = ToDispErrCode(hdi_v1_2_->GetDisplayProperty(devId, id, value));
85         if (ret == DISPLAY_SUCCESS && id == V1_2::DisplayPropertyID::DISPLAY_PROPERTY_ID_SKIP_VALIDATE) {
86             isSupportSkipValidate_ = value;
87         }
88 
89         return ret;
90     }
91 
RegDisplayVBlankIdleCallback(VBlankIdleCallback cb,void * data)92     virtual int32_t RegDisplayVBlankIdleCallback(VBlankIdleCallback cb, void *data) override
93     {
94         VBlankIdleCb_ = cb;
95         VBlankIdleCbData_ = data;
96         COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_);
97         return ToDispErrCode(hdi_v1_2_->RegDisplayVBlankIdleCallback(this));
98     }
99 
SetDisplayConstraint(uint32_t devId,uint64_t frameID,uint64_t ns,uint32_t type)100     virtual int32_t SetDisplayConstraint(uint32_t devId, uint64_t frameID, uint64_t ns, uint32_t type) override
101     {
102         COMPOSER_CHECK_NULLPTR_RETURN(req_v1_2_);
103         return ToDispErrCode(req_v1_2_->SetDisplayConstraint(devId, frameID, ns, type));
104     }
105 
OnVBlankIdleCallback(uint32_t devId,uint64_t ns)106     virtual int32_t OnVBlankIdleCallback(uint32_t devId, uint64_t ns) override
107     {
108         int32_t ret = HDF_SUCCESS;
109         if (VBlankIdleCb_ != nullptr) {
110             VBlankIdleCb_(devId, ns, VBlankIdleCbData_);
111         } else {
112             HDF_LOGE("error: VBlankIdle is nullptr");
113             ret = HDF_FAILURE;
114         }
115         return ret;
116     }
ClearClientBuffer(uint32_t devId)117     virtual int32_t ClearClientBuffer(uint32_t devId) override
118     {
119         COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_);
120         return ToDispErrCode(hdi_v1_2_->ClearClientBuffer(devId));
121     }
122 
ClearLayerBuffer(uint32_t devId,uint32_t layerId)123     virtual int32_t ClearLayerBuffer(uint32_t devId, uint32_t layerId) override
124     {
125         COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_);
126         return ToDispErrCode(hdi_v1_2_->ClearLayerBuffer(devId, layerId));
127     }
128 
UpdateHardwareCursor(uint32_t devId,int32_t x,int32_t y,BufferHandle * buffer)129     virtual int32_t UpdateHardwareCursor(uint32_t devId, int32_t x, int32_t y, BufferHandle* buffer) override
130     {
131         COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_);
132         COMPOSER_CHECK_NULLPTR_RETURN(buffer);
133         sptr<NativeBuffer> hdiBuffer = new NativeBuffer(buffer);
134         COMPOSER_CHECK_NULLPTR_RETURN(hdiBuffer);
135 
136         int32_t ret = ToDispErrCode(hdi_v1_2_->UpdateHardwareCursor(devId, x, y, hdiBuffer));
137         return ret;
138     }
139 
EnableHardwareCursorStats(uint32_t devId,bool enable)140     virtual int32_t EnableHardwareCursorStats(uint32_t devId, bool enable) override
141     {
142         COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_);
143         int32_t ret = ToDispErrCode(hdi_v1_2_->EnableHardwareCursorStats(devId, enable));
144         return ret;
145     }
146 
GetHardwareCursorStats(uint32_t devId,uint32_t & frameCount,uint32_t & vsyncCount)147     virtual int32_t GetHardwareCursorStats(uint32_t devId, uint32_t& frameCount, uint32_t& vsyncCount) override
148     {
149         COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_);
150         int32_t ret = ToDispErrCode(hdi_v1_2_->GetHardwareCursorStats(devId, frameCount, vsyncCount));
151         return ret;
152     }
153 
SetDisplayActiveRegion(uint32_t devId,const IRect & rect)154     virtual int32_t SetDisplayActiveRegion(uint32_t devId, const IRect& rect) override
155     {
156         COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_);
157         int32_t ret = ToDispErrCode(hdi_v1_2_->SetDisplayActiveRegion(devId, rect));
158         return ret;
159     }
160 
FastPresent(uint32_t devId,const PresentParam & param,const std::vector<BufferHandle * > inHandles)161     virtual int32_t FastPresent(uint32_t devId, const PresentParam& param,
162         const std::vector<BufferHandle*> inHandles) override
163     {
164         COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_);
165         std::vector<sptr<NativeBuffer>> outHandles;
166         for (auto inHandle : inHandles) {
167             sptr<NativeBuffer> nativeBuffer = new NativeBuffer(inHandle);
168             if (nativeBuffer == nullptr) {
169                 HDF_LOGE("failed to alloc mem for NativeBuffer");
170                 return DISPLAY_FAILURE;
171             }
172             outHandles.emplace_back(nativeBuffer);
173         }
174         return ToDispErrCode(hdi_v1_2_->FastPresent(devId, param, outHandles));
175     }
176 
SetLayerPerFrameParameterSmq(uint32_t devId,uint32_t layerId,const std::string & key,const std::vector<int8_t> & value)177     virtual int32_t SetLayerPerFrameParameterSmq(uint32_t devId, uint32_t layerId, const std::string& key,
178         const std::vector<int8_t>& value) override
179     {
180         return ToDispErrCode(req_v1_2_->SetLayerPerFrameParameterSmq(devId, layerId, key, value));
181     }
182 
SetDisplayPerFrameParameterSmq(uint32_t devId,const std::string & key,const std::vector<int8_t> & value)183     virtual int32_t SetDisplayPerFrameParameterSmq(uint32_t devId, const std::string& key,
184         const std::vector<int8_t>& value) override
185     {
186         return ToDispErrCode(req_v1_2_->SetDisplayPerFrameParameterSmq(devId, key, value));
187     }
188 
GetDisplayIdentificationData(uint32_t devId,uint8_t & portId,std::vector<uint8_t> & edidData)189     virtual int32_t GetDisplayIdentificationData(uint32_t devId, uint8_t& portId,
190         std::vector<uint8_t>& edidData) override
191     {
192         COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_2_);
193         return ToDispErrCode(hdi_v1_2_->GetDisplayIdentificationData(devId, portId, edidData));
194     }
195 
196 protected:
197     using BaseType1_1 = V1_1::DisplayComposerHdiImpl<Interface, CompHdi, CmdReq>;
198     using BaseType1_1::WAIT_TIME_INTERVAL;
199     using BaseType1_1::ToDispErrCode;
200     std::shared_ptr<CmdReq> req_v1_2_;
201     sptr<CompHdi> hdi_v1_2_;
202     uint64_t isSupportSkipValidate_;
203 private:
204     VBlankIdleCallback VBlankIdleCb_;
205     void *VBlankIdleCbData_;
206 };
207 using HdiDisplayComposer = DisplayComposerHdiImpl<IDisplayComposerInterface, IDisplayComposer, HdiDisplayCmdRequester>;
208 } // namespace V1_2
209 } // namespace Composer
210 } // namespace Display
211 } // namespace HDI
212 } // namespace OHOS
213 #endif // OHOS_HDI_DISPLAY_V1_2_DISPLAY_COMPOSER_HDI_IMPL_H
214