Bug 586279 - Broken DeviceManagerD3D9.h compilation on mingw r=bas.schouten a=joe
authorJacek Caban <jacek@codeweavers.com>
Sat, 14 Aug 2010 16:43:14 +0200
changeset 50600 8da350429494759d535df5271d81c0940fdfdd3a
parent 50599 f544ad24c9d3b1fac441c20f42561aec1735c117
child 50601 5761fb5b379fe032921fdd222cc8be4168238dd2
push idunknown
push userunknown
push dateunknown
reviewersbas, joe
bugs586279
milestone2.0b4pre
Bug 586279 - Broken DeviceManagerD3D9.h compilation on mingw r=bas.schouten a=joe
gfx/layers/d3d9/DeviceManagerD3D9.cpp
gfx/layers/d3d9/DeviceManagerD3D9.h
gfx/layers/d3d9/LayerManagerD3D9.cpp
gfx/layers/d3d9/LayerManagerD3D9.h
--- a/gfx/layers/d3d9/DeviceManagerD3D9.cpp
+++ b/gfx/layers/d3d9/DeviceManagerD3D9.cpp
@@ -177,16 +177,21 @@ SwapChainD3D9::Reset()
 #define HAS_CAP(a, b) (((a) & (b)) == (b))
 #define LACKS_CAP(a, b) !(((a) & (b)) == (b))
 
 DeviceManagerD3D9::DeviceManagerD3D9()
   : mHasDynamicTextures(false)
 {
 }
 
+DeviceManagerD3D9::~DeviceManagerD3D9()
+{
+  LayerManagerD3D9::OnDeviceManagerDestroy(this);
+}
+
 bool
 DeviceManagerD3D9::Init()
 {
   WNDCLASSW wc;
   HRESULT hr;
 
   if (!GetClassInfoW(GetModuleHandle(NULL), kClassName, &wc)) {
       ZeroMemory(&wc, sizeof(WNDCLASSW));
--- a/gfx/layers/d3d9/DeviceManagerD3D9.h
+++ b/gfx/layers/d3d9/DeviceManagerD3D9.h
@@ -101,19 +101,17 @@ private:
  * device and create swap chains for the individual windows the layer managers
  * belong to.
  */
 class THEBES_API DeviceManagerD3D9
 {
 public:
   DeviceManagerD3D9();
 
-  // We want the nsrefcnt return value. So we cannot use the inline refcnt macro
-  NS_IMPL_ADDREF(DeviceManagerD3D9)
-  NS_IMPL_RELEASE(DeviceManagerD3D9)
+  NS_INLINE_DECL_REFCOUNTING(DeviceManagerD3D9)
 
   bool Init();
 
   /**
    * Sets up the render state for the device for layer rendering.
    */
   void SetupRenderState();
 
@@ -139,16 +137,18 @@ public:
   /**
    * We keep a list of all thebes layers since we need their D3DPOOL_DEFAULT
    * surfaces to be released when we want to reset the device.
    */
   nsTArray<ThebesLayerD3D9*> mThebesLayers;
 private:
   friend class SwapChainD3D9;
 
+  ~DeviceManagerD3D9();
+
   /**
    * This function verifies the device is ready for rendering, internally this
    * will test the cooperative level of the device and reset the device if
    * needed. If this returns false subsequent rendering calls may return errors.
    */
   bool VerifyReadyForRendering();
 
   /* Array used to store all swap chains for device resets */
@@ -187,19 +187,16 @@ 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;
 
-  nsAutoRefCnt mRefCnt;
-  NS_DECL_OWNINGTHREAD
-
   /**
    * Verifies all required device capabilities are present.
    */
   bool VerifyCaps();
 };
 
 } /* namespace layers */
 } /* namespace mozilla */
--- a/gfx/layers/d3d9/LayerManagerD3D9.cpp
+++ b/gfx/layers/d3d9/LayerManagerD3D9.cpp
@@ -58,19 +58,17 @@ LayerManagerD3D9::LayerManagerD3D9(nsIWi
 LayerManagerD3D9::~LayerManagerD3D9()
 {
   /* Important to release this first since it also holds a reference to the
    * device manager
    */
   mSwapChain = nsnull;
 
   if (mDeviceManager) {
-    if (!mDeviceManager->Release()) {
-      mDeviceManager = nsnull;
-    }
+    mDeviceManager->Release();
   }
 }
 
 PRBool
 LayerManagerD3D9::Initialize()
 {
   if (!mDeviceManager) {
     mDeviceManager = new DeviceManagerD3D9;
--- a/gfx/layers/d3d9/LayerManagerD3D9.h
+++ b/gfx/layers/d3d9/LayerManagerD3D9.h
@@ -125,16 +125,21 @@ public:
   void SetClippingEnabled(PRBool aEnabled);
 
   void SetShaderMode(DeviceManagerD3D9::ShaderMode aMode)
     { mDeviceManager->SetShaderMode(aMode); }
 
   IDirect3DDevice9 *device() const { return mDeviceManager->device(); }
   DeviceManagerD3D9 *deviceManager() const { return mDeviceManager; }
 
+  static void OnDeviceManagerDestroy(DeviceManagerD3D9 *aDeviceManager) {
+    if(aDeviceManager == mDeviceManager)
+      mDeviceManager = nsnull;
+  }
+
 private:
   /* Device manager instance */
   static DeviceManagerD3D9 *mDeviceManager;
 
   /* Swap chain associated with this layer manager */
   nsRefPtr<SwapChainD3D9> mSwapChain;
 
   /* Widget associated with this layer manager */