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 HELLO_COMPOSER_H
17#define HELLO_COMPOSER_H
18
19#include <surface.h>
20#include <event_handler.h>
21#include "hdi_backend.h"
22#include "hdi_layer_info.h"
23#include "hdi_output.h"
24#include "hdi_screen.h"
25#include "layer_context.h"
26
27namespace OHOS {
28namespace Rosen {
29class HelloComposer {
30public:
31    HelloComposer() = default;
32    virtual ~HelloComposer() = default;
33
34    void Init();
35    void Run(const std::vector<std::string> &runArgs);
36
37private:
38    uint32_t freq_ = 30;
39    uint32_t currScreenId_ = 0;
40    // Draw color with PIXEL_FMT_YCBCR_420_SP format in LAYER_EXTRA layer, if YUVFormat_ is true
41    // Draw color with PIXEL_FMT_RGBA_8888 format in LAYER_EXTRA layer, if YUVFormat_ is false
42    bool yuvFormat_ = false;
43    bool dump_ = false;
44    bool ready_ = false;
45    bool initDeviceFinished_ = false;
46    bool deviceConnected_ = false;
47    bool postHotPlugEvent_ = false;
48    bool testClient_ = false;
49    bool testLayerRotate_ = false;
50    bool testLayerColor_ = false;
51    HdiBackend* backend_ = nullptr;
52    std::vector<std::unique_ptr<HdiScreen>> screens_;
53    std::shared_ptr<HdiOutput> curOutput_;
54    std::shared_ptr<OHOS::AppExecFwk::EventHandler> mainThreadHandler_;
55
56    /* map: key is screenId */
57    std::unordered_map<uint32_t, uint32_t> displayWidthsMap_;
58    std::unordered_map<uint32_t, uint32_t> displayHeightsMap_;
59    std::unordered_map<uint32_t, std::shared_ptr<HdiOutput>> outputMap_;
60    std::unordered_map<uint32_t, std::unique_ptr<HdiScreen>> screensMap_;
61    std::unordered_map<uint32_t, std::vector<std::unique_ptr<LayerContext>>> drawLayersMap_;
62
63    void InitLayers(uint32_t screenId);
64    void RequestSync();
65    void CreateLayers();
66    void CreateShowLayers();
67    void Draw();
68    void Sync(int64_t, void *data);
69    void DoPrepareCompleted(sptr<Surface> surface, const struct PrepareCompleteParam &param);
70    void OnHotPlug(std::shared_ptr<HdiOutput> &output, bool connected);
71    void OnHotPlugEvent(std::shared_ptr<HdiOutput> &output, bool connected);
72    void ParseArgs(const std::vector<std::string> &runArgs);
73    void SetRunArgs(const std::unique_ptr<LayerContext> &drawLayer) const;
74    void RemoveOffScreenData(uint32_t offScreenId);
75    uint32_t CreatePhysicalScreen();
76
77    static void OnScreenPlug(std::shared_ptr<HdiOutput> &output, bool connected, void* data);
78    static void OnPrepareCompleted(
79        sptr<Surface> &surface, const struct PrepareCompleteParam &param, void* data);
80};
81} // namespace Rosen
82} // namespace OHOS
83
84#endif // HELLO_COMPOSER_H