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