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 DRM_DISPLAY_H
17 #define DRM_DISPLAY_H
18 #include <unordered_map>
19 #include <memory>
20 #include "drm_connector.h"
21 #include "drm_crtc.h"
22 #include "drm_device.h"
23 #include "drm_plane.h"
24 #include "hdi_composer.h"
25 #include "hdi_drm_composition.h"
26 
27 namespace OHOS {
28     namespace HDI {
29         namespace DISPLAY {
30             class DrmDisplay : public HdiDisplay {
31             public:
32                 DrmDisplay(std::shared_ptr<DrmConnector> connector, std::shared_ptr<DrmCrtc> crtc,
33                            std::shared_ptr<DrmDevice> drmDevice);
34 
35                 ~DrmDisplay() override;
36 
37                 int32_t Init() override;
38                 int32_t GetDisplayCapability(DisplayCapability *info) override;
39                 int32_t GetDisplaySupportedModes(uint32_t *num, DisplayModeInfo *modes) override;
40                 int32_t GetDisplayMode(uint32_t *modeId) override;
41                 int32_t SetDisplayMode(uint32_t modeId) override;
42                 int32_t GetDisplayPowerStatus(DispPowerStatus *status) override;
43                 int32_t SetDisplayPowerStatus(DispPowerStatus status) override;
44                 int32_t GetDisplayBacklight(uint32_t *value) override;
45                 int32_t SetDisplayBacklight(uint32_t value) override;
46                 int32_t ChosePreferenceMode();
47                 int32_t RegDisplayVBlankCallback(VBlankCallback cb, void *data) override;
48                 int32_t WaitForVBlank(uint64_t *ns) override;
49                 bool IsConnected() override;
50                 int32_t SetDisplayVsyncEnabled(bool enabled) override;
51                 HdiDrmComposition *GetDrmComposition();
52 
53             protected:
54                 std::unique_ptr<HdiLayer> CreateHdiLayer(LayerType type) override;
55 
56             private:
57                 int32_t PushFirstFrame();
58                 int32_t ConvertToHdiPowerState(uint32_t drmPowerState, DispPowerStatus &hdiPowerState);
59                 int32_t ConvertToDrmPowerState(DispPowerStatus hdiPowerState, uint32_t &drmPowerState);
60                 std::shared_ptr<DrmDevice> mDrmDevice;
61                 std::shared_ptr<DrmConnector> mConnector;
62                 std::shared_ptr<DrmCrtc> mCrtc;
63             };
64         } // namespace OHOS
65     }     // namespace HDI
66 } // namespace DISPLAY
67 
68 #endif // HDI_DISPLAY_H
69