Navigation Menu

Skip to content

Commit

Permalink
native resolution
Browse files Browse the repository at this point in the history
From adam-aph pull xbmc#1096
Rebased to master with appropriate code change
Removed AdvancedSettings and move them to a struct with sensible
defaults
  • Loading branch information
Cedric Girard authored and popcornmix committed Feb 4, 2015
1 parent 9e6e9c6 commit 7bba547
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 1 deletion.
109 changes: 108 additions & 1 deletion xbmc/cores/VideoRenderers/BaseRenderer.cpp
Expand Up @@ -41,12 +41,27 @@ CBaseRenderer::CBaseRenderer()
m_sourceWidth = 720;
m_sourceHeight = 480;
m_resolution = RES_DESKTOP;
m_bestResolution = m_resolution;
m_fps = 0.0f;
m_renderOrientation = 0;
m_oldRenderOrientation = 0;
m_oldDestRect.SetRect(0.0f, 0.0f, 0.0f, 0.0f);
m_iFlags = 0;

m_nativeUpscaleSettings =
{
true, //NativeUpscaleMode
true, //OverrideFPS
false, //CorrectPixelRatio
1920, //DestWidth
1080, //DestHeight
0, //MinWidth
0, //MinHeight
1920, //MaxWidth
1080,//MaxHeight
};


for(int i=0; i < 4; i++)
{
m_rotatedDestCoords[i].x = 0;
Expand Down Expand Up @@ -99,6 +114,72 @@ void CBaseRenderer::ChooseBestResolution(float fps)
#endif
CLog::Log(LOGNOTICE, "Display resolution %s : %s (%d)",
m_resolution == RES_DESKTOP ? "DESKTOP" : "USER", g_graphicsContext.GetResInfo(m_resolution).strMode.c_str(), m_resolution);

m_bestResolution = m_resolution; // save it
int iNatW = (int)m_sourceWidth;
int iNatH = (int)m_sourceHeight;

if( m_nativeUpscaleSettings.MaxWidth && iNatW > m_nativeUpscaleSettings.MaxWidth )
iNatW = 0;

if( m_nativeUpscaleSettings.MaxHeight && iNatH > m_nativeUpscaleSettings.MaxHeight )
iNatH = 0;

if( m_nativeUpscaleSettings.NativeUpscaleMode && iNatW && iNatH ) // Native Upscale Mode
{
CLog::Log(LOGNOTICE, "Searching for NATIVE resolution: %dx%d", m_sourceWidth, m_sourceHeight);

RESOLUTION_INFO org = g_graphicsContext.GetResInfo(m_resolution);

bool bOverrideFPS = m_nativeUpscaleSettings.OverrideFPS;
double nfRD, fRD, fD, fODist = 100000000.0;
int iWD, iHD;
float fOrgRefreshRate = org.fRefreshRate;
int iOrgScreen = org.iScreen;

if(iNatW <= m_nativeUpscaleSettings.MinWidth &&
iNatH <= m_nativeUpscaleSettings.MinHeight)
{
iNatW = m_nativeUpscaleSettings.MinWidth;
iNatH = m_nativeUpscaleSettings.MinHeight;
}

// best fit
for (size_t i = (int)RES_DESKTOP; i < CDisplaySettings::Get().ResolutionInfoSize(); i++)
{
const RESOLUTION_INFO info = g_graphicsContext.GetResInfo((RESOLUTION)i);
fRD = info.fRefreshRate - fOrgRefreshRate; // refreshrate delta
nfRD = info.fRefreshRate / fOrgRefreshRate; // refreshrate fit
iWD = info.iWidth - iNatW; // width delta
iHD = info.iHeight - iNatH; // height delta
// distance function:
// refreshrate, witdh and height deltas are multiplied by weight factors
// current weights values do not prefer any parameter (well, almost...)
// so we will search for lowest width, height and refresh rate which fit to the source parameters
// however if any of these parameters need to be preferred, bump up the weight value for it
fD = (iWD * 1.0) + (iHD * 1.0); // default weights for width and height resolution

if (!bOverrideFPS)
{ // if original fps should be preserved, accept only these
fRD = (fRD == 0.0) ? (0.0) : (-1.0); // resolutions where refreshrate is the same
}
else
{ // preferred multiple fps
fD += fRD + ( (abs(nfRD-floor(nfRD+0.5)) < 1e-6) ? 10.0 : 1000.0 );
}

if( fRD >= 0.0 && iWD >= 0 && iHD >= 0 && fD <= fODist &&
info.iScreen == iOrgScreen )
{
m_resolution = (RESOLUTION)i; // if we are here, then this resolution is closer to
fODist = fD; // the source parameters than previous one
}
}

CLog::Log(LOGNOTICE, "Display resolution ADJUST2 : %s (%d)",
org.strMode.c_str(), m_resolution);
}

}

