Skip to content

Commit

Permalink
Merge pull request xbmc#24756 from thexai/android-gui-sdr-peak
Browse files Browse the repository at this point in the history
[Android] Adjust GUI SRD peak luminance when display is in HDR PQ mode
  • Loading branch information
thexai authored Mar 6, 2024
2 parents 495a07a + b6cc5eb commit 8cdb881
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 7 deletions.
7 changes: 6 additions & 1 deletion system/settings/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2998,7 +2998,12 @@
<control type="toggle" />
</setting>
<setting id="videoscreen.guipeakluminance" type="integer" label="36097" help="36547">
<requirement>HAS_DX</requirement>
<requirement>
<or>
<condition>HAS_DX</condition>
<condition>HAS_MEDIACODEC</condition>
</or>
</requirement>
<dependencies>
<dependency type="visible" on="property" name="ishdrdisplay"/>
<dependency type="enable">
Expand Down
5 changes: 5 additions & 0 deletions system/shaders/GLES/2.0/gles_shader_default.frag
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

precision mediump float;
uniform lowp vec4 m_unicol;
uniform float m_sdrPeak;

void main ()
{
Expand All @@ -34,5 +35,9 @@ void main ()
rgb.rgb += 16.0 / 255.0;
#endif

#if defined(KODI_TRANSFER_PQ)
rgb.rgb *= m_sdrPeak;
#endif

gl_FragColor = rgb;
}
5 changes: 5 additions & 0 deletions system/shaders/GLES/2.0/gles_shader_fonts.frag
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ precision mediump float;
uniform sampler2D m_samp0;
varying vec4 m_cord0;
varying lowp vec4 m_colour;
uniform float m_sdrPeak;

void main ()
{
Expand All @@ -37,5 +38,9 @@ void main ()
rgb.rgb += 16.0 / 255.0;
#endif

#if defined(KODI_TRANSFER_PQ)
rgb.rgb *= m_sdrPeak;
#endif

gl_FragColor = rgb;
}
5 changes: 5 additions & 0 deletions system/shaders/GLES/2.0/gles_shader_multi.frag
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ uniform sampler2D m_samp0;
uniform sampler2D m_samp1;
varying vec4 m_cord0;
varying vec4 m_cord1;
uniform float m_sdrPeak;

void main ()
{
Expand All @@ -37,5 +38,9 @@ void main ()
rgb.rgb += 16.0 / 255.0;
#endif

#if defined(KODI_TRANSFER_PQ)
rgb.rgb *= m_sdrPeak;
#endif

gl_FragColor = rgb;
}
5 changes: 5 additions & 0 deletions system/shaders/GLES/2.0/gles_shader_multi_blendcolor.frag
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ uniform sampler2D m_samp1;
varying vec4 m_cord0;
varying vec4 m_cord1;
uniform lowp vec4 m_unicol;
uniform float m_sdrPeak;

void main ()
{
Expand All @@ -38,5 +39,9 @@ void main ()
rgb.rgb += 16.0 / 255.0;
#endif

#if defined(KODI_TRANSFER_PQ)
rgb.rgb *= m_sdrPeak;
#endif

gl_FragColor = rgb;
}
5 changes: 5 additions & 0 deletions system/shaders/GLES/2.0/gles_shader_texture.frag
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ precision mediump float;
uniform sampler2D m_samp0;
uniform lowp vec4 m_unicol;
varying vec4 m_cord0;
uniform float m_sdrPeak;

void main ()
{
Expand All @@ -36,5 +37,9 @@ void main ()
rgb.rgb += 16.0 / 255.0;
#endif

#if defined(KODI_TRANSFER_PQ)
rgb.rgb *= m_sdrPeak;
#endif

gl_FragColor = rgb;
}
5 changes: 5 additions & 0 deletions system/shaders/GLES/2.0/gles_shader_texture_noalpha.frag
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
precision mediump float;
uniform sampler2D m_samp0;
varying vec4 m_cord0;
uniform float m_sdrPeak;

void main ()
{
Expand All @@ -21,5 +22,9 @@ void main ()
rgb += 16.0 / 255.0;
#endif

#if defined(KODI_TRANSFER_PQ)
rgb.rgb *= m_sdrPeak;
#endif

gl_FragColor = vec4(rgb, 1.0);
}
5 changes: 5 additions & 0 deletions system/shaders/GLES/2.0/gles_shader_texture_noblend.frag
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
precision mediump float;
uniform sampler2D m_samp0;
varying vec4 m_cord0;
uniform float m_sdrPeak;

void main ()
{
Expand All @@ -35,5 +36,9 @@ void main ()
rgb.rgb += 16.0 / 255.0;
#endif

#if defined(KODI_TRANSFER_PQ)
rgb.rgb *= m_sdrPeak;
#endif

gl_FragColor = rgb;
}
2 changes: 2 additions & 0 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ void VideoPicture::Reset()
qscale_type = 0;
pict_type = 0;

hdrType = StreamHdrType::HDR_TYPE_NONE;

hasDisplayMetadata = false;
hasLightMetadata = false;

