• 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 #ifndef HDI_TEST_LAYER_H
17 #define HDI_TEST_LAYER_H
18 #include <queue>
19 #include "v1_0/display_composer_type.h"
20 #include "v1_0/include/idisplay_buffer.h"
21 
22 namespace OHOS {
23 namespace HDI {
24 namespace Display {
25 namespace TEST {
26 using namespace OHOS::HDI::Display::Composer::V1_0;
27 
28 class HdiGrallocBuffer {
29 public:
30     HdiGrallocBuffer(uint32_t seqNo, uint32_t w, uint32_t h, PixelFormat fmt);
31     ~HdiGrallocBuffer();
Get()32     BufferHandle* Get() const
33     {
34         return buffer_;
35     }
36     void SetReleaseFence(int fd);
37     void SetAcquirceFence(int fd);
GetAcquireFence()38     int GetAcquireFence() const
39     {
40         return mAcquireFence;
41     }
GetReleaseFence()42     int GetReleaseFence() const
43     {
44         return mReleaseFence;
45     }
46     int32_t SetGraphicBuffer(std::function<int32_t (const BufferHandle*, uint32_t)> realFunc);
47 
48 private:
49     BufferHandle* buffer_ = nullptr;
50     int mAcquireFence = -1;
51     int mReleaseFence = -1;
52     uint32_t seqNo_ = UINT32_MAX;
53     bool cacheValid_ = false;
54 };
55 
56 class HdiTestLayer {
57 public:
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 
GetId()64     uint32_t GetId() const
65     {
66         return id_;
67     }
GetCompType()68     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(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 
90 private:
GenerateSeq()91     uint32_t GenerateSeq() const
92     {
93         static uint32_t originSeq = 0;
94         return originSeq++;
95     }
96 
97     uint32_t id_;
98     uint32_t displayID_;
99     uint32_t layerBufferCount_;
100     std::queue<std::unique_ptr<HdiGrallocBuffer>> frontBuffers_;
101     std::queue<std::unique_ptr<HdiGrallocBuffer>> backBuffers_;
102     LayerInfo layerInfo_ = { 0 };
103 
104 #ifdef DISPLAY_COMMUNITY
105     CompositionType compType_ = COMPOSITION_CLIENT;
106 #else
107     CompositionType compType_ = COMPOSITION_DEVICE;
108 #endif // DISPLAY_COMMUNITY
109     IRect displayRect_ = { 0 };
110     IRect cropRect_ = { 0 };
111     uint32_t zorder_ = 0;
112     LayerAlpha alpha_ = { 0 };
113     BlendType blendType_ = BLEND_SRC;
114     std::unique_ptr<HdiGrallocBuffer> currentBuffer_;
115     TransformType transform_ = ROTATE_NONE;
116 };
117 } // OHOS
118 } // HDI
119 } // Display
120 } // TEST
121 
122 #endif // HDI_TEST_LAYER_H
123