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