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, NUI.Rectangle rect);
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;
75 private readonly NUI.Rectangle _rect;
77 internal EcoreDisplaySetter(IntPtr windowHandle, NUI.Rectangle rect)
79 _windowHandle = windowHandle;
83 public TError SetDisplay<TError>(IDisplayable<TError> target)
85 return target.ApplyEcoreWindow(_windowHandle, _rect);
90 /// Provides a means to wrap various display types.
92 /// <seealso cref="T:Tizen.Multimedia.Player"/>
93 /// <seealso cref="T:Tizen.Multimedia.Camera"/>
94 /// <seealso cref="T:Tizen.Multimedia.Remoting.ScreenMirroring"/>
95 /// <since_tizen> 3 </since_tizen>
98 private readonly IDisplaySetter _setter;
101 /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="MediaView"/> class.
103 /// <param name="mediaView">A <see cref="MediaView"/> to display.</param>
104 /// <since_tizen> 3 </since_tizen>
105 [Obsolete("Deprecated in API10; Will be removed in API12")]
106 public Display(MediaView mediaView)
108 if (mediaView == null)
110 throw new ArgumentNullException(nameof(mediaView));
113 _setter = new EvasDisplaySetter(DisplayType.Surface, mediaView);
119 /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="Window"/> class.
121 /// <param name="window">A <see cref="Window"/> to display.</param>
122 /// <since_tizen> 3 </since_tizen>
123 [Obsolete("Deprecated in API10; Will be removed in API12")]
124 public Display(Window window)
128 throw new ArgumentNullException(nameof(window));
131 _setter = new EvasDisplaySetter(DisplayType.Overlay, window);
135 /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="NUI.Window"/> class.
137 /// <param name="window">A <see cref="NUI.Window"/> to display.</param>
139 /// The <see cref="NUI.Window.BackgroundColor"/> must be <see cref="NUI.Color.Transparent"/>
140 /// for the <see cref="Display"/> to be rendered correctly.
142 /// <since_tizen> 3 </since_tizen>
143 public Display(NUI.Window window)
144 : this (window, false)
149 /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="NUI.Window"/> class.
151 /// <param name="window">A <see cref="NUI.Window"/> to display.</param>
152 /// <param name="uiSync">A value indicates whether video and UI is in sync or not.</param>
154 /// The <see cref="NUI.Window.BackgroundColor"/> must be <see cref="NUI.Color.Transparent"/>
155 /// for the <see cref="Display"/> to be rendered correctly.<br/>
156 /// UI sync is only for <see cref="T:Tizen.Multimedia.Player"/> and
157 /// <see cref="T:Tizen.Multimedia.Player.DisplaySettings"/> will not work in UI sync mode.
159 /// <since_tizen> 9 </since_tizen>
160 public Display(NUI.Window window, bool uiSync)
164 throw new ArgumentNullException(nameof(window));
166 _setter = new EcoreDisplaySetter(window.GetNativeWindowHandler(), window.WindowPositionSize);
171 private EvasObject EvasObject { get; }
173 private DisplayType Type { get; }
175 private object _owner;
177 internal bool HasMediaView { get; } = false;
179 internal bool UiSync { get; } = false;
181 internal object Owner => _owner;
183 internal void SetOwner(object newOwner)
185 if (_owner != null && newOwner != null)
187 throw new ArgumentException("The display has already been assigned to another.");
193 internal TError ApplyTo<TError>(IDisplayable<TError> target)
195 return _setter.SetDisplay(target);