1 /*
2  * Copyright (c) 2023 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_1_DISPLAY_CMD_REQUESTER_H
17 #define OHOS_HDI_DISPLAY_V1_1_DISPLAY_CMD_REQUESTER_H
18 
19 #include "v1_0/display_command/display_cmd_requester.h"
20 #include "v1_1/display_command/display_cmd_utils.h"
21 #include "v1_1/display_composer_type.h"
22 #include "v1_1/idisplay_composer.h"
23 
24 namespace OHOS {
25 namespace HDI {
26 namespace Display {
27 namespace Composer {
28 namespace V1_1 {
29 using namespace OHOS::HDI::Base;
30 
31 template <typename Transfer, typename CompHdi>
32 class DisplayCmdRequester : public V1_0::DisplayCmdRequester<Transfer, CompHdi> {
33 public:
DisplayCmdRequester(sptr<CompHdi> hdi)34     DisplayCmdRequester(sptr<CompHdi> hdi) : BaseType1_0(hdi) {}
35 
Create(sptr<CompHdi> hdi)36     static std::unique_ptr<DisplayCmdRequester> Create(sptr<CompHdi> hdi)
37     {
38         DISPLAY_CHK_RETURN(hdi == nullptr, nullptr, HDF_LOGE("%{public}s: hdi is nullptr", __func__));
39         auto requester = std::make_unique<DisplayCmdRequester>(hdi);
40         DISPLAY_CHK_RETURN(requester == nullptr, nullptr,
41             HDF_LOGE("%{public}s: CmdRequester is nullptr", __func__));
42         auto ret = requester->Init(CmdUtils::INIT_ELEMENT_COUNT);
43         if (ret != HDF_SUCCESS) {
44             HDF_LOGE("DisplayCmdRequester init failed");
45             return nullptr;
46         }
47         return requester;
48     }
49 
50 private:
51     using BaseType1_0 = V1_0::DisplayCmdRequester<Transfer, CompHdi>;
52 };
53 using HdiDisplayCmdRequester = V1_1::DisplayCmdRequester<SharedMemQueue<int32_t>, V1_1::IDisplayComposer>;
54 } // namespace V1_1
55 } // namespace Composer
56 } // namespace Display
57 } // namespace HDI
58 } // namespace OHOS
59 #endif // OHOS_HDI_DISPLAY_V1_1_DISPLAY_CMD_REQUESTER_H
60