From 836bee21cad8c5259f24972fc2b55f93dc712486 Mon Sep 17 00:00:00 2001
From: Alex Deryskyba <alex@codesnake.com>
Date: Wed, 1 Jul 2015 23:37:11 +0200
Subject: [PATCH 3/6] [aml] Add support for 4k resolutions

Conflicts:
	xbmc/windowing/egl/EGLNativeTypeAmlogic.cpp
---
 xbmc/utils/AMLUtils.cpp                     |   16 +++---
 xbmc/windowing/egl/EGLNativeTypeAmlogic.cpp |   81 +++++++++++++++++++++------
 xbmc/windowing/egl/EGLNativeTypeAmlogic.h   |    2 +
 3 files changed, 73 insertions(+), 26 deletions(-)

diff --git a/xbmc/utils/AMLUtils.cpp b/xbmc/utils/AMLUtils.cpp
index 1b54435..05f2cd0 100644
--- a/xbmc/utils/AMLUtils.cpp
+++ b/xbmc/utils/AMLUtils.cpp
@@ -449,8 +449,8 @@ bool aml_mode_to_resolution(const char *mode, RESOLUTION_INFO *res)
   }
   else if (StringUtils::EqualsNoCase(fromMode, "4k2ksmpte") || StringUtils::EqualsNoCase(fromMode, "smpte24hz"))
   {
-    res->iWidth = 1920;
-    res->iHeight= 1080;
+    res->iWidth = 4096;
+    res->iHeight= 2160;
     res->iScreenWidth = 4096;
     res->iScreenHeight= 2160;
     res->fRefreshRate = 24;
@@ -467,8 +467,8 @@ bool aml_mode_to_resolution(const char *mode, RESOLUTION_INFO *res)
   }
   else if (StringUtils::EqualsNoCase(fromMode, "4k2k24hz") || StringUtils::EqualsNoCase(fromMode, "2160p24hz"))
   {
-    res->iWidth = 1920;
-    res->iHeight= 1080;
+    res->iWidth = 3840;
+    res->iHeight= 2160;
     res->iScreenWidth = 3840;
     res->iScreenHeight= 2160;
     res->fRefreshRate = 24;
@@ -476,8 +476,8 @@ bool aml_mode_to_resolution(const char *mode, RESOLUTION_INFO *res)
   }
   else if (StringUtils::EqualsNoCase(fromMode, "4k2k25hz") || StringUtils::EqualsNoCase(fromMode, "2160p25hz"))
   {
-    res->iWidth = 1920;
-    res->iHeight= 1080;
+    res->iWidth = 3840;
+    res->iHeight= 2160;
     res->iScreenWidth = 3840;
     res->iScreenHeight= 2160;
     res->fRefreshRate = 25;
@@ -494,8 +494,8 @@ bool aml_mode_to_resolution(const char *mode, RESOLUTION_INFO *res)
   }
   else if (StringUtils::EqualsNoCase(fromMode, "4k2k30hz") || StringUtils::EqualsNoCase(fromMode, "2160p30hz"))
   {
-    res->iWidth = 1920;
-    res->iHeight= 1080;
+    res->iWidth = 3840;
+    res->iHeight= 2160;
     res->iScreenWidth = 3840;
     res->iScreenHeight= 2160;
     res->fRefreshRate = 30;
diff --git a/xbmc/windowing/egl/EGLNativeTypeAmlogic.cpp b/xbmc/windowing/egl/EGLNativeTypeAmlogic.cpp
index 21256ef..2103f0b 100644
--- a/xbmc/windowing/egl/EGLNativeTypeAmlogic.cpp
+++ b/xbmc/windowing/egl/EGLNativeTypeAmlogic.cpp
@@ -65,7 +65,22 @@ void CEGLNativeTypeAmlogic::Initialize()
 {
   aml_permissions();
   DisableFreeScale();
+  GetMaxResolution(m_maxResolution);
 }
+
+void CEGLNativeTypeAmlogic::GetMaxResolution(RESOLUTION_INFO &maxResolution)
+{
+  std::vector<RESOLUTION_INFO> resolutions;
+  ProbeResolutions(resolutions);
+
+  maxResolution = {0};
+  for (size_t i = 0; i < resolutions.size(); i++)
+  {
+    if (resolutions[i].iScreenWidth > maxResolution.iScreenWidth || resolutions[i].iScreenHeight > maxResolution.iScreenHeight)
+      maxResolution = resolutions[i];
+  }
+}
+
 void CEGLNativeTypeAmlogic::Destroy()
 {
   return;
@@ -84,8 +99,8 @@ bool CEGLNativeTypeAmlogic::CreateNativeWindow()
   if (!nativeWindow)
     return false;
 
-  nativeWindow->width = 1920;
-  nativeWindow->height = 1080;
+  nativeWindow->width = m_maxResolution.iScreenWidth;
+  nativeWindow->height = m_maxResolution.iScreenHeight;
   m_nativeWindow = nativeWindow;
 
   SetFramebufferResolution(nativeWindow->width, nativeWindow->height);
@@ -280,8 +325,8 @@ void CEGLNativeTypeAmlogic::SetFramebufferResolution(int width, int height) cons
     {
       vinfo.xres = width;
       vinfo.yres = height;
-      vinfo.xres_virtual = 1920;
-      vinfo.yres_virtual = 2160;
+      vinfo.xres_virtual = m_maxResolution.iScreenWidth;
+      vinfo.yres_virtual = m_maxResolution.iScreenHeight * 2;
       vinfo.bits_per_pixel = 32;
       vinfo.activate = FB_ACTIVATE_ALL;
       ioctl(fd0, FBIOPUT_VSCREENINFO, &vinfo);
diff --git a/xbmc/windowing/egl/EGLNativeTypeAmlogic.h b/xbmc/windowing/egl/EGLNativeTypeAmlogic.h
index 6867c38..9ca41d4 100644
--- a/xbmc/windowing/egl/EGLNativeTypeAmlogic.h
+++ b/xbmc/windowing/egl/EGLNativeTypeAmlogic.h
@@ -55,6 +55,8 @@ protected:
 private:
   void SetFramebufferResolution(const RESOLUTION_INFO &res) const;
   void SetFramebufferResolution(int width, int height) const;
+  void GetMaxResolution(RESOLUTION_INFO &maxResolution);
 
   std::string m_framebuffer_name;
+  RESOLUTION_INFO m_maxResolution;
 };
-- 
1.7.10.4

