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_SCREEN_H
17 #define HDI_BACKEND_HDI_SCREEN_H
18 
19 #include <functional>
20 #include <vector>
21 #include <refbase.h>
22 #include <mutex>
23 
24 #include "hdi_layer.h"
25 #include "hdi_device.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 
30 using OnVsyncFunc = std::function<void()>;
31 
32 class HdiScreen {
33 public:
34     HdiScreen(uint32_t screenId);
35     virtual ~HdiScreen();
36 
37     static std::unique_ptr<HdiScreen> CreateHdiScreen(uint32_t screenId);
38     bool Init();
39 
40     int32_t GetScreenCapability(GraphicDisplayCapability &info) const;
41     int32_t GetScreenSupportedModes(std::vector<GraphicDisplayModeInfo> &modes) const;
42     int32_t GetScreenMode(uint32_t &modeId);
43     int32_t SetScreenMode(uint32_t modeId);
44     int32_t SetScreenOverlayResolution(uint32_t width, uint32_t height) const;
45     int32_t GetScreenPowerStatus(GraphicDispPowerStatus &status) const;
46     int32_t SetScreenPowerStatus(GraphicDispPowerStatus status) const;
47     int32_t GetScreenBacklight(uint32_t &level) const;
48     int32_t SetScreenBacklight(uint32_t level) const;
49     int32_t SetScreenVsyncEnabled(bool enabled) const;
50 
51     int32_t GetScreenSupportedColorGamuts(std::vector<GraphicColorGamut> &gamuts) const;
52     int32_t SetScreenColorGamut(GraphicColorGamut gamut) const;
53     int32_t GetScreenColorGamut(GraphicColorGamut &gamut) const;
54     int32_t SetScreenGamutMap(GraphicGamutMap gamutMap) const;
55     int32_t GetScreenGamutMap(GraphicGamutMap &gamutMap) const;
56     int32_t SetScreenColorTransform(const std::vector<float>& matrix) const;
57     int32_t GetHDRCapabilityInfos(GraphicHDRCapability &info) const;
58     int32_t GetSupportedMetaDataKey(std::vector<GraphicHDRMetadataKey> &keys) const;
59     int32_t SetScreenConstraint(uint64_t frameId, uint64_t timestamp, uint32_t type);
60     bool GetDisplayPropertyForHardCursor(uint32_t screenId);
61 
62     static void OnVsync(uint32_t sequence, uint64_t ns, void *data);
63 
64     /* only used for mock and fuzz tests */
65     bool SetHdiDevice(HdiDevice* device);
66 
67 private:
68     uint32_t screenId_;
69     HdiDevice *device_ = nullptr;
70     uint32_t modeId_ = UINT32_MAX; // UINT32_MAX is invalid modeId
71     std::mutex mutex_;
72 
73     void Destroy();
74 };
75 
76 } // namespace Rosen
77 } // namespace OHOS
78 
79 #endif // HDI_BACKEND_HDI_SCREEN_H