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_DM_SCREEN_H 17 #define FOUNDATION_DM_SCREEN_H 18 19 #include <cstdint> 20 #include <screen_manager/screen_types.h> 21 #include <string> 22 #include <surface.h> 23 #include <vector> 24 25 #include "dm_common.h" 26 #include "noncopyable.h" 27 28 namespace OHOS::Rosen { 29 class ScreenInfo; 30 31 struct VirtualScreenOption { 32 std::string name_; 33 uint32_t width_; 34 uint32_t height_; 35 float density_; 36 sptr<Surface> surface_; 37 int32_t flags_; 38 bool isForShot_ {true}; 39 std::vector<uint64_t> missionIds_ {}; 40 VirtualScreenType virtualScreenType_ {VirtualScreenType::UNKNOWN}; 41 }; 42 43 class Screen : public RefBase { 44 friend class ScreenManager; 45 public: 46 ~Screen(); 47 Screen(const Screen&) = delete; 48 Screen(Screen&&) = delete; 49 Screen& operator=(const Screen&) = delete; 50 Screen& operator=(Screen&&) = delete; 51 bool IsGroup() const; 52 std::string GetName() const; 53 54 /** 55 * @brief Get screen id. 56 * 57 * @return Screen id. 58 */ 59 ScreenId GetId() const; 60 61 /** 62 * @brief Get width of the screen. 63 * 64 * @return Width of the screen. 65 */ 66 uint32_t GetWidth() const; 67 68 /** 69 * @brief Get height of the screen. 70 * 71 * @return Height of the screen. 72 */ 73 uint32_t GetHeight() const; 74 75 /** 76 * @brief Get virtual width of the screen. 77 * 78 * @return Virtual width of the screen. 79 */ 80 uint32_t GetVirtualWidth() const; 81 82 /** 83 * @brief Get virtual height of the screen. 84 * 85 * @return Virtual height of the screen. 86 */ 87 uint32_t GetVirtualHeight() const; 88 89 /** 90 * @brief Get virtual pixel ratio of the screen. 91 * 92 * @return Virtual pixel ratio of the screen. 93 */ 94 float GetVirtualPixelRatio() const; 95 96 /** 97 * @brief Get the Rotation of the screen. 98 * 99 * @return The Rotation of the screen. 100 */ 101 Rotation GetRotation() const; 102 103 /** 104 * @brief Get the orientation of the screen. 105 * 106 * @return Orientation of the screen. 107 */ 108 Orientation GetOrientation() const; 109 110 /** 111 * @brief Is a real screen. 112 * 113 * @return True means screen is real, false means the opposite. 114 */ 115 bool IsReal() const; 116 117 /** 118 * @brief Get screen parent id. 119 * 120 * @return Screen parent id. 121 */ 122 ScreenId GetParentId() const; 123 124 /** 125 * @brief Get screen mode id. 126 * 127 * @return Screen mode id. 128 */ 129 uint32_t GetModeId() const; 130 131 /** 132 * @brief Get supported modes of the screen. 133 * 134 * @return Supported modes of the screen. 135 */ 136 std::vector<sptr<SupportedScreenModes>> GetSupportedModes() const; 137 138 /** 139 * @brief Set screen active mode. 140 * 141 * @param modeId Mode id. 142 * @return DM_OK means set success, others means set failed. 143 */ 144 DMError SetScreenActiveMode(uint32_t modeId); 145 146 /** 147 * @brief Set orientation for the screen. 148 * 149 * @param orientation Orientation for the screen. 150 * @return DM_OK means set success, others means set failed. 151 */ 152 DMError SetOrientation(Orientation orientation) const; 153 154 /** 155 * @brief Set the density dpi of the screen. 156 * 157 * @param dpi Density dpi of the screen. 158 * @return DM_OK means set success, others means set failed. 159 */ 160 DMError SetDensityDpi(uint32_t dpi) const; 161 162 /** 163 * @brief Set the density dpi of the screen system window. 164 * 165 * @param dpi Density dpi of the screen. 166 * @return DM_OK means set success, others means set failed. 167 */ 168 DMError SetDensityDpiSystem(uint32_t dpi) const; 169 170 /** 171 * @brief Get the screen info. 172 * 173 * @return Screen info. 174 */ 175 sptr<ScreenInfo> GetScreenInfo() const; 176 177 // colorspace, gamut 178 /** 179 * @brief Get the supported color gamuts of the screen. 180 * 181 * @param colorGamuts Supported color gamuts of the screen. 182 * @return DM_OK means get success, others means get failed. 183 */ 184 DMError GetScreenSupportedColorGamuts(std::vector<ScreenColorGamut>& colorGamuts) const; 185 186 /** 187 * @brief Get the color gamut of the screen. 188 * 189 * @param colorGamut Color gamut of the screen. 190 * @return DM_OK means get success, others means get failed. 191 */ 192 DMError GetScreenColorGamut(ScreenColorGamut& colorGamut) const; 193 194 /** 195 * @brief Set the color gamut of the screen. 196 * 197 * @param colorGamutIdx Color gamut of the screen. 198 * @return DM_OK means set success, others means set failed. 199 */ 200 DMError SetScreenColorGamut(int32_t colorGamutIdx); 201 202 /** 203 * @brief Get the gamut map of the screen. 204 * 205 * @param gamutMap Gamut map of the screen. 206 * @return DM_OK means get success, others means get failed. 207 */ 208 DMError GetScreenGamutMap(ScreenGamutMap& gamutMap) const; 209 210 /** 211 * @brief Set the gamut map of the screen. 212 * 213 * @param gamutMap Gamut map of the screen. 214 * @return DM_OK means set success, others means set failed. 215 */ 216 DMError SetScreenGamutMap(ScreenGamutMap gamutMap); 217 218 /** 219 * @brief Set color transform for the screen. 220 * 221 * @return DM_OK means set success, others means set failed. 222 */ 223 DMError SetScreenColorTransform(); 224 225 /** 226 * @brief Set the resolution for the screen. 227 * 228 * @param width width of the screen 229 * @param height height of the screen 230 * @param dpi dpi of the screen 231 * @return DM_OK means set success, others means set failed. 232 */ 233 DMError SetResolution(uint32_t width, uint32_t height, uint32_t dpi) const; 234 235 /** 236 * @brief get Density in current resolution 237 * @param virtualPixelRatio virtualPixelRatio of the screen 238 * @return DM_OK means set success, others means set failed. 239 */ 240 DMError GetDensityInCurResolution(float& virtualPixelRatio) const; 241 242 /** 243 * @brief Get the pixel format of the screen. 244 * 245 * @return DM_OK means set success, others means set failed. 246 */ 247 DMError GetPixelFormat(GraphicPixelFormat& pixelFormat) const; 248 249 /** 250 * @brief Set the pixel format of the screen. 251 * 252 * @return DM_OK means set success, others means set failed. 253 */ 254 DMError SetPixelFormat(GraphicPixelFormat pixelFormat); 255 256 /** 257 * @brief Get the supported HDR format of the screen. 258 * 259 * @param colorSpaces Supported HDR format of the screen. 260 * @return DM_OK means get success, others means get failed. 261 */ 262 DMError GetSupportedHDRFormats(std::vector<ScreenHDRFormat>& hdrFormats) const; 263 264 /** 265 * @brief Get the HDR format of the screen. 266 * 267 * @return DM_OK means set success, others means set failed. 268 */ 269 DMError GetScreenHDRFormat(ScreenHDRFormat& hdrFormat) const; 270 271 /** 272 * @brief Set the HDR format of the screen. 273 * 274 * @return DM_OK means set success, others means set failed. 275 */ 276 DMError SetScreenHDRFormat(int32_t modeIdx); 277 278 /** 279 * @brief Get the supported color space of the screen. 280 * 281 * @param colorSpaces Supported color space of the screen. 282 * @return DM_OK means get success, others means get failed. 283 */ 284 DMError GetSupportedColorSpaces(std::vector<GraphicCM_ColorSpaceType>& colorSpaces) const; 285 286 /** 287 * @brief Get the color space of the screen. 288 * 289 * @param colorSpace Color space of the screen. 290 * @return DM_OK means get success, others means get failed. 291 */ 292 DMError GetScreenColorSpace(GraphicCM_ColorSpaceType& colorSpace) const; 293 294 /** 295 * @brief Set the color space of the screen. 296 * 297 * @param colorSpace Color space of the screen. 298 * @return DM_OK means set success, others means set failed. 299 */ 300 DMError SetScreenColorSpace(GraphicCM_ColorSpaceType colorSpace); 301 302 protected: 303 // No more methods or variables can be defined here. 304 explicit Screen(sptr<ScreenInfo> info); 305 void UpdateScreenInfo() const; 306 void UpdateScreenInfo(sptr<ScreenInfo> info) const; 307 private: 308 // No more methods or variables can be defined here. 309 class Impl; 310 sptr<Impl> pImpl_; 311 }; 312 } // namespace OHOS::Rosen 313 314 #endif // FOUNDATION_DM_SCREEN_H