From b5b7d1053fff161a1ed58bf4c10d798e42dd8942 Mon Sep 17 00:00:00 2001
From: Timothy Strelchun <Timothy.Strelchun@Intel.Com>
Date: Mon, 21 Jun 2010 21:22:07 -0700
Subject: [PATCH] Added systems driver specific shared surface data structure

Added a systems driver specific shared surface data structure
that is created/destroyed by the core.  Added three new functions
to the systems driver to do this: system_surface_data_size,
system_surface_data_init, and system_surface_data_destroy.  This
allows the systems driver to store custom data in the
CoreSurface.
---
 src/core/core_system.h  |   14 +++++++++++++-
 src/core/surface.c      |   35 ++++++++++++++++++++++++++++++++++-
 src/core/surface.h      |    2 ++
 src/core/system.c       |   28 +++++++++++++++++++++++++++-
 src/core/system.h       |   26 +++++++++++++++++++++++++-
 systems/devmem/devmem.c |   23 ++++++++++++++++++++++-
 systems/fbdev/fbdev.c   |   21 ++++++++++++++++++++-
 systems/osx/osx.c       |   23 ++++++++++++++++++++++-
 systems/sdl/sdl.c       |   23 ++++++++++++++++++++++-
 systems/vnc/vnc.c       |   23 ++++++++++++++++++++++-
 systems/x11/x11.c       |   21 ++++++++++++++++++++-
 11 files changed, 229 insertions(+), 10 deletions(-)

diff --git a/src/core/core_system.h b/src/core/core_system.h
index dfa2abc..1ea857a 100644
--- a/src/core/core_system.h
+++ b/src/core/core_system.h
@@ -1,5 +1,5 @@
 /*
-   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
+   (c) Copyright 2001-2010  The world wide DirectFB Open Source Community (directfb.org)
    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
 
    All rights reserved.
@@ -100,6 +100,15 @@ system_get_busid( int *ret_bus, int *ret_dev, int *ret_func );
 static void
 system_get_deviceid( unsigned int *ret_vendor_id, unsigned int *ret_device_id );
 
+static int
+system_surface_data_size( void );
+
+static void
+system_surface_data_init( CoreSurface *surface, void *data );
+
+static void
+system_surface_data_destroy( CoreSurface *surface, void *data );
+
 
 static CoreSystemFuncs system_funcs = {
      .GetSystemInfo       = system_get_info,
@@ -123,6 +132,9 @@ static CoreSystemFuncs system_funcs = {
      .AuxMemoryVirtual    = system_aux_memory_virtual,
      .AuxRamLength        = system_auxram_length,
      .GetBusID            = system_get_busid,
+     .SurfaceDataSize     = system_surface_data_size,
+     .SurfaceDataInit     = system_surface_data_init,
+     .SurfaceDataDestroy  = system_surface_data_destroy,
      .GetDeviceID         = system_get_deviceid
 };
 
diff --git a/src/core/surface.c b/src/core/surface.c
index 87c10fd..a06858d 100644
--- a/src/core/surface.c
+++ b/src/core/surface.c
@@ -1,5 +1,5 @@
 /*
-   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
+   (c) Copyright 2001-2010  The world wide DirectFB Open Source Community (directfb.org)
    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
 
    All rights reserved.
@@ -34,6 +34,9 @@
 #include <core/palette.h>
 #include <core/surface.h>
 
+#include <core/system.h>
+#include <fusion/shmalloc.h>
+
 #include <core/layers_internal.h>
 #include <core/windows_internal.h>
 
@@ -80,6 +83,14 @@ surface_destructor( FusionObject *object, bool zombie, void *ctx )
                dfb_surface_buffer_destroy( surface->buffers[i] );
      }
 
+     dfb_system_surface_data_destroy( surface, surface->data );
+
+     /* release the system driver specific surface data */
+     if (surface->data) {
+          SHFREE( surface->shmpool, surface->data );
+          surface->data = NULL;
+     }
+
      direct_serial_deinit( &surface->serial );
 
      dfb_surface_unlock( surface );
