mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-12-14 21:32:27 +00:00
Revert "Allow renderers to apply size and display changes seamlessly"
This reverts commit c989133d27
.
This commit is contained in:
parent
c989133d27
commit
220f50ebe4
8 changed files with 15 additions and 106 deletions
|
@ -1640,50 +1640,6 @@ void Session::execInternal()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have a window size or display change, ask the decoder if it can apply the change
|
|
||||||
if (m_VideoDecoder != nullptr &&
|
|
||||||
(event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED || SDL_GetWindowDisplayIndex(m_Window) != currentDisplayIndex)) {
|
|
||||||
int width, height;
|
|
||||||
bool handled;
|
|
||||||
int flags = 0;
|
|
||||||
|
|
||||||
// If this is a resize, use the new width and height from the event itself
|
|
||||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
|
|
||||||
flags |= WINDOW_SIZE_CHANGED;
|
|
||||||
width = event.window.data1;
|
|
||||||
height = event.window.data2;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
SDL_GetWindowSize(m_Window, &width, &height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SDL_GetWindowDisplayIndex(m_Window) != currentDisplayIndex) {
|
|
||||||
flags |= WINDOW_DISPLAY_CHANGED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// See if the decoder can apply this change
|
|
||||||
SDL_AtomicLock(&m_DecoderLock);
|
|
||||||
handled = m_VideoDecoder->applyWindowChange(width, height, flags);
|
|
||||||
SDL_AtomicUnlock(&m_DecoderLock);
|
|
||||||
|
|
||||||
// If it did, we don't need to recreate the decoder
|
|
||||||
if (handled) {
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"Applied seamless window change: %x", flags);
|
|
||||||
|
|
||||||
if (currentDisplayIndex != SDL_GetWindowDisplayIndex(m_Window)) {
|
|
||||||
// Update the window display mode based on our current monitor
|
|
||||||
currentDisplayIndex = SDL_GetWindowDisplayIndex(m_Window);
|
|
||||||
updateOptimalWindowDisplayMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
// After a window resize, we need to reset the pointer lock region
|
|
||||||
m_InputHandler->updatePointerRegionLock();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Recreating renderer for window event: %d (%d %d)",
|
"Recreating renderer for window event: %d (%d %d)",
|
||||||
event.window.event,
|
event.window.event,
|
||||||
|
@ -1705,11 +1661,9 @@ void Session::execInternal()
|
||||||
// important events to be lost.
|
// important events to be lost.
|
||||||
flushWindowEvents();
|
flushWindowEvents();
|
||||||
|
|
||||||
if (currentDisplayIndex != SDL_GetWindowDisplayIndex(m_Window)) {
|
// Update the window display mode based on our current monitor
|
||||||
// Update the window display mode based on our current monitor
|
currentDisplayIndex = SDL_GetWindowDisplayIndex(m_Window);
|
||||||
currentDisplayIndex = SDL_GetWindowDisplayIndex(m_Window);
|
updateOptimalWindowDisplayMode();
|
||||||
updateOptimalWindowDisplayMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now that the old decoder is dead, flush any events it may
|
// Now that the old decoder is dead, flush any events it may
|
||||||
// have queued to reset itself (if this reset was the result
|
// have queued to reset itself (if this reset was the result
|
||||||
|
|
|
@ -58,11 +58,6 @@ typedef struct _DECODER_PARAMETERS {
|
||||||
HDR_MASTERING_METADATA hdrMetadata;
|
HDR_MASTERING_METADATA hdrMetadata;
|
||||||
} DECODER_PARAMETERS, *PDECODER_PARAMETERS;
|
} DECODER_PARAMETERS, *PDECODER_PARAMETERS;
|
||||||
|
|
||||||
|
|
||||||
// Flags for applyWindowChange()
|
|
||||||
#define WINDOW_SIZE_CHANGED 0x01
|
|
||||||
#define WINDOW_DISPLAY_CHANGED 0x02
|
|
||||||
|
|
||||||
class IVideoDecoder {
|
class IVideoDecoder {
|
||||||
public:
|
public:
|
||||||
virtual ~IVideoDecoder() {}
|
virtual ~IVideoDecoder() {}
|
||||||
|
@ -76,5 +71,4 @@ public:
|
||||||
virtual int submitDecodeUnit(PDECODE_UNIT du) = 0;
|
virtual int submitDecodeUnit(PDECODE_UNIT du) = 0;
|
||||||
virtual void renderFrameOnMainThread() = 0;
|
virtual void renderFrameOnMainThread() = 0;
|
||||||
virtual void setHdrMode(bool enabled) = 0;
|
virtual void setHdrMode(bool enabled) = 0;
|
||||||
virtual bool applyWindowChange(int width, int height, int flags) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -167,12 +167,6 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool applyWindowChange(int, int, int) {
|
|
||||||
// By default, we cannot apply any changes. The renderer
|
|
||||||
// will be recreated after any window change.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual AVPixelFormat getPreferredPixelFormat(int videoFormat) {
|
virtual AVPixelFormat getPreferredPixelFormat(int videoFormat) {
|
||||||
if (videoFormat == VIDEO_FORMAT_H265_MAIN10) {
|
if (videoFormat == VIDEO_FORMAT_H265_MAIN10) {
|
||||||
// 10-bit YUV 4:2:0
|
// 10-bit YUV 4:2:0
|
||||||
|
|
|
@ -91,8 +91,6 @@ bool SdlRenderer::initialize(PDECODER_PARAMETERS params)
|
||||||
Uint32 rendererFlags = SDL_RENDERER_ACCELERATED;
|
Uint32 rendererFlags = SDL_RENDERER_ACCELERATED;
|
||||||
|
|
||||||
m_VideoFormat = params->videoFormat;
|
m_VideoFormat = params->videoFormat;
|
||||||
m_VideoWidth = params->width;
|
|
||||||
m_VideoHeight = params->height;
|
|
||||||
|
|
||||||
if (params->videoFormat == VIDEO_FORMAT_H265_MAIN10) {
|
if (params->videoFormat == VIDEO_FORMAT_H265_MAIN10) {
|
||||||
// SDL doesn't support rendering YUV 10-bit textures yet
|
// SDL doesn't support rendering YUV 10-bit textures yet
|
||||||
|
@ -141,8 +139,18 @@ bool SdlRenderer::initialize(PDECODER_PARAMETERS params)
|
||||||
SDL_FlushEvent(SDL_WINDOWEVENT);
|
SDL_FlushEvent(SDL_WINDOWEVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the renderer viewport to draw the video while preserving aspect ratio
|
// Calculate the video region size, scaling to fill the output size while
|
||||||
updateViewport();
|
// preserving the aspect ratio of the video stream.
|
||||||
|
SDL_Rect src, dst;
|
||||||
|
src.x = src.y = 0;
|
||||||
|
src.w = params->width;
|
||||||
|
src.h = params->height;
|
||||||
|
dst.x = dst.y = 0;
|
||||||
|
SDL_GetRendererOutputSize(m_Renderer, &dst.w, &dst.h);
|
||||||
|
StreamUtils::scaleSourceToDestinationSurface(&src, &dst);
|
||||||
|
|
||||||
|
// Ensure the viewport is set to the desired video region
|
||||||
|
SDL_RenderSetViewport(m_Renderer, &dst);
|
||||||
|
|
||||||
// Draw a black frame until the video stream starts rendering
|
// Draw a black frame until the video stream starts rendering
|
||||||
SDL_SetRenderDrawColor(m_Renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
SDL_SetRenderDrawColor(m_Renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
||||||
|
@ -331,22 +339,6 @@ AVFrame* SdlRenderer::getSwFrameFromHwFrame(AVFrame* hwFrame)
|
||||||
return swFrame;
|
return swFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SdlRenderer::updateViewport()
|
|
||||||
{
|
|
||||||
// Calculate the video region size, scaling to fill the output size while
|
|
||||||
// preserving the aspect ratio of the video stream.
|
|
||||||
SDL_Rect src, dst;
|
|
||||||
src.x = src.y = 0;
|
|
||||||
src.w = m_VideoWidth;
|
|
||||||
src.h = m_VideoHeight;
|
|
||||||
dst.x = dst.y = 0;
|
|
||||||
SDL_GetRendererOutputSize(m_Renderer, &dst.w, &dst.h);
|
|
||||||
StreamUtils::scaleSourceToDestinationSurface(&src, &dst);
|
|
||||||
|
|
||||||
// Ensure the viewport is set to the desired video region
|
|
||||||
SDL_RenderSetViewport(m_Renderer, &dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SdlRenderer::renderFrame(AVFrame* frame)
|
void SdlRenderer::renderFrame(AVFrame* frame)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -588,13 +580,3 @@ bool SdlRenderer::testRenderFrame(AVFrame* frame)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SdlRenderer::applyWindowChange(int, int, int flags)
|
|
||||||
{
|
|
||||||
if (flags == WINDOW_SIZE_CHANGED) {
|
|
||||||
updateViewport();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
|
@ -16,17 +16,13 @@ public:
|
||||||
virtual bool isRenderThreadSupported() override;
|
virtual bool isRenderThreadSupported() override;
|
||||||
virtual bool isPixelFormatSupported(int videoFormat, enum AVPixelFormat pixelFormat) override;
|
virtual bool isPixelFormatSupported(int videoFormat, enum AVPixelFormat pixelFormat) override;
|
||||||
virtual bool testRenderFrame(AVFrame* frame) override;
|
virtual bool testRenderFrame(AVFrame* frame) override;
|
||||||
virtual bool applyWindowChange(int width, int height, int flags) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void renderOverlay(Overlay::OverlayType type);
|
void renderOverlay(Overlay::OverlayType type);
|
||||||
bool initializeReadBackFormat(AVBufferRef* hwFrameCtxRef, AVFrame* testFrame);
|
bool initializeReadBackFormat(AVBufferRef* hwFrameCtxRef, AVFrame* testFrame);
|
||||||
AVFrame* getSwFrameFromHwFrame(AVFrame* hwFrame);
|
AVFrame* getSwFrameFromHwFrame(AVFrame* hwFrame);
|
||||||
void updateViewport();
|
|
||||||
|
|
||||||
int m_VideoFormat;
|
int m_VideoFormat;
|
||||||
int m_VideoWidth;
|
|
||||||
int m_VideoHeight;
|
|
||||||
SDL_Renderer* m_Renderer;
|
SDL_Renderer* m_Renderer;
|
||||||
SDL_Texture* m_Texture;
|
SDL_Texture* m_Texture;
|
||||||
enum AVPixelFormat m_SwPixelFormat;
|
enum AVPixelFormat m_SwPixelFormat;
|
||||||
|
|
|
@ -68,11 +68,6 @@ void FFmpegVideoDecoder::setHdrMode(bool enabled)
|
||||||
m_FrontendRenderer->setHdrMode(enabled);
|
m_FrontendRenderer->setHdrMode(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FFmpegVideoDecoder::applyWindowChange(int width, int height, int flags)
|
|
||||||
{
|
|
||||||
return m_FrontendRenderer->applyWindowChange(width, height, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
int FFmpegVideoDecoder::getDecoderCapabilities()
|
int FFmpegVideoDecoder::getDecoderCapabilities()
|
||||||
{
|
{
|
||||||
int capabilities = m_BackendRenderer->getDecoderCapabilities();
|
int capabilities = m_BackendRenderer->getDecoderCapabilities();
|
||||||
|
|
|
@ -25,7 +25,6 @@ public:
|
||||||
virtual int submitDecodeUnit(PDECODE_UNIT du) override;
|
virtual int submitDecodeUnit(PDECODE_UNIT du) override;
|
||||||
virtual void renderFrameOnMainThread() override;
|
virtual void renderFrameOnMainThread() override;
|
||||||
virtual void setHdrMode(bool enabled) override;
|
virtual void setHdrMode(bool enabled) override;
|
||||||
virtual bool applyWindowChange(int width, int height, int flags) override;
|
|
||||||
|
|
||||||
virtual IFFmpegRenderer* getBackendRenderer();
|
virtual IFFmpegRenderer* getBackendRenderer();
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,6 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SLVideo cannot apply any window changes (nor do we expect any)
|
|
||||||
virtual bool applyWindowChange(int, int, int) override {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void slLogCallback(void* context, ESLVideoLog logLevel, const char* message);
|
static void slLogCallback(void* context, ESLVideoLog logLevel, const char* message);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue