Browse Source

Fix ALT-TAB problem by saving each graphics buffer into the gsg and releasing the previously non-managed surfaces.

aignacio_sf 19 years ago
parent
commit
626136548f

+ 22 - 0
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -61,6 +61,7 @@
 #include "pStatTimer.h"
 #include "pStatTimer.h"
 #include "pStatCollector.h"
 #include "pStatCollector.h"
 #include "dxgsg8base.h"
 #include "dxgsg8base.h"
+#include "wdxGraphicsBuffer8.h"
 
 
 #include <mmsystem.h>
 #include <mmsystem.h>
 
 
@@ -3437,6 +3438,27 @@ reset_d3d_device(D3DPRESENT_PARAMETERS *presentation_params,
     Thread *current_thread = Thread::get_current_thread();
     Thread *current_thread = Thread::get_current_thread();
     _prepared_objects->begin_frame(this, current_thread);
     _prepared_objects->begin_frame(this, current_thread);
 
 
+    // release graphics buffer surfaces
+    {
+      wdxGraphicsBuffer8 *graphics_buffer;
+      list <wdxGraphicsBuffer8 *>::iterator graphics_buffer_iterator;
+
+      for (graphics_buffer_iterator = _graphics_buffer_list.begin( ); graphics_buffer_iterator != _graphics_buffer_list.end( ); graphics_buffer_iterator++)
+      {
+        graphics_buffer = (*graphics_buffer_iterator);
+        if (graphics_buffer -> _color_backing_store)
+        {
+          graphics_buffer -> _color_backing_store -> Release ( );
+          graphics_buffer -> _color_backing_store = 0;
+        }
+        if (graphics_buffer -> _depth_backing_store)
+        {
+          graphics_buffer -> _depth_backing_store -> Release ( );
+          graphics_buffer -> _depth_backing_store = 0;
+        }
+      }
+    }
+
     hr = _d3d_device->Reset(&_presentation_reset);
     hr = _d3d_device->Reset(&_presentation_reset);
     if (FAILED(hr)) {
     if (FAILED(hr)) {
       return hr;
       return hr;

+ 2 - 0
panda/src/dxgsg8/dxGraphicsStateGuardian8.h

@@ -242,6 +242,8 @@ protected:
   static unsigned char *_temp_buffer;
   static unsigned char *_temp_buffer;
   static unsigned char *_safe_buffer_start;
   static unsigned char *_safe_buffer_start;
 
 
+  list <wdxGraphicsBuffer8 *> _graphics_buffer_list;
+
 public:
 public:
   virtual TypeHandle get_type() const {
   virtual TypeHandle get_type() const {
     return get_class_type();
     return get_class_type();

+ 16 - 0
panda/src/dxgsg8/wdxGraphicsBuffer8.cxx

@@ -61,6 +61,14 @@ wdxGraphicsBuffer8(GraphicsPipe *pipe,
   // Since the pbuffer never gets flipped, we get screenshots from the
   // Since the pbuffer never gets flipped, we get screenshots from the
   // same buffer we draw into.
   // same buffer we draw into.
   _screenshot_buffer_type = _draw_buffer_type;
   _screenshot_buffer_type = _draw_buffer_type;
+
+  if (_gsg) {
+    // save to GSG list to handle device lost issues
+    DXGraphicsStateGuardian8 *dxgsg;
+
+    dxgsg = DCAST (DXGraphicsStateGuardian8, _gsg);
+    dxgsg -> _graphics_buffer_list.push_back(this);
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -71,6 +79,14 @@ wdxGraphicsBuffer8(GraphicsPipe *pipe,
 wdxGraphicsBuffer8::
 wdxGraphicsBuffer8::
 ~wdxGraphicsBuffer8() {
 ~wdxGraphicsBuffer8() {
   this -> close_buffer ( );
   this -> close_buffer ( );
+
+  if (_gsg) {
+    // remove from GSG list
+    DXGraphicsStateGuardian8 *dxgsg;
+
+    dxgsg = DCAST (DXGraphicsStateGuardian8, _gsg);
+    dxgsg -> _graphics_buffer_list.remove(this);
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 31 - 2
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -60,6 +60,7 @@
 #include "dxIndexBufferContext9.h"
 #include "dxIndexBufferContext9.h"
 #include "pStatTimer.h"
 #include "pStatTimer.h"
 #include "pStatCollector.h"
 #include "pStatCollector.h"
+#include "wdxGraphicsBuffer9.h"
 
 
 #include <mmsystem.h>
 #include <mmsystem.h>
 
 
@@ -150,7 +151,6 @@ DXGraphicsStateGuardian9(GraphicsPipe *pipe) :
 #ifdef HAVE_CGDX9
 #ifdef HAVE_CGDX9
   _cg_context = 0;
   _cg_context = 0;
 #endif
 #endif
-
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -4554,6 +4554,27 @@ reset_d3d_device(D3DPRESENT_PARAMETERS *presentation_params,
     Thread *current_thread = Thread::get_current_thread();
     Thread *current_thread = Thread::get_current_thread();
     _prepared_objects->begin_frame(this, current_thread);
     _prepared_objects->begin_frame(this, current_thread);
 
 
+    // release graphics buffer surfaces
+    {
+      wdxGraphicsBuffer9 *graphics_buffer;
+      list <wdxGraphicsBuffer9 *>::iterator graphics_buffer_iterator;
+
+      for (graphics_buffer_iterator = _graphics_buffer_list.begin( ); graphics_buffer_iterator != _graphics_buffer_list.end( ); graphics_buffer_iterator++)
+      {
+        graphics_buffer = (*graphics_buffer_iterator);
+        if (graphics_buffer -> _color_backing_store)
+        {
+          graphics_buffer -> _color_backing_store -> Release ( );
+          graphics_buffer -> _color_backing_store = 0;
+        }
+        if (graphics_buffer -> _depth_backing_store)
+        {
+          graphics_buffer -> _depth_backing_store -> Release ( );
+          graphics_buffer -> _depth_backing_store = 0;
+        }
+      }
+    }
+
     hr = _d3d_device->Reset(&_presentation_reset);
     hr = _d3d_device->Reset(&_presentation_reset);
     if (FAILED(hr)) {
     if (FAILED(hr)) {
       return hr;
       return hr;
@@ -4659,6 +4680,15 @@ show_frame() {
 
 
 DBG_S dxgsg9_cat.debug ( ) << "- - - - - DXGraphicsStateGuardian9::show_frame\n"; DBG_E
 DBG_S dxgsg9_cat.debug ( ) << "- - - - - DXGraphicsStateGuardian9::show_frame\n"; DBG_E
 
 
+  // DEBUG
+  /*
+    EXPCL_DTOOL void reset_memory_stats (void);
+    EXPCL_DTOOL void print_memory_stats (void);
+
+    print_memory_stats ( );
+    reset_memory_stats ( );
+
  */
+
   HRESULT hr;
   HRESULT hr;
 
 
   if (_swap_chain) {
   if (_swap_chain) {
@@ -5299,4 +5329,3 @@ calc_fb_properties(DWORD cformat, DWORD dformat,
   }
   }
   return props;
   return props;
 }
 }
-

+ 3 - 1
panda/src/dxgsg9/dxGraphicsStateGuardian9.h

@@ -82,7 +82,7 @@ public:
   ~DXGraphicsStateGuardian9();
   ~DXGraphicsStateGuardian9();
 
 
   FrameBufferProperties
   FrameBufferProperties
-    calc_fb_properties(DWORD cformat, DWORD dformat, 
+    calc_fb_properties(DWORD cformat, DWORD dformat,
                        DWORD multisampletype, DWORD multisamplequality);
                        DWORD multisampletype, DWORD multisamplequality);
 
 
   virtual TextureContext *prepare_texture(Texture *tex);
   virtual TextureContext *prepare_texture(Texture *tex);
@@ -355,6 +355,8 @@ protected:
 
 
   bool _supports_stream_offset;
   bool _supports_stream_offset;
 
 
+  list <wdxGraphicsBuffer9 *> _graphics_buffer_list;
+
 public:
 public:
   virtual TypeHandle get_type() const {
   virtual TypeHandle get_type() const {
     return get_class_type();
     return get_class_type();

+ 16 - 8
panda/src/dxgsg9/wdxGraphicsBuffer9.cxx

@@ -21,14 +21,6 @@
 #include "dxGraphicsStateGuardian9.h"
 #include "dxGraphicsStateGuardian9.h"
 #include "pStatTimer.h"
 #include "pStatTimer.h"
 
 
-// ISSUES:
-  // render to texure format
-    // can be specified via the DXGraphicsStateGuardian8 member
-    // _render_to_texture_d3d_format  default = D3DFMT_X8R8G8B8
-
-  // should check texture creation with CheckDepthStencilMatch
-  // support copy from texture to ram?
-    // check D3DCAPS2_DYNAMICTEXTURES
 
 
 #define FL << "\n" << __FILE__ << " " << __LINE__ << "\n"
 #define FL << "\n" << __FILE__ << " " << __LINE__ << "\n"
 
 
@@ -61,6 +53,14 @@ wdxGraphicsBuffer9(GraphicsPipe *pipe,
   // Since the pbuffer never gets flipped, we get screenshots from the
   // Since the pbuffer never gets flipped, we get screenshots from the
   // same buffer we draw into.
   // same buffer we draw into.
   _screenshot_buffer_type = _draw_buffer_type;
   _screenshot_buffer_type = _draw_buffer_type;
+
+  if (_gsg) {
+    // save to GSG list to handle device lost issues
+    DXGraphicsStateGuardian9 *dxgsg;
+
+    dxgsg = DCAST (DXGraphicsStateGuardian9, _gsg);
+    dxgsg -> _graphics_buffer_list.push_back(this);
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -71,6 +71,14 @@ wdxGraphicsBuffer9(GraphicsPipe *pipe,
 wdxGraphicsBuffer9::
 wdxGraphicsBuffer9::
 ~wdxGraphicsBuffer9() {
 ~wdxGraphicsBuffer9() {
   this -> close_buffer ( );
   this -> close_buffer ( );
+
+  if (_gsg) {
+    // remove from GSG list
+    DXGraphicsStateGuardian9 *dxgsg;
+
+    dxgsg = DCAST (DXGraphicsStateGuardian9, _gsg);
+    dxgsg -> _graphics_buffer_list.remove(this);
+  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////