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 RS_SCREEN 17 #define RS_SCREEN 18 19 #include <memory> 20 #include <optional> 21 22 #include <hdi_output.h> 23 #include <hdi_screen.h> 24 #include <screen_manager/screen_types.h> 25 26 namespace OHOS { 27 namespace Rosen { 28 struct VirtualScreenConfigs { 29 ScreenId id = INVALID_SCREEN_ID; 30 ScreenId mirrorId = INVALID_SCREEN_ID; 31 std::string name; 32 uint32_t width = 0; 33 uint32_t height = 0; 34 sptr<Surface> surface = nullptr; 35 int32_t flags = 0; // reserve flag. 36 }; 37 38 class RSScreen { 39 public: 40 RSScreen() = default; 41 virtual ~RSScreen() noexcept = default; 42 43 virtual ScreenId Id() const = 0; 44 virtual ScreenId MirrorId() const = 0; 45 virtual void SetMirror(ScreenId mirrorId) = 0; 46 virtual const std::string& Name() const = 0; 47 virtual uint32_t Width() const = 0; 48 virtual uint32_t Height() const = 0; 49 virtual bool IsEnable() const = 0; 50 virtual bool IsVirtual() const = 0; 51 virtual void SetActiveMode(uint32_t modeId) = 0; 52 virtual void SetResolution(uint32_t width, uint32_t height) = 0; 53 virtual void SetPowerStatus(uint32_t powerStatus) = 0; 54 virtual std::optional<DisplayModeInfo> GetActiveMode() const = 0; 55 virtual const std::vector<DisplayModeInfo>& GetSupportedModes() const = 0; 56 virtual const DisplayCapability& GetCapability() const = 0; 57 virtual uint32_t GetPowerStatus() const = 0; 58 virtual std::shared_ptr<HdiOutput> GetOutput() const = 0; 59 virtual sptr<Surface> GetProducerSurface() const = 0; 60 virtual void SetProducerSurface(sptr<Surface> producerSurface) = 0; 61 virtual void DisplayDump(int32_t screenIndex, std::string& dumpString) = 0; 62 virtual void SurfaceDump(int32_t screenIndex, std::string& dumpString) = 0; 63 virtual void FpsDump(int32_t screenIndex, std::string& dumpString, std::string& arg) = 0; 64 virtual void ClearFpsDump(int32_t screenIndex, std::string& dumpString, std::string& arg) = 0; 65 virtual void SetScreenBacklight(uint32_t level) = 0; 66 virtual int32_t GetScreenBacklight() const = 0; 67 virtual int32_t GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut> &mode) const = 0; 68 virtual int32_t GetScreenSupportedMetaDataKeys(std::vector<ScreenHDRMetadataKey> &keys) const = 0; 69 virtual int32_t GetScreenColorGamut(ScreenColorGamut &mode) const = 0; 70 virtual int32_t SetScreenColorGamut(int32_t modeIdx) = 0; 71 virtual int32_t SetScreenGamutMap(ScreenGamutMap mode) = 0; 72 virtual int32_t GetScreenGamutMap(ScreenGamutMap &mode) const = 0; 73 virtual int32_t GetActiveModePosByModeId(int32_t modeId) const = 0; 74 virtual const HDRCapability& GetHDRCapability() = 0; 75 virtual const RSScreenType& GetScreenType() const = 0; 76 virtual void SetScreenSkipFrameInterval(uint32_t skipFrameInterval) = 0; 77 virtual uint32_t GetScreenSkipFrameInterval() const = 0; 78 virtual void SetScreenVsyncEnabled(bool enabled) const = 0; 79 }; 80 81 namespace impl { 82 class RSScreen : public OHOS::Rosen::RSScreen { 83 public: 84 RSScreen( 85 ScreenId id, 86 bool isVirtual, 87 std::shared_ptr<HdiOutput> output, 88 sptr<Surface> surface); 89 RSScreen(const VirtualScreenConfigs &configs); 90 ~RSScreen() noexcept override; 91 92 RSScreen(const RSScreen &) = delete; 93 RSScreen &operator=(const RSScreen &) = delete; 94 95 ScreenId Id() const override; 96 ScreenId MirrorId() const override; 97 void SetMirror(ScreenId mirrorId) override; 98 const std::string& Name() const override; 99 uint32_t Width() const override; 100 uint32_t Height() const override; 101 bool IsEnable() const override; 102 bool IsVirtual() const override; 103 void SetActiveMode(uint32_t modeId) override; 104 void SetResolution(uint32_t width, uint32_t height) override; 105 void SetPowerStatus(uint32_t powerStatus) override; 106 std::optional<DisplayModeInfo> GetActiveMode() const override; 107 const std::vector<DisplayModeInfo>& GetSupportedModes() const override; 108 const DisplayCapability& GetCapability() const override; 109 uint32_t GetPowerStatus() const override; 110 std::shared_ptr<HdiOutput> GetOutput() const override; 111 sptr<Surface> GetProducerSurface() const override; 112 void SetProducerSurface(sptr<Surface> producerSurface) override; 113 void DisplayDump(int32_t screenIndex, std::string& dumpString) override; 114 void SurfaceDump(int32_t screenIndex, std::string& dumpString) override; 115 void FpsDump(int32_t screenIndex, std::string& dumpString, std::string& arg) override; 116 void ClearFpsDump(int32_t screenIndex, std::string& dumpString, std::string& arg) override; 117 void SetScreenBacklight(uint32_t level) override; 118 int32_t GetScreenBacklight() const override; 119 int32_t GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut> &mode) const override; 120 int32_t GetScreenSupportedMetaDataKeys(std::vector<ScreenHDRMetadataKey> &keys) const override; 121 int32_t GetScreenColorGamut(ScreenColorGamut &mode) const override; 122 int32_t SetScreenColorGamut(int32_t modeIdx) override; 123 int32_t SetScreenGamutMap(ScreenGamutMap mode) override; 124 int32_t GetScreenGamutMap(ScreenGamutMap &mode) const override; 125 int32_t GetActiveModePosByModeId(int32_t modeId) const override; 126 const HDRCapability& GetHDRCapability() override; 127 const RSScreenType& GetScreenType() const override; 128 void SetScreenSkipFrameInterval(uint32_t skipFrameInterval) override; 129 uint32_t GetScreenSkipFrameInterval() const override; 130 void SetScreenVsyncEnabled(bool enabled) const override; 131 132 private: 133 // create hdiScreen and get some information from drivers. 134 void PhysicalScreenInit() noexcept; 135 136 void ModeInfoDump(std::string& dumpString); 137 void CapabilityDump(std::string& dumpString); 138 void PropDump(std::string& dumpString); 139 void PowerStatusDump(std::string& dumpString); 140 void CapabilityTypeDump(InterfaceType capabilityType, std::string& dumpString); 141 void ScreenTypeDump(std::string& dumpString); 142 143 // ScreenId for this screen. 144 ScreenId id_ = INVALID_SCREEN_ID; 145 // If this screen is the mirror of other screen, this member would be a valid id. 146 ScreenId mirrorId_ = INVALID_SCREEN_ID; 147 148 std::string name_; 149 150 int32_t width_ = 0; 151 int32_t height_ = 0; 152 153 bool isVirtual_ = true; 154 std::shared_ptr<HdiOutput> hdiOutput_; // has value if the screen is physical 155 std::unique_ptr<HdiScreen> hdiScreen_; // has value if the screen is physical 156 std::vector<DisplayModeInfo> supportedModes_; 157 DisplayCapability capability_ = {"", ::DISP_INTF_HDMI, 0, 0, 0, 0, true, 0, nullptr}; 158 HDRCapability hdrCapability_ = {0, nullptr, 0, 0, 0}; 159 sptr<Surface> producerSurface_; // has value if the screen is virtual 160 DispPowerStatus powerStatus_ = ::POWER_STATUS_ON; 161 162 std::vector<ScreenColorGamut> supportedVirtualColorGamuts_ = { 163 COLOR_GAMUT_SRGB, 164 COLOR_GAMUT_DCI_P3, 165 COLOR_GAMUT_ADOBE_RGB }; 166 int32_t currentVirtualColorGamutIdx_ = 0; 167 ScreenGamutMap currentVirtualGamutMap_ = GAMUT_MAP_CONSTANT; 168 RSScreenType screenType_ = RSScreenType::UNKNOWN_TYPE_SCREEN; 169 uint32_t skipFrameInterval_ = DEFAULT_SKIP_FRAME_INTERVAL; 170 }; 171 } // namespace impl 172 } // namespace Rosen 173 } // namespace OHOS 174 175 #endif // RS_SCREEN 176