Release 4.0.0-preview1-00051
[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<ErrorType>
40     {
41         ErrorType ApplyEvasDisplay(DisplayType type, EvasObject evasObject);
42     }
43
44     /// <summary>
45     /// Provides a means to wrap various display types.
46     /// </summary>
47     /// <seealso cref="Player"/>
48     /// <seealso cref="Camera"/>
49     /// <seealso cref="ScreenMirroring"/>
50     public class Display
51     {
52         private Display(DisplayType type, EvasObject target)
53         {
54             if (target == null)
55             {
56                 throw new ArgumentNullException(nameof(target));
57             }
58
59             if (target == IntPtr.Zero)
60             {
61                 throw new ArgumentException("The evas object is not realized.");
62             }
63
64             Type = type;
65             EvasObject = target;
66         }
67
68         /// <summary>
69         /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="MediaView"/> class.
70         /// </summary>
71         /// <feature>http://tizen.org/feature/multimedia.raw_video</feature>
72         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
73         public Display(MediaView mediaView) : this(DisplayType.Surface, mediaView)
74         {
75             ValidationUtil.ValidateFeatureSupported(Features.RawVideo);
76         }
77
78         /// <summary>
79         /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="Window"/> class.
80         /// </summary>
81         public Display(Window window) : this(DisplayType.Overlay, window)
82         {
83         }
84
85         private EvasObject EvasObject { get; }
86
87         private DisplayType Type { get; }
88
89         private object _owner;
90
91         internal object Owner => _owner;
92
93         internal void SetOwner(object newOwner)
94         {
95             if (_owner != null && newOwner != null)
96             {
97                 throw new ArgumentException("The display has already been assigned to another.");
98             }
99
100             _owner = newOwner;
101         }
102
103         internal ErrorType ApplyTo<ErrorType>(IDisplayable<ErrorType> target)
104         {
105             return target.ApplyEvasDisplay(Type, EvasObject);
106         }
107     }
108 }