3546f9356369ffbaeb7fd24d1167a60fc864cea1
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.MediaPlayer / Player / PlayerDisplaySettings.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Diagnostics;
19 using Native = Interop.Display;
20
21 namespace Tizen.Multimedia
22 {
23     /// <summary>
24     /// Provides a means to configure display settings for video <see cref="Player"/>.
25     /// </summary>
26     public class PlayerDisplaySettings
27     {
28         protected PlayerDisplaySettings(Player player)
29         {
30             if (player == null)
31             {
32                 throw new ArgumentNullException(nameof(player));
33             }
34
35             Player = player;
36         }
37
38         internal static PlayerDisplaySettings Create(Player player) => new PlayerDisplaySettings(player);
39
40         protected Player Player { get; }
41
42         /// <summary>
43         /// Gets or sets the <see cref="PlayerDisplayMode"/>.
44         /// </summary>
45         /// <exception cref="InvalidOperationException">
46         ///     The display is not assigned.\n
47         ///     -or-\n
48         ///     Operation failed; internal error.
49         /// </exception>
50         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
51         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
52         public PlayerDisplayMode Mode
53         {
54             get
55             {
56                 Native.GetMode(Player.Handle, out var value).
57                     ThrowIfFailed("Failed to get display mode");
58
59                 return value;
60             }
61             set
62             {
63                 ValidationUtil.ValidateEnum(typeof(PlayerDisplayMode), value);
64
65                 Native.SetMode(Player.Handle, value).
66                     ThrowIfFailed("Failed to set display mode");
67             }
68         }
69
70         /// <summary>
71         /// Gets or sets the value indicating whether the display is visible.
72         /// </summary>
73         /// <value>true if the display is visible; otherwise false.</value>
74         /// <exception cref="InvalidOperationException">
75         ///     The display is not assigned.\n
76         ///     -or-\n
77         ///     Operation failed; internal error.
78         /// </exception>
79         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
80         public bool IsVisible
81         {
82             get
83             {
84                 Native.IsVisible(Player.Handle, out var value).
85                     ThrowIfFailed("Failed to get the visible state of the display");
86
87                 return value;
88             }
89             set
90             {
91                 Native.SetVisible(Player.Handle, value).ThrowIfFailed("Failed to set the visible state of the display");
92             }
93         }
94
95         /// <summary>
96         /// Gets or sets the rotation of the display.
97         /// </summary>
98         /// <value><see cref="Rotation.Rotate0"/>, <see cref="Rotation.Rotate90"/>, <see cref="Rotation.Rotate180"/>,
99         ///     <see cref="Rotation.Rotate270"/></value>
100         /// <exception cref="InvalidOperationException">
101         ///     The display is not assigned.\n
102         ///     -or-\n
103         ///     Operation failed; internal error.
104         /// </exception>
105         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
106         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
107         public Rotation Rotation
108         {
109             get
110             {
111                 Native.GetRotation(Player.Handle, out var value).
112                     ThrowIfFailed("Failed to get the rotation state of the display");
113
114                 return value;
115             }
116             set
117             {
118                 ValidationUtil.ValidateEnum(typeof(Rotation), value);
119
120                 Native.SetRotation(Player.Handle, value).
121                     ThrowIfFailed("Failed to set the rotation state of the display");
122             }
123         }
124
125         /// <summary>
126         /// Sets the roi(region of interest).
127         /// </summary>
128         /// <param name="roi">The region.</param>
129         /// <remarks>
130         /// To set roi, <see cref="Mode"/> must be set to <see cref="PlayerDisplayMode.Roi"/> first.
131         /// </remarks>
132         /// <exception cref="InvalidOperationException">
133         ///     The display is not assigned.\n
134         ///     -or-\n
135         ///     Operation failed; internal error.\n
136         ///     -or-\n
137         ///     <see cref="Mode"/> is not set to <see cref="PlayerDisplayMode.Roi"/>.
138         /// </exception>
139         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
140         /// <exception cref="ArgumentOutOfRangeException">width or height is less than or equal to zero.</exception>
141         public void SetRoi(Rectangle roi)
142         {
143             if (roi.Width <= 0)
144             {
145                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Width,
146                     $"The width of the roi can't be less than or equal to zero.");
147             }
148             if (roi.Height <= 0)
149             {
150                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Height,
151                     $"The height of the roi can't be less than or equal to zero.");
152             }
153
154             if (Mode != PlayerDisplayMode.Roi)
155             {
156                 throw new InvalidOperationException("Mode is not set to Roi");
157             }
158
159             Native.SetRoi(Player.Handle, roi.X, roi.Y, roi.Width, roi.Height).
160                 ThrowIfFailed("Failed to set the roi");
161         }
162     }
163 }