mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-04 00:36:36 +00:00
Fix scaling logic in the Linux renderers using the new helper function
This commit is contained in:
parent
5cbb38091b
commit
b04bc5117d
@ -1,4 +1,5 @@
|
|||||||
#include "vaapi.h"
|
#include "vaapi.h"
|
||||||
|
#include <streaming/streamutils.h>
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
@ -109,34 +110,23 @@ VAAPIRenderer::renderFrame(AVFrame* frame)
|
|||||||
AVHWDeviceContext* deviceContext = (AVHWDeviceContext*)m_HwContext->data;
|
AVHWDeviceContext* deviceContext = (AVHWDeviceContext*)m_HwContext->data;
|
||||||
AVVAAPIDeviceContext* vaDeviceContext = (AVVAAPIDeviceContext*)deviceContext->hwctx;
|
AVVAAPIDeviceContext* vaDeviceContext = (AVVAAPIDeviceContext*)deviceContext->hwctx;
|
||||||
|
|
||||||
// Center in frame and preserve aspect ratio
|
SDL_Rect src, dst;
|
||||||
int x, y, width, height;
|
src.x = src.y = 0;
|
||||||
double srcAspectRatio = (double)m_VideoWidth / (double)m_VideoHeight;
|
src.w = m_VideoWidth;
|
||||||
double dstAspectRatio = (double)m_DisplayWidth / (double)m_DisplayHeight;
|
src.h = m_VideoHeight;
|
||||||
if (dstAspectRatio < srcAspectRatio) {
|
dst.x = dst.y = 0;
|
||||||
// Greater height per width
|
dst.w = m_DisplayWidth;
|
||||||
int drawHeight = (int)(m_DisplayWidth / srcAspectRatio);
|
dst.h = m_DisplayHeight;
|
||||||
y = (m_DisplayHeight - drawHeight) / 2;
|
|
||||||
height = drawHeight;
|
StreamUtils::scaleSourceToDestinationSurface(&src, &dst);
|
||||||
x = 0;
|
|
||||||
width = m_DisplayWidth;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Greater width per height
|
|
||||||
int drawWidth = (int)(m_DisplayHeight * srcAspectRatio);
|
|
||||||
y = 0;
|
|
||||||
height = m_DisplayHeight;
|
|
||||||
x = (m_DisplayWidth - drawWidth) / 2;
|
|
||||||
width = drawWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_vaPutSurface(vaDeviceContext->display,
|
m_vaPutSurface(vaDeviceContext->display,
|
||||||
surface,
|
surface,
|
||||||
m_XWindow,
|
m_XWindow,
|
||||||
0, 0,
|
0, 0,
|
||||||
m_VideoWidth, m_VideoHeight,
|
m_VideoWidth, m_VideoHeight,
|
||||||
x, y,
|
dst.x, dst.y,
|
||||||
width, height,
|
dst.w, dst.h,
|
||||||
NULL, 0, 0);
|
NULL, 0, 0);
|
||||||
|
|
||||||
av_frame_free(&frame);
|
av_frame_free(&frame);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "vdpau.h"
|
#include "vdpau.h"
|
||||||
|
#include <streaming/streamutils.h>
|
||||||
|
|
||||||
#include <SDL_syswm.h>
|
#include <SDL_syswm.h>
|
||||||
|
|
||||||
@ -256,25 +257,20 @@ void VDPAURenderer::renderFrame(AVFrame* frame)
|
|||||||
|
|
||||||
VdpRect outputRect;
|
VdpRect outputRect;
|
||||||
|
|
||||||
// Center in frame and preserve aspect ratio
|
SDL_Rect src, dst;
|
||||||
double srcAspectRatio = (double)m_VideoWidth / (double)m_VideoHeight;
|
src.x = src.y = 0;
|
||||||
double dstAspectRatio = (double)m_DisplayWidth / (double)m_DisplayHeight;
|
src.w = m_VideoWidth;
|
||||||
if (dstAspectRatio < srcAspectRatio) {
|
src.h = m_VideoHeight;
|
||||||
// Greater height per width
|
dst.x = dst.y = 0;
|
||||||
uint32_t drawHeight = (uint32_t)(m_DisplayWidth / srcAspectRatio);
|
dst.w = m_DisplayWidth;
|
||||||
outputRect.y0 = (m_DisplayHeight - drawHeight) / 2;
|
dst.h = m_DisplayHeight;
|
||||||
outputRect.y1 = outputRect.y0 + drawHeight;
|
|
||||||
outputRect.x0 = 0;
|
StreamUtils::scaleSourceToDestinationSurface(&src, &dst);
|
||||||
outputRect.x1 = outputRect.x0 + m_DisplayWidth;
|
|
||||||
}
|
outputRect.x0 = dst.x;
|
||||||
else {
|
outputRect.x1 = dst.x + dst.w;
|
||||||
// Greater width per height
|
outputRect.y0 = dst.y;
|
||||||
uint32_t drawWidth = (uint32_t)(m_DisplayHeight * srcAspectRatio);
|
outputRect.y1 = dst.y + dst.h;
|
||||||
outputRect.y0 = 0;
|
|
||||||
outputRect.y1 = outputRect.y0 + m_DisplayHeight;
|
|
||||||
outputRect.x0 = (m_DisplayWidth - drawWidth) / 2;
|
|
||||||
outputRect.x1 = outputRect.x0 + drawWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render the next frame into the output surface
|
// Render the next frame into the output surface
|
||||||
status = m_VdpVideoMixerRender(m_VideoMixer,
|
status = m_VdpVideoMixerRender(m_VideoMixer,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user