2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 namespace Tizen.Multimedia
21 internal enum DisplayType
24 /// Overlay surface display.
29 /// Evas image object surface display.
34 /// This disposes off buffers.
39 internal interface IDisplayable<TError>
41 TError ApplyEvasDisplay(DisplayType type, EvasObject evasObject);
42 TError ApplyEcoreWindow(IntPtr windowHandle);
45 internal interface IDisplaySetter
47 TError SetDisplay<TError>(IDisplayable<TError> target);
50 internal class EvasDisplaySetter : IDisplaySetter
52 private readonly DisplayType _type;
53 private readonly EvasObject _target;
55 internal EvasDisplaySetter(DisplayType type, EvasObject target)
57 if (target == IntPtr.Zero)
59 throw new ArgumentException("The evas object is not realized.");
66 public TError SetDisplay<TError>(IDisplayable<TError> target)
68 return target.ApplyEvasDisplay(_type, _target);
72 internal class EcoreDisplaySetter : IDisplaySetter
74 private readonly IntPtr _windowHandle;
76 internal EcoreDisplaySetter(IntPtr windowHandle)
78 _windowHandle = windowHandle;
81 public TError SetDisplay<TError>(IDisplayable<TError> target)
83 return target.ApplyEcoreWindow(_windowHandle);
88 /// Provides a means to wrap various display types.
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>
96 private readonly IDisplaySetter _setter;
99 /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="MediaView"/> class.
101 /// <param name="mediaView">A <see cref="MediaView"/> to display.</param>
102 /// <feature>http://tizen.org/feature/multimedia.raw_video</feature>
103 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
104 /// <since_tizen> 3 </since_tizen>
105 public Display(MediaView mediaView)
107 ValidationUtil.ValidateFeatureSupported(Features.RawVideo);
109 if (mediaView == null)
111 throw new ArgumentNullException(nameof(mediaView));
114 _setter = new EvasDisplaySetter(DisplayType.Surface, mediaView);
118 /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="Window"/> class.
120 /// <param name="window">A <see cref="Window"/> to display.</param>
121 /// <since_tizen> 3 </since_tizen>
122 public Display(Window window)
126 throw new ArgumentNullException(nameof(window));
129 _setter = new EvasDisplaySetter(DisplayType.Overlay, window);
133 /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="NUI.Window"/> class.
135 /// <param name="window">A <see cref="NUI.Window"/> to display.</param>
137 /// The <see cref="NUI.Window.BackgroundColor"/> must be <see cref="NUI.Color.Transparent"/>
138 /// for the <see cref="Display"/> to be rendered correctly.
140 /// <since_tizen> 3 </since_tizen>
141 public Display(NUI.Window window)
145 throw new ArgumentNullException(nameof(window));
148 _setter = new EcoreDisplaySetter(window.GetNativeWindowHandler());
151 private EvasObject EvasObject { get; }
153 private DisplayType Type { get; }
155 private object _owner;
157 internal object Owner => _owner;
159 internal void SetOwner(object newOwner)
161 if (_owner != null && newOwner != null)
163 throw new ArgumentException("The display has already been assigned to another.");
169 internal TError ApplyTo<TError>(IDisplayable<TError> target)
171 return _setter.SetDisplay(target);