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, Rectangle rect, Rotation rotation);
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 Rectangle _rect;
76 private readonly Rotation _rotation;
78 internal EcoreDisplaySetter(IntPtr windowHandle, Rectangle rect, Rotation rotation)
80 _windowHandle = windowHandle;
85 public TError SetDisplay<TError>(IDisplayable<TError> target)
87 return target.ApplyEcoreWindow(_windowHandle, _rect, _rotation);
92 /// Provides a means to wrap various display types.
94 /// <seealso cref="T:Tizen.Multimedia.Player"/>
95 /// <seealso cref="T:Tizen.Multimedia.Camera"/>
96 /// <seealso cref="T:Tizen.Multimedia.Remoting.ScreenMirroring"/>
97 /// <since_tizen> 3 </since_tizen>
100 private readonly IDisplaySetter _setter;
103 /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="MediaView"/> class.
105 /// <param name="mediaView">A <see cref="MediaView"/> to display.</param>
106 /// <since_tizen> 3 </since_tizen>
107 [Obsolete("Deprecated in API10; Will be removed in API12")]
108 public Display(MediaView mediaView)
110 if (mediaView == null)
112 throw new ArgumentNullException(nameof(mediaView));
115 _setter = new EvasDisplaySetter(DisplayType.Surface, mediaView);
121 /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="Window"/> class.
123 /// <param name="window">A <see cref="Window"/> to display.</param>
124 /// <since_tizen> 3 </since_tizen>
125 [Obsolete("Deprecated in API10; Will be removed in API12")]
126 public Display(Window window)
130 throw new ArgumentNullException(nameof(window));
133 _setter = new EvasDisplaySetter(DisplayType.Overlay, window);
137 /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="NUI.Window"/> class.
139 /// <param name="window">A <see cref="NUI.Window"/> to display.</param>
141 /// The <see cref="NUI.Window.BackgroundColor"/> must be <see cref="NUI.Color.Transparent"/>
142 /// for the <see cref="Display"/> to be rendered correctly.
144 /// <since_tizen> 3 </since_tizen>
145 public Display(NUI.Window window)
146 : this (window, false)
151 /// Initializes a new instance of the <see cref="Display"/> class with a <see cref="NUI.Window"/> class.
153 /// <param name="window">A <see cref="NUI.Window"/> to display.</param>
154 /// <param name="uiSync">A value indicates whether video and UI is in sync or not.</param>
156 /// The <see cref="NUI.Window.BackgroundColor"/> must be <see cref="NUI.Color.Transparent"/>
157 /// for the <see cref="Display"/> to be rendered correctly.<br/>
158 /// UI sync is only for <see cref="T:Tizen.Multimedia.Player"/> and
159 /// <see cref="T:Tizen.Multimedia.Player.DisplaySettings"/> will not work in UI sync mode.
161 /// <since_tizen> 9 </since_tizen>
162 public Display(NUI.Window window, bool uiSync)
166 throw new ArgumentNullException(nameof(window));
169 var windowSize = new Rectangle(window.WindowPositionSize.X, window.WindowPositionSize.Y,
170 window.WindowPositionSize.Width, window.WindowPositionSize.Height);
172 _setter = new EcoreDisplaySetter(window.GetNativeWindowHandler(), windowSize, window.GetCurrentOrientation().ToMmRotation());
177 private EvasObject EvasObject { get; }
179 private DisplayType Type { get; }
181 private object _owner;
183 internal bool HasMediaView { get; } = false;
185 internal bool UiSync { get; } = false;
187 internal object Owner => _owner;
189 internal void SetOwner(object newOwner)
191 if (_owner != null && newOwner != null)
193 throw new ArgumentException("The display has already been assigned to another.");
199 internal TError ApplyTo<TError>(IDisplayable<TError> target)
201 return _setter.SetDisplay(target);
205 internal static class WindowOrientationExtension
207 internal static Tizen.Multimedia.Rotation ToMmRotation(this NUI.Window.WindowOrientation rotation)
211 case NUI.Window.WindowOrientation.Portrait:
212 return Tizen.Multimedia.Rotation.Rotate0;
213 case NUI.Window.WindowOrientation.Landscape:
214 return Tizen.Multimedia.Rotation.Rotate90;
215 case NUI.Window.WindowOrientation.PortraitInverse:
216 return Tizen.Multimedia.Rotation.Rotate180;
217 case NUI.Window.WindowOrientation.LandscapeInverse:
218 return Tizen.Multimedia.Rotation.Rotate270;
223 return Tizen.Multimedia.Rotation.Rotate90;