@@ -131,6 +142,8 @@ dfb_surface_create( CoreDFB                  *core,
      if (!surface)
           return DFB_FUSION;
 
+     surface->data = NULL;
+
      if (config) {
           D_FLAGS_ASSERT( config->flags, CSCONF_ALL );
 
@@ -234,6 +247,19 @@ dfb_surface_create( CoreDFB                  *core,
                goto error;
      }
 
+     /* Create the system driver specific surface data information */
+     int data_size = dfb_system_surface_data_size();
+
+     if (data_size) {
+          surface->data = SHCALLOC( surface->shmpool, 1, data_size );
+          if (!surface->data) {    
+              ret = D_OOSHM();
+              goto error;
+          }
+     }
+
+     dfb_system_surface_data_init(surface,surface->data);
+	 
      /* Create the Surface Buffers. */
      for (i=0; i<buffers; i++) {
           CoreSurfaceBuffer *buffer;
@@ -269,6 +295,13 @@ error:
           if (surface->buffers[i])
                dfb_surface_buffer_destroy( surface->buffers[i] );
      }
+	 
+     /* release the system driver specific surface data */
+     if (surface->data) {
+         dfb_system_surface_data_destroy( surface, surface->data );
+         SHFREE( surface->shmpool, surface->data );
+         surface->data = NULL;
+     }
 
      fusion_skirmish_destroy( &surface->lock );
 
diff --git a/src/core/surface.h b/src/core/surface.h
index 426741a..53f29aa 100644
--- a/src/core/surface.h
+++ b/src/core/surface.h
@@ -214,6 +214,8 @@ struct __DFB_CoreSurface
      GlobalReaction           palette_reaction;
 
      FusionSHMPoolShared     *shmpool;
+
+     void                    *data;         /* Shared system driver-specific data for this surface. */
 };
 
 
diff --git a/src/core/system.c b/src/core/system.c
index 6a78eb0..3395d8a 100644
--- a/src/core/system.c
+++ b/src/core/system.c
@@ -1,5 +1,5 @@
 /*
-   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
+   (c) Copyright 2001-2010  The world wide DirectFB Open Source Community (directfb.org)
    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
 
    All rights reserved.
@@ -462,3 +462,29 @@ dfb_system_get_deviceid( unsigned int *ret_vendor_id,
           *ret_device_id = device_id;
 }
 
+int 
+dfb_system_surface_data_size( void )
+{
+     D_ASSERT( system_funcs != NULL );
+     
+     return system_funcs->SurfaceDataSize();
+}
+
+void
+dfb_system_surface_data_init( CoreSurface *surface, void *data )
+{
+     D_ASSERT( surface );
+     D_ASSERT( system_funcs != NULL );
+
+     system_funcs->SurfaceDataInit(surface,data);
+}
+
+void
+dfb_system_surface_data_destroy( CoreSurface *surface, void *data )
+{
+     D_ASSERT( surface );
+     D_ASSERT( system_funcs != NULL );
+
+     system_funcs->SurfaceDataDestroy(surface,data);
+}
+
diff --git a/src/core/system.h b/src/core/system.h
index 8ecc564..476ca40 100644
--- a/src/core/system.h
+++ b/src/core/system.h
@@ -1,5 +1,5 @@
 /*
-   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
+   (c) Copyright 2001-2010  The world wide DirectFB Open Source Community (directfb.org)
    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
 
    All rights reserved.
@@ -189,6 +189,21 @@ typedef struct {
      void           (*GetBusID)( int *ret_bus, int *ret_dev, int *ret_func );
      void           (*GetDeviceID)( unsigned int *ret_vendor_id,
                                     unsigned int *ret_device_id );
+
+     /*
+      * Shared Surface Data Creation/Destruction Functions
+      *
+      * These functions are used to create and destroy the shared CoreSurface
+      * data.  The Init function is called before the surface's buffers are
+      * created.  The Destroy function is called after the surface buffers are
+      * released.  The allocated data is only used by the systems driver.
+      * 
+      * Note: In the init and destroy functions it is legal for the data 
+      *       parameter to be null.
+      */
+     int            (*SurfaceDataSize)( void );
+     void           (*SurfaceDataInit)( CoreSurface *surface, void *data );
+     void           (*SurfaceDataDestroy)( CoreSurface *surface, void *data );
 } CoreSystemFuncs;
 
 
@@ -254,5 +269,14 @@ void
 dfb_system_get_deviceid( unsigned int *ret_vendor_id,
                          unsigned int *ret_device_id );
 
+int 
+dfb_system_surface_data_size( void );
+
+void
+dfb_system_surface_data_init( CoreSurface *surface, void *data );
+
+void
+dfb_system_surface_data_destroy( CoreSurface *surface, void *data );
+
 #endif
 
diff --git a/systems/devmem/devmem.c b/systems/devmem/devmem.c
index 9e77777..dad9fb8 100644
--- a/systems/devmem/devmem.c
+++ b/systems/devmem/devmem.c
@@ -1,5 +1,5 @@
 /*
-   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
+   (c) Copyright 2001-2010  The world wide DirectFB Open Source Community (directfb.org)
    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
 
    All rights reserved.
@@ -365,6 +365,27 @@ system_get_busid( int *ret_bus, int *ret_dev, int *ret_func )
      return;
 }
 
+static int
+system_surface_data_size( void )
+{
+     /* Return zero because shared surface data is unneeded. */
+     return 0;
+}
+
+static void
+system_surface_data_init( CoreSurface *surface, void *data )
+{
+     /* Ignore since unneeded. */
+     return;
+}
+
+static void
+system_surface_data_destroy( CoreSurface *surface, void *data );
+{
+     /* Ignore since unneeded. */
+     return;
+}
+
 static void
 system_get_deviceid( unsigned int *ret_vendor_id,
                      unsigned int *ret_device_id )