bool CBaseRenderer::FindResolutionFromOverride(float fps, float& weight, bool fallback)
Expand Down Expand Up @@ -619,10 +700,12 @@ void CBaseRenderer::ManageDisplay()

void CBaseRenderer::SetViewMode(int viewMode)
{
int savedViewMode;

if (viewMode < ViewModeNormal || viewMode > ViewModeCustom)
viewMode = ViewModeNormal;

CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode = viewMode;
CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode = savedViewMode = viewMode;

// get our calibrated full screen resolution
RESOLUTION res = GetResolution();
Expand All @@ -633,6 +716,27 @@ void CBaseRenderer::SetViewMode(int viewMode)
// and the source frame ratio
float sourceFrameRatio = GetAspectRatio();

// if we upscale via external AVR device, correct the pixel ratio
if( m_nativeUpscaleSettings.NativeUpscaleMode && m_bestResolution != m_resolution
&& m_nativeUpscaleSettings.CorrectPixelRatio )
{
float destWidth = (float)(m_nativeUpscaleSettings.DestWidth);
float destHeight = (float)(m_nativeUpscaleSettings.DestHeight);
float destFrameRatio = (float)destWidth / destHeight;
bool destScreenIs43 = (destFrameRatio < 8.f/(3.f*sqrt(3.f))); // final output
float outWidth = (float)(info.iWidth);
float outHeight = (float)(info.iHeight);
float outFrameRatio = (float)outWidth / outHeight;
bool outScreenIs43 = (outFrameRatio < 8.f/(3.f*sqrt(3.f))); // xbmc output

if( outScreenIs43 && !destScreenIs43 ) // final output is 16x9
viewMode = ViewModeStretch16x9;
else if( !outScreenIs43 && destScreenIs43 ) // final output is 4x3
viewMode = ViewModeStretch4x3;

CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode = viewMode;
}

bool is43 = (sourceFrameRatio < 8.f/(3.f*sqrt(3.f)) &&
CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode == ViewModeNormal);

Expand Down Expand Up @@ -729,6 +833,9 @@ void CBaseRenderer::SetViewMode(int viewMode)
CDisplaySettings::Get().SetZoomAmount(1.0);
}

// restore original view mode
CMediaSettings::Get().GetCurrentVideoSettings().m_ViewMode = savedViewMode;

CMediaSettings::Get().GetCurrentVideoSettings().m_CustomZoomAmount = CDisplaySettings::Get().GetZoomAmount();
CMediaSettings::Get().GetCurrentVideoSettings().m_CustomPixelRatio = CDisplaySettings::Get().GetPixelRatio();
CMediaSettings::Get().GetCurrentVideoSettings().m_CustomNonLinStretch = CDisplaySettings::Get().IsNonLinearStretched();
Expand Down
17 changes: 17 additions & 0 deletions xbmc/cores/VideoRenderers/BaseRenderer.h
Expand Up @@ -72,6 +72,20 @@ typedef void (*RenderFeaturesCallBackFn)(const void *ctx, Features &renderFeatur

struct DVDVideoPicture;

typedef struct NativeUpscale
{
bool NativeUpscaleMode;
bool OverrideFPS;
bool CorrectPixelRatio;
int DestWidth;
int DestHeight;
int MinWidth;
int MinHeight;
int MaxWidth;
int MaxHeight;
} NativeUpscale;


class CBaseRenderer
{
public:
Expand Down Expand Up @@ -123,11 +137,14 @@ class CBaseRenderer
void MarkDirty();

RESOLUTION m_resolution; // the resolution we're running in
RESOLUTION m_bestResolution; // the preferred resolution
unsigned int m_sourceWidth;
unsigned int m_sourceHeight;
float m_sourceFrameRatio;
float m_fps;

NativeUpscale m_nativeUpscaleSettings;

unsigned int m_renderOrientation; // orientation of the video in degress counter clockwise
unsigned int m_oldRenderOrientation; // orientation of the previous frame
// for drawing the texture with glVertex4f (holds all 4 corner points of the destination rect
Expand Down

0 comments on commit 7bba547

Please sign in to comment.