1/*
2 * Copyright (c) 2023 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 OHOS_HDI_DISPLAY_COMPOSER_V1_0_IDISPLAYCOMPOSER_H
17#define OHOS_HDI_DISPLAY_COMPOSER_V1_0_IDISPLAYCOMPOSER_H
18
19#include <stdint.h>
20#include <vector>
21#include <base/hdi_smq.h>
22#include <base/native_buffer.h>
23#include <hdf_base.h>
24#include <hdi_base.h>
25#include "display/composer/v1_0/display_composer_type.h"
26#include "display/composer/v1_0/ihot_plug_callback.h"
27#include "display/composer/v1_0/irefresh_callback.h"
28#include "display/composer/v1_0/iv_blank_callback.h"
29#include "hdifd_parcelable.h"
30
31#ifndef HDI_BUFF_MAX_SIZE
32#define HDI_BUFF_MAX_SIZE (1024 * 200)
33#endif
34
35#ifndef HDI_CHECK_VALUE_RETURN
36#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \
37    if ((lv) compare (rv)) { \
38        return ret; \
39    } \
40} while (false)
41#endif
42
43#ifndef HDI_CHECK_VALUE_RET_GOTO
44#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \
45    if ((lv) compare (rv)) { \
46        ret = value; \
47        goto table; \
48    } \
49} while (false)
50#endif
51
52namespace OHOS {
53namespace HDI {
54namespace Display {
55namespace Composer {
56namespace V1_0 {
57using namespace OHOS;
58using namespace OHOS::HDI;
59using namespace OHOS::HDI::Base;
60using namespace OHOS::HDI::Display;
61
62enum {
63    CMD_DISPLAY_COMPOSER_GET_VERSION = 0,
64    CMD_DISPLAY_COMPOSER_REG_HOT_PLUG_CALLBACK = 1,
65    CMD_DISPLAY_COMPOSER_SET_CLIENT_BUFFER_CACHE_COUNT = 2,
66    CMD_DISPLAY_COMPOSER_REG_DISPLAY_V_BLANK_CALLBACK = 3,
67    CMD_DISPLAY_COMPOSER_GET_DISPLAY_CAPABILITY = 4,
68    CMD_DISPLAY_COMPOSER_GET_DISPLAY_SUPPORTED_MODES = 5,
69    CMD_DISPLAY_COMPOSER_GET_DISPLAY_MODE = 6,
70    CMD_DISPLAY_COMPOSER_SET_DISPLAY_MODE = 7,
71    CMD_DISPLAY_COMPOSER_GET_DISPLAY_POWER_STATUS = 8,
72    CMD_DISPLAY_COMPOSER_SET_DISPLAY_POWER_STATUS = 9,
73    CMD_DISPLAY_COMPOSER_GET_DISPLAY_BACKLIGHT = 10,
74    CMD_DISPLAY_COMPOSER_SET_DISPLAY_BACKLIGHT = 11,
75    CMD_DISPLAY_COMPOSER_SET_DISPLAY_VSYNC_ENABLED = 12,
76    CMD_DISPLAY_COMPOSER_CREATE_LAYER = 13,
77    CMD_DISPLAY_COMPOSER_DESTROY_LAYER = 14,
78    CMD_DISPLAY_COMPOSER_SET_DISPLAY_CLIENT_CROP = 15,
79    CMD_DISPLAY_COMPOSER_GET_DISPLAY_RELEASE_FENCE = 16,
80    CMD_DISPLAY_COMPOSER_CREATE_VIRTUAL_DISPLAY = 17,
81    CMD_DISPLAY_COMPOSER_DESTROY_VIRTUAL_DISPLAY = 18,
82    CMD_DISPLAY_COMPOSER_SET_VIRTUAL_DISPLAY_BUFFER = 19,
83    CMD_DISPLAY_COMPOSER_SET_DISPLAY_PROPERTY = 20,
84    CMD_DISPLAY_COMPOSER_GET_DISPLAY_PROPERTY = 21,
85    CMD_DISPLAY_COMPOSER_INIT_CMD_REQUEST = 22,
86    CMD_DISPLAY_COMPOSER_CMD_REQUEST = 23,
87    CMD_DISPLAY_COMPOSER_GET_CMD_REPLY = 24,
88};
89
90class IDisplayComposer : public HdiBase {
91public:
92    DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.display.composer.v1_0.IDisplayComposer");
93
94    virtual ~IDisplayComposer() = default;
95
96    static sptr<OHOS::HDI::Display::Composer::V1_0::IDisplayComposer> Get(bool isStub = false);
97    static sptr<OHOS::HDI::Display::Composer::V1_0::IDisplayComposer> Get(const std::string &serviceName, bool isStub = false);
98
99    virtual int32_t RegHotPlugCallback(const sptr<OHOS::HDI::Display::Composer::V1_0::IHotPlugCallback>& cb) = 0;
100
101    virtual int32_t SetClientBufferCacheCount(uint32_t devId, uint32_t count) = 0;
102
103    virtual int32_t RegDisplayVBlankCallback(uint32_t devId,
104         const sptr<OHOS::HDI::Display::Composer::V1_0::IVBlankCallback>& cb) = 0;
105
106    virtual int32_t GetDisplayCapability(uint32_t devId,
107         OHOS::HDI::Display::Composer::V1_0::DisplayCapability& info) = 0;
108
109    virtual int32_t GetDisplaySupportedModes(uint32_t devId,
110         std::vector<OHOS::HDI::Display::Composer::V1_0::DisplayModeInfo>& modes) = 0;
111
112    virtual int32_t GetDisplayMode(uint32_t devId, uint32_t& modeId) = 0;
113
114    virtual int32_t SetDisplayMode(uint32_t devId, uint32_t modeId) = 0;
115
116    virtual int32_t GetDisplayPowerStatus(uint32_t devId,
117         OHOS::HDI::Display::Composer::V1_0::DispPowerStatus& status) = 0;
118
119    virtual int32_t SetDisplayPowerStatus(uint32_t devId,
120         OHOS::HDI::Display::Composer::V1_0::DispPowerStatus status) = 0;
121
122    virtual int32_t GetDisplayBacklight(uint32_t devId, uint32_t& level) = 0;
123
124    virtual int32_t SetDisplayBacklight(uint32_t devId, uint32_t level) = 0;
125
126    virtual int32_t SetDisplayVsyncEnabled(uint32_t devId, bool enabled) = 0;
127
128    virtual int32_t CreateLayer(uint32_t devId, const OHOS::HDI::Display::Composer::V1_0::LayerInfo& layerInfo,
129         uint32_t cacheCount, uint32_t& layerId) = 0;
130
131    virtual int32_t DestroyLayer(uint32_t devId, uint32_t layerId) = 0;
132
133    virtual int32_t SetDisplayClientCrop(uint32_t devId, const OHOS::HDI::Display::Composer::V1_0::IRect& rect) = 0;
134
135    virtual int32_t GetDisplayReleaseFence(uint32_t devId, std::vector<uint32_t>& layers,
136         std::vector<sptr<OHOS::HDI::Display::HdifdParcelable>>& fences) = 0;
137
138    virtual int32_t CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, uint32_t& devId) = 0;
139
140    virtual int32_t DestroyVirtualDisplay(uint32_t devId) = 0;
141
142    virtual int32_t SetVirtualDisplayBuffer(uint32_t devId, const sptr<NativeBuffer>& buffer,
143         const sptr<OHOS::HDI::Display::HdifdParcelable>& fence) = 0;
144
145    virtual int32_t SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value) = 0;
146
147    virtual int32_t GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value) = 0;
148
149    virtual int32_t InitCmdRequest(const std::shared_ptr<SharedMemQueue<int32_t>>& request) = 0;
150
151    virtual int32_t CmdRequest(uint32_t inEleCnt,
152         const std::vector<OHOS::HDI::Display::Composer::V1_0::HdifdInfo>& inFds, uint32_t& outEleCnt, std::vector<OHOS::HDI::Display::Composer::V1_0::HdifdInfo>& outFds) = 0;
153
154    virtual int32_t GetCmdReply(std::shared_ptr<SharedMemQueue<int32_t>>& reply) = 0;
155
156    virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer)
157    {
158        majorVer = 1;
159        minorVer = 0;
160        return HDF_SUCCESS;
161    }
162
163    virtual bool IsProxy()
164    {
165        return false;
166    }
167
168    virtual const std::u16string GetDesc()
169    {
170        return metaDescriptor_;
171    }
172};
173} // V1_0
174} // Composer
175} // Display
176} // HDI
177} // OHOS
178
179#endif // OHOS_HDI_DISPLAY_COMPOSER_V1_0_IDISPLAYCOMPOSER_H
180
181