1/*
2 * Copyright (c) 2023-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 HDI_TEST_DISPLAY_H
17#define HDI_TEST_DISPLAY_H
18#include <cinttypes>
19#include "v1_0/include/idisplay_buffer.h"
20#include "v1_2/include/idisplay_composer_interface.h"
21#include "v1_1/display_composer_type.h"
22#include "display_test.h"
23#include "hdi_test_device_common.h"
24#include "hdi_test_layer.h"
25
26namespace OHOS {
27namespace HDI {
28namespace Display {
29namespace TEST {
30using namespace OHOS::HDI::Display::Composer::V1_1;
31class HdiTestDisplay {
32public:
33    HdiTestDisplay(uint32_t id, sptr<Composer::V1_2::IDisplayComposerInterface> device);
34    virtual ~HdiTestDisplay() {}
35    int32_t Init();
36    int32_t GetModeInfoFromId(int32_t id, DisplayModeInfo& modeInfo) const;
37    std::shared_ptr<HdiTestLayer> CreateHdiTestLayer(LayerInfo& info);
38    std::shared_ptr<HdiTestLayer> CreateHdiTestLayer(uint32_t w, uint32_t h);
39    int32_t Commit();
40    int32_t PrepareDisplayLayers();
41    DisplayModeInfo GetCurrentMode() const
42    {
43        return currentMode_;
44    }
45    int32_t RegDisplayVBlankCallback(VBlankCallback cb, void* data) const;
46    int32_t SetDisplayVsyncEnabled(bool enabled) const;
47    std::shared_ptr<HdiTestLayer> GetLayerFromId(uint32_t id);
48    std::unordered_map<uint32_t, std::shared_ptr<HdiTestLayer>> &GetLayers()
49    {
50        return layerMaps_;
51    }
52    void Clear();
53    BufferHandle* SnapShot()
54    {
55        return currentFb_;
56    }
57    void ResetClientLayer()
58    {
59        clientLayer_.reset();
60    }
61
62private:
63    int32_t RefreshLayersCompType();
64    int32_t GetLayersReleaseFence();
65    uint32_t activeModeId_ = 0;
66    DisplayModeInfo currentMode_ = { 0 };
67    uint32_t id_;
68    sptr<Composer::V1_2::IDisplayComposerInterface> device_;
69
70    DisplayCapability cap_;
71    std::vector<DisplayModeInfo> modes_;
72    std::unordered_map<uint32_t, std::shared_ptr<HdiTestLayer>> layerMaps_;
73    std::unique_ptr<HdiTestLayer> clientLayer_;
74    BufferHandle* currentFb_;
75    bool needFlushFb_ = false;
76};
77} // OHOS
78} // HDI
79} // Display
80} // TEST
81#endif // HDI_TEST_DISPLAY_H
82