• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "hdi_test_device.h"
17 #include <mutex>
18 #include "v1_0/include/idisplay_buffer.h"
19 #include "v1_1/display_composer_type.h"
20 #include "hdi_test_device_common.h"
21 
22 namespace OHOS {
23 namespace HDI {
24 namespace Display {
25 namespace TEST {
26 using namespace OHOS::HDI::Display::Buffer::V1_0;
GetInstance()27 HdiTestDevice& HdiTestDevice::GetInstance()
28 {
29     static HdiTestDevice device;
30     return device;
31 }
32 
HotPlug(uint32_t outputId,bool connected,void * data)33 void HdiTestDevice::HotPlug(uint32_t outputId, bool connected, void* data)
34 {
35     DISPLAY_TEST_LOGE("outputId %{public}u connected %{public}d", outputId, connected);
36     DISPLAY_TEST_CHK_RETURN_NOT_VALUE((data == nullptr), DISPLAY_TEST_LOGE("the data is null ptr"));
37     HdiTestDevice* device = static_cast<HdiTestDevice *>(data);
38     if (connected) {
39         device->FindDisplayOrCreate(outputId);
40     }
41     DISPLAY_TEST_LOGE("end");
42 }
43 
InitDevice()44 int32_t HdiTestDevice::InitDevice()
45 {
46     displayDevice_ = Composer::V1_1::IDisplayComposerInterface::Get();
47     DISPLAY_TEST_CHK_RETURN((displayDevice_ == nullptr), DISPLAY_FAILURE,
48         DISPLAY_TEST_LOGE("get IDisplayComposerInterface failed"));
49 
50     gralloc_.reset(IDisplayBuffer::Get());
51     DISPLAY_TEST_CHK_RETURN((gralloc_ == nullptr), DISPLAY_FAILURE, DISPLAY_TEST_LOGE("get IDisplayBuffer failed"));
52 
53     displayDevice_->RegHotPlugCallback(HotPlug, static_cast<void *>(this));
54 
55     return DISPLAY_SUCCESS;
56 }
57 
GetDisplayFromId(uint32_t id)58 std::shared_ptr<HdiTestDisplay> HdiTestDevice::GetDisplayFromId(uint32_t id)
59 {
60     auto iter = displays_.find(id);
61     DISPLAY_TEST_CHK_RETURN((iter == displays_.end()), nullptr, DISPLAY_TEST_LOGE("can not find the display %{public}u",
62         id));
63     return displays_[id];
64 }
65 
FindDisplayOrCreate(uint32_t id)66 std::shared_ptr<HdiTestDisplay> HdiTestDevice::FindDisplayOrCreate(uint32_t id)
67 {
68     int ret;
69     std::shared_ptr<HdiTestDisplay> display = GetDisplayFromId(id);
70     if (display == nullptr) {
71         DISPLAY_TEST_LOGE("the display not find will creat a display");
72     }
73     display = std::make_shared<HdiTestDisplay>(id, displayDevice_);
74     ret = display->Init();
75     DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), nullptr, DISPLAY_TEST_LOGE("can not init the display"));
76     displays_.emplace(id, display);
77     displayIds_.push_back(id);
78     return display;
79 }
80 
GetFirstDisplay()81 std::shared_ptr<HdiTestDisplay> HdiTestDevice::GetFirstDisplay()
82 {
83     DISPLAY_TEST_CHK_RETURN((displays_.begin() == displays_.end()), nullptr,
84         DISPLAY_TEST_LOGE("the displays_ is empty"));
85     return displays_.begin()->second;
86 }
87 
Clear() const88 void HdiTestDevice::Clear() const
89 {
90     for (auto const & iter : displays_) {
91         iter.second->Clear();
92     }
93 }
94 
GetDevIds() const95 std::vector<uint32_t> HdiTestDevice::GetDevIds() const
96 {
97     return displayIds_;
98 }
99 } // OHOS
100 } // HDI
101 } // Display
102 } // TEST
103