1 /* 2 * Copyright (c) 2021-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 FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H 17 #define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H 18 19 #include <refbase.h> 20 21 #include "abstract_screen.h" 22 #include "display_info.h" 23 24 namespace OHOS::Rosen { 25 enum class FreezeFlag : uint32_t { 26 FREEZING, 27 UNFREEZING, 28 }; 29 30 class AbstractDisplay : public RefBase { 31 public: 32 constexpr static int32_t DEFAULT_WIDTH = 720; 33 constexpr static int32_t DEFAULT_HIGHT = 1280; 34 constexpr static float DEFAULT_VIRTUAL_PIXEL_RATIO = 1.0; 35 constexpr static uint32_t DEFAULT_FRESH_RATE = 60; 36 AbstractDisplay(DisplayId id, sptr<SupportedScreenModes>& info, sptr<AbstractScreen>& absScreen); 37 WM_DISALLOW_COPY_AND_MOVE(AbstractDisplay); 38 ~AbstractDisplay() = default; IsVertical(Rotation rotation)39 static inline bool IsVertical(Rotation rotation) 40 { 41 return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180); 42 } 43 DisplayId GetId() const; 44 int32_t GetOffsetX() const; 45 int32_t GetOffsetY() const; 46 int32_t GetWidth() const; 47 int32_t GetHeight() const; 48 uint32_t GetRefreshRate() const; 49 float GetVirtualPixelRatio() const; 50 ScreenId GetAbstractScreenId() const; 51 ScreenId GetAbstractScreenGroupId() const; 52 bool BindAbstractScreen(sptr<AbstractScreen> abstractDisplay); 53 sptr<DisplayInfo> ConvertToDisplayInfo() const; 54 Rotation GetRotation() const; 55 Orientation GetOrientation() const; 56 DisplayOrientation GetDisplayOrientation() const; 57 FreezeFlag GetFreezeFlag() const; 58 59 void SetId(DisplayId displayId); 60 void SetOffsetX(int32_t offsetX); 61 void SetOffsetY(int32_t offsetY); 62 void SetWidth(int32_t width); 63 void SetHeight(int32_t height); 64 void SetOffset(int32_t offsetX, int32_t offsetY); 65 void SetRefreshRate(uint32_t refreshRate); 66 void SetVirtualPixelRatio(float virtualPixelRatio); 67 void SetOrientation(Orientation orientation); 68 void SetDisplayOrientation(DisplayOrientation displayOrientation); 69 bool RequestRotation(Rotation rotation); 70 void SetFreezeFlag(FreezeFlag); 71 DEFINE_VAR_DEFAULT_FUNC_GET_SET(bool, WaterfallDisplayCompressionStatus, waterfallDisplayCompressionStatus, false); 72 73 private: 74 DisplayId id_ { DISPLAY_ID_INVALID }; 75 std::string name_ { "" }; 76 ScreenId screenId_ { SCREEN_ID_INVALID }; 77 ScreenId screenGroupId_ { SCREEN_ID_INVALID }; 78 int32_t offsetX_ { 0 }; 79 int32_t offsetY_ { 0 }; 80 int32_t width_ { 0 }; 81 int32_t height_ { 0 }; 82 uint32_t refreshRate_ { 0 }; 83 float virtualPixelRatio_ { 1.0f }; 84 Rotation rotation_ { Rotation::ROTATION_0 }; 85 Orientation orientation_ { Orientation::UNSPECIFIED }; 86 DisplayOrientation displayOrientation_ { DisplayOrientation::UNKNOWN }; 87 FreezeFlag freezeFlag_ { FreezeFlag::UNFREEZING }; 88 DEFINE_VAR_DEFAULT_FUNC_SET(DisplayState, DisplayState, displayState, DisplayState::UNKNOWN); 89 bool isDefaultVertical_ { true }; 90 uint32_t phyWidth_ { UINT32_MAX }; 91 uint32_t phyHeight_ { UINT32_MAX }; 92 float xDpi_ { 0.0f }; 93 float yDpi_ { 0.0f }; 94 95 void UpdateXDpi(); 96 void UpdateYDpi(); 97 void CalculateXYDpi(uint32_t phyWidth, uint32_t phyHeight); 98 }; 99 } // namespace OHOS::Rosen 100 #endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H