1 /* 2 * Copyright (c) 2022 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 DISPLAY_MANAGER_ADAPTER_IMPL_H 17 #define DISPLAY_MANAGER_ADAPTER_IMPL_H 18 19 #include <map> 20 21 #include "display_manager_adapter.h" 22 23 #include "display.h" 24 #include "display_manager.h" 25 #include "dm_common.h" 26 27 namespace OHOS::NWeb { 28 class DisplayListenerAdapterImpl 29 : public OHOS::Rosen::DisplayManager::IDisplayListener { 30 public: 31 explicit DisplayListenerAdapterImpl(std::shared_ptr<DisplayListenerAdapter> listener); 32 ~DisplayListenerAdapterImpl() override = default; 33 void OnCreate(DisplayId id) override; 34 void OnDestroy(DisplayId id) override; 35 void OnChange(DisplayId id) override; 36 private: 37 std::shared_ptr<DisplayListenerAdapter> listener_; 38 }; 39 40 class DisplayAdapterImpl : public DisplayAdapter { 41 public: 42 DisplayAdapterImpl() = delete; 43 explicit DisplayAdapterImpl(sptr<OHOS::Rosen::Display> display); 44 ~DisplayAdapterImpl() override = default; 45 DisplayId GetId() override; 46 int32_t GetWidth() override; 47 int32_t GetHeight() override; 48 float GetVirtualPixelRatio() override; 49 RotationType GetRotation() override; 50 OrientationType GetOrientation() override; 51 private: 52 sptr<OHOS::Rosen::Display> display_; 53 OHOS::NWeb::RotationType ConvertRotationType(OHOS::Rosen::Rotation type); 54 OHOS::NWeb::OrientationType ConvertOrientationType(OHOS::Rosen::Orientation type); 55 }; 56 57 using ListenerMap = 58 std::map<DisplayListenerAdapter*, sptr<DisplayListenerAdapterImpl>>; 59 class DisplayManagerAdapterImpl : public DisplayManagerAdapter { 60 public: 61 DisplayManagerAdapterImpl() = default; 62 ~DisplayManagerAdapterImpl() override = default; 63 DisplayId GetDefaultDisplayId() override; 64 std::shared_ptr<DisplayAdapter> GetDefaultDisplay() override; 65 bool RegisterDisplayListener(std::shared_ptr<DisplayListenerAdapter> listener) override; 66 bool UnregisterDisplayListener(std::shared_ptr<DisplayListenerAdapter> listener) override; 67 bool IsDefaultPortrait() override; 68 private: 69 ListenerMap reg_; 70 }; 71 } 72 73 #endif