• 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 "hdi_device.h"
23 #include "hdi_layer_info.h"
24 
25 
26 namespace OHOS {
27 namespace Rosen {
28 
29 using LayerInfoPtr = std::shared_ptr<HdiLayerInfo>;
30 
31 class HdiLayer {
32 public:
33     explicit HdiLayer(uint32_t screenId);
34     virtual ~HdiLayer();
35 
36     static constexpr int FRAME_RECORDS_NUM = 256;
37 
38     /* output create and set layer info */
39     static std::shared_ptr<HdiLayer> CreateHdiLayer(uint32_t screenId);
40 
41     bool Init(const LayerInfoPtr &layerInfo);
42     void MergeWithFramebufferFence(const sptr<SyncFence> &fbAcquireFence);
43     void MergeWithLayerFence(const sptr<SyncFence> &layerReleaseFence);
44     void UpdateCompositionType(GraphicCompositionType type);
45 
46     const LayerInfoPtr& GetLayerInfo();
47     void SetLayerStatus(bool inUsing);
48     bool GetLayerStatus() const;
49     void UpdateLayerInfo(const LayerInfoPtr &layerInfo);
50     int32_t SetHdiLayerInfo();
51     uint32_t GetLayerId() const;
52     void RecordPresentTime(int64_t timestamp);
53     void Dump(std::string &result);
54     void ClearDump();
55 
56     sptr<SyncFence> GetReleaseFence() const;
57     void SavePrevLayerInfo();
58 
59     /* only used for mock tests */
60     int32_t SetHdiDeviceMock(HdiDevice* hdiDeviceMock);
61 private:
62     // layer buffer & fence
63     class LayerBufferInfo : public RefBase {
64     public:
65         LayerBufferInfo() = default;
66         virtual ~LayerBufferInfo() = default;
67 
68         sptr<SurfaceBuffer> sbuffer_ = nullptr;
69         sptr<SyncFence> acquireFence_ = SyncFence::INVALID_FENCE;
70         sptr<SyncFence> releaseFence_ = SyncFence::INVALID_FENCE;
71     };
72 
73     std::array<int64_t, FRAME_RECORDS_NUM> presentTimeRecords {};
74     uint32_t count = 0;
75     uint32_t screenId_ = INT_MAX;
76     uint32_t layerId_ = INT_MAX;
77     bool isInUsing_ = false;
78     sptr<LayerBufferInfo> currSbuffer_ = nullptr;
79     sptr<LayerBufferInfo> prevSbuffer_ = nullptr;
80     LayerInfoPtr layerInfo_ = nullptr;
81     LayerInfoPtr prevLayerInfo_ = nullptr;
82     GraphicPresentTimestampType supportedPresentTimestamptype_ = GRAPHIC_DISPLAY_PTS_UNSUPPORTED;
83     HdiDevice *device_ = nullptr;
84     bool doLayerInfoCompare_ = false;
85 
86     std::vector<sptr<SurfaceBuffer> > bufferCache_;
87     uint32_t bufferCacheCountMax_ = 0;
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 SetLayerColor();
103     int32_t SetLayerColorTransform();
104     int32_t SetLayerColorDataSpace();
105     int32_t SetLayerMetaData();
106     int32_t SetLayerMetaDataSet();
107     sptr<SyncFence> Merge(const sptr<SyncFence> &fence1, const sptr<SyncFence> &fence2);
108     int32_t SetLayerTunnelHandle();
109     int32_t SetLayerPresentTimestamp();
110     int32_t InitDevice();
111     bool IsSameLayerMetaData();
112     bool IsSameLayerMetaDataSet();
113     inline void CheckRet(int32_t ret, const char* func);
114     int32_t SetLayerMaskInfo();
115     bool CheckAndUpdateLayerBufferCahce(sptr<SurfaceBuffer> buffer, uint32_t& index,
116                                         std::vector<uint32_t>& deletingList);
117 };
118 } // namespace Rosen
119 } // namespace OHOS
120 
121 #endif // HDI_BACKEND_HDI_LAYER_H