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 27 namespace OHOS { 28 namespace Rosen { 29 class HelloComposer { 30 public: 31 HelloComposer() = default; 32 virtual ~HelloComposer() = default; 33 34 void Init(); 35 void Run(const std::vector<std::string> &runArgs); 36 37 private: 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 HdiBackend* backend_ = nullptr; 51 std::vector<std::unique_ptr<HdiScreen>> screens_; 52 std::shared_ptr<HdiOutput> curOutput_; 53 std::shared_ptr<OHOS::AppExecFwk::EventHandler> mainThreadHandler_; 54 55 /* map: key is screenId */ 56 std::unordered_map<uint32_t, uint32_t> displayWidthsMap_; 57 std::unordered_map<uint32_t, uint32_t> displayHeightsMap_; 58 std::unordered_map<uint32_t, std::shared_ptr<HdiOutput>> outputMap_; 59 std::unordered_map<uint32_t, std::unique_ptr<HdiScreen>> screensMap_; 60 std::unordered_map<uint32_t, std::vector<std::unique_ptr<LayerContext>>> drawLayersMap_; 61 62 void InitLayers(uint32_t screenId); 63 void RequestSync(); 64 void CreateLayers(); 65 void CreateShowLayers(); 66 void Draw(); 67 void Sync(int64_t, void *data); 68 void DoPrepareCompleted(sptr<Surface> surface, const struct PrepareCompleteParam ¶m); 69 void OnHotPlug(std::shared_ptr<HdiOutput> &output, bool connected); 70 void OnHotPlugEvent(std::shared_ptr<HdiOutput> &output, bool connected); 71 void ParseArgs(const std::vector<std::string> &runArgs); 72 void SetRunArgs(const std::unique_ptr<LayerContext> &drawLayer) const; 73 void RemoveOffScreenData(uint32_t offScreenId); 74 uint32_t CreatePhysicalScreen(); 75 76 static void OnScreenPlug(std::shared_ptr<HdiOutput> &output, bool connected, void* data); 77 static void OnPrepareCompleted( 78 sptr<Surface> &surface, const struct PrepareCompleteParam ¶m, void* data); 79 }; 80 } // namespace Rosen 81 } // namespace OHOS 82 83 #endif // HELLO_COMPOSER_H