diff options
author | Chris "Koying" Browet <cbro@semperpax.com> | 2015-04-04 17:20:33 +0200 |
---|---|---|
committer | Chris "Koying" Browet <cbro@semperpax.com> | 2015-04-11 17:33:04 +0200 |
commit | 6169b6ff6039a8efaf8557a6dd432dce5de6b976 (patch) | |
tree | f207ed2f1e48244e4590a37265a43997d3e67c6e | |
parent | 7fe0aa3002be118a954a2c852de04763ece665e3 (diff) |
ADD: [droid;aml+rk] specific aml and rk egl windowing for droid; allows framerate autoswitch
-rw-r--r-- | xbmc/windowing/egl/EGLNativeTypeAmlAndroid.cpp | 186 | ||||
-rw-r--r-- | xbmc/windowing/egl/EGLNativeTypeAmlAndroid.h | 41 | ||||
-rw-r--r-- | xbmc/windowing/egl/EGLNativeTypeRKAndroid.cpp | 235 | ||||
-rw-r--r-- | xbmc/windowing/egl/EGLNativeTypeRKAndroid.h | 42 | ||||
-rw-r--r-- | xbmc/windowing/egl/EGLWrapper.cpp | 5 | ||||
-rw-r--r-- | xbmc/windowing/egl/Makefile.in | 2 |
6 files changed, 511 insertions, 0 deletions
diff --git a/xbmc/windowing/egl/EGLNativeTypeAmlAndroid.cpp b/xbmc/windowing/egl/EGLNativeTypeAmlAndroid.cpp new file mode 100644 index 0000000000..37264f3866 --- /dev/null +++ b/xbmc/windowing/egl/EGLNativeTypeAmlAndroid.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2011-2014 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "system.h" +#include <EGL/egl.h> +#include "EGLNativeTypeAmlAndroid.h" +#include "utils/log.h" +#include "guilib/gui3d.h" +#if defined(TARGET_ANDROID) + #include "android/activity/XBMCApp.h" +#endif +#include "utils/StringUtils.h" +#include "utils/SysfsUtils.h" +#include "utils/AMLUtils.h" + +bool CEGLNativeTypeAmlAndroid::CheckCompatibility() +{ +#if defined(TARGET_ANDROID) + if (aml_present()) + { + if (SysfsUtils::HasRW("/sys/class/display/mode")) + return true; + else + CLog::Log(LOGERROR, "AMLEGL: no rw on /sys/class/display/mode"); + } +#endif + return false; +} + +bool CEGLNativeTypeAmlAndroid::GetNativeResolution(RESOLUTION_INFO *res) const +{ + CEGLNativeTypeAndroid::GetNativeResolution(&m_fb_res); + + std::string mode; + RESOLUTION_INFO hdmi_res; + if (SysfsUtils::GetString("/sys/class/display/mode", mode) == 0 && aml_mode_to_resolution(mode.c_str(), &hdmi_res)) + { + m_curHdmiResolution = mode; + *res = hdmi_res; + res->iWidth = m_fb_res.iWidth; + res->iHeight = m_fb_res.iHeight; + res->iSubtitles = (int)(0.965 * res->iHeight); + } + else + *res = m_fb_res; + + return true; +} + +bool CEGLNativeTypeAmlAndroid::SetNativeResolution(const RESOLUTION_INFO &res) +{ + switch((int)(res.fRefreshRate*10)) + { + default: + case 600: + switch(res.iScreenWidth) + { + default: + case 1280: + return SetDisplayResolution("720p"); + break; + case 1920: + if (res.dwFlags & D3DPRESENTFLAG_INTERLACED) + return SetDisplayResolution("1080i"); + else + return SetDisplayResolution("1080p"); + break; + } + break; + case 500: + switch(res.iScreenWidth) + { + default: + case 1280: + return SetDisplayResolution("720p50hz"); + break; + case 1920: + if (res.dwFlags & D3DPRESENTFLAG_INTERLACED) + return SetDisplayResolution("1080i50hz"); + else + return SetDisplayResolution("1080p50hz"); + break; + } + break; + case 300: + switch(res.iScreenWidth) + { + case 3840: + return SetDisplayResolution("4k2k30hz"); + break; + default: + return SetDisplayResolution("1080p30hz"); + break; + } + break; + case 250: + switch(res.iScreenWidth) + { + case 3840: + return SetDisplayResolution("4k2k25hz"); + break; + default: + return SetDisplayResolution("1080p25hz"); + break; + } + break; + case 240: + switch(res.iScreenWidth) + { + case 3840: + return SetDisplayResolution("4k2k24hz"); + break; + case 4096: + return SetDisplayResolution("4k2ksmpte"); + break; + default: + return SetDisplayResolution("1080p24hz"); + break; + } + break; + } + + return false; +} + +bool CEGLNativeTypeAmlAndroid::ProbeResolutions(std::vector<RESOLUTION_INFO> &resolutions) +{ + CEGLNativeTypeAndroid::GetNativeResolution(&m_fb_res); + + std::string valstr; + if (SysfsUtils::GetString("/sys/class/amhdmitx/amhdmitx0/disp_cap", valstr) < 0) + return false; + std::vector<std::string> probe_str = StringUtils::Split(valstr, "\n"); + + resolutions.clear(); + RESOLUTION_INFO res; + for (size_t i = 0; i < probe_str.size(); i++) + { + if(aml_mode_to_resolution(probe_str[i].c_str(), &res)) + { + res.iWidth = m_fb_res.iWidth; + res.iHeight = m_fb_res.iHeight; + res.iSubtitles = (int)(0.965 * res.iHeight); + resolutions.push_back(res); + } + } + return resolutions.size() > 0; + +} + +bool CEGLNativeTypeAmlAndroid::GetPreferredResolution(RESOLUTION_INFO *res) const +{ + return GetNativeResolution(res); +} + +bool CEGLNativeTypeAmlAndroid::SetDisplayResolution(const char *resolution) +{ + if (m_curHdmiResolution == resolution) + return true; + + // switch display resolution + if (SysfsUtils::SetString("/sys/class/display/mode", resolution) < 0) + return false; + + m_curHdmiResolution = resolution; + + return true; +} + diff --git a/xbmc/windowing/egl/EGLNativeTypeAmlAndroid.h b/xbmc/windowing/egl/EGLNativeTypeAmlAndroid.h new file mode 100644 index 0000000000..27a935ba58 --- /dev/null +++ b/xbmc/windowing/egl/EGLNativeTypeAmlAndroid.h @@ -0,0 +1,41 @@ +#pragma once + +/* + * Copyright (C) 2011-2014 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "EGLNativeTypeAndroid.h" +class CEGLNativeTypeAmlAndroid : public CEGLNativeTypeAndroid +{ +public: + virtual std::string GetNativeName() const { return "amlandroid"; } + virtual bool CheckCompatibility(); + virtual int GetQuirks() { return EGL_QUIRK_DESTROY_NATIVE_WINDOW_WITH_SURFACE; } + + virtual bool GetNativeResolution(RESOLUTION_INFO *res) const; + virtual bool SetNativeResolution(const RESOLUTION_INFO &res); + virtual bool ProbeResolutions(std::vector<RESOLUTION_INFO> &resolutions); + virtual bool GetPreferredResolution(RESOLUTION_INFO *res) const; + +protected: + mutable std::string m_curHdmiResolution; + mutable RESOLUTION_INFO m_fb_res; + + bool SetDisplayResolution(const char *resolution); +}; diff --git a/xbmc/windowing/egl/EGLNativeTypeRKAndroid.cpp b/xbmc/windowing/egl/EGLNativeTypeRKAndroid.cpp new file mode 100644 index 0000000000..dd7ddfb861 --- /dev/null +++ b/xbmc/windowing/egl/EGLNativeTypeRKAndroid.cpp @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2011-2014 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include <stdlib.h> + +#include "system.h" +#include <EGL/egl.h> +#include "EGLNativeTypeRKAndroid.h" +#include "utils/log.h" +#include "guilib/gui3d.h" +#if defined(TARGET_ANDROID) + #include "android/activity/XBMCApp.h" + #include "android/jni/Build.h" +#endif +#include "utils/StringUtils.h" +#include "utils/SysfsUtils.h" +#include "utils/RegExp.h" + +bool CEGLNativeTypeRKAndroid::CheckCompatibility() +{ +#if defined(TARGET_ANDROID) + if (StringUtils::StartsWithNoCase(CJNIBuild::HARDWARE, "rk3")) // Rockchip + { + if (SysfsUtils::HasRW("/sys/class/display/display0.HDMI/mode")) + return true; + else + CLog::Log(LOGERROR, "RKEGL: no rw on /sys/class/display/display0.HDMI/mode"); + } +#endif + return false; +} + +bool CEGLNativeTypeRKAndroid::SysModeToResolution(std::string mode, RESOLUTION_INFO *res) const +{ + if (!res) + return false; + + res->iWidth = 0; + res->iHeight= 0; + + if(mode.empty()) + return false; + + std::string fromMode = mode; + if (!isdigit(mode[0])) + fromMode = StringUtils::Mid(mode, 2); + StringUtils::Trim(fromMode); + + CRegExp split(true); + split.RegComp("([0-9]+)x([0-9]+)([pi])-([0-9]+)"); + if (split.RegFind(fromMode) < 0) + return false; + + int w = atoi(split.GetMatch(1).c_str()); + int h = atoi(split.GetMatch(2).c_str()); + std::string p = split.GetMatch(3); + int r = atoi(split.GetMatch(4).c_str()); + + res->iWidth = w; + res->iHeight= h; + res->iScreenWidth = w; + res->iScreenHeight= h; + res->fRefreshRate = r; + res->dwFlags = p[0] == 'p' ? D3DPRESENTFLAG_PROGRESSIVE : D3DPRESENTFLAG_INTERLACED; + + res->iScreen = 0; + res->bFullScreen = true; + res->iSubtitles = (int)(0.965 * res->iHeight); + res->fPixelRatio = 1.0f; + res->strMode = StringUtils::Format("%dx%d @ %.2f%s - Full Screen", res->iScreenWidth, res->iScreenHeight, res->fRefreshRate, + res->dwFlags & D3DPRESENTFLAG_INTERLACED ? "i" : ""); + res->strId = mode; + + return res->iWidth > 0 && res->iHeight> 0; +} + +bool CEGLNativeTypeRKAndroid::GetNativeResolution(RESOLUTION_INFO *res) const +{ + CEGLNativeTypeAndroid::GetNativeResolution(&m_fb_res); + + std::string mode; + RESOLUTION_INFO hdmi_res; + if (SysfsUtils::GetString("/sys/class/display/display0.HDMI/mode", mode) == 0 && SysModeToResolution(mode, &hdmi_res)) + { + m_curHdmiResolution = mode; + *res = hdmi_res; + res->iWidth = m_fb_res.iWidth; + res->iHeight = m_fb_res.iHeight; + res->iSubtitles = (int)(0.965 * res->iHeight); + } + else + *res = m_fb_res; + + return true; +} + +bool CEGLNativeTypeRKAndroid::SetNativeResolution(const RESOLUTION_INFO &res) +{ + switch((int)(res.fRefreshRate*10)) + { + default: + case 600: + switch(res.iScreenWidth) + { + default: + case 1280: + return SetDisplayResolution("1280x720p-60"); + break; + case 1920: + if (res.dwFlags & D3DPRESENTFLAG_INTERLACED) + return SetDisplayResolution("1920x1080i-60"); + else + return SetDisplayResolution("1920x1080p-60"); + break; + } + break; + case 500: + switch(res.iScreenWidth) + { + default: + case 1280: + return SetDisplayResolution("1280x720p-50"); + break; + case 1920: + if (res.dwFlags & D3DPRESENTFLAG_INTERLACED) + return SetDisplayResolution("1920x1080i-50"); + else + return SetDisplayResolution("1920x1080p-50"); + break; + } + break; + case 300: + switch(res.iScreenWidth) + { + case 3840: + return SetDisplayResolution("4k2k30hz"); + break; + default: + return SetDisplayResolution("1920x1080p-30"); + break; + } + break; + case 250: + switch(res.iScreenWidth) + { + case 3840: + return SetDisplayResolution("4k2k25hz"); + break; + default: + return SetDisplayResolution("1920x1080p-25"); + break; + } + break; + case 240: + switch(res.iScreenWidth) + { + case 3840: + return SetDisplayResolution("4k2k24hz"); + break; + case 4096: + return SetDisplayResolution("4k2ksmpte"); + break; + default: + return SetDisplayResolution("1920x1080p-24"); + break; + } + break; + } + + return false; +} + +bool CEGLNativeTypeRKAndroid::ProbeResolutions(std::vector<RESOLUTION_INFO> &resolutions) +{ + CEGLNativeTypeAndroid::GetNativeResolution(&m_fb_res); + + std::string valstr; + if (SysfsUtils::GetString("/sys/class/display/display0.HDMI/modes", valstr) < 0) + return false; + std::vector<std::string> probe_str = StringUtils::Split(valstr, "\n"); + + resolutions.clear(); + RESOLUTION_INFO res; + for (size_t i = 0; i < probe_str.size(); i++) + { + if(SysModeToResolution(probe_str[i].c_str(), &res)) + { + res.iWidth = m_fb_res.iWidth; + res.iHeight = m_fb_res.iHeight; + res.iSubtitles = (int)(0.965 * res.iHeight); + resolutions.push_back(res); + } + } + return resolutions.size() > 0; + +} + +bool CEGLNativeTypeRKAndroid::GetPreferredResolution(RESOLUTION_INFO *res) const +{ + return GetNativeResolution(res); +} + +bool CEGLNativeTypeRKAndroid::SetDisplayResolution(const char *resolution) +{ + if (m_curHdmiResolution == resolution) + return true; + + // switch display resolution + std::string out = resolution; + out += '\n'; + if (SysfsUtils::SetString("/sys/class/display/display0.HDMI/mode", out.c_str()) < 0) + return false; + + m_curHdmiResolution = resolution; + + return true; +} + diff --git a/xbmc/windowing/egl/EGLNativeTypeRKAndroid.h b/xbmc/windowing/egl/EGLNativeTypeRKAndroid.h new file mode 100644 index 0000000000..69baaed48e --- /dev/null +++ b/xbmc/windowing/egl/EGLNativeTypeRKAndroid.h @@ -0,0 +1,42 @@ +#pragma once + +/* + * Copyright (C) 2011-2014 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + */ + +#include "EGLNativeTypeAndroid.h" +class CEGLNativeTypeRKAndroid : public CEGLNativeTypeAndroid +{ +public: + virtual std::string GetNativeName() const { return "rkandroid"; } + virtual bool CheckCompatibility(); + virtual int GetQuirks() { return EGL_QUIRK_DESTROY_NATIVE_WINDOW_WITH_SURFACE; } + + virtual bool GetNativeResolution(RESOLUTION_INFO *res) const; + virtual bool SetNativeResolution(const RESOLUTION_INFO &res); + virtual bool ProbeResolutions(std::vector<RESOLUTION_INFO> &resolutions); + virtual bool GetPreferredResolution(RESOLUTION_INFO *res) const; + +protected: + mutable std::string m_curHdmiResolution; + mutable RESOLUTION_INFO m_fb_res; + + bool SetDisplayResolution(const char *resolution); + bool SysModeToResolution(std::string mode, RESOLUTION_INFO *res) const; +}; diff --git a/xbmc/windowing/egl/EGLWrapper.cpp b/xbmc/windowing/egl/EGLWrapper.cpp index 8310d4b0ff..7e32772874 100644 --- a/xbmc/windowing/egl/EGLWrapper.cpp +++ b/xbmc/windowing/egl/EGLWrapper.cpp @@ -21,7 +21,10 @@ #ifdef HAS_EGL #include "utils/log.h" +#include <assert.h> #include "EGLNativeTypeAndroid.h" +#include "EGLNativeTypeAmlAndroid.h" +#include "EGLNativeTypeRKAndroid.h" #include "EGLNativeTypeAmlogic.h" #include "EGLNativeTypeRaspberryPI.h" #include "EGLNativeTypeWayland.h" @@ -80,6 +83,8 @@ bool CEGLWrapper::Initialize(const std::string &implementation) // Try to create each backend in sequence and go with the first one // that we know will work if ((nativeGuess = CreateEGLNativeType<CEGLNativeTypeWayland>(implementation)) || + (nativeGuess = CreateEGLNativeType<CEGLNativeTypeAmlAndroid>(implementation)) || + (nativeGuess = CreateEGLNativeType<CEGLNativeTypeRKAndroid>(implementation)) || (nativeGuess = CreateEGLNativeType<CEGLNativeTypeAndroid>(implementation)) || (nativeGuess = CreateEGLNativeType<CEGLNativeTypeAmlogic>(implementation)) || (nativeGuess = CreateEGLNativeType<CEGLNativeTypeRaspberryPI>(implementation)) || diff --git a/xbmc/windowing/egl/Makefile.in b/xbmc/windowing/egl/Makefile.in index f59f9cb7f9..aefeb568a7 100644 --- a/xbmc/windowing/egl/Makefile.in +++ b/xbmc/windowing/egl/Makefile.in @@ -3,6 +3,8 @@ INCLUDES=-I. SRCS = WinSystemEGL.cpp SRCS+= EGLNativeTypeAmlogic.cpp SRCS+= EGLNativeTypeAndroid.cpp +SRCS+= EGLNativeTypeAmlAndroid.cpp +SRCS+= EGLNativeTypeRKAndroid.cpp SRCS+= EGLNativeTypeRaspberryPI.cpp SRCS+= EGLNativeTypeWayland.cpp SRCS+= EGLNativeTypeIMX.cpp |