Notify the display of a lost device and mark all contexts lost.

TRAC #18606 Signed-off-by: Daniel Koch Author: Shannon Woods git-svn-id: https://angleproject.googlecode.com/svn/trunk@845 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 6f5c5fc0
...@@ -88,6 +88,7 @@ Display::Display(EGLNativeDisplayType displayId, HDC deviceContext, bool softwar ...@@ -88,6 +88,7 @@ Display::Display(EGLNativeDisplayType displayId, HDC deviceContext, bool softwar
mMaxSwapInterval = 1; mMaxSwapInterval = 1;
mSoftwareDevice = software; mSoftwareDevice = software;
mDisplayId = displayId; mDisplayId = displayId;
mDeviceLost = false;
} }
Display::~Display() Display::~Display()
...@@ -304,7 +305,7 @@ void Display::terminate() ...@@ -304,7 +305,7 @@ void Display::terminate()
if (mDevice) if (mDevice)
{ {
// If the device is lost, reset it first to prevent leaving the driver in an unstable state // If the device is lost, reset it first to prevent leaving the driver in an unstable state
if (isDeviceLost()) if (testDeviceLost())
{ {
resetDevice(); resetDevice();
} }
...@@ -459,7 +460,7 @@ bool Display::resetDevice() ...@@ -459,7 +460,7 @@ bool Display::resetDevice()
D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters(); D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters();
HRESULT result = D3D_OK; HRESULT result = D3D_OK;
bool lost = isDeviceLost(); bool lost = testDeviceLost();
int attempts = 3; int attempts = 3;
while (lost && attempts > 0) while (lost && attempts > 0)
...@@ -485,7 +486,7 @@ bool Display::resetDevice() ...@@ -485,7 +486,7 @@ bool Display::resetDevice()
} }
} }
lost = isDeviceLost(); lost = testDeviceLost();
attempts --; attempts --;
} }
...@@ -536,7 +537,7 @@ EGLSurface Display::createWindowSurface(HWND window, EGLConfig config, const EGL ...@@ -536,7 +537,7 @@ EGLSurface Display::createWindowSurface(HWND window, EGLConfig config, const EGL
return error(EGL_BAD_ALLOC, EGL_NO_SURFACE); return error(EGL_BAD_ALLOC, EGL_NO_SURFACE);
} }
if (isDeviceLost()) { if (testDeviceLost()) {
if (!restoreLostDevice()) if (!restoreLostDevice())
return EGL_NO_SURFACE; return EGL_NO_SURFACE;
} }
...@@ -648,7 +649,7 @@ EGLSurface Display::createOffscreenSurface(EGLConfig config, HANDLE shareHandle, ...@@ -648,7 +649,7 @@ EGLSurface Display::createOffscreenSurface(EGLConfig config, HANDLE shareHandle,
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
} }
if (isDeviceLost()) { if (testDeviceLost()) {
if (!restoreLostDevice()) if (!restoreLostDevice())
return EGL_NO_SURFACE; return EGL_NO_SURFACE;
} }
...@@ -675,7 +676,7 @@ EGLContext Display::createContext(EGLConfig configHandle, const gl::Context *sha ...@@ -675,7 +676,7 @@ EGLContext Display::createContext(EGLConfig configHandle, const gl::Context *sha
return NULL; return NULL;
} }
} }
else if (isDeviceLost()) // Lost device else if (testDeviceLost()) // Lost device
{ {
if (!restoreLostDevice()) if (!restoreLostDevice())
return NULL; return NULL;
...@@ -685,6 +686,7 @@ EGLContext Display::createContext(EGLConfig configHandle, const gl::Context *sha ...@@ -685,6 +686,7 @@ EGLContext Display::createContext(EGLConfig configHandle, const gl::Context *sha
gl::Context *context = glCreateContext(config, shareContext); gl::Context *context = glCreateContext(config, shareContext);
mContextSet.insert(context); mContextSet.insert(context);
mDeviceLost = false;
return context; return context;
} }
...@@ -724,6 +726,21 @@ void Display::destroyContext(gl::Context *context) ...@@ -724,6 +726,21 @@ void Display::destroyContext(gl::Context *context)
mContextSet.erase(context); mContextSet.erase(context);
} }
void Display::notifyDeviceLost()
{
for (ContextSet::iterator context = mContextSet.begin(); context != mContextSet.end(); context++)
{
(*context)->markContextLost();
}
mDeviceLost = true;
error(EGL_CONTEXT_LOST);
}
bool Display::isDeviceLost()
{
return mDeviceLost;
}
bool Display::isInitialized() const bool Display::isInitialized() const
{ {
return mD3d9 != NULL && mConfigSet.size() > 0; return mD3d9 != NULL && mConfigSet.size() > 0;
...@@ -790,7 +807,7 @@ D3DADAPTER_IDENTIFIER9 *Display::getAdapterIdentifier() ...@@ -790,7 +807,7 @@ D3DADAPTER_IDENTIFIER9 *Display::getAdapterIdentifier()
return &mAdapterIdentifier; return &mAdapterIdentifier;
} }
bool Display::isDeviceLost() bool Display::testDeviceLost()
{ {
if (mDeviceEx) if (mDeviceEx)
{ {
......
...@@ -61,7 +61,7 @@ class Display ...@@ -61,7 +61,7 @@ class Display
virtual IDirect3DDevice9 *getDevice(); virtual IDirect3DDevice9 *getDevice();
virtual D3DCAPS9 getDeviceCaps(); virtual D3DCAPS9 getDeviceCaps();
virtual D3DADAPTER_IDENTIFIER9 *getAdapterIdentifier(); virtual D3DADAPTER_IDENTIFIER9 *getAdapterIdentifier();
bool isDeviceLost(); bool testDeviceLost();
virtual void getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray); virtual void getMultiSampleSupport(D3DFORMAT format, bool *multiSampleArray);
virtual bool getDXT1TextureSupport(); virtual bool getDXT1TextureSupport();
virtual bool getDXT3TextureSupport(); virtual bool getDXT3TextureSupport();
...@@ -75,6 +75,9 @@ class Display ...@@ -75,6 +75,9 @@ class Display
virtual bool getNonPower2TextureSupport() const; virtual bool getNonPower2TextureSupport() const;
virtual D3DPOOL getBufferPool(DWORD usage) const; virtual D3DPOOL getBufferPool(DWORD usage) const;
virtual void notifyDeviceLost();
bool isDeviceLost();
bool isD3d9ExDevice() { return mD3d9Ex != NULL; } bool isD3d9ExDevice() { return mD3d9Ex != NULL; }
const char *getExtensionString() const; const char *getExtensionString() const;
...@@ -114,6 +117,7 @@ class Display ...@@ -114,6 +117,7 @@ class Display
typedef std::set<gl::Context*> ContextSet; typedef std::set<gl::Context*> ContextSet;
ContextSet mContextSet; ContextSet mContextSet;
bool mDeviceLost;
bool createDevice(); bool createDevice();
bool resetDevice(); bool resetDevice();
......
...@@ -257,7 +257,8 @@ bool Surface::resetSwapChain(int backbufferWidth, int backbufferHeight) ...@@ -257,7 +257,8 @@ bool Surface::resetSwapChain(int backbufferWidth, int backbufferHeight)
if(isDeviceLostError(result)) if(isDeviceLostError(result))
{ {
return error(EGL_CONTEXT_LOST, false); mDisplay->notifyDeviceLost();
return false;
} }
else else
{ {
...@@ -428,7 +429,8 @@ bool Surface::swap() ...@@ -428,7 +429,8 @@ bool Surface::swap()
if (isDeviceLostError(result)) if (isDeviceLostError(result))
{ {
return error(EGL_CONTEXT_LOST, false); mDisplay->notifyDeviceLost();
return false;
} }
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
......
...@@ -895,7 +895,13 @@ EGLBoolean __stdcall eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface ...@@ -895,7 +895,13 @@ EGLBoolean __stdcall eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface
gl::Context *context = static_cast<gl::Context*>(ctx); gl::Context *context = static_cast<gl::Context*>(ctx);
IDirect3DDevice9 *device = display->getDevice(); IDirect3DDevice9 *device = display->getDevice();
if (!device || display->isDeviceLost()) if (!device || display->testDeviceLost())
{
display->notifyDeviceLost();
return EGL_FALSE;
}
if (display->isDeviceLost())
{ {
return error(EGL_CONTEXT_LOST, EGL_FALSE); return error(EGL_CONTEXT_LOST, EGL_FALSE);
} }
...@@ -1077,6 +1083,11 @@ EGLBoolean __stdcall eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) ...@@ -1077,6 +1083,11 @@ EGLBoolean __stdcall eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
return EGL_FALSE; return EGL_FALSE;
} }
if (display->isDeviceLost())
{
return error(EGL_CONTEXT_LOST, EGL_FALSE);
}
if (surface == EGL_NO_SURFACE) if (surface == EGL_NO_SURFACE)
{ {
return error(EGL_BAD_SURFACE, EGL_FALSE); return error(EGL_BAD_SURFACE, EGL_FALSE);
...@@ -1109,6 +1120,11 @@ EGLBoolean __stdcall eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativ ...@@ -1109,6 +1120,11 @@ EGLBoolean __stdcall eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativ
return EGL_FALSE; return EGL_FALSE;
} }
if (display->isDeviceLost())
{
return error(EGL_CONTEXT_LOST, EGL_FALSE);
}
UNIMPLEMENTED(); // FIXME UNIMPLEMENTED(); // FIXME
return success(0); return success(0);
......
...@@ -158,6 +158,7 @@ Context::Context(const egl::Config *config, const gl::Context *shareContext) : m ...@@ -158,6 +158,7 @@ Context::Context(const egl::Config *config, const gl::Context *shareContext) : m
mInvalidFramebufferOperation = false; mInvalidFramebufferOperation = false;
mHasBeenCurrent = false; mHasBeenCurrent = false;
mContextLost = false;
mSupportsDXT1Textures = false; mSupportsDXT1Textures = false;
mSupportsDXT3Textures = false; mSupportsDXT3Textures = false;
...@@ -389,6 +390,16 @@ void Context::markAllStateDirty() ...@@ -389,6 +390,16 @@ void Context::markAllStateDirty()
mCachedCurrentProgram = NULL; mCachedCurrentProgram = NULL;
} }
void Context::markContextLost()
{
mContextLost = true;
}
bool Context::isContextLost()
{
return mContextLost;
}
void Context::setClearColor(float red, float green, float blue, float alpha) void Context::setClearColor(float red, float green, float blue, float alpha)
{ {
mState.colorClearValue.red = red; mState.colorClearValue.red = red;
......
...@@ -266,6 +266,9 @@ class Context ...@@ -266,6 +266,9 @@ class Context
void markAllStateDirty(); void markAllStateDirty();
virtual void markContextLost();
bool isContextLost();
// State manipulation // State manipulation
void setClearColor(float red, float green, float blue, float alpha); void setClearColor(float red, float green, float blue, float alpha);
...@@ -531,7 +534,9 @@ class Context ...@@ -531,7 +534,9 @@ class Context
bool mOutOfMemory; bool mOutOfMemory;
bool mInvalidFramebufferOperation; bool mInvalidFramebufferOperation;
// Current/lost context flags
bool mHasBeenCurrent; bool mHasBeenCurrent;
bool mContextLost;
unsigned int mAppliedTextureSerialPS[MAX_TEXTURE_IMAGE_UNITS]; unsigned int mAppliedTextureSerialPS[MAX_TEXTURE_IMAGE_UNITS];
unsigned int mAppliedTextureSerialVS[MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF]; unsigned int mAppliedTextureSerialVS[MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF];
......
...@@ -114,6 +114,8 @@ bool checkDeviceLost(HRESULT errorCode) ...@@ -114,6 +114,8 @@ bool checkDeviceLost(HRESULT errorCode)
if (isDeviceLostError(errorCode)) if (isDeviceLostError(errorCode))
{ {
display = gl::getDisplay();
display->notifyDeviceLost();
return true; return true;
} }
return false; return false;
......
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