Expand Down
2 changes: 2 additions & 0 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ struct VideoPicture
int qscale_type;
int pict_type;

StreamHdrType hdrType;

bool hasDisplayMetadata = false;
AVMasteringDisplayMetadata displayMetadata;
bool hasLightMetadata = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,11 @@ void CDVDVideoCodecAndroidMediaCodec::ConfigureOutputFormat(CJNIMediaFormat& med
m_videobuffer.iDisplayHeight = ((int)lrint(m_videobuffer.iWidth / m_hints.aspect)) & ~3;
}
}

m_videobuffer.hdrType = m_hints.hdrType;
m_videobuffer.color_space = m_hints.colorSpace;
m_videobuffer.color_primaries = m_hints.colorPrimaries;
m_videobuffer.color_transfer = m_hints.colorTransferCharacteristic;
}

void CDVDVideoCodecAndroidMediaCodec::CallbackInitSurfaceTexture(void *userdata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,8 @@ bool CDVDVideoCodecFFmpeg::GetPictureCommon(VideoPicture* pVideoPicture)
pVideoPicture->qstride = 0;
pVideoPicture->qscale_type = 0;

pVideoPicture->hdrType = m_hints.hdrType;

AVFrameSideData* sd;

// https://github.com/FFmpeg/FFmpeg/blob/991d417692/doc/APIchanges#L18-L20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ bool CRendererMediaCodecSurface::Configure(const VideoPicture &picture, float fp
CalculateFrameAspectRatio(picture.iDisplayWidth, picture.iDisplayHeight);
SetViewMode(m_videoSettings.m_ViewMode);

// Configure GUI/OSD for HDR PQ when display is in HDR PQ mode
if (picture.color_transfer == AVCOL_TRC_SMPTE2084)
{
if (CServiceBroker::GetWinSystem()->IsHDRDisplay())
CServiceBroker::GetWinSystem()->GetGfxContext().SetTransferPQ(true);
}
else if (picture.hdrType == StreamHdrType::HDR_TYPE_DOLBYVISION)
{
if (CServiceBroker::GetWinSystem()->GetDisplayHDRCapabilities().SupportsDolbyVision())
CServiceBroker::GetWinSystem()->GetGfxContext().SetTransferPQ(true);
}

return true;
}

Expand Down Expand Up @@ -130,6 +142,8 @@ void CRendererMediaCodecSurface::Reset()
for (int i = 0 ; i < 4 ; ++i)
ReleaseVideoBuffer(i, false);
m_lastIndex = -1;

CServiceBroker::GetWinSystem()->GetGfxContext().SetTransferPQ(false);
}

void CRendererMediaCodecSurface::RenderUpdate(int index, int index2, bool clear, unsigned int flags, unsigned int alpha)
Expand Down
1 change: 1 addition & 0 deletions xbmc/rendering/RenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class CRenderSystemBase
RENDER_STEREO_VIEW m_stereoView = RENDER_STEREO_VIEW_OFF;
RENDER_STEREO_MODE m_stereoMode = RENDER_STEREO_MODE_OFF;
bool m_limitedColorRange = false;
bool m_transferPQ{false};

std::unique_ptr<CGUIImage> m_splashImage;
std::unique_ptr<CGUITextLayout> m_splashMessageLayout;
Expand Down
4 changes: 4 additions & 0 deletions xbmc/rendering/gles/GLESShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void CGLESShader::OnCompiledAndLinked()
m_hStep = glGetUniformLocation(ProgramHandle(), "m_step");
m_hContrast = glGetUniformLocation(ProgramHandle(), "m_contrast");
m_hBrightness = glGetUniformLocation(ProgramHandle(), "m_brightness");
m_sdrPeak = glGetUniformLocation(ProgramHandle(), "m_sdrPeak");

// Variables passed directly to the Vertex shader
m_hProj = glGetUniformLocation(ProgramHandle(), "m_proj");
Expand Down Expand Up @@ -167,6 +168,9 @@ bool CGLESShader::OnEnabled()
glUniform1f(m_hBrightness, 0.0f);
glUniform1f(m_hContrast, 1.0f);

const float sdrPeak = CServiceBroker::GetWinSystem()->GetGuiSdrPeakLuminance();
glUniform1f(m_sdrPeak, sdrPeak);

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions xbmc/rendering/gles/GLESShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ class CGLESShader : public Shaders::CGLSLShaderProgram
GLfloat m_clipXOffset;
GLfloat m_clipYFactor;
GLfloat m_clipYOffset;

GLfloat m_sdrPeak;
};
16 changes: 12 additions & 4 deletions xbmc/rendering/gles/RenderSystemGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,19 @@ bool CRenderSystemGLES::BeginRender()
if (!m_bRenderCreated)
return false;

bool useLimited = CServiceBroker::GetWinSystem()->UseLimitedColor();
const bool useLimited = CServiceBroker::GetWinSystem()->UseLimitedColor();
const bool usePQ = CServiceBroker::GetWinSystem()->GetGfxContext().IsTransferPQ();

