[Multimedia] Modified a constructor of the Display class not to check the raw video...
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / Common / Display.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 using System;
17 using ElmSharp;
18
19 namespace Tizen.Multimedia
20 {
21     internal enum DisplayType
22     {
23         /// <summary>
24         /// Overlay surface display.
25         /// </summary>
26         Overlay,
27
28         /// <summary>
29         ///  Evas image object surface display.
30         /// </summary>
31         Surface,
32
33         /// <summary>
34         /// This disposes off buffers.
35         /// </summary>
36         None,
37     }
38
39     internal interface IDisplayable<TError>
40     {
41         TError ApplyEvasDisplay(DisplayType type, EvasObject evasObject);
42         TError ApplyEcoreWindow(IntPtr windowHandle);
43     }
44
45     internal interface IDisplaySetter
46     {
47         TError SetDisplay<TError>(IDisplayable<TError> target);
48     }
49
50     internal class EvasDisplaySetter : IDisplaySetter
51     {
52         private readonly DisplayType _type;
53         private readonly EvasObject _target;
54
55         internal EvasDisplaySetter(DisplayType type, EvasObject target)
56         {
57             if (target == IntPtr.Zero)
58             {
59                 throw new ArgumentException("The evas object is not realized.");
60             }
61
62             _type = type;
63             _target = target;
64         }
65
66         public TError SetDisplay<TError>(IDisplayable<TError> target)
67         {
68             return target.ApplyEvasDisplay(_type, _target);
69         }
70     }
71
72     internal class EcoreDisplaySetter : IDisplaySetter
73     {
74         private readonly IntPtr _windowHandle;
75
76         internal EcoreDisplaySetter(IntPtr windowHandle)
77         {
78             _windowHandle = windowHandle;
79         }
80
81         public TError SetDisplay<TError>(IDisplayable<TError> target)
82         {
83             return target.ApplyEcoreWindow(_windowHandle);
84         }
85     }
86
87     /// <summary>
88     /// Provides a means to wrap various display types.
89     /// </summary>
90     /// <seealso cref="T:Tizen.Multimedia.Player"/>
91     /// <seealso cref="T:Tizen.Multimedia.Camera"/>
92     /// <seealso cref="T:Tizen.Multimedia.Remoting.ScreenMirroring"/>
93     /// <since_tizen> 3 </since_tizen>
94     public class Display
95     {
96         private readonly IDisplaySetter _setter;
97
98         /// <summary>
99         /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="MediaView"/> class.
100         /// </summary>
101         /// <param name="mediaView">A <see cref="MediaView"/> to display.</param>
102         /// <since_tizen> 3 </since_tizen>
103         public Display(MediaView mediaView)
104         {
105             if (mediaView == null)
106             {
107                 throw new ArgumentNullException(nameof(mediaView));
108             }
109
110             _setter = new EvasDisplaySetter(DisplayType.Surface, mediaView);
111
112             HasMediaView = true;
113         }
114
115         /// <summary>
116         /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="Window"/> class.
117         /// </summary>
118         /// <param name="window">A <see cref="Window"/> to display.</param>
119         /// <since_tizen> 3 </since_tizen>
120         public Display(Window window)
121         {
122             if (window == null)
123             {
124                 throw new ArgumentNullException(nameof(window));
125             }
126
127             _setter = new EvasDisplaySetter(DisplayType.Overlay, window);
128         }
129
130         /// <summary>
131         /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="NUI.Window"/> class.
132         /// </summary>
133         /// <param name="window">A <see cref="NUI.Window"/> to display.</param>
134         /// <remarks>
135         /// The <see cref="NUI.Window.BackgroundColor"/> must be <see cref="NUI.Color.Transparent"/>
136         /// for the <see cref="Display"/> to be rendered correctly.
137         /// </remarks>
138         /// <since_tizen> 3 </since_tizen>
139         public Display(NUI.Window window)
140         {
141             if (window == null)
142             {
143                 throw new ArgumentNullException(nameof(window));
144             }
145
146             _setter = new EcoreDisplaySetter(window.GetNativeWindowHandler());
147         }
148
149         private EvasObject EvasObject { get; }
150
151         private DisplayType Type { get; }
152
153         private object _owner;
154
155         internal bool HasMediaView { get; } = false;
156
157         internal object Owner => _owner;
158
159         internal void SetOwner(object newOwner)
160         {
161             if (_owner != null && newOwner != null)
162             {
163                 throw new ArgumentException("The display has already been assigned to another.");
164             }
165
166             _owner = newOwner;
167         }
168
169         internal TError ApplyTo<TError>(IDisplayable<TError> target)
170         {
171             return _setter.SetDisplay(target);
172         }
173     }
174 }