diff options
author | Garrett Brown <themagnificentmrb@gmail.com> | 2022-12-28 15:37:59 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-28 15:37:59 -0800 |
commit | bf1c61e6fc005b0326fa2d10ce61cabc195d6b3f (patch) | |
tree | 50b5e602876ac65d6458f2c005e615a3b3e6358a | |
parent | b228c778668f7adfb20639086ef9d40376d15e4d (diff) | |
parent | 3b05dc0bb89e3c9cb673e264cf319e38bcd3526c (diff) |
Merge pull request #22330 from garbear/retroplayer-zoom
RetroPlayer: Add "zoom" stretch mode
-rw-r--r-- | xbmc/cores/GameSettings.h | 7 | ||||
-rw-r--r-- | xbmc/cores/RetroPlayer/RetroPlayerUtils.cpp | 4 | ||||
-rw-r--r-- | xbmc/cores/RetroPlayer/rendering/RenderUtils.cpp | 51 | ||||
-rw-r--r-- | xbmc/cores/RetroPlayer/rendering/RenderUtils.h | 9 | ||||
-rw-r--r-- | xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPBaseRenderer.cpp | 9 |
5 files changed, 80 insertions, 0 deletions
diff --git a/xbmc/cores/GameSettings.h b/xbmc/cores/GameSettings.h index a6b34c64e8..f9e0a3e9ca 100644 --- a/xbmc/cores/GameSettings.h +++ b/xbmc/cores/GameSettings.h @@ -48,12 +48,19 @@ enum class STRETCHMODE * on 4K TVs) */ Original, + + /*! + * \brief Show the game at its normal aspect ratio but zoom to fill the + * viewing area + */ + Zoom, }; constexpr const char* STRETCHMODE_NORMAL_ID = "normal"; constexpr const char* STRETCHMODE_STRETCH_4_3_ID = "4:3"; constexpr const char* STRETCHMODE_FULLSCREEN_ID = "fullscreen"; constexpr const char* STRETCHMODE_ORIGINAL_ID = "original"; +constexpr const char* STRETCHMODE_ZOOM_ID = "zoom"; enum class RENDERFEATURE { diff --git a/xbmc/cores/RetroPlayer/RetroPlayerUtils.cpp b/xbmc/cores/RetroPlayer/RetroPlayerUtils.cpp index 42d6e47db7..17d582a2b9 100644 --- a/xbmc/cores/RetroPlayer/RetroPlayerUtils.cpp +++ b/xbmc/cores/RetroPlayer/RetroPlayerUtils.cpp @@ -23,6 +23,8 @@ const char* CRetroPlayerUtils::StretchModeToIdentifier(STRETCHMODE stretchMode) return STRETCHMODE_FULLSCREEN_ID; case STRETCHMODE::Original: return STRETCHMODE_ORIGINAL_ID; + case STRETCHMODE::Zoom: + return STRETCHMODE_ZOOM_ID; default: break; } @@ -40,6 +42,8 @@ STRETCHMODE CRetroPlayerUtils::IdentifierToStretchMode(const std::string& stretc return STRETCHMODE::Fullscreen; else if (stretchMode == STRETCHMODE_ORIGINAL_ID) return STRETCHMODE::Original; + else if (stretchMode == STRETCHMODE_ZOOM_ID) + return STRETCHMODE::Zoom; return STRETCHMODE::Normal; } diff --git a/xbmc/cores/RetroPlayer/rendering/RenderUtils.cpp b/xbmc/cores/RetroPlayer/rendering/RenderUtils.cpp index f8769dda81..654ae526c0 100644 --- a/xbmc/cores/RetroPlayer/rendering/RenderUtils.cpp +++ b/xbmc/cores/RetroPlayer/rendering/RenderUtils.cpp @@ -29,6 +29,7 @@ void CRenderUtils::CalculateStretchMode(STRETCHMODE stretchMode, switch (stretchMode) { case STRETCHMODE::Normal: + case STRETCHMODE::Zoom: { switch (rotationDegCCW) { @@ -175,6 +176,56 @@ void CRenderUtils::ClipRect(const CRect& viewRect, CRect& sourceRect, CRect& des } } +void CRenderUtils::CropSource(CRect& sourceRect, + unsigned int rotationDegCCW, + float viewWidth, + float viewHeight, + float sourceWidth, + float sourceHeight, + float destWidth, + float destHeight) +{ + float reduceX = 0.0f; + float reduceY = 0.0f; + + switch (rotationDegCCW) + { + case 90: + case 270: + { + if (destWidth < viewWidth) + reduceX = (1.0f - destWidth / viewWidth); + + if (destHeight < viewHeight) + reduceY = (1.0f - destHeight / viewHeight); + + break; + } + default: + { + if (destHeight < viewHeight) + reduceX = (1.0f - destHeight / viewHeight); + + if (destWidth < viewWidth) + reduceY = (1.0f - destWidth / viewWidth); + + break; + } + } + + if (reduceX > 0.0f) + { + sourceRect.x1 += sourceRect.Width() * reduceX / 2.0f; + sourceRect.x2 = sourceWidth - sourceRect.x1; + } + + if (reduceY > 0.0f) + { + sourceRect.y1 += sourceRect.Height() * reduceY / 2.0f; + sourceRect.y2 = sourceHeight - sourceRect.y1; + } +} + std::array<CPoint, 4> CRenderUtils::ReorderDrawPoints(const CRect& destRect, unsigned int orientationDegCCW) { diff --git a/xbmc/cores/RetroPlayer/rendering/RenderUtils.h b/xbmc/cores/RetroPlayer/rendering/RenderUtils.h index 0976c3e9ca..3f2207f634 100644 --- a/xbmc/cores/RetroPlayer/rendering/RenderUtils.h +++ b/xbmc/cores/RetroPlayer/rendering/RenderUtils.h @@ -36,6 +36,15 @@ public: static void ClipRect(const CRect& viewRect, CRect& sourceRect, CRect& destRect); + static void CropSource(CRect& sourceRect, + unsigned int rotationDegCCW, + float viewWidth, + float viewHeight, + float sourceWidth, + float sourceHeight, + float destWidth, + float destHeight); + static std::array<CPoint, 4> ReorderDrawPoints(const CRect& destRect, unsigned int orientationDegCCW); }; diff --git a/xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPBaseRenderer.cpp b/xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPBaseRenderer.cpp index 43174ee8da..88a8f42f25 100644 --- a/xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPBaseRenderer.cpp +++ b/xbmc/cores/RetroPlayer/rendering/VideoRenderers/RPBaseRenderer.cpp @@ -176,6 +176,15 @@ void CRPBaseRenderer::ManageRenderArea(const IRenderBuffer& renderBuffer) if (!(m_context.IsFullScreenVideo() || m_context.IsCalibrating())) CRenderUtils::ClipRect(viewRect, m_sourceRect, destRect); + if (stretchMode == STRETCHMODE::Zoom) + { + // Crop for zoom mode + CRenderUtils::CropSource(m_sourceRect, rotationDegCCW, viewRect.Width(), viewRect.Height(), + static_cast<float>(sourceWidth), static_cast<float>(sourceHeight), + destRect.Width(), destRect.Height()); + destRect = viewRect; + } + // Adapt the drawing rect points if we have to rotate m_rotatedDestCoords = CRenderUtils::ReorderDrawPoints(destRect, rotationDegCCW); } |