Skip to content

Commit

Permalink
DisplayMode: Prefer to keep the refresh rate near the original rate
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 22, 2012
1 parent 8bd9331 commit b6a71b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions doomsday/engine/portable/src/canvas.cpp
Expand Up @@ -2,6 +2,9 @@
* @file canvas.cpp
* OpenGL drawing surface implementation. @ingroup gl
*
* @todo Merge mouse_qt.c with this source file since the mouse tracking
* functionality is implemented here.
*
* @authors Copyright (c) 2012 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
Expand Down
22 changes: 17 additions & 5 deletions doomsday/engine/portable/src/displaymode.cpp
Expand Up @@ -57,6 +57,8 @@ static bool reduce(int& ratioX, int& ratioY)
}
#endif

static float differenceToOriginalHz(float hz);

struct Mode : public DisplayMode
{
Mode()
Expand Down Expand Up @@ -102,8 +104,8 @@ struct Mode : public DisplayMode
{
if(depth == b.depth)
{
// Biggest refresh rate first.
return refreshRate > b.refreshRate;
// The refresh rate that more closely matches the original is preferable.
return differenceToOriginalHz(refreshRate) < differenceToOriginalHz(b.refreshRate);
}
return depth < b.depth;
}
Expand Down Expand Up @@ -163,25 +165,31 @@ struct Mode : public DisplayMode
}
};

typedef std::set<Mode> Modes;
typedef std::set<Mode> Modes; // note: no duplicates
static Modes modes;
static Mode originalMode;
static bool captured;

static float differenceToOriginalHz(float hz)
{
return qAbs(hz - originalMode.refreshRate);
}

int DisplayMode_Init(void)
{
if(inited) return true;

captured = false;
DisplayMode_Native_Init();

// This is used for sorting the mode set (Hz).
originalMode = Mode::fromCurrent();

for(int i = 0; i < DisplayMode_Native_Count(); ++i)
{
modes.insert(Mode(i));
}

originalMode = Mode::fromCurrent();

#ifdef _DEBUG
qDebug() << "Current mode is:";
originalMode.debugPrint();
Expand Down Expand Up @@ -265,6 +273,10 @@ const DisplayMode* DisplayMode_FindClosest(int width, int height, int depth, flo
score += squared(i->refreshRate - freq);
}

// Note: The first mode to hit the lowest score wins; if there are many modes
// with the same score, the first one will be chosen. Particularly if the
// frequency has not been specified, the sort order of the modes defines which
// one is picked.
if(!best || score < bestScore)
{
/*
Expand Down

0 comments on commit b6a71b4

Please sign in to comment.