1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#ifndef OHOS_HDI_DISPLAY_COMPOSER_SERVICE_H
17094332d3Sopenharmony_ci#define OHOS_HDI_DISPLAY_COMPOSER_SERVICE_H
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_ci#include "idisplay_composer_vdi_v1_1.h"
20094332d3Sopenharmony_ci#include "cache_manager/device_cache_manager.h"
21094332d3Sopenharmony_ci#include "v1_1/display_command/display_cmd_responser.h"
22094332d3Sopenharmony_ci#include "v1_1/idisplay_composer.h"
23094332d3Sopenharmony_ci#include "v1_2/display_command/display_cmd_responser.h"
24094332d3Sopenharmony_ci#include "v1_2/idisplay_composer.h"
25094332d3Sopenharmony_ci#include "v1_2/display_composer_type.h"
26094332d3Sopenharmony_ci#include <mutex>
27094332d3Sopenharmony_ci
28094332d3Sopenharmony_cinamespace OHOS {
29094332d3Sopenharmony_cinamespace HDI {
30094332d3Sopenharmony_cinamespace Display {
31094332d3Sopenharmony_cinamespace Composer {
32094332d3Sopenharmony_ciusing namespace OHOS::HDI::Display::Composer::V1_2;
33094332d3Sopenharmony_ci
34094332d3Sopenharmony_ciclass DisplayComposerService : public V1_2::IDisplayComposer {
35094332d3Sopenharmony_cipublic:
36094332d3Sopenharmony_ci    DisplayComposerService();
37094332d3Sopenharmony_ci    virtual ~DisplayComposerService();
38094332d3Sopenharmony_ci    int32_t RegHotPlugCallback(const sptr<IHotPlugCallback>& cb) override;
39094332d3Sopenharmony_ci    int32_t SetClientBufferCacheCount(uint32_t devId, uint32_t count) override;
40094332d3Sopenharmony_ci    int32_t GetDisplayCapability(uint32_t devId, DisplayCapability& info) override;
41094332d3Sopenharmony_ci    int32_t GetDisplaySupportedModes(uint32_t devId, std::vector<DisplayModeInfo>& modes) override;
42094332d3Sopenharmony_ci    int32_t GetDisplayMode(uint32_t devId, uint32_t& modeId) override;
43094332d3Sopenharmony_ci    int32_t SetDisplayMode(uint32_t devId, uint32_t modeId) override;
44094332d3Sopenharmony_ci    int32_t GetDisplayPowerStatus(uint32_t devId, V1_0::DispPowerStatus& status) override;
45094332d3Sopenharmony_ci    int32_t SetDisplayPowerStatus(uint32_t devId, V1_0::DispPowerStatus status) override;
46094332d3Sopenharmony_ci    int32_t GetDisplayBacklight(uint32_t devId, uint32_t& level) override;
47094332d3Sopenharmony_ci    int32_t SetDisplayBacklight(uint32_t devId, uint32_t level) override;
48094332d3Sopenharmony_ci    int32_t GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value) override;
49094332d3Sopenharmony_ci    int32_t SetHardwareCursorPosition(uint32_t devId, int32_t x, int32_t y) override;
50094332d3Sopenharmony_ci    int32_t EnableHardwareCursorStats(uint32_t devId, bool enable) override;
51094332d3Sopenharmony_ci    int32_t GetHardwareCursorStats(uint32_t devId, uint32_t& frameCount, uint32_t& vsyncCount) override;
52094332d3Sopenharmony_ci    int32_t SetDisplayClientCrop(uint32_t devId, const IRect& rect) override;
53094332d3Sopenharmony_ci    int32_t SetDisplayVsyncEnabled(uint32_t devId, bool enabled) override;
54094332d3Sopenharmony_ci    int32_t RegDisplayVBlankCallback(uint32_t devId, const sptr<IVBlankCallback>& cb) override;
55094332d3Sopenharmony_ci    int32_t GetDisplayReleaseFence(
56094332d3Sopenharmony_ci        uint32_t devId, std::vector<uint32_t>& layers, std::vector<sptr<HdifdParcelable>>& fences) override;
57094332d3Sopenharmony_ci    int32_t CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, uint32_t& devId) override;
58094332d3Sopenharmony_ci    int32_t DestroyVirtualDisplay(uint32_t devId) override;
59094332d3Sopenharmony_ci    int32_t SetVirtualDisplayBuffer(
60094332d3Sopenharmony_ci        uint32_t devId, const sptr<NativeBuffer>& buffer, const sptr<HdifdParcelable>& fence) override;
61094332d3Sopenharmony_ci    int32_t SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value) override;
62094332d3Sopenharmony_ci    int32_t CreateLayer(uint32_t devId, const LayerInfo& layerInfo, uint32_t cacheCount, uint32_t& layerId) override;
63094332d3Sopenharmony_ci    int32_t DestroyLayer(uint32_t devId, uint32_t layerId) override;
64094332d3Sopenharmony_ci    int32_t InitCmdRequest(const std::shared_ptr<SharedMemQueue<int32_t>>& request) override;
65094332d3Sopenharmony_ci    int32_t CmdRequest(uint32_t inEleCnt, const std::vector<HdifdInfo>& inFds, uint32_t& outEleCnt,
66094332d3Sopenharmony_ci        std::vector<HdifdInfo>& outFds) override;
67094332d3Sopenharmony_ci    int32_t GetCmdReply(std::shared_ptr<SharedMemQueue<int32_t>>& reply) override;
68094332d3Sopenharmony_ci
69094332d3Sopenharmony_ci    int32_t RegSeamlessChangeCallback(const sptr<ISeamlessChangeCallback>& cb) override;
70094332d3Sopenharmony_ci    int32_t GetDisplaySupportedModesExt(uint32_t devId, std::vector<DisplayModeInfoExt>& modes) override;
71094332d3Sopenharmony_ci    int32_t SetDisplayModeAsync(uint32_t devId, uint32_t modeId, const sptr<IModeCallback>& cb) override;
72094332d3Sopenharmony_ci    int32_t GetDisplayVBlankPeriod(uint32_t devId, uint64_t &period) override;
73094332d3Sopenharmony_ci    int32_t SetLayerPerFrameParameter(uint32_t devId, uint32_t layerId, const std::string& key,
74094332d3Sopenharmony_ci        const std::vector<int8_t>& value)  override;
75094332d3Sopenharmony_ci    int32_t GetSupportedLayerPerFrameParameterKey(std::vector<std::string>& keys) override;
76094332d3Sopenharmony_ci    int32_t SetDisplayOverlayResolution(uint32_t devId, uint32_t width, uint32_t height) override;
77094332d3Sopenharmony_ci    int32_t GetDisplaySupportedColorGamuts(uint32_t devId, std::vector<ColorGamut>& gamuts) override;
78094332d3Sopenharmony_ci    int32_t GetHDRCapabilityInfos(uint32_t devId, HDRCapability& info) override;
79094332d3Sopenharmony_ci    int32_t RegRefreshCallback(const sptr<IRefreshCallback>& cb) override;
80094332d3Sopenharmony_ci    int32_t RegDisplayVBlankIdleCallback (const sptr<IVBlankIdleCallback>& cb) override;
81094332d3Sopenharmony_ci    int32_t ClearClientBuffer(uint32_t devId) override;
82094332d3Sopenharmony_ci    int32_t ClearLayerBuffer(uint32_t devId, uint32_t layerId) override;
83094332d3Sopenharmony_ci
84094332d3Sopenharmony_ciprivate:
85094332d3Sopenharmony_ci    void HidumperInit();
86094332d3Sopenharmony_ci    int32_t LoadVdiSo();
87094332d3Sopenharmony_ci    int32_t LoadVdiV1_0();
88094332d3Sopenharmony_ci    int32_t LoadVdiV1_1();
89094332d3Sopenharmony_ci    static void OnHotPlug(uint32_t outputId, bool connected, void* data);
90094332d3Sopenharmony_ci    static void OnVBlank(unsigned int sequence, uint64_t ns, void* data);
91094332d3Sopenharmony_ci    static void OnMode(uint32_t modeId, uint64_t vBlankPeriod, void* data);
92094332d3Sopenharmony_ci    static void OnSeamlessChange(uint32_t devId, void* data);
93094332d3Sopenharmony_ci    static void OnRefresh(uint32_t devId, void *data);
94094332d3Sopenharmony_ci    static void OnVBlankIdleCallback(uint32_t devId, uint64_t ns, void* data);
95094332d3Sopenharmony_ciprivate:
96094332d3Sopenharmony_ci    /* Common */
97094332d3Sopenharmony_ci    void* libHandle_;
98094332d3Sopenharmony_ci    std::mutex mutex_;
99094332d3Sopenharmony_ci    std::shared_ptr<DeviceCacheManager> cacheMgr_;
100094332d3Sopenharmony_ci    uint32_t currentBacklightLevel_;
101094332d3Sopenharmony_ci    sptr<IHotPlugCallback> hotPlugCb_;
102094332d3Sopenharmony_ci    sptr<IVBlankCallback> vBlankCb_;
103094332d3Sopenharmony_ci    sptr<IModeCallback> modeCb_;
104094332d3Sopenharmony_ci    sptr<ISeamlessChangeCallback> seamlessChangeCb_;
105094332d3Sopenharmony_ci
106094332d3Sopenharmony_ci    /* V1_0, which is the version of vdi */
107094332d3Sopenharmony_ci    IDisplayComposerVdi* vdiImpl_;
108094332d3Sopenharmony_ci    DestroyComposerVdiFunc destroyVdiFunc_;
109094332d3Sopenharmony_ci    std::unique_ptr<V1_2::HdiDisplayCmdResponser> cmdResponser_;
110094332d3Sopenharmony_ci
111094332d3Sopenharmony_ci    /* V1_1, which is the version of vdi */
112094332d3Sopenharmony_ci    IDisplayComposerVdiV1_1* vdiImplV1_1_;
113094332d3Sopenharmony_ci    DestroyComposerVdiFuncV1_1 destroyVdiFuncV1_1_;
114094332d3Sopenharmony_ci    std::unique_ptr<V1_2::HdiDisplayCmdResponser_1_1> cmdResponserV1_1_;
115094332d3Sopenharmony_ci    sptr<IRefreshCallback> refreshCb_;
116094332d3Sopenharmony_ci    sptr<IVBlankIdleCallback> VBlankIdleCb_;
117094332d3Sopenharmony_ci};
118094332d3Sopenharmony_ci} // namespace Composer
119094332d3Sopenharmony_ci} // namespace Display
120094332d3Sopenharmony_ci} // namespace HDI
121094332d3Sopenharmony_ci} // namespace OHOS
122094332d3Sopenharmony_ci#endif // OHOS_HDI_DISPLAY_COMPOSER_SERVICE_H
123