• 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_BACKEND_H
17 #define HDI_BACKEND_HDI_BACKEND_H
18 
19 #include <functional>
20 #include <unordered_map>
21 #include <refbase.h>
22 
23 #include "hdi_device.h"
24 #include "hdi_screen.h"
25 #include "hdi_layer.h"
26 #include "hdi_output.h"
27 #include "surface_type.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 
32 using OutputPtr = std::shared_ptr<HdiOutput>;
33 
34 struct PrepareCompleteParam {
35     bool needFlushFramebuffer;
36     std::vector<LayerInfoPtr> layers;
37     uint32_t screenId;
38 };
39 
40 using OnScreenHotplugFunc = std::function<void(OutputPtr &output, bool connected, void* data)>;
41 using OnPrepareCompleteFunc = std::function<void(sptr<Surface>& surface,
42                                                  const struct PrepareCompleteParam &param, void* data)>;
43 
44 class HdiBackend {
45 public:
46     /* for RS begin */
47     static HdiBackend* GetInstance();
48     RosenError RegScreenHotplug(OnScreenHotplugFunc func, void* data);
49     RosenError RegPrepareComplete(OnPrepareCompleteFunc func, void* data);
50     RosenError RegHwcDeadListener(OnHwcDeadCallback func, void* data);
51     void Repaint(const OutputPtr &output);
52     void ResetDevice();
53     /* for RS end */
54 
55     /* only used for mock tests */
56     RosenError SetHdiBackendDevice(HdiDevice* device);
57     void StartSample(const OutputPtr &output);
58     /* set a temporary period used only for VSyncSampler::GetHardwarePeriod interface */
59     void SetPendingMode(const OutputPtr &output, int64_t period, int64_t timestamp);
60 private:
61     HdiBackend() = default;
62     virtual ~HdiBackend() = default;
63 
64     HdiBackend(const HdiBackend& rhs) = delete;
65     HdiBackend& operator=(const HdiBackend& rhs) = delete;
66     HdiBackend(HdiBackend&& rhs) = delete;
67     HdiBackend& operator=(HdiBackend&& rhs) = delete;
68 
69     HdiDevice *device_ = nullptr;
70     void* onHotPlugCbData_ = nullptr;
71     void* onPrepareCompleteCbData_ = nullptr;
72     OnScreenHotplugFunc onScreenHotplugCb_ = nullptr;
73     OnPrepareCompleteFunc onPrepareCompleteCb_ = nullptr;
74     std::unordered_map<uint32_t, OutputPtr> outputs_;
75 
76     static void OnHdiBackendHotPlugEvent(uint32_t deviceId, bool connected, void *data);
77     RosenError InitDevice();
78     void OnHdiBackendConnected(uint32_t screenId, bool connected);
79     void CreateHdiOutput(uint32_t screenId);
80     void OnScreenHotplug(uint32_t screenId, bool connected);
81     void ReorderLayerInfo(std::vector<LayerInfoPtr> &newLayerInfos);
82     void OnPrepareComplete(bool needFlush, const OutputPtr &output, std::vector<LayerInfoPtr> &newLayerInfos);
83     int32_t PrepareCompleteIfNeed(const OutputPtr &output, bool needFlush);
84 };
85 } // namespace Rosen
86 } // namespace OHOS
87 
88 #endif // HDI_BACKEND_HDI_BACKEND_H