Skip to content

Commit

Permalink
[Multimedia] Fix rotation issue for portrait mode (Samsung#5767)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsgwon authored Nov 21, 2023
1 parent 0f9ec84 commit 71c833b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Tizen.Multimedia.Camera/Camera/Camera.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ CameraError IDisplayable<CameraError>.ApplyEvasDisplay(DisplayType type, ElmShar
return CameraDisplay.SetDisplay(GetHandle(), type, evasObject);
}

CameraError IDisplayable<CameraError>.ApplyEcoreWindow(IntPtr windowHandle, NUI.Rectangle rect)
CameraError IDisplayable<CameraError>.ApplyEcoreWindow(IntPtr windowHandle, Rectangle rect, Rotation rotation)
{
Debug.Assert(_disposed == false);

Expand Down
6 changes: 4 additions & 2 deletions src/Tizen.Multimedia.MediaPlayer/Player/Player.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,14 @@ PlayerErrorCode IDisplayable<PlayerErrorCode>.ApplyEvasDisplay(DisplayType type,
type == DisplayType.Overlay ? PlayerDisplayType.Overlay : PlayerDisplayType.Evas, evasObject);
}

PlayerErrorCode IDisplayable<PlayerErrorCode>.ApplyEcoreWindow(IntPtr windowHandle, NUI.Rectangle rect)
PlayerErrorCode IDisplayable<PlayerErrorCode>.ApplyEcoreWindow(IntPtr windowHandle, Rectangle rect, Rotation rotation)
{
Debug.Assert(IsDisposed == false);

return NativeDisplay.SetEcoreDisplay(Handle,
_uiSync ? PlayerDisplayType.OverlayUISync : PlayerDisplayType.Overlay, windowHandle, rect.X, rect.Y, rect.Width, rect.Height);
_uiSync ? PlayerDisplayType.OverlayUISync : PlayerDisplayType.Overlay, windowHandle, rect.X, rect.Y,
rotation == Rotation.Rotate0 || rotation == Rotation.Rotate180 ? rect.Height : rect.Width,
rotation == Rotation.Rotate0 || rotation == Rotation.Rotate180 ? rect.Width : rect.Height);
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ ScreenMirroringErrorCode IDisplayable<ScreenMirroringErrorCode>.ApplyEvasDisplay
return Native.SetDisplay(Handle, (int)type, evasObject);
}

ScreenMirroringErrorCode IDisplayable<ScreenMirroringErrorCode>.ApplyEcoreWindow(IntPtr windowHandle, NUI.Rectangle rect)
ScreenMirroringErrorCode IDisplayable<ScreenMirroringErrorCode>.ApplyEcoreWindow(IntPtr windowHandle, Rectangle rect, Rotation rotation)
{
return Native.SetEcoreDisplay(Handle, windowHandle);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tizen.Multimedia.Remoting/WebRTC/MediaSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ uint IDisplayable<uint>.ApplyEvasDisplay(DisplayType type, ElmSharp.EvasObject e
return trackId;
}

uint IDisplayable<uint>.ApplyEcoreWindow(IntPtr windowHandle, NUI.Rectangle rect)
uint IDisplayable<uint>.ApplyEcoreWindow(IntPtr windowHandle, Rectangle rect, Rotation rotation)
{
NativeWebRTC.SetEcoreVideoLoopback(WebRtc.Handle, SourceId.Value, windowHandle, out uint trackId).
ThrowIfFailed("Failed to set ecore video loopback");
Expand Down
2 changes: 1 addition & 1 deletion src/Tizen.Multimedia.Remoting/WebRTC/MediaStreamTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ WebRTCErrorCode IDisplayable<WebRTCErrorCode>.ApplyEvasDisplay(DisplayType type,
type == DisplayType.Overlay ? WebRTCDisplayType.Overlay : WebRTCDisplayType.Evas, evasObject);
}

WebRTCErrorCode IDisplayable<WebRTCErrorCode>.ApplyEcoreWindow(IntPtr windowHandle, NUI.Rectangle rect)
WebRTCErrorCode IDisplayable<WebRTCErrorCode>.ApplyEcoreWindow(IntPtr windowHandle, Rectangle rect, Rotation rotation)
{
return NativeWebRTC.SetEcoreDisplay(_webRtc.Handle, _trackId, windowHandle);
}
Expand Down
38 changes: 33 additions & 5 deletions src/Tizen.Multimedia/Common/Display.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal enum DisplayType
internal interface IDisplayable<TError>
{
TError ApplyEvasDisplay(DisplayType type, EvasObject evasObject);
TError ApplyEcoreWindow(IntPtr windowHandle, NUI.Rectangle rect);
TError ApplyEcoreWindow(IntPtr windowHandle, Rectangle rect, Rotation rotation);
}

internal interface IDisplaySetter
Expand Down Expand Up @@ -72,17 +72,19 @@ public TError SetDisplay<TError>(IDisplayable<TError> target)
internal class EcoreDisplaySetter : IDisplaySetter
{
private readonly IntPtr _windowHandle;
private readonly NUI.Rectangle _rect;
private readonly Rectangle _rect;
private readonly Rotation _rotation;

internal EcoreDisplaySetter(IntPtr windowHandle, NUI.Rectangle rect)
internal EcoreDisplaySetter(IntPtr windowHandle, Rectangle rect, Rotation rotation)
{
_windowHandle = windowHandle;
_rect = rect;
_rotation = rotation;
}

public TError SetDisplay<TError>(IDisplayable<TError> target)
{
return target.ApplyEcoreWindow(_windowHandle, _rect);
return target.ApplyEcoreWindow(_windowHandle, _rect, _rotation);
}
}

Expand Down Expand Up @@ -163,7 +165,11 @@ public Display(NUI.Window window, bool uiSync)
{
throw new ArgumentNullException(nameof(window));
}
_setter = new EcoreDisplaySetter(window.GetNativeWindowHandler(), window.WindowPositionSize);

var windowSize = new Rectangle(window.WindowPositionSize.X, window.WindowPositionSize.Y,
window.WindowPositionSize.Width, window.WindowPositionSize.Height);

_setter = new EcoreDisplaySetter(window.GetNativeWindowHandler(), windowSize, window.GetCurrentOrientation().ToMmRotation());

UiSync = uiSync;
}
Expand Down Expand Up @@ -195,4 +201,26 @@ internal TError ApplyTo<TError>(IDisplayable<TError> target)
return _setter.SetDisplay(target);
}
}

internal static class WindowOrientationExtension
{
internal static Tizen.Multimedia.Rotation ToMmRotation(this NUI.Window.WindowOrientation rotation)
{
switch (rotation)
{
case NUI.Window.WindowOrientation.Portrait:
return Tizen.Multimedia.Rotation.Rotate0;
case NUI.Window.WindowOrientation.Landscape:
return Tizen.Multimedia.Rotation.Rotate90;
case NUI.Window.WindowOrientation.PortraitInverse:
return Tizen.Multimedia.Rotation.Rotate180;
case NUI.Window.WindowOrientation.LandscapeInverse:
return Tizen.Multimedia.Rotation.Rotate270;
default:
break;
}

return Tizen.Multimedia.Rotation.Rotate90;
}
}
}

0 comments on commit 71c833b

Please sign in to comment.