From f8a6012c3a29addb886fcac775fbf52e762f7c6b Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 28 May 2022 22:48:23 -0500 Subject: [PATCH] Improve overlay format handling --- app/streaming/video/ffmpeg-renderers/d3d11va.cpp | 1 + app/streaming/video/ffmpeg-renderers/dxva2.cpp | 16 +++------------- app/streaming/video/ffmpeg-renderers/eglvid.cpp | 1 + app/streaming/video/ffmpeg-renderers/vdpau.cpp | 1 + 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/streaming/video/ffmpeg-renderers/d3d11va.cpp b/app/streaming/video/ffmpeg-renderers/d3d11va.cpp index b13ac0ed..d4915070 100644 --- a/app/streaming/video/ffmpeg-renderers/d3d11va.cpp +++ b/app/streaming/video/ffmpeg-renderers/d3d11va.cpp @@ -816,6 +816,7 @@ void D3D11VARenderer::notifyOverlayUpdated(Overlay::OverlayType type) // Create a texture with our pixel data SDL_assert(!SDL_MUSTLOCK(newSurface)); + SDL_assert(newSurface->format->format == SDL_PIXELFORMAT_ARGB8888); D3D11_TEXTURE2D_DESC texDesc = {}; texDesc.Width = newSurface->w; diff --git a/app/streaming/video/ffmpeg-renderers/dxva2.cpp b/app/streaming/video/ffmpeg-renderers/dxva2.cpp index 3b52c998..f575afbe 100644 --- a/app/streaming/video/ffmpeg-renderers/dxva2.cpp +++ b/app/streaming/video/ffmpeg-renderers/dxva2.cpp @@ -834,19 +834,9 @@ void DXVA2Renderer::notifyOverlayUpdated(Overlay::OverlayType type) return; } - if (newSurface->pitch == lockedRect.Pitch) { - // If the pitch matches, we can take the fast path and use a single copy to transfer the pixels - RtlCopyMemory(lockedRect.pBits, newSurface->pixels, newSurface->pitch * newSurface->h); - } - else { - // If the pitch doesn't match, we'll need to copy each row separately - int pitch = SDL_min(newSurface->pitch, lockedRect.Pitch); - for (int i = 0; i < newSurface->h; i++) { - RtlCopyMemory(((PUCHAR)lockedRect.pBits) + (lockedRect.Pitch * i), - ((PUCHAR)newSurface->pixels) + (newSurface->pitch * i), - pitch); - } - } + // Copy (and convert, if necessary) the surface pixels to the texture + SDL_ConvertPixels(newSurface->w, newSurface->h, newSurface->format->format, newSurface->pixels, + newSurface->pitch, SDL_PIXELFORMAT_ARGB8888, lockedRect.pBits, lockedRect.Pitch); newTexture->UnlockRect(0); diff --git a/app/streaming/video/ffmpeg-renderers/eglvid.cpp b/app/streaming/video/ffmpeg-renderers/eglvid.cpp index efc7a07b..a880dc95 100644 --- a/app/streaming/video/ffmpeg-renderers/eglvid.cpp +++ b/app/streaming/video/ffmpeg-renderers/eglvid.cpp @@ -193,6 +193,7 @@ void EGLRenderer::renderOverlay(Overlay::OverlayType type) SDL_Surface* newSurface = Session::get()->getOverlayManager().getUpdatedOverlaySurface(type); if (newSurface != nullptr) { SDL_assert(!SDL_MUSTLOCK(newSurface)); + SDL_assert(newSurface->format->format == SDL_PIXELFORMAT_ARGB8888); glBindTexture(GL_TEXTURE_2D, m_OverlayTextures[type]); diff --git a/app/streaming/video/ffmpeg-renderers/vdpau.cpp b/app/streaming/video/ffmpeg-renderers/vdpau.cpp index 1e6f0027..f2538b3f 100644 --- a/app/streaming/video/ffmpeg-renderers/vdpau.cpp +++ b/app/streaming/video/ffmpeg-renderers/vdpau.cpp @@ -365,6 +365,7 @@ void VDPAURenderer::notifyOverlayUpdated(Overlay::OverlayType type) if (newSurface != nullptr) { SDL_assert(!SDL_MUSTLOCK(newSurface)); + SDL_assert(newSurface->format->format == SDL_PIXELFORMAT_ARGB8888); VdpBitmapSurface newBitmapSurface = 0; status = m_VdpBitmapSurfaceCreate(m_Device,