Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Adjust GUI SRD peak luminance when display is in HDR PQ mode #24756

Merged
merged 1 commit into from Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion system/settings/settings.xml
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
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
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
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
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
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
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
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
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
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
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
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
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);
}
CrystalP marked this conversation as resolved.
Show resolved Hide resolved

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
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
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
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
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
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
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
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
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
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
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