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 HDI_TEST_LAYER_H
17#define HDI_TEST_LAYER_H
18#include <queue>
19#include "v1_1/display_composer_type.h"
20#include "v1_0/include/idisplay_buffer.h"
21
22namespace OHOS {
23namespace HDI {
24namespace Display {
25namespace TEST {
26using namespace OHOS::HDI::Display::Composer::V1_1;
27
28class HdiGrallocBuffer {
29public:
30    HdiGrallocBuffer(uint32_t seqNo, uint32_t w, uint32_t h, Composer::V1_0::PixelFormat fmt);
31    ~HdiGrallocBuffer();
32    BufferHandle* Get() const
33    {
34        return buffer_;
35    }
36    void SetReleaseFence(int fd);
37    void SetAcquirceFence(int fd);
38    int GetAcquireFence() const
39    {
40        return mAcquireFence;
41    }
42    int GetReleaseFence() const
43    {
44        return mReleaseFence;
45    }
46    int32_t SetGraphicBuffer(std::function<int32_t (const BufferHandle*, uint32_t)> realFunc);
47
48private:
49    BufferHandle* buffer_ = nullptr;
50    int mAcquireFence = -1;
51    int mReleaseFence = -1;
52    uint32_t seqNo_ = UINT32_MAX;
53    bool cacheValid_ = false;
54};
55
56class HdiTestLayer {
57public:
58    static const uint32_t MAX_BUFFER_COUNT = 3;
59    HdiTestLayer(LayerInfo& info, uint32_t id, uint32_t displayId);
60    virtual ~HdiTestLayer();
61    int32_t Init(uint32_t bufferCount = MAX_BUFFER_COUNT);
62    int32_t PreparePresent();
63
64    uint32_t GetId() const
65    {
66        return id_;
67    }
68    Composer::V1_0::CompositionType GetCompType() const
69    {
70        return compType_;
71    }
72
73    HdiGrallocBuffer* GetFrontBuffer() const;
74    HdiGrallocBuffer* GetBackBuffer() const;
75    HdiGrallocBuffer* AcquireBackBuffer();
76
77    int32_t SwapFrontToBackQ();
78    int32_t SwapBackToFrontQ();
79
80    void SetLayerPosition(const IRect& rect);
81    void SetLayerCrop(const IRect& rect);
82    void SetZorder(uint32_t zorder);
83    void SetCompType(Composer::V1_0::CompositionType type);
84    void SetReleaseFence(int fd);
85    void SetAlpha(LayerAlpha alpha);
86    void SetBlendType(BlendType type);
87    void SetTransform(TransformType transform);
88    uint32_t GetLayerBuffercount() const;
89
90private:
91    uint32_t id_;
92    uint32_t displayID_;
93    uint32_t layerBufferCount_;
94    std::queue<std::unique_ptr<HdiGrallocBuffer>> frontBuffers_;
95    std::queue<std::unique_ptr<HdiGrallocBuffer>> backBuffers_;
96    LayerInfo layerInfo_ = { 0 };
97
98#ifdef DISPLAY_COMMUNITY
99    Composer::V1_0::CompositionType compType_ = Composer::V1_0::CompositionType::COMPOSITION_CLIENT;
100#else
101    Composer::V1_0::CompositionType compType_ = Composer::V1_0::CompositionType::COMPOSITION_DEVICE;
102#endif // DISPLAY_COMMUNITY
103    IRect displayRect_ = { 0 };
104    IRect cropRect_ = { 0 };
105    uint32_t zorder_ = 0;
106    LayerAlpha alpha_ = { 0 };
107    BlendType blendType_ = BLEND_SRC;
108    std::unique_ptr<HdiGrallocBuffer> currentBuffer_;
109    TransformType transform_ = ROTATE_NONE;
110};
111} // OHOS
112} // HDI
113} // Display
114} // TEST
115
116#endif // HDI_TEST_LAYER_H
117