Bug 596489 - Part 2: Expose when a device manager is removed. r=jrmuizel
authorBas Schouten <bschouten@mozilla.com>
Wed, 15 Sep 2010 22:15:59 +0000
changeset 53981 70e0e08ed6dd9999757dde540f607a73422622ff
parent 53980 a38c033e298bd3d9620ed1af1a5c18988d5b1a2d
child 53982 20f4616058da7db583c16c41b30892dc5509afa4
push idunknown
push userunknown
push dateunknown
reviewersjrmuizel
bugs596489
milestone2.0b7pre
Bug 596489 - Part 2: Expose when a device manager is removed. r=jrmuizel
gfx/layers/d3d9/DeviceManagerD3D9.cpp
gfx/layers/d3d9/DeviceManagerD3D9.h
--- a/gfx/layers/d3d9/DeviceManagerD3D9.cpp
+++ b/gfx/layers/d3d9/DeviceManagerD3D9.cpp
@@ -176,16 +176,17 @@ SwapChainD3D9::Reset()
   mSwapChain = nsnull;
 }
 
 #define HAS_CAP(a, b) (((a) & (b)) == (b))
 #define LACKS_CAP(a, b) !(((a) & (b)) == (b))
 
 DeviceManagerD3D9::DeviceManagerD3D9()
   : mHasDynamicTextures(false)
+  , mDeviceWasRemoved(false)
 {
 }
 
 DeviceManagerD3D9::~DeviceManagerD3D9()
 {
   LayerManagerD3D9::OnDeviceManagerDestroy(this);
 }
 
@@ -487,42 +488,44 @@ DeviceManagerD3D9::SetShaderMode(ShaderM
 bool
 DeviceManagerD3D9::VerifyReadyForRendering()
 {
   HRESULT hr = mDevice->TestCooperativeLevel();
 
   if (SUCCEEDED(hr)) {
     if (IsD3D9Ex()) {
       hr = mDeviceEx->CheckDeviceState(mFocusWnd);
+
+      if (hr == D3DERR_DEVICEREMOVED) {
+        mDeviceWasRemoved = true;
+        LayerManagerD3D9::OnDeviceManagerDestroy(this);
+        return false;
+      }
+
       if (FAILED(hr)) {
         D3DPRESENT_PARAMETERS pp;
         memset(&pp, 0, sizeof(D3DPRESENT_PARAMETERS));
 
         pp.BackBufferWidth = 1;
         pp.BackBufferHeight = 1;
         pp.BackBufferFormat = D3DFMT_A8R8G8B8;
         pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
         pp.Windowed = TRUE;
         pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
         pp.hDeviceWindow = mFocusWnd;
         
         hr = mDeviceEx->ResetEx(&pp, NULL);
-        // Handle D3DERR_DEVICEREMOVED!
         if (FAILED(hr)) {
           return false;
         }
       }
     }
     return true;
   }
 
-  if (hr != D3DERR_DEVICENOTRESET) {
-    return false;
-  }
-
   for(unsigned int i = 0; i < mLayersWithResources.Length(); i++) {
     mLayersWithResources[i]->CleanResources();
   }
   for(unsigned int i = 0; i < mSwapChains.Length(); i++) {
     mSwapChains[i]->Reset();
   }
   
   D3DPRESENT_PARAMETERS pp;
@@ -533,17 +536,23 @@ DeviceManagerD3D9::VerifyReadyForRenderi
   pp.BackBufferFormat = D3DFMT_A8R8G8B8;
   pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
   pp.Windowed = TRUE;
   pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
   pp.hDeviceWindow = mFocusWnd;
 
   hr = mDevice->Reset(&pp);
 
+  if (hr == D3DERR_DEVICELOST) {
+    return false;
+  }
+
   if (FAILED(hr)) {
+    mDeviceWasRemoved = true;
+    LayerManagerD3D9::OnDeviceManagerDestroy(this);
     return false;
   }
 
   return true;
 }
 
 bool
 DeviceManagerD3D9::VerifyCaps()
--- a/gfx/layers/d3d9/DeviceManagerD3D9.h
+++ b/gfx/layers/d3d9/DeviceManagerD3D9.h
@@ -138,17 +138,22 @@ public:
     SOLIDCOLORLAYER
   };
 
   void SetShaderMode(ShaderMode aMode);
 
   /** 
    * Return pointer to the Nv3DVUtils instance 
    */ 
-  Nv3DVUtils *GetNv3DVUtils()  { return mNv3DVUtils; } 
+  Nv3DVUtils *GetNv3DVUtils()  { return mNv3DVUtils; }
+
+  /**
+   * Returns true if this device was removed.
+   */
+  bool DeviceWasRemoved() { return mDeviceWasRemoved; }
 
   /**
    * We keep a list of all layers here that may have hardware resource allocated
    * so we can clean their resources on reset.
    */
   nsTArray<LayerD3D9*> mLayersWithResources;
 private:
   friend class SwapChainD3D9;
@@ -201,16 +206,19 @@ private:
   /* Our focus window - this is really a dummy window we can associate our
    * device with.
    */
   HWND mFocusWnd;
 
   /* If this device supports dynamic textures */
   bool mHasDynamicTextures;
 
+  /* If this device was removed */
+  bool mDeviceWasRemoved;
+
   /* Nv3DVUtils instance */ 
   nsAutoPtr<Nv3DVUtils> mNv3DVUtils; 
 
   /**
    * Verifies all required device capabilities are present.
    */
   bool VerifyCaps();
 };