diff --git a/app/streaming/streamutils.cpp b/app/streaming/streamutils.cpp index 964b5d8b..c38eddbd 100644 --- a/app/streaming/streamutils.cpp +++ b/app/streaming/streamutils.cpp @@ -32,6 +32,22 @@ void StreamUtils::scaleSourceToDestinationSurface(SDL_Rect* src, SDL_Rect* dst) } } +void StreamUtils::screenSpaceToNormalizedDeviceCoords(SDL_FRect* rect, int viewportWidth, int viewportHeight) +{ + rect->x = (rect->x / (viewportWidth / 2.0f)) - 1.0f; + rect->y = (rect->y / (viewportHeight / 2.0f)) - 1.0f; + rect->w = rect->w / (viewportWidth / 2.0f); + rect->h = rect->h / (viewportHeight / 2.0f); +} + +void StreamUtils::screenSpaceToNormalizedDeviceCoords(SDL_Rect* src, SDL_FRect* dst, int viewportWidth, int viewportHeight) +{ + dst->x = ((float)src->x / (viewportWidth / 2.0f)) - 1.0f; + dst->y = ((float)src->y / (viewportHeight / 2.0f)) - 1.0f; + dst->w = (float)src->w / (viewportWidth / 2.0f); + dst->h = (float)src->h / (viewportHeight / 2.0f); +} + int StreamUtils::getDisplayRefreshRate(SDL_Window* window) { int displayIndex = SDL_GetWindowDisplayIndex(window); diff --git a/app/streaming/streamutils.h b/app/streaming/streamutils.h index db6bc779..d4d72a6b 100644 --- a/app/streaming/streamutils.h +++ b/app/streaming/streamutils.h @@ -2,6 +2,17 @@ #include +// SDL_FRect wasn't added until 2.0.10 +#if !SDL_VERSION_ATLEAST(2, 0, 10) +typedef struct SDL_FRect +{ + float x; + float y; + float w; + float h; +} SDL_FRect; +#endif + class StreamUtils { public: @@ -11,6 +22,12 @@ public: static void scaleSourceToDestinationSurface(SDL_Rect* src, SDL_Rect* dst); + static + void screenSpaceToNormalizedDeviceCoords(SDL_FRect* rect, int viewportWidth, int viewportHeight); + + static + void screenSpaceToNormalizedDeviceCoords(SDL_Rect* src, SDL_FRect* dst, int viewportWidth, int viewportHeight); + static bool getRealDesktopMode(int displayIndex, SDL_DisplayMode* mode); diff --git a/app/streaming/video/ffmpeg-renderers/eglvid.cpp b/app/streaming/video/ffmpeg-renderers/eglvid.cpp index 4895b808..407bacfa 100644 --- a/app/streaming/video/ffmpeg-renderers/eglvid.cpp +++ b/app/streaming/video/ffmpeg-renderers/eglvid.cpp @@ -214,13 +214,7 @@ void EGLRenderer::renderOverlay(Overlay::OverlayType type) free(packedPixelData); } - // SDL_FRect wasn't added until 2.0.10 - struct { - float x; - float y; - float w; - float h; - } overlayRect = {}; + SDL_FRect overlayRect; // These overlay positions differ from the other renderers because OpenGL // places the origin in the lower-left corner instead of the upper-left. @@ -243,12 +237,7 @@ void EGLRenderer::renderOverlay(Overlay::OverlayType type) SDL_FreeSurface(newSurface); // Convert screen space to normalized device coordinates - overlayRect.x /= m_ViewportWidth / 2; - overlayRect.w /= m_ViewportWidth / 2; - overlayRect.y /= m_ViewportHeight / 2; - overlayRect.h /= m_ViewportHeight / 2; - overlayRect.x -= 1.0f; - overlayRect.y -= 1.0f; + StreamUtils::screenSpaceToNormalizedDeviceCoords(&overlayRect, m_ViewportWidth, m_ViewportHeight); OVERLAY_VERTEX verts[] = {