1 /*
2  * Copyright (c) 2022 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_DEVICE_H
17 #define HDI_BACKEND_HDI_DEVICE_H
18 
19 #include <vector>
20 #include <refbase.h>
21 #include <unordered_map>
22 #include <sync_fence.h>
23 #include "hdi_display_type.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class HdiDevice {
28 public:
29     static HdiDevice* GetInstance();
30     HdiDevice() = default;
31     virtual ~HdiDevice() = default;
32     /* set & get device screen info begin */
33     virtual int32_t RegHotPlugCallback(HotPlugCallback callback, void *data) = 0;
34     virtual int32_t RegRefreshCallback(RefreshCallback callback, void *data) = 0;
35     virtual int32_t RegScreenVBlankCallback(uint32_t screenId, VBlankCallback callback, void *data) = 0;
36     virtual bool RegHwcDeadCallback(OnHwcDeadCallback callback, void *data) = 0;
37     virtual int32_t RegScreenVBlankIdleCallback(OnVBlankIdleCallback callback, void *data) = 0;
38     virtual int32_t SetScreenConstraint(uint32_t screenId, uint64_t frameId, uint64_t timestamp, uint32_t type) = 0;
39     virtual int32_t GetDisplayProperty(uint32_t screenId, uint32_t propertyId, uint64_t& propertyValue) = 0;
40     virtual int32_t GetScreenCapability(uint32_t screenId, GraphicDisplayCapability &info) = 0;
41     virtual int32_t GetScreenSupportedModes(uint32_t screenId, std::vector<GraphicDisplayModeInfo> &modes) = 0;
42     virtual int32_t GetScreenMode(uint32_t screenId, uint32_t &modeId) = 0;
43     virtual int32_t SetScreenMode(uint32_t screenId, uint32_t modeId) = 0;
44     virtual int32_t SetScreenOverlayResolution(uint32_t screenId, uint32_t width, uint32_t height) = 0;
45     virtual int32_t GetScreenPowerStatus(uint32_t screenId, GraphicDispPowerStatus &status) = 0;
46     virtual int32_t SetScreenPowerStatus(uint32_t screenId, GraphicDispPowerStatus status) = 0;
47     virtual int32_t GetScreenBacklight(uint32_t screenId, uint32_t &level) = 0;
48     virtual int32_t SetScreenBacklight(uint32_t screenId, uint32_t level) = 0;
49     virtual int32_t PrepareScreenLayers(uint32_t screenId, bool &needFlushFb) = 0;
50     virtual int32_t GetScreenCompChange(uint32_t screenId, std::vector<uint32_t> &layersId,
51                                         std::vector<int32_t> &types) = 0;
52     virtual int32_t SetScreenClientBuffer(uint32_t screenId, const BufferHandle *buffer, uint32_t cacheIndex,
53                                           const sptr<SyncFence> &fence) = 0;
54     virtual int32_t SetScreenClientBufferCacheCount(uint32_t screen, uint32_t count) = 0;
55     virtual int32_t SetScreenClientDamage(uint32_t screenId, const std::vector<GraphicIRect> &damageRect) = 0;
56     virtual int32_t SetScreenVsyncEnabled(uint32_t screenId, bool enabled) = 0;
57     virtual int32_t GetScreenSupportedColorGamuts(uint32_t screenId, std::vector<GraphicColorGamut> &gamuts) = 0;
58     virtual int32_t SetScreenColorGamut(uint32_t screenId, GraphicColorGamut gamut) = 0;
59     virtual int32_t GetScreenColorGamut(uint32_t screenId, GraphicColorGamut &gamut) = 0;
60     virtual int32_t SetScreenGamutMap(uint32_t screenId, GraphicGamutMap gamutMap) = 0;
61     virtual int32_t GetScreenGamutMap(uint32_t screenId, GraphicGamutMap &gamutMap) = 0;
62     virtual int32_t SetScreenColorTransform(uint32_t screenId, const std::vector<float> &matrix) = 0;
63     virtual int32_t GetHDRCapabilityInfos(uint32_t screenId, GraphicHDRCapability &info) = 0;
64     virtual int32_t GetSupportedMetaDataKey(uint32_t screenId, std::vector<GraphicHDRMetadataKey> &keys) = 0;
65     virtual int32_t Commit(uint32_t screenId, sptr<SyncFence> &fence) = 0;
66     virtual int32_t CommitAndGetReleaseFence(uint32_t screenId, sptr<SyncFence> &fence, int32_t &skipState,
67         bool &needFlush, std::vector<uint32_t>& layers, std::vector<sptr<SyncFence>>& fences, bool isValidated) = 0;
68     /* set & get device screen info end */
69 
70     /* set & get device layer info begin */
71     virtual int32_t SetLayerAlpha(uint32_t screenId, uint32_t layerId, const GraphicLayerAlpha &alpha) = 0;
72     virtual int32_t SetLayerSize(uint32_t screenId, uint32_t layerId, const GraphicIRect &layerRect) = 0;
73     virtual int32_t SetTransformMode(uint32_t screenId, uint32_t layerId, GraphicTransformType type) = 0;
74     virtual int32_t SetLayerVisibleRegion(uint32_t screenId, uint32_t layerId,
75                                           const std::vector<GraphicIRect> &visibles) = 0;
76     virtual int32_t SetLayerDirtyRegion(uint32_t screenId, uint32_t layerId,
77                                         const std::vector<GraphicIRect> &dirtyRegions) = 0;
78     virtual int32_t SetLayerBuffer(uint32_t screenId, uint32_t layerId, const GraphicLayerBuffer &layerBuffer) = 0;
79     virtual int32_t SetLayerCompositionType(uint32_t screenId, uint32_t layerId, GraphicCompositionType type) = 0;
80     virtual int32_t SetLayerBlendType(uint32_t screenId, uint32_t layerId, GraphicBlendType type) = 0;
81     virtual int32_t SetLayerCrop(uint32_t screenId, uint32_t layerId, const GraphicIRect &crop) = 0;
82     virtual int32_t SetLayerZorder(uint32_t screenId, uint32_t layerId, uint32_t zorder) = 0;
83     virtual int32_t SetLayerPreMulti(uint32_t screenId, uint32_t layerId, bool isPreMulti) = 0;
84     virtual int32_t SetLayerColor(uint32_t screenId, uint32_t layerId, GraphicLayerColor layerColor) = 0;
85     virtual int32_t SetLayerColorTransform(uint32_t screenId, uint32_t layerId, const std::vector<float> &matrix) = 0;
86     virtual int32_t SetLayerColorDataSpace(uint32_t screenId, uint32_t layerId, GraphicColorDataSpace colorSpace) = 0;
87     virtual int32_t GetLayerColorDataSpace(uint32_t screenId, uint32_t layerId, GraphicColorDataSpace &colorSpace) = 0;
88     virtual int32_t SetLayerMetaData(uint32_t screenId, uint32_t layerId,
89                                      const std::vector<GraphicHDRMetaData> &graphicMetaData) = 0;
90     virtual int32_t SetLayerMetaDataSet(uint32_t screenId, uint32_t layerId, GraphicHDRMetadataKey gkey,
91                                         const std::vector<uint8_t> &metaData) = 0;
92     virtual std::vector<std::string>& GetSupportedLayerPerFrameParameterKey() = 0;
93     virtual int32_t SetLayerPerFrameParameter(uint32_t devId, uint32_t layerId, const std::string& key,
94                                               const std::vector<int8_t>& value) = 0;
95     virtual int32_t SetLayerTunnelHandle(uint32_t screenId, uint32_t layerId, GraphicExtDataHandle *handle) = 0;
96     virtual int32_t GetSupportedPresentTimestampType(uint32_t screenId, uint32_t layerId,
97                                                      GraphicPresentTimestampType &type) = 0;
98     virtual int32_t GetPresentTimestamp(uint32_t screenId, uint32_t layerId, GraphicPresentTimestamp &timestamp) = 0;
99     virtual int32_t SetLayerMaskInfo(uint32_t screenId, uint32_t layerId, uint32_t maskInfo) = 0;
100     /* set & get device layer info end */
101 
102     virtual int32_t CreateLayer(uint32_t screenId, const GraphicLayerInfo &layerInfo, uint32_t cacheCount,
103                                 uint32_t &layerId) = 0;
104     virtual int32_t CloseLayer(uint32_t screenId, uint32_t layerId) = 0;
105     virtual int32_t ClearLayerBuffer(uint32_t screenId, uint32_t layerId) = 0;
106     virtual int32_t ClearClientBuffer(uint32_t screenId) = 0;
107     virtual void Destroy() = 0;
108 
109 private:
110     HdiDevice(const HdiDevice& rhs) = delete;
111     HdiDevice& operator=(const HdiDevice& rhs) = delete;
112     HdiDevice(HdiDevice&& rhs) = delete;
113     HdiDevice& operator=(HdiDevice&& rhs) = delete;
114 };
115 } // namespace Rosen
116 } // namespace OHOS
117 #endif // HDI_BACKEND_HDI_DEVICE_H