Optimized getPresentInterval

TRAC #12180 Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@252 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent d091b198
...@@ -26,7 +26,10 @@ Display::Display(HDC deviceContext) : mDc(deviceContext) ...@@ -26,7 +26,10 @@ Display::Display(HDC deviceContext) : mDc(deviceContext)
mAdapter = D3DADAPTER_DEFAULT; mAdapter = D3DADAPTER_DEFAULT;
mDeviceType = D3DDEVTYPE_HAL; mDeviceType = D3DDEVTYPE_HAL;
mSwapInterval = 1;
mMinSwapInterval = 1;
mMaxSwapInterval = 1;
setSwapInterval(1);
} }
Display::~Display() Display::~Display()
...@@ -65,14 +68,14 @@ bool Display::initialize() ...@@ -65,14 +68,14 @@ bool Display::initialize()
} }
else else
{ {
EGLint minSwapInterval = 4; mMinSwapInterval = 4;
EGLint maxSwapInterval = 0; mMaxSwapInterval = 0;
if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) {minSwapInterval = std::min(minSwapInterval, 0); maxSwapInterval = std::max(maxSwapInterval, 0);} if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) {mMinSwapInterval = std::min(mMinSwapInterval, 0); mMaxSwapInterval = std::max(mMaxSwapInterval, 0);}
if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) {minSwapInterval = std::min(minSwapInterval, 1); maxSwapInterval = std::max(maxSwapInterval, 1);} if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE) {mMinSwapInterval = std::min(mMinSwapInterval, 1); mMaxSwapInterval = std::max(mMaxSwapInterval, 1);}
if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) {minSwapInterval = std::min(minSwapInterval, 2); maxSwapInterval = std::max(maxSwapInterval, 2);} if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) {mMinSwapInterval = std::min(mMinSwapInterval, 2); mMaxSwapInterval = std::max(mMaxSwapInterval, 2);}
if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_THREE) {minSwapInterval = std::min(minSwapInterval, 3); maxSwapInterval = std::max(maxSwapInterval, 3);} if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_THREE) {mMinSwapInterval = std::min(mMinSwapInterval, 3); mMaxSwapInterval = std::max(mMaxSwapInterval, 3);}
if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_FOUR) {minSwapInterval = std::min(minSwapInterval, 4); maxSwapInterval = std::max(maxSwapInterval, 4);} if (caps.PresentationIntervals & D3DPRESENT_INTERVAL_FOUR) {mMinSwapInterval = std::min(mMinSwapInterval, 4); mMaxSwapInterval = std::max(mMaxSwapInterval, 4);}
const D3DFORMAT renderTargetFormats[] = const D3DFORMAT renderTargetFormats[] =
{ {
...@@ -121,7 +124,7 @@ bool Display::initialize() ...@@ -121,7 +124,7 @@ bool Display::initialize()
{ {
// FIXME: Enumerate multi-sampling // FIXME: Enumerate multi-sampling
mConfigSet.add(currentDisplayMode, minSwapInterval, maxSwapInterval, renderTargetFormat, depthStencilFormat, 0); mConfigSet.add(currentDisplayMode, mMinSwapInterval, mMaxSwapInterval, renderTargetFormat, depthStencilFormat, 0);
} }
} }
} }
...@@ -250,7 +253,7 @@ Surface *Display::createWindowSurface(HWND window, EGLConfig config) ...@@ -250,7 +253,7 @@ Surface *Display::createWindowSurface(HWND window, EGLConfig config)
presentParameters.hDeviceWindow = window; presentParameters.hDeviceWindow = window;
presentParameters.MultiSampleQuality = 0; // FIXME: Unimplemented presentParameters.MultiSampleQuality = 0; // FIXME: Unimplemented
presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; // FIXME: Unimplemented presentParameters.MultiSampleType = D3DMULTISAMPLE_NONE; // FIXME: Unimplemented
presentParameters.PresentationInterval = getPresentInterval(configuration, true); presentParameters.PresentationInterval = convertInterval(mMinSwapInterval);
presentParameters.SwapEffect = D3DSWAPEFFECT_COPY; presentParameters.SwapEffect = D3DSWAPEFFECT_COPY;
presentParameters.Windowed = TRUE; // FIXME presentParameters.Windowed = TRUE; // FIXME
...@@ -413,14 +416,19 @@ bool Display::hasExistingWindowSurface(HWND window) ...@@ -413,14 +416,19 @@ bool Display::hasExistingWindowSurface(HWND window)
void Display::setSwapInterval(GLint interval) void Display::setSwapInterval(GLint interval)
{ {
mSwapInterval = interval; mSwapInterval = interval;
mSwapInterval = std::max(mSwapInterval, mMinSwapInterval);
mSwapInterval = std::min(mSwapInterval, mMaxSwapInterval);
mPresentInterval = convertInterval(mSwapInterval);
} }
DWORD Display::getPresentInterval(const egl::Config *config, bool maximumRate) DWORD Display::getPresentInterval()
{ {
GLint interval = maximumRate ? 0 : mSwapInterval; return mPresentInterval;
interval = interval < config->mMinSwapInterval ? config->mMinSwapInterval : interval; }
interval = interval > config->mMaxSwapInterval ? config->mMaxSwapInterval : interval;
DWORD Display::convertInterval(GLint interval)
{
switch(interval) switch(interval)
{ {
case 0: return D3DPRESENT_INTERVAL_IMMEDIATE; case 0: return D3DPRESENT_INTERVAL_IMMEDIATE;
......
...@@ -55,7 +55,8 @@ class Display ...@@ -55,7 +55,8 @@ class Display
bool hasExistingWindowSurface(HWND window); bool hasExistingWindowSurface(HWND window);
void setSwapInterval(GLint interval); void setSwapInterval(GLint interval);
DWORD getPresentInterval(const egl::Config *config, bool maximumRate); DWORD getPresentInterval();
static DWORD convertInterval(GLint interval);
virtual IDirect3DDevice9 *getDevice(); virtual IDirect3DDevice9 *getDevice();
...@@ -70,6 +71,9 @@ class Display ...@@ -70,6 +71,9 @@ class Display
bool mSceneStarted; bool mSceneStarted;
GLint mSwapInterval; GLint mSwapInterval;
EGLint mMaxSwapInterval;
EGLint mMinSwapInterval;
DWORD mPresentInterval;
typedef std::set<Surface*> SurfaceSet; typedef std::set<Surface*> SurfaceSet;
SurfaceSet mSurfaceSet; SurfaceSet mSurfaceSet;
......
...@@ -151,7 +151,7 @@ void Surface::swap() ...@@ -151,7 +151,7 @@ void Surface::swap()
texture->Release(); texture->Release();
mDisplay->endScene(); mDisplay->endScene();
result = mSwapChain->Present(NULL, NULL, NULL, NULL, mDisplay->getPresentInterval(mConfig, false)); result = mSwapChain->Present(NULL, NULL, NULL, NULL, mDisplay->getPresentInterval());
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DRIVERINTERNALERROR) if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DRIVERINTERNALERROR)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment