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