Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/Mediaportal/MP1-5154-Mediaporta…
Browse files Browse the repository at this point in the history
…l_x64_version_with_SharpDX' into MP1.32_Final_Test3
  • Loading branch information
andrewjswan committed Oct 27, 2023
2 parents 5cbb7a9 + 6c2bf7b commit f60daab
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
19 changes: 16 additions & 3 deletions mediaportal/Core/Player/PlaneScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,9 @@ private void InternalPresentImage(int width, int height, int arWidth, int arHeig
SubEngine.GetInstance().Render(_subsRect, _destinationRect, 0);
}

GUIGraphicsContext.DX9Device.Present();
//Present
this.PresentScene(isRepaint);

backbuffer.Dispose();

auto3DSurface.Dispose();
Expand Down Expand Up @@ -1888,7 +1890,8 @@ private void InternalPresentImage(int width, int height, int arWidth, int arHeig
GUIGraphicsContext.DX9Device.EndScene();
}

GUIGraphicsContext.DX9Device.Present();
//Present
this.PresentScene(isRepaint);
}
}
else if (GUIGraphicsContext.Render3DMode == GUIGraphicsContext.eRender3DMode.SideBySide ||
Expand Down Expand Up @@ -1963,7 +1966,9 @@ private void InternalPresentImage(int width, int height, int arWidth, int arHeig
SubEngine.GetInstance().Render(_subsRect, _destinationRect, 0);
}

GUIGraphicsContext.DX9Device.Present();
//Present
this.PresentScene(isRepaint);

backbuffer.Dispose();

auto3DSurface.Dispose();
Expand Down Expand Up @@ -2003,6 +2008,14 @@ private void InternalPresentImage(int width, int height, int arWidth, int arHeig
}
}

private void PresentScene(bool bIsRepaint)
{
if (GUIGraphicsContext.PresentationParameters.SwapEffect == SwapEffect.FlipEx)
((DeviceEx)GUIGraphicsContext.DX9Device).PresentEx(Present.ForceImmediate);
else
GUIGraphicsContext.DX9Device.Present();
}

private void DrawTextureSegment(VertexBuffer vertexBuffer, float srcX, float srcY, float srcWidth, float srcHeight,
float dstX, float dstY, float dstWidth, float dstHeight, long lColorDiffuse)
{
Expand Down
7 changes: 7 additions & 0 deletions mediaportal/Core/guilib/GraphicContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public enum VideoRendererType

public static IntPtr SubDeviceMadVr = IntPtr.Zero; // pointer to current DX9 madVR device

public static SwapChain SwapChain = null; // pointer to current device swapchain

// ReSharper disable InconsistentNaming
public static Graphics graphics = null; // GDI+ Graphics object
public static Form form = null; // Current GDI form
Expand Down Expand Up @@ -252,6 +254,11 @@ public static void Create(Device device, PresentParameters prms)
DX9Device = device;
PresentationParameters = prms;
RenderTarget = device.GetRenderTarget(0);

if (device is DeviceEx)
SwapChain = new SwapChain9Ex(((DeviceEx)device).GetSwapChain(0).NativePointer);
else
SwapChain = device.GetSwapChain(0);
}

/// <summary>
Expand Down
21 changes: 21 additions & 0 deletions mediaportal/MediaPortal.Application/D3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,12 @@ internal void RecreateSwapChain(bool useBackup)
lock (GUIGraphicsContext.RenderLock)
{
GUIGraphicsContext.DX9Device.EvictManagedResources();

if (GUIGraphicsContext.SwapChain != null)
{
GUIGraphicsContext.SwapChain.Dispose();
GUIGraphicsContext.SwapChain = null;
}
}

if (useBackup)
Expand All @@ -737,6 +743,11 @@ internal void RecreateSwapChain(bool useBackup)
lock (GUIGraphicsContext.RenderLock)
{
GUIGraphicsContext.DX9Device.Reset(_presentParamsBackup);

if (GUIGraphicsContext.DX9Device is DeviceEx)
GUIGraphicsContext.SwapChain = new SwapChain9Ex(((DeviceEx)GUIGraphicsContext.DX9Device).GetSwapChain(0).NativePointer);
else
GUIGraphicsContext.SwapChain = GUIGraphicsContext.DX9Device.GetSwapChain(0);
}
}
catch (SharpDXException ex)
Expand Down Expand Up @@ -785,6 +796,11 @@ internal void RecreateSwapChain(bool useBackup)
lock (GUIGraphicsContext.RenderLock)
{
GUIGraphicsContext.DX9Device.Reset(_presentParams);

if (GUIGraphicsContext.DX9Device is DeviceEx)
GUIGraphicsContext.SwapChain = new SwapChain9Ex(((DeviceEx)GUIGraphicsContext.DX9Device).GetSwapChain(0).NativePointer);
else
GUIGraphicsContext.SwapChain = GUIGraphicsContext.DX9Device.GetSwapChain(0);
}
}
catch (SharpDXException ex)
Expand Down Expand Up @@ -1795,6 +1811,11 @@ public Device CreateDevice(D3DConfiguration configuration)
Log.Debug("D3D: Backup PresentParams with buffer size set to: {0}x{1}", _presentParamsBackup.BackBufferWidth, _presentParamsBackup.BackBufferHeight);


if (GUIGraphicsContext.SwapChain != null)
{
GUIGraphicsContext.SwapChain.Dispose();
GUIGraphicsContext.SwapChain = null;
}

if (GUIGraphicsContext.DX9Device != null)
{
Expand Down

0 comments on commit f60daab

Please sign in to comment.