[Multimedia] Add a new constructor of Display to remove dependency of UI frameworks...
authorSeungkeun Lee <sngn.lee@samsung.com>
Mon, 29 Jan 2024 06:52:04 +0000 (15:52 +0900)
committerGitHub <noreply@github.com>
Mon, 29 Jan 2024 06:52:04 +0000 (15:52 +0900)
* Add a new constructor of Display to remove depenendcy of UI frameworks

* Rename property

* Apply review comment

---------

Co-authored-by: Jay Cho <chojoong@gmail.com>
src/Tizen.Multimedia/Common/Display.cs
src/Tizen.Multimedia/Common/IWindowProvider.cs [new file with mode: 0644]

index 1082110..8415951 100644 (file)
@@ -174,6 +174,41 @@ namespace Tizen.Multimedia
             UiSync = uiSync;
         }
 
+        /// <summary>
+        /// Initializes a new instance of the <see cref="Display"/> class with an <see cref="IWindowProvider"/> interface.
+        /// </summary>
+        /// <param name="window">An <see cref="IWindowProvider"/> object that provides a handle to a window.</param>
+        /// <since_tizen> 12 </since_tizen>
+        public Display(IWindowProvider window)
+            : this(window, false)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="Display"/> class with an <see cref="IWindowProvider"/> interface.
+        /// </summary>
+        /// <param name="window">An <see cref="IWindowProvider"/> object that provides a handle to a window.</param>
+        /// <param name="uiSync">A value indicating whether video and UI are in sync or not.</param>
+        /// <remarks>
+        /// UI sync is only for <see cref="T:Tizen.Multimedia.Player"/> and
+        /// <see cref="T:Tizen.Multimedia.Player.DisplaySettings"/> will not work in UI sync mode.
+        /// </remarks>
+        /// <since_tizen> 12 </since_tizen>
+        public Display(IWindowProvider window, bool uiSync)
+        {
+            if (window == null)
+            {
+                throw new ArgumentNullException(nameof(window));
+            }
+
+            _setter = new EcoreDisplaySetter(window.WindowHandle,
+                new Rectangle((int)window.X, (int)window.Y, (int)window.Width, (int)window.Height),
+                window.Rotation.ToMmRotation());
+
+            UiSync = uiSync;
+        }
+
+
         private EvasObject EvasObject { get; }
 
         private DisplayType Type { get; }
@@ -222,5 +257,24 @@ namespace Tizen.Multimedia
 
             return Tizen.Multimedia.Rotation.Rotate90;
         }
+
+        internal static Rotation ToMmRotation(this int rotation)
+        {
+            switch (rotation)
+            {
+                case 0:
+                    return Rotation.Rotate0;
+                case 90:
+                    return Rotation.Rotate90;
+                case 180:
+                    return Rotation.Rotate180;
+                case 270:
+                    return Rotation.Rotate270;
+                default:
+                    break;
+            }
+
+            return Rotation.Rotate90;
+        }
     }
 }
diff --git a/src/Tizen.Multimedia/Common/IWindowProvider.cs b/src/Tizen.Multimedia/Common/IWindowProvider.cs
new file mode 100644 (file)
index 0000000..0a86da5
--- /dev/null
@@ -0,0 +1,43 @@
+using System;
+
+namespace Tizen.Multimedia
+{
+    /// <summary>
+    /// The IWindowProvider interface provides the window handle and information about the window's position, size, and rotation.
+    /// </summary>
+    /// <since_tizen> 12 </since_tizen>
+    public interface IWindowProvider
+    {
+        /// <summary>
+        /// Gets the window handle
+        /// </summary>
+        /// <remarks>
+        /// This handle represents Ecore_Wl2_Window on native.
+        /// </remarks>
+        IntPtr WindowHandle { get; }
+
+        /// <summary>
+        /// Gets the x-coordinate of the window's position.
+        /// </summary>
+        float X { get; }
+        /// <summary>
+        /// Gets the y-coordinate of the window's position.
+        /// </summary>
+        float Y { get; }
+
+        /// <summary>
+        /// Gets the width of the window.
+        /// </summary>
+        float Width { get; }
+
+        /// <summary>
+        /// Gets the height of the window.
+        /// </summary>
+        float Height { get; }
+
+        /// <summary>
+        /// Gets the rotation of the window in degrees. The value can only be 0, 90, 180, or 270.
+        /// </summary>
+        int Rotation { get; }
+    }
+}