[Camera] Fixed possible memory leak and Add some descriptions
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / Camera / CameraDisplay.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
19 namespace Tizen.Multimedia
20 {
21     /// <summary>
22     /// The CameraDisplay class allows you to manage display for the camera.
23     /// It allows to set and get various display properties such as
24     /// rotation, display visibility and display mode.
25     /// </summary>
26     public class CameraDisplay
27     {
28         internal readonly Camera _camera;
29
30         internal CameraDisplay(Camera camera)
31         {
32             _camera = camera;
33         }
34
35         /// <summary>
36         /// The display mode.
37         /// </summary>
38         /// <value>A <see cref="CameraDisplayMode"/> that specifies the display mode.</value>
39         /// <exception cref="ObjectDisposedException" > The camera already has been disposed.</exception>
40         public CameraDisplayMode Mode
41         {
42             get
43             {
44                 CameraDisplayMode val = CameraDisplayMode.LetterBox;
45
46                 CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.GetMode(_camera.GetHandle(), out val),
47                     "Failed to get camera display mode");
48
49                 return val;
50             }
51
52             set
53             {
54                 CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.SetMode(_camera.GetHandle(), value),
55                     "Failed to set camera display mode.");
56             }
57         }
58
59         /// <summary>
60         /// The display visibility.
61         /// True if camera display visible, otherwise false.
62         /// </summary>
63         /// <exception cref="ObjectDisposedException" > The camera already has been disposed.</exception>
64         public bool Visible
65         {
66             get
67             {
68                 bool val = false;
69
70                 CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.GetVisible(_camera.GetHandle(), out val),
71                     "Failed to get visible value");
72
73                 return val;
74             }
75
76             set
77             {
78                 CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.SetVisible(_camera.GetHandle(), value),
79                     "Failed to set display visible.");
80             }
81         }
82
83         /// <summary>
84         /// The display rotation.
85         /// </summary>
86         /// <value>A <see cref="CameraRotation"/> that specifies the rotation of camera device.</value>
87         /// <privilege>
88         /// http://tizen.org/privilege/camera.
89         /// </privilege>
90         /// <exception cref="ObjectDisposedException" > The camera already has been disposed.</exception>
91         public CameraRotation Rotation
92         {
93             get
94             {
95                 CameraRotation val = CameraRotation.None;
96
97                 CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.GetRotation(_camera.GetHandle(), out val),
98                     "Failed to get display rotation");
99
100                 return val;
101             }
102
103             set
104             {
105                 CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.SetRotation(_camera.GetHandle(), value),
106                     "Failed to set display rotation.");
107             }
108         }
109
110         /// <summary>
111         /// The display flip.
112         /// </summary>
113         /// <value>A <see cref="CameraFlip"/> that specifies camera flip type.</value>
114         /// <privilege>
115         /// http://tizen.org/privilege/camera.
116         /// </privilege>
117         /// <exception cref="ObjectDisposedException" > The camera already has been disposed.</exception>
118         public CameraFlip Flip
119         {
120             get
121             {
122                 CameraFlip val = CameraFlip.None;
123
124                 CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.GetFlip(_camera.GetHandle(), out val),
125                     "Failed to get display flip");
126
127                 return val;
128             }
129
130             set
131             {
132                 CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.SetFlip(_camera.GetHandle(), value),
133                     "Failed to set display flip.");
134             }
135         }
136
137         /// <summary>
138         /// the ROI(Region Of Interest) area of display.
139         /// </summary>
140         /// <exception cref="ObjectDisposedException" > The camera already has been disposed.</exception>
141         public Rectangle RoiArea
142         {
143             get
144             {
145                 int x = 0;
146                 int y = 0;
147                 int width = 0;
148                 int height = 0;
149
150                 CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.GetRoiArea(_camera.GetHandle(), out x, out y, out width, out height),
151                     "Failed to get display roi area");
152
153                 return new Rectangle(x, y, width, height);
154             }
155
156             set
157             {
158                 CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.SetRoiArea(_camera.GetHandle(),
159                     value.X, value.Y, value.Width, value.Height), "Failed to set display roi area.");
160             }
161         }
162
163         /// <summary>
164         /// Sets the display type and handle to show preview images.
165         /// The camera must be in the <see cref="CameraState.Created"/> state.
166         /// </summary>
167         /// <param name="displayType">Display type.</param>
168         /// <param name="preview">MediaView object to display preview.</param>
169         /// <remarks>
170         /// This method must be called before StartPreview() method.
171         /// In Custom ROI display mode, DisplayRoiArea property must be set before calling this method.
172         /// </remarks>
173         /// <exception cref="ArgumentException">In case of invalid parameters.</exception>
174         /// <exception cref="InvalidOperationException">In case of any invalid operations.</exception>
175         /// <exception cref="NotSupportedException">In case of this feature is not supported.</exception>
176         /// <exception cref="ObjectDisposedException" > The camera already has been disposed.</exception>
177         /// <exception cref="UnauthorizedAccessException">In case of access to the resources cannot be granted.</exception>
178         public void SetInfo(CameraDisplayType displayType, MediaView displayHandle)
179         {
180             _camera.ValidateState(CameraState.Created);
181
182             ValidationUtil.ValidateEnum(typeof(CameraDisplayType), displayType);
183
184             CameraErrorFactory.ThrowIfError(Interop.CameraDisplay.SetInfo(_camera.GetHandle(), displayType, displayHandle),
185                 "Failed to set the camera display.");
186         }
187     }
188 }
189