diff --git a/systems/fbdev/fbdev.c b/systems/fbdev/fbdev.c
index ebfdf8b..977c468 100644
--- a/systems/fbdev/fbdev.c
+++ b/systems/fbdev/fbdev.c
@@ -1,5 +1,5 @@
 /*
-   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
+   (c) Copyright 2001-2010  The world wide DirectFB Open Source Community (directfb.org)
    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
 
    All rights reserved.
@@ -956,6 +956,25 @@ system_get_busid( int *ret_bus, int *ret_dev, int *ret_func )
      *ret_func = dfb_fbdev->shared->pci.func;
 }
 
+static int
+system_surface_data_size( void )
+{
+     /* Return zero because shared surface data is unneeded. */
+     return 0;
+}
+
+static void
+system_surface_data_init( CoreSurface *surface, void *data )
+{
+     /* Ignore since unneeded. */
+}
+
+static void
+system_surface_data_destroy( CoreSurface *surface, void *data );
+{
+     /* Ignore since unneeded. */
+}
+
 static void
 system_get_deviceid( unsigned int *ret_vendor_id,
                      unsigned int *ret_device_id )
diff --git a/systems/osx/osx.c b/systems/osx/osx.c
index 5d6cfa7..8fdf993 100644
--- a/systems/osx/osx.c
+++ b/systems/osx/osx.c
@@ -1,5 +1,5 @@
 /*
-   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
+   (c) Copyright 2001-2010  The world wide DirectFB Open Source Community (directfb.org)
    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
 
    All rights reserved.
@@ -254,6 +254,27 @@ system_get_busid( int *ret_bus, int *ret_dev, int *ret_func )
      return;
 }
 
+static int
+system_surface_data_size( void )
+{
+     /* Return zero because shared surface data is unneeded. */
+     return 0;
+}
+
+static void
+system_surface_data_init( CoreSurface *surface, void *data )
+{
+     /* Ignore since unneeded. */
+     return;
+}
+
+static void
+system_surface_data_destroy( CoreSurface *surface, void *data );
+{
+     /* Ignore since unneeded. */
+     return;
+}
+
 static void
 system_get_deviceid( unsigned int *ret_vendor_id,
                      unsigned int *ret_device_id )
diff --git a/systems/sdl/sdl.c b/systems/sdl/sdl.c
index 04e2cd8..c2a879d 100644
--- a/systems/sdl/sdl.c
+++ b/systems/sdl/sdl.c
@@ -1,5 +1,5 @@
 /*
-   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
+   (c) Copyright 2001-2010  The world wide DirectFB Open Source Community (directfb.org)
    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
 
    All rights reserved.
@@ -311,6 +311,27 @@ system_get_busid( int *ret_bus, int *ret_dev, int *ret_func )
      return;
 }
 
+static int
+system_surface_data_size( void )
+{
+     /* Return zero because shared surface data is unneeded. */
+     return 0;
+}
+
+static void
+system_surface_data_init( CoreSurface *surface, void *data )
+{
+     /* Ignore since unneeded. */
+     return;
+}
+
+static void
+system_surface_data_destroy( CoreSurface *surface, void *data );
+{
+     /* Ignore since unneeded. */
+     return;
+}
+
 static void
 system_get_deviceid( unsigned int *ret_vendor_id,
                      unsigned int *ret_device_id )
diff --git a/systems/vnc/vnc.c b/systems/vnc/vnc.c
index d37dabd..2ebf3f7 100644
--- a/systems/vnc/vnc.c
+++ b/systems/vnc/vnc.c
@@ -1,5 +1,5 @@
 /*
-   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
+   (c) Copyright 2001-2010  The world wide DirectFB Open Source Community (directfb.org)
    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
 
    All rights reserved.
@@ -255,6 +255,27 @@ system_get_busid( int *ret_bus, int *ret_dev, int *ret_func )
      return;
 }
 
+static int
+system_surface_data_size( void )
+{
+     /* Return zero because shared surface data is unneeded. */
+     return 0;
+}
+
+static void
+system_surface_data_init( CoreSurface *surface, void *data )
+{
+     /* Ignore since unneeded. */
+     return;
+}
+
+static void
+system_surface_data_destroy( CoreSurface *surface, void *data );
+{
+     /* Ignore since unneeded. */
+     return;
+}
+
 static void
 system_get_deviceid( unsigned int *ret_vendor_id,
                      unsigned int *ret_device_id )
diff --git a/systems/x11/x11.c b/systems/x11/x11.c
index a294a4e..4938be4 100644
--- a/systems/x11/x11.c
+++ b/systems/x11/x11.c
@@ -1,5 +1,5 @@
 /*
-   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
+   (c) Copyright 2001-2010  The world wide DirectFB Open Source Community (directfb.org)
    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
 
    All rights reserved.
@@ -557,6 +557,25 @@ system_get_busid( int *ret_bus, int *ret_dev, int *ret_func )
 {
 }
 
+static int
+system_surface_data_size( void )
+{
+     /* Return zero because shared surface data is unneeded. */
+     return 0;
+}
+
+static void
+system_surface_data_init( CoreSurface *surface, void *data )
+{
+     /* Ignore since unneeded. */
+}
+
+static void
+system_surface_data_destroy( CoreSurface *surface, void *data );
+{
+     /* Ignore since unneeded. */
+}
+
 static void
 system_get_deviceid( unsigned int *ret_vendor_id,
                      unsigned int *ret_device_id )
-- 
1.6.1.9.g97c34

