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 HDI_BACKEND_HDI_BACKEND_H 17 #define HDI_BACKEND_HDI_BACKEND_H 18 19 #include <functional> 20 #include <unordered_map> 21 #include <refbase.h> 22 23 #include "hdi_device.h" 24 #include "hdi_screen.h" 25 #include "hdi_layer.h" 26 #include "hdi_output.h" 27 #include "surface_type.h" 28 29 namespace OHOS { 30 namespace Rosen { 31 32 using OutputPtr = std::shared_ptr<HdiOutput>; 33 34 struct PrepareCompleteParam { 35 bool needFlushFramebuffer; 36 std::vector<LayerInfoPtr> layers; 37 uint32_t screenId; 38 }; 39 40 using OnScreenHotplugFunc = std::function<void(OutputPtr &output, bool connected, void* data)>; 41 using OnPrepareCompleteFunc = std::function<void(sptr<Surface>& surface, 42 const struct PrepareCompleteParam ¶m, void* data)>; 43 44 class HdiBackend { 45 public: 46 /* for RS begin */ 47 static HdiBackend* GetInstance(); 48 RosenError RegScreenHotplug(OnScreenHotplugFunc func, void* data); 49 RosenError RegPrepareComplete(OnPrepareCompleteFunc func, void* data); 50 RosenError RegHwcDeadListener(OnHwcDeadCallback func, void* data); 51 void Repaint(const OutputPtr &output); 52 void ResetDevice(); 53 /* for RS end */ 54 55 /* only used for mock tests */ 56 RosenError SetHdiBackendDevice(HdiDevice* device); 57 private: 58 HdiBackend() = default; 59 virtual ~HdiBackend() = default; 60 61 HdiBackend(const HdiBackend& rhs) = delete; 62 HdiBackend& operator=(const HdiBackend& rhs) = delete; 63 HdiBackend(HdiBackend&& rhs) = delete; 64 HdiBackend& operator=(HdiBackend&& rhs) = delete; 65 66 HdiDevice *device_ = nullptr; 67 void* onHotPlugCbData_ = nullptr; 68 void* onPrepareCompleteCbData_ = nullptr; 69 OnScreenHotplugFunc onScreenHotplugCb_ = nullptr; 70 OnPrepareCompleteFunc onPrepareCompleteCb_ = nullptr; 71 std::unordered_map<uint32_t, OutputPtr> outputs_; 72 73 static void OnHdiBackendHotPlugEvent(uint32_t deviceId, bool connected, void *data); 74 RosenError InitDevice(); 75 void OnHdiBackendConnected(uint32_t screenId, bool connected); 76 void CreateHdiOutput(uint32_t screenId); 77 void OnScreenHotplug(uint32_t screenId, bool connected); 78 void ReorderLayerInfo(std::vector<LayerInfoPtr> &newLayerInfos); 79 void OnPrepareComplete(bool needFlush, const OutputPtr &output, std::vector<LayerInfoPtr> &newLayerInfos); 80 int32_t PrepareCompleteIfNeed(const OutputPtr &output, bool needFlush); 81 }; 82 } // namespace Rosen 83 } // namespace OHOS 84 85 #endif // HDI_BACKEND_HDI_BACKEND_H