if (m_limitedColorRange != useLimited)
if (m_limitedColorRange != useLimited || m_transferPQ != usePQ)
{
ReleaseShaders();

m_limitedColorRange = useLimited;
m_transferPQ = usePQ;

InitialiseShaders();
}

m_limitedColorRange = useLimited;

return true;
}

Expand Down Expand Up @@ -389,6 +392,11 @@ void CRenderSystemGLES::InitialiseShaders()
defines += "#define KODI_LIMITED_RANGE 1\n";
}

if (m_transferPQ)
{
defines += "#define KODI_TRANSFER_PQ 1\n";
}

m_pShader[ShaderMethodGLES::SM_DEFAULT] =
std::make_unique<CGLESShader>("gles_shader.vert", "gles_shader_default.frag", defines);
if (!m_pShader[ShaderMethodGLES::SM_DEFAULT]->CompileAndLink())
Expand Down
5 changes: 5 additions & 0 deletions xbmc/windowing/GraphicContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class CGraphicContext : public CCriticalSection
const std::string& GetMediaDir() const;
void SetMediaDir(const std::string& strMediaDir);

void SetTransferPQ(bool PQ) { m_isTransferPQ = PQ; }
bool IsTransferPQ() const { return m_isTransferPQ; }

protected:

void UpdateCameraPosition(const CPoint &camera, const float &factor);
Expand Down Expand Up @@ -229,4 +232,6 @@ class CGraphicContext : public CCriticalSection
RENDER_STEREO_VIEW m_stereoView = RENDER_STEREO_VIEW_OFF;
RENDER_STEREO_MODE m_stereoMode = RENDER_STEREO_MODE_OFF;
RENDER_STEREO_MODE m_nextStereoMode = RENDER_STEREO_MODE_OFF;

bool m_isTransferPQ{false};
};
1 change: 1 addition & 0 deletions xbmc/windowing/WinSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class CWinSystemBase
virtual HDR_STATUS GetOSHDRStatus() { return HDR_STATUS::HDR_UNSUPPORTED; }
virtual CHDRCapabilities GetDisplayHDRCapabilities() const { return {}; }
static const char* SETTING_WINSYSTEM_IS_HDR_DISPLAY;
virtual float GetGuiSdrPeakLuminance() const { return .0f; }
virtual bool HasSystemSdrPeakLuminance() { return false; }

/*!
Expand Down
8 changes: 8 additions & 0 deletions xbmc/windowing/android/WinSystemAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,11 @@ CHDRCapabilities CWinSystemAndroid::GetDisplayHDRCapabilities() const
{
return CAndroidUtils::GetDisplayHDRCapabilities();
}

float CWinSystemAndroid::GetGuiSdrPeakLuminance() const
{
const auto settings = CServiceBroker::GetSettingsComponent()->GetSettings();
const int guiSdrPeak = settings->GetInt(CSettings::SETTING_VIDEOSCREEN_GUISDRPEAKLUMINANCE);

return ((0.7f * guiSdrPeak + 30.0f) / 100.0f);
}
1 change: 1 addition & 0 deletions xbmc/windowing/android/WinSystemAndroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CWinSystemAndroid : public CWinSystemBase, public ITimerCallback
bool IsHDRDisplay() override;

CHDRCapabilities GetDisplayHDRCapabilities() const override;
float GetGuiSdrPeakLuminance() const override;

protected:
std::unique_ptr<KODI::WINDOWING::IOSScreenSaver> GetOSScreenSaverImpl() override;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/windowing/win10/WinSystemWin10.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class CWinSystemWin10 : public CWinSystemBase
bool Show(bool raise = true) override;
std::string GetClipboardText() override;
bool UseLimitedColor() override;
float GetGuiSdrPeakLuminance() const override;
bool HasSystemSdrPeakLuminance() override;

// videosync
Expand All @@ -98,7 +99,6 @@ class CWinSystemWin10 : public CWinSystemBase
virtual bool DPIChanged(WORD dpi, RECT windowRect) const;
bool IsMinimized() const { return m_bMinimized; }
void SetMinimized(bool minimized) { m_bMinimized = minimized; }
float GetGuiSdrPeakLuminance() const;
void CacheSystemSdrPeakLuminance();

bool CanDoWindowed() override;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/windowing/windows/WinSystemWin32.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class CWinSystemWin32 : public CWinSystemBase
bool Show(bool raise = true) override;
std::string GetClipboardText() override;
bool UseLimitedColor() override;
float GetGuiSdrPeakLuminance() const override;
bool HasSystemSdrPeakLuminance() override;

// videosync
Expand All @@ -114,7 +115,6 @@ class CWinSystemWin32 : public CWinSystemBase
virtual bool DPIChanged(WORD dpi, RECT windowRect) const;
bool IsMinimized() const { return m_bMinimized; }
void SetMinimized(bool minimized);
float GetGuiSdrPeakLuminance() const;
void CacheSystemSdrPeakLuminance();

void SetSizeMoveMode(bool mode) { m_bSizeMoveEnabled = mode; }
Expand Down

0 comments on commit 8cdb881

Please sign in to comment.