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