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 <display_type.h> 20 #include <surface.h> 21 #include <event_handler.h> 22 #include "hdi_backend.h" 23 #include "hdi_layer_info.h" 24 #include "hdi_output.h" 25 #include "hdi_screen.h" 26 #include "layer_context.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 class HelloComposer { 31 public: 32 HelloComposer() = default; 33 virtual ~HelloComposer() = default; 34 35 void Init(); 36 void Run(std::vector<std::string> &runArgs); 37 38 private: 39 uint32_t freq_ = 30; 40 uint32_t currScreenId_ = 0; 41 // key is screenId 42 std::unordered_map<uint32_t, uint32_t> displayWidthsMap_; 43 std::unordered_map<uint32_t, uint32_t> displayHeightsMap_; 44 uint32_t currentModeIndex_ = 0; 45 std::vector<DisplayModeInfo> displayModeInfos_; 46 // key is screenId 47 std::unordered_map<uint32_t, std::shared_ptr<HdiOutput>> outputMap_; 48 bool dump_ = false; 49 bool ready_ = false; 50 bool initDeviceFinished_ = false; 51 bool deviceConnected_ = false; 52 bool postHotPlugEvent_ = false; 53 HdiBackend* backend_ = nullptr; 54 std::vector<std::unique_ptr<HdiScreen>> screens_; 55 std::shared_ptr<HdiOutput> curOutput_; 56 // key is screenId 57 std::unordered_map<uint32_t, std::vector<std::unique_ptr<LayerContext>>> drawLayersMap_; 58 std::shared_ptr<OHOS::AppExecFwk::EventHandler> mainThreadHandler_; 59 60 void InitLayers(uint32_t screenId); 61 void RequestSync(); 62 void CreateShowLayers(); 63 void DrawFrameBufferData(void *image, uint32_t width, uint32_t height); 64 void Draw(); 65 void Sync(int64_t, void *data); 66 void DoPrepareCompleted(sptr<Surface> &surface, const struct PrepareCompleteParam ¶m); 67 void OnHotPlug(std::shared_ptr<HdiOutput> &output, bool connected); 68 void OnHotPlugEvent(std::shared_ptr<HdiOutput> &output, bool connected); 69 uint32_t CreatePhysicalScreen(); 70 71 static void OnScreenPlug(std::shared_ptr<HdiOutput> &output, bool connected, void* data); 72 static void OnPrepareCompleted(OHOS::sptr<Surface> &surface, const struct PrepareCompleteParam ¶m, void* data); 73 }; 74 } // namespace Rosen 75 } // namespace OHOS 76 77 #endif // HELLO_COMPOSER_H