• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_3_DISPLAY_COMPOSER_HDI_IMPL_H
17 #define OHOS_HDI_DISPLAY_V1_3_DISPLAY_COMPOSER_HDI_IMPL_H
18 
19 #include "v1_2/hdi_impl/display_composer_hdi_impl.h"
20 #include "v1_3/display_command/display_cmd_requester.h"
21 #include "v1_3/display_composer_type.h"
22 #include "v1_3/idisplay_composer.h"
23 #include "v1_3/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_3 {
36 
37 template <typename Interface, typename CompHdi, typename CmdReq>
38 class DisplayComposerHdiImpl : public V1_2::DisplayComposerHdiImpl<Interface, CompHdi, CmdReq>,
39     public IHwcEventCallback {
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_3 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_3 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_2(hdi, req),
63         hdi_v1_3_(hdi),
64         hwcEventCb_(nullptr),
65         hwcEventCbData_(nullptr) {}
66 
~DisplayComposerHdiImpl()67     virtual ~DisplayComposerHdiImpl() {}
68 
OnHwcEvent(uint32_t devId,uint32_t eventId,const std::vector<int32_t> & eventData)69     virtual int32_t OnHwcEvent(uint32_t devId, uint32_t eventId, const std::vector<int32_t>& eventData) override
70     {
71         DISPLAY_TRACE;
72 
73         int32_t ret = HDF_SUCCESS;
74         if (hwcEventCb_) {
75             hwcEventCb_(devId, eventId, eventData, hwcEventCbData_);
76         } else {
77             HDF_LOGE("HwcEvent callback is nullptr");
78             ret = HDF_FAILURE;
79         }
80         return ret;
81     }
82 
RegHwcEventCallback(HwcEventCallback cb,void * data)83     virtual int32_t RegHwcEventCallback(HwcEventCallback cb, void *data) override
84     {
85         hwcEventCb_ = cb;
86         hwcEventCbData_ = data;
87         COMPOSER_CHECK_NULLPTR_RETURN(hdi_v1_3_);
88         return ToDispErrCode(hdi_v1_3_->RegHwcEventCallback(this));
89     }
90 
91 protected:
92     using BaseType1_2 = V1_2::DisplayComposerHdiImpl<Interface, CompHdi, CmdReq>;
93     using BaseType1_2::WAIT_TIME_INTERVAL;
94     using BaseType1_2::ToDispErrCode;
95     sptr<CompHdi> hdi_v1_3_;
96 private:
97     HwcEventCallback hwcEventCb_;
98     void *hwcEventCbData_;
99 };
100 using HdiDisplayComposer = DisplayComposerHdiImpl<IDisplayComposerInterface, IDisplayComposer, HdiDisplayCmdRequester>;
101 } // namespace V1_3
102 } // namespace Composer
103 } // namespace Display
104 } // namespace HDI
105 } // namespace OHOS
106 #endif // OHOS_HDI_DISPLAY_V1_3_DISPLAY_COMPOSER_HDI_IMPL_H
107