• 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_OUTPUT_H
17 #define HDI_BACKEND_HDI_OUTPUT_H
18 
19 #include <array>
20 #include <stdint.h>
21 #include <vector>
22 #include <unordered_map>
23 
24 #include "surface_type.h"
25 #include "hdi_layer.h"
26 #include "hdi_framebuffer_surface.h"
27 #include "hdi_screen.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 
32 using LayerPtr = std::shared_ptr<HdiLayer>;
33 static constexpr uint32_t LAYER_COMPOSITION_CAPACITY_INVALID = 0;
34 
35 // dump layer
36 struct LayerDumpInfo {
37     uint64_t surfaceId;
38     LayerPtr layer;
39 };
40 
41 class HdiOutput {
42 public:
43     HdiOutput(uint32_t screenId);
44     virtual ~HdiOutput();
45 
46     static constexpr uint32_t COMPOSITION_RECORDS_NUM = 128;
47 
48     /* for RS begin */
49     void SetLayerInfo(const std::vector<LayerInfoPtr> &layerInfos);
50     void SetOutputDamage(uint32_t num, const IRect &outputDamage);
51     uint32_t GetScreenId() const;
52     void SetLayerCompCapacity(uint32_t layerCompositionCapacity);
53     uint32_t GetLayerCompCapacity() const;
54     /* for RS end */
55 
56     static std::shared_ptr<HdiOutput> CreateHdiOutput(uint32_t screenId);
57     RosenError Init();
58     const std::unordered_map<uint32_t, LayerPtr>& GetLayers();
59     IRect& GetOutputDamage();
60     uint32_t GetOutputDamageNum() const;
61     sptr<Surface> GetFrameBufferSurface();
62     std::unique_ptr<FrameBufferEntry> GetFramebuffer();
63     int32_t ReleaseFramebuffer(
64         sptr<SurfaceBuffer> &buffer, const sptr<SyncFence>& releaseFence);
65 
66     void Dump(std::string &result) const;
67     void DumpFps(std::string &result, const std::string &arg) const;
68     void ClearFpsDump(std::string &result, const std::string &arg);
69     void RecordCompositionTime(int64_t timeStamp);
70     void SetDirectClientCompEnableStatus(bool enableStatus);
71     bool GetDirectClientCompEnableStatus() const;
72     void UpdatePrevLayerInfo();
73 
74 private:
75     std::array<int64_t, COMPOSITION_RECORDS_NUM> compositionTimeRecords_ = {};
76     uint32_t compTimeRcdIndex_ = 0;
77     sptr<HdiFramebufferSurface> fbSurface_ = nullptr;
78     // layerId -- layer ptr
79     std::unordered_map<uint32_t, LayerPtr> layerIdMap_;
80     // surface unique id -- layer ptr
81     std::unordered_map<uint64_t, LayerPtr> surfaceIdMap_;
82     uint32_t screenId_;
83     uint32_t layerCompCapacity_ = LAYER_COMPOSITION_CAPACITY_INVALID;
84     IRect outputDamage_;
85     uint32_t outputDamageNum_;
86     bool directClientCompositionEnabled_ = true;
87 
88     int32_t CreateLayer(uint64_t surfaceId, const LayerInfoPtr &layerInfo);
89     void DeletePrevLayers();
90     void ResetLayerStatus();
91     void ReorderLayerInfo(std::vector<LayerDumpInfo> &dumpLayerInfos) const;
92 
93     inline bool CheckFbSurface();
94 };
95 } // namespace Rosen
96 } // namespace OHOS
97 
98 #endif // HDI_BACKEND_HDI_OUTPUT_H