Release 4.0.0-preview1-00051
[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         ///     Operation failed; internal error.
47         /// </exception>
48         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
49         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
50         public PlayerDisplayMode Mode
51         {
52             get
53             {
54                 Native.GetMode(Player.Handle, out var value).
55                     ThrowIfFailed("Failed to get display mode");
56
57                 return value;
58             }
59             set
60             {
61                 ValidationUtil.ValidateEnum(typeof(PlayerDisplayMode), value);
62
63                 Native.SetMode(Player.Handle, value).
64                     ThrowIfFailed("Failed to set display mode");
65             }
66         }
67
68         /// <summary>
69         /// Gets or sets the value indicating whether the display is visible.
70         /// </summary>
71         /// <value>true if the display is visible; otherwise false.</value>
72         /// <exception cref="InvalidOperationException">
73         ///     Operation failed; internal error.
74         /// </exception>
75         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
76         public bool IsVisible
77         {
78             get
79             {
80                 Native.IsVisible(Player.Handle, out var value).
81                     ThrowIfFailed("Failed to get the visible state of the display");
82
83                 return value;
84             }
85             set
86             {
87                 Native.SetVisible(Player.Handle, value).ThrowIfFailed("Failed to set the visible state of the display");
88             }
89         }
90
91         /// <summary>
92         /// Gets or sets the rotation of the display.
93         /// </summary>
94         /// <value><see cref="Rotation.Rotate0"/>, <see cref="Rotation.Rotate90"/>, <see cref="Rotation.Rotate180"/>,
95         ///     <see cref="Rotation.Rotate270"/></value>
96         /// <exception cref="InvalidOperationException">
97         ///     Operation failed; internal error.
98         /// </exception>
99         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
100         /// <exception cref="ArgumentException">The specified value to set is invalid.</exception>
101         public Rotation Rotation
102         {
103             get
104             {
105                 Native.GetRotation(Player.Handle, out var value).
106                     ThrowIfFailed("Failed to get the rotation state of the display");
107
108                 return value;
109             }
110             set
111             {
112                 ValidationUtil.ValidateEnum(typeof(Rotation), value);
113
114                 Native.SetRotation(Player.Handle, value).
115                     ThrowIfFailed("Failed to set the rotation state of the display");
116             }
117         }
118
119         /// <summary>
120         /// Sets the roi(region of interest).
121         /// </summary>
122         /// <param name="roi">The region.</param>
123         /// <remarks>
124         /// To set roi, <see cref="Mode"/> must be set to <see cref="PlayerDisplayMode.Roi"/> first.
125         /// </remarks>
126         /// <exception cref="InvalidOperationException">
127         ///     Operation failed; internal error.\n
128         ///     -or-\n
129         ///     <see cref="Mode"/> is not set to <see cref="PlayerDisplayMode.Roi"/>.
130         /// </exception>
131         /// <exception cref="ObjectDisposedException">The player already has been disposed of.</exception>
132         /// <exception cref="ArgumentOutOfRangeException">width or height is less than or equal to zero.</exception>
133         public void SetRoi(Rectangle roi)
134         {
135             if (roi.Width <= 0)
136             {
137                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Width,
138                     $"The width of the roi can't be less than or equal to zero.");
139             }
140             if (roi.Height <= 0)
141             {
142                 throw new ArgumentOutOfRangeException(nameof(roi), roi.Height,
143                     $"The height of the roi can't be less than or equal to zero.");
144             }
145
146             if (Mode != PlayerDisplayMode.Roi)
147             {
148                 throw new InvalidOperationException("Mode is not set to Roi");
149             }
150
151             Native.SetRoi(Player.Handle, roi.X, roi.Y, roi.Width, roi.Height).
152                 ThrowIfFailed("Failed to set the roi");
153         }
154     }
155 }