Two new callbacks are added to GraphicsDeviceFuncs, that if set, will be
called whenever a state is created or destroyed. This allows a graphics
driver to store custom state specific data in CardState, which is useful
if e.g. extra data needs to be preserved between calls to CheckState() and
SetState().
---
 src/core/gfxcard.c |   36 ++++++++++++++++++++++++++++++++++++
 src/core/gfxcard.h |    8 ++++++++
 src/core/state.c   |    6 ++++++
 src/core/state.h   |    2 ++
 4 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/src/core/gfxcard.c b/src/core/gfxcard.c
index 58cc260..12d06b4 100644
--- a/src/core/gfxcard.c
+++ b/src/core/gfxcard.c
@@ -918,6 +918,42 @@ dfb_gfxcard_state_release( CardState *state )
      Core_PopIdentity();
 }
 
+void
+dfb_gfxcard_state_init ( CardState *state )
+{
+     D_MAGIC_ASSERT( state, CardState );
+
+     if (dfb_config->software_only)
+          return;
+
+     if (card) {
+          D_ASSERT( card != NULL );
+          D_ASSERT( card->shared != NULL );
+
+          if (card->funcs.StateInit)
+               card->funcs.StateInit( card->driver_data, card->device_data,
+                                      state );
+     }
+}
+
+void
+dfb_gfxcard_state_destroy ( CardState *state )
+{
+     D_MAGIC_ASSERT( state, CardState );
+
+     if (dfb_config->software_only)
+          return;
+
+     if (card) {
+          D_ASSERT( card != NULL );
+          D_ASSERT( card->shared != NULL );
+
+          if (card->funcs.StateDestroy)
+               card->funcs.StateDestroy( card->driver_data, card->device_data,
+                                         state );
+     }
+}
+
 /** DRAWING FUNCTIONS **/
 
 #define DFB_TRANSFORM(x, y, m, affine) \
diff --git a/src/core/gfxcard.h b/src/core/gfxcard.h
index f7de485..1cb391d 100644
--- a/src/core/gfxcard.h
+++ b/src/core/gfxcard.h
@@ -304,6 +304,11 @@ typedef struct _GraphicsDeviceFuncs {
      bool (*BatchFill)( void *driver_data, void *device_data,
                         const DFBRectangle *rects,
                         unsigned int num, unsigned int *ret_num );
+
+     /* callbacks when a state is created or destroyed. This allows a graphics
+        driver to hold additional state. */
+     void (*StateInit)   ( void *driver_data, void *device_data, CardState 
*state );
+     void (*StateDestroy)( void *driver_data, void *device_data, CardState 
*state );
 } GraphicsDeviceFuncs;
 
 typedef struct {
@@ -343,6 +348,9 @@ void dfb_gfxcard_unlock( void );
 
 bool dfb_gfxcard_state_check( CardState *state, DFBAccelerationMask accel );
 
+void dfb_gfxcard_state_init( CardState *state );
+void dfb_gfxcard_state_destroy( CardState *state );
+
 /*
  * Signal beginning of a sequence of operations using this state.
  * Any number of states can be 'drawing'.
diff --git a/src/core/state.c b/src/core/state.c
index 8853160..e683b22 100644
--- a/src/core/state.c
+++ b/src/core/state.c
@@ -145,6 +145,9 @@ dfb_state_init( CardState *state, CoreDFB *core )
 
      D_MAGIC_SET( state, CardState );
 
+     state->gfxcard_data = NULL;
+     dfb_gfxcard_state_init( state );
+
      return 0;
 }
 
@@ -160,6 +163,9 @@ dfb_state_destroy( CardState *state )
      D_ASSERT( state->source2 == NULL );
      D_ASSERT( state->source_mask == NULL );
 
+     dfb_gfxcard_state_destroy( state );
+     state->gfxcard_data = NULL;
+
      D_MAGIC_CLEAR( state );
 
      direct_serial_deinit( &state->dst_serial );
diff --git a/src/core/state.h b/src/core/state.h
index e64ad7d..730bf6f 100644
--- a/src/core/state.h
+++ b/src/core/state.h
@@ -208,6 +208,8 @@ struct _CardState {
      s32                      src_colormatrix[12];     /* transformation 
matrix for DSBLIT_SRC_COLORMATRIX (fixed 16.16) */
 
      DFBConvolutionFilter     src_convolution;
+
+     void                    *gfxcard_data; /* gfx driver specific state data 
*/
 };
 
 int  dfb_state_init( CardState *state, CoreDFB *core );
-- 
1.7.5.4

_______________________________________________
directfb-dev mailing list
directfb-dev@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev

Reply via email to