• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_BACKEND_HDI_LAYER_H
17 #define HDI_BACKEND_HDI_LAYER_H
18 
19 #include <array>
20 #include <stdint.h>
21 #include <surface.h>
22 #include <surface_buffer.h>
23 
24 #include "surface_type.h"
25 #include "display_type.h"
26 #include "hdi_device.h"
27 #include "hdi_layer_info.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 
32 using LayerInfoPtr = std::shared_ptr<HdiLayerInfo>;
33 
34 class HdiLayer {
35 public:
36     explicit HdiLayer(uint32_t screenId);
37     virtual ~HdiLayer();
38 
39     static constexpr int FRAME_RECORDS_NUM = 128;
40 
41     /* output create and set layer info */
42     static std::shared_ptr<HdiLayer> CreateHdiLayer(uint32_t screenId);
43 
44     bool Init(const LayerInfoPtr &layerInfo);
45     void MergeWithFramebufferFence(const sptr<SyncFence> &fbAcquireFence);
46     void MergeWithLayerFence(const sptr<SyncFence> &layerReleaseFence);
47     void UpdateCompositionType(GraphicCompositionType type);
48 
49     const LayerInfoPtr& GetLayerInfo();
50     void SetLayerStatus(bool inUsing);
51     bool GetLayerStatus() const;
52     void UpdateLayerInfo(const LayerInfoPtr &layerInfo);
53     int32_t SetHdiLayerInfo();
54     uint32_t GetLayerId() const;
55     void RecordPresentTime(int64_t timestamp);
56     void Dump(std::string &result);
57     void ClearDump();
58 
59     sptr<SyncFence> GetReleaseFence() const;
60     void SavePrevLayerInfo();
61 
62     /* only used for mock tests */
63     int32_t SetHdiDeviceMock(Base::HdiDevice* hdiDeviceMock);
64 private:
65     // layer buffer & fence
66     class LayerBufferInfo : public RefBase {
67     public:
68         LayerBufferInfo() = default;
69         virtual ~LayerBufferInfo() = default;
70 
71         sptr<SurfaceBuffer> sbuffer_ = nullptr;
72         sptr<SyncFence> acquireFence_ = SyncFence::INVALID_FENCE;
73         sptr<SyncFence> releaseFence_ = SyncFence::INVALID_FENCE;
74     };
75 
76     std::array<int64_t, FRAME_RECORDS_NUM> presentTimeRecords {};
77     uint32_t count = 0;
78     uint32_t screenId_ = INT_MAX;
79     uint32_t layerId_ = INT_MAX;
80     bool isInUsing_ = false;
81     sptr<LayerBufferInfo> currSbuffer_ = nullptr;
82     sptr<LayerBufferInfo> prevSbuffer_ = nullptr;
83     LayerInfoPtr layerInfo_ = nullptr;
84     LayerInfoPtr prevLayerInfo_ = nullptr;
85     GraphicPresentTimestampType supportedPresentTimestamptype_ = GRAPHIC_DISPLAY_PTS_UNSUPPORTED;
86     Base::HdiDevice *device_ = nullptr;
87     bool doLayerInfoCompare_ = false;
88 
89     int32_t CreateLayer(const LayerInfoPtr &layerInfo);
90     void CloseLayer();
91     int32_t SetLayerAlpha();
92     int32_t SetLayerSize();
93     int32_t SetTransformMode();
94     int32_t SetLayerVisibleRegion();
95     int32_t SetLayerDirtyRegion();
96     int32_t SetLayerBuffer();
97     int32_t SetLayerCompositionType();
98     int32_t SetLayerBlendType();
99     int32_t SetLayerCrop();
100     int32_t SetLayerZorder();
101     int32_t SetLayerPreMulti();
102     int32_t SetLayerColorTransform();
103     int32_t SetLayerColorDataSpace();
104     int32_t SetLayerMetaData();
105     int32_t SetLayerMetaDataSet();
106     sptr<SyncFence> Merge(const sptr<SyncFence> &fence1, const sptr<SyncFence> &fence2);
107     int32_t SetLayerTunnelHandle();
108     int32_t SetLayerPresentTimestamp();
109     int32_t InitDevice();
110     bool IsSameRect(const IRect& rect1, const IRect& rect2);
111     bool IsSameLayerMetaData();
112     bool IsSameLayerMetaDataSet();
113     inline void CheckRet(int32_t ret, const char* func);
114 };
115 } // namespace Rosen
116 } // namespace OHOS
117 
118 #endif // HDI_BACKEND_HDI_LAYER_H