From 6a0368c3894cef146d1a22073eb0104a477d32fe Mon Sep 17 00:00:00 2001
From: Dom Cobley <popcornmix@gmail.com>
Date: Fri, 3 Dec 2021 16:00:50 +0000
Subject: [PATCH 01/13] gbm: Set max bpc for high bit depth videos

---
 .../HwDecRender/VideoLayerBridgeDRMPRIME.cpp      | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/VideoLayerBridgeDRMPRIME.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/VideoLayerBridgeDRMPRIME.cpp
index 34d1ab623559..f1e73ee36474 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/VideoLayerBridgeDRMPRIME.cpp
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/VideoLayerBridgeDRMPRIME.cpp
@@ -34,6 +34,14 @@ void CVideoLayerBridgeDRMPRIME::Disable()
 {
   // disable video plane
   auto plane = m_DRM->GetVideoPlane();
+  auto connector = m_DRM->GetConnector();
+
+  // reset max bpc back to default of 8
+  int bpc = 8;
+  bool result = m_DRM->AddProperty(connector, "max bpc", bpc);
+  CLog::Log(LOGDEBUG, "CVideoLayerBridgeDRMPRIME::{} - setting max bpc to {} ({})",
+            __FUNCTION__, bpc, result);
+
   m_DRM->AddProperty(plane, "FB_ID", 0);
   m_DRM->AddProperty(plane, "CRTC_ID", 0);
 
@@ -175,6 +183,13 @@ void CVideoLayerBridgeDRMPRIME::Configure(CVideoBufferDRMPRIME* buffer)
       plane->GetPropertyValue("COLOR_RANGE", GetColorRange(picture));
   if (colorRange)
     m_DRM->AddProperty(plane, "COLOR_RANGE", colorRange.value());
+
+  // set max bpc to allow the drm driver to choose a deep colour mode
+  int bpc = buffer->GetPicture().colorBits > 8 ? 12 : 8;
+  auto connector = m_DRM->GetConnector();
+  bool result = m_DRM->AddProperty(connector, "max bpc", bpc);
+  CLog::Log(LOGDEBUG, "CVideoLayerBridgeDRMPRIME::{} - setting max bpc to {} ({})", __FUNCTION__,
+            bpc, result);
 }
 
 void CVideoLayerBridgeDRMPRIME::SetVideoPlane(CVideoBufferDRMPRIME* buffer, const CRect& destRect)
-- 
2.39.5

