The null system avoids dependency on a particular system (like fbdev, devmem, 
etc...)
when you're writing a gfxdriver for relaying on proprietary interfaces, which 
can't be
exposed in an opensource project.
The behavior of this system is to answer "no" to any memory allocation request, 
so the
requests are redirected to the gfxdriver which implements its own allocation 
system.

Signed-off-by: Lionel Landwerlin <llandwer...@gmail.com>
---
 configure.in                     |   68 +++++++-----
 src/core/system.h                |    7 +-
 src/misc/conf.c                  |   12 +-
 systems/Makefile.am              |   10 ++-
 systems/null/Makefile.am         |   38 +++++++
 systems/null/null.c              |  187 +++++++++++++++++++++++++++++++++
 systems/null/null.h              |   14 +++
 systems/null/null_surface_pool.c |  211 ++++++++++++++++++++++++++++++++++++++
 systems/null/surfacemanager.c    |   97 +++++++++++++++++
 systems/null/surfacemanager.h    |   52 +++++++++
 10 files changed, 656 insertions(+), 40 deletions(-)
 create mode 100644 systems/null/Makefile.am
 create mode 100644 systems/null/null.c
 create mode 100644 systems/null/null.h
 create mode 100644 systems/null/null_surface_pool.c
 create mode 100644 systems/null/surfacemanager.c
 create mode 100644 systems/null/surfacemanager.h

diff --git a/configure.in b/configure.in
index 9c5877b..a0d1255 100644
--- a/configure.in
+++ b/configure.in
@@ -565,6 +565,14 @@ fi

 AM_CONDITIONAL(BUILDMMX, test "$enable_mmx" = "yes")

+dnl Test for Null system
+AC_ARG_ENABLE(null,
+  [  --enable-null             build with generic null support 
[[default=yes]]],,
+  enable_null=yes)
+
+AM_CONDITIONAL(NULL_CORE, test "$enable_null" = "yes")
+
+

 dnl Test for DevMem system
 AC_ARG_ENABLE(devmem,
@@ -1610,6 +1618,7 @@ src/windows/Makefile
 systems/Makefile
 systems/devmem/Makefile
 systems/fbdev/Makefile
+systems/null/Makefile
 systems/x11/Makefile
 systems/osx/Makefile
 systems/sdl/Makefile
@@ -1729,6 +1738,7 @@ Building Tools              $with_tools
 Building System Modules:
   Linux FBDev support       $enable_fbdev
   Generic /dev/mem support  $enable_devmem
+  Generic null support      $enable_null
   X11 support               $enable_x11                 $X11_CFLAGS    
$X11_LIBS
   OSX support               $enable_osx                 $OSX_CFLAGS    
$OSX_LIBS
   SDL support               $enable_sdl                 $SDL_CFLAGS    
$SDL_LIBS
diff --git a/src/core/system.h b/src/core/system.h
index f6d4df1..fe5e02f 100644
--- a/src/core/system.h
+++ b/src/core/system.h
@@ -45,5 +45,6 @@ typedef enum {
      CORE_SDL,
      CORE_VNC,
      CORE_DEVMEM,
-     CORE_TI_CMEM
+     CORE_TI_CMEM,
+     CORE_NULL
 } CoreSystemType;

 typedef enum {
diff --git a/src/misc/conf.c b/src/misc/conf.c
index 2c882a9..987a808 100644
--- a/src/misc/conf.c
+++ b/src/misc/conf.c
@@ -140,7 +140,7 @@ static const char *config_usage =
      "  video-length=<bytes>           Length of video memory (devmem 
system)\n"
      "  mmio-phys=<hexaddress>         Physical start of MMIO area (devmem 
system)\n"
      "  mmio-length=<bytes>            Length of MMIO area (devmem system)\n"
-     "  accelerator=<id>               Accelerator ID selecting graphics 
driver (devmem system)\n"
+     "  accelerator=<id>               Accelerator ID selecting graphics 
driver (devmem/null system)\n"
      "\n"
      "  [no-]matrox-sgram              Use Matrox SGRAM features\n"
      "  [no-]matrox-crtc2              Experimental Matrox CRTC2 support\n"
diff --git a/systems/Makefile.am b/systems/Makefile.am
index 4137b44..b853ed9 100644
--- a/systems/Makefile.am
+++ b/systems/Makefile.am
@@ -36,5 +36,11 @@ else
 VNC_DIR =
 endif
   
+if NULL_CORE
+NULL_DIR = null
+else
+NULL_DIR =
+endif
+
+SUBDIRS = $(DEVMEM_DIR) $(FBDEV_DIR) $(X11_DIR) $(SDL_DIR) $(OSX_DIR) 
$(VNC_DIR) $(NULL_DIR)
 
-SUBDIRS = $(DEVMEM_DIR) $(FBDEV_DIR) $(X11_DIR) $(SDL_DIR) $(OSX_DIR) 
$(VNC_DIR)
diff --git a/systems/null/Makefile.am b/systems/null/Makefile.am
new file mode 100644
index 0000000..a72a5b1
--- /dev/null
+++ b/systems/null/Makefile.am
@@ -0,0 +1,38 @@
+## Makefile.am for DirectFB/systems/null
+
+INCLUDES = \
+       -I$(top_srcdir)/include         \
+       -I$(top_builddir)/include       \
+       -I$(top_builddir)/lib           \
+       -I$(top_srcdir)/lib             \
+       -I$(top_srcdir)/src
+
+
+internalincludedir = $(INTERNALINCLUDEDIR)/null
+
+internalinclude_HEADERS = \
+       surfacemanager.h
+
+
+systemsdir = $(MODULEDIR)/systems
+
+if BUILD_STATIC
+systems_DATA = libdirectfb_null.o
+endif
+systems_LTLIBRARIES = libdirectfb_null.la
+
+libdirectfb_null_la_LDFLAGS = \
+       -avoid-version  \
+       -module
+
+libdirectfb_null_la_SOURCES = \
+       null.c \
+       surfacemanager.c \
+       null_surface_pool.c
+
+libdirectfb_null_la_LIBADD = \
+       $(top_builddir)/lib/direct/libdirect.la \
+       $(top_builddir)/src/libdirectfb.la
+
+
+include $(top_srcdir)/rules/libobject.make
diff --git a/systems/null/null.c b/systems/null/null.c
new file mode 100644
index 0000000..3b7e7c5
--- /dev/null
+++ b/systems/null/null.c
@@ -0,0 +1,187 @@
+/*
+   (c) Copyright 2009  The world wide DirectFB Open Source Community 
(directfb.org)
+
+   All rights reserved.
+
+   Written by Lionel Landwerlin <llandwer...@gmail.com>.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the
+   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include <directfb.h>
+
+#include <direct/mem.h>
+
+#include <fusion/arena.h>
+#include <fusion/shmalloc.h>
+
+#include <core/core.h>
+#include <core/surface_pool.h>
+
+#include <misc/conf.h>
+
+#include <core/core_system.h>
+
+#include "null.h"
+
+DFB_CORE_SYSTEM( null )
+
+static void
+system_get_info( CoreSystemInfo *info )
+{
+     info->type = CORE_NULL;
+     info->caps = CSCAPS_ACCELERATION;
+
+     snprintf( info->name, DFB_CORE_SYSTEM_INFO_NAME_LENGTH, "Null" );
+}
+
+static DFBResult
+system_initialize( CoreDFB *core, void **ret_data )
+{
+     dfb_surface_pool_initialize( core, &nullSurfacePoolFuncs, ret_data );
+
+     return DFB_OK;
+}
+
+static DFBResult
+system_join( CoreDFB *core, void **ret_data )
+{
+     dfb_surface_pool_join( core, *ret_data, &nullSurfacePoolFuncs );
+
+     return DFB_OK;
+}
+
+static DFBResult
+system_shutdown( bool emergency )
+{
+     return DFB_OK;
+}
+
+static DFBResult
+system_leave( bool emergency )
+{
+     return DFB_OK;
+}
+
+static DFBResult
+system_suspend( void )
+{
+     return DFB_OK;
+}
+
+static DFBResult
+system_resume( void )
+{
+     return DFB_OK;
+}
+
+static volatile void *
+system_map_mmio( unsigned int    offset,
+                 int             length )
+{
+     return 0;
+}
+
+static void
+system_unmap_mmio( volatile void  *addr,
+                   int             length )
+{
+}
+
+static int
+system_get_accelerator( void )
+{
+     return dfb_config->accelerator;
+}
+
+static VideoMode *
+system_get_modes( void )
+{
+     return NULL;
+}
+
+static VideoMode *
+system_get_current_mode( void )
+{
+     return NULL;
+}
+
+static DFBResult
+system_thread_init( void )
+{
+     return DFB_OK;
+}
+
+static bool
+system_input_filter( CoreInputDevice *device,
+                     DFBInputEvent   *event )
+{
+     return false;
+}
+
+static unsigned long
+system_video_memory_physical( unsigned int offset )
+{
+     return 0;
+}
+
+static void *
+system_video_memory_virtual( unsigned int offset )
+{
+     return 0;
+}
+
+static unsigned int
+system_videoram_length( void )
+{
+     return 0;
+}
+
+static unsigned long
+system_aux_memory_physical( unsigned int offset )
+{
+     return 0;
+}
+
+static void *
+system_aux_memory_virtual( unsigned int offset )
+{
+     return NULL;
+}
+
+static unsigned int
+system_auxram_length( void )
+{
+     return 0;
+}
+
+static void
+system_get_busid( int *ret_bus, int *ret_dev, int *ret_func )
+{
+     return;
+}
+
+static void
+system_get_deviceid( unsigned int *ret_vendor_id,
+                     unsigned int *ret_device_id )
+{
+     return;
+}
diff --git a/systems/null/null.h b/systems/null/null.h
new file mode 100644
index 0000000..b32154b
--- /dev/null
+++ b/systems/null/null.h
@@ -0,0 +1,14 @@
+#ifndef __NULL_H__
+#define __NULL_H__
+
+#include <core/surface_pool.h>
+
+typedef struct {
+     void                *mem;
+     volatile void       *reg;
+} NullData;
+
+
+extern const SurfacePoolFuncs nullSurfacePoolFuncs;
+
+#endif /* __NULL_H__ */
diff --git a/systems/null/null_surface_pool.c b/systems/null/null_surface_pool.c
new file mode 100644
index 0000000..db31bc4
--- /dev/null
+++ b/systems/null/null_surface_pool.c
@@ -0,0 +1,211 @@
+/*
+  (c) Copyright 2009  The world wide DirectFB Open Source Community 
(directfb.org)
+
+  All rights reserved.
+
+  Written by Lionel Landwerlin <llandwer...@gmail.com>.
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the
+  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+  Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+
+#include <direct/debug.h>
+#include <direct/mem.h>
+
+#include <core/surface_pool.h>
+
+#include <gfx/convert.h>
+
+#include <misc/conf.h>
+
+#include "null.h"
+#include "surfacemanager.h"
+
+D_DEBUG_DOMAIN( Null_Surfaces, "Null/Surfaces", "Null Framebuffer Surface 
Pool" );
+D_DEBUG_DOMAIN( Null_SurfLock, "Null/SurfLock", "Null Framebuffer Surface Pool 
Locks" );
+
+/**********************************************************************************************************************/
+
+static int
+nullPoolDataSize( void )
+{
+     return 0;
+}
+
+static int
+nullPoolLocalDataSize( void )
+{
+     return 0;
+}
+
+static int
+nullAllocationDataSize( void )
+{
+     return 0;
+}
+
+static DFBResult
+nullInitPool( CoreDFB                    *core,
+              CoreSurfacePool            *pool,
+              void                       *pool_data,
+              void                       *pool_local,
+              void                       *system_data,
+              CoreSurfacePoolDescription *ret_desc )
+{
+     D_DEBUG_AT( Null_Surfaces, "%s()\n", __FUNCTION__ );
+
+     D_ASSERT( core != NULL );
+     D_MAGIC_ASSERT( pool, CoreSurfacePool );
+     D_ASSERT( ret_desc != NULL );
+
+     ret_desc->caps              = CSPCAPS_PHYSICAL | CSPCAPS_VIRTUAL;
+     ret_desc->access[CSAID_CPU] = CSAF_READ | CSAF_WRITE | CSAF_SHARED;
+     ret_desc->access[CSAID_GPU] = CSAF_READ | CSAF_WRITE | CSAF_SHARED;
+     ret_desc->types             = CSTF_LAYER | CSTF_WINDOW | CSTF_CURSOR | 
CSTF_FONT | CSTF_SHARED | CSTF_EXTERNAL;
+     ret_desc->priority          = CSPP_DEFAULT;
+     ret_desc->size              = dfb_config->video_length;
+
+     /* For hardware layers */
+     ret_desc->access[CSAID_LAYER0] = CSAF_READ;
+     ret_desc->access[CSAID_LAYER1] = CSAF_READ;
+     ret_desc->access[CSAID_LAYER2] = CSAF_READ;
+     ret_desc->access[CSAID_LAYER3] = CSAF_READ;
+     ret_desc->access[CSAID_LAYER4] = CSAF_READ;
+     ret_desc->access[CSAID_LAYER5] = CSAF_READ;
+     ret_desc->access[CSAID_LAYER6] = CSAF_READ;
+     ret_desc->access[CSAID_LAYER7] = CSAF_READ;
+
+     snprintf( ret_desc->name, DFB_SURFACE_POOL_DESC_NAME_LENGTH, "/dev/null" 
);
+
+     return DFB_OK;
+}
+
+static DFBResult
+nullJoinPool( CoreDFB                    *core,
+              CoreSurfacePool            *pool,
+              void                       *pool_data,
+              void                       *pool_local,
+              void                       *system_data )
+{
+     D_DEBUG_AT( Null_Surfaces, "%s()\n", __FUNCTION__ );
+
+     D_ASSERT( core != NULL );
+     D_MAGIC_ASSERT( pool, CoreSurfacePool );
+
+     return DFB_OK;
+}
+
+static DFBResult
+nullDestroyPool( CoreSurfacePool *pool,
+                 void            *pool_data,
+                 void            *pool_local )
+{
+     D_DEBUG_AT( Null_Surfaces, "%s()\n", __FUNCTION__ );
+
+     D_MAGIC_ASSERT( pool, CoreSurfacePool );
+
+     return DFB_OK;
+}
+
+static DFBResult
+nullLeavePool( CoreSurfacePool *pool,
+               void            *pool_data,
+               void            *pool_local )
+{
+     D_DEBUG_AT( Null_Surfaces, "%s()\n", __FUNCTION__ );
+
+     D_MAGIC_ASSERT( pool, CoreSurfacePool );
+
+     return DFB_OK;
+}
+
+static DFBResult
+nullTestConfig( CoreSurfacePool         *pool,
+                void                    *pool_data,
+                void                    *pool_local,
+                CoreSurfaceBuffer       *buffer,
+                const CoreSurfaceConfig *config )
+{
+     D_DEBUG_AT( Null_Surfaces, "%s( %p )\n", __FUNCTION__, buffer );
+
+     D_MAGIC_ASSERT( pool, CoreSurfacePool );
+     D_MAGIC_ASSERT( buffer, CoreSurfaceBuffer );
+
+     return DFB_UNSUPPORTED;
+}
+
+static DFBResult
+nullAllocateBuffer( CoreSurfacePool       *pool,
+                    void                  *pool_data,
+                    void                  *pool_local,
+                    CoreSurfaceBuffer     *buffer,
+                    CoreSurfaceAllocation *allocation,
+                    void                  *alloc_data )
+{
+     return DFB_NOVIDEOMEMORY;
+}
+
+static DFBResult
+nullDeallocateBuffer( CoreSurfacePool       *pool,
+                      void                  *pool_data,
+                      void                  *pool_local,
+                      CoreSurfaceBuffer     *buffer,
+                      CoreSurfaceAllocation *allocation,
+                      void                  *alloc_data )
+{
+     return DFB_UNSUPPORTED;
+}
+
+static DFBResult
+nullLock( CoreSurfacePool       *pool,
+          void                  *pool_data,
+          void                  *pool_local,
+          CoreSurfaceAllocation *allocation,
+          void                  *alloc_data,
+          CoreSurfaceBufferLock *lock )
+{
+     return DFB_UNSUPPORTED;
+}
+
+static DFBResult
+nullUnlock( CoreSurfacePool       *pool,
+            void                  *pool_data,
+            void                  *pool_local,
+            CoreSurfaceAllocation *allocation,
+            void                  *alloc_data,
+            CoreSurfaceBufferLock *lock )
+{
+     return DFB_UNSUPPORTED;
+}
+
+const SurfacePoolFuncs nullSurfacePoolFuncs = {
+     .PoolDataSize       = nullPoolDataSize,
+     .PoolLocalDataSize  = nullPoolLocalDataSize,
+     .AllocationDataSize = nullAllocationDataSize,
+
+     .InitPool           = nullInitPool,
+     .JoinPool           = nullJoinPool,
+     .DestroyPool        = nullDestroyPool,
+     .LeavePool          = nullLeavePool,
+
+     .TestConfig         = nullTestConfig,
+     .AllocateBuffer     = nullAllocateBuffer,
+     .DeallocateBuffer   = nullDeallocateBuffer,
+
+     .Lock               = nullLock,
+     .Unlock             = nullUnlock,
+};
diff --git a/systems/null/surfacemanager.c b/systems/null/surfacemanager.c
new file mode 100644
index 0000000..3f86021
--- /dev/null
+++ b/systems/null/surfacemanager.c
@@ -0,0 +1,97 @@
+/*
+   (c) Copyright 2009  The world wide DirectFB Open Source Community 
(directfb.org)
+
+   All rights reserved.
+
+   Written by Lionel Landwerlin <llandwer...@gmail.com>.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the
+   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+
+#include <fusion/shmalloc.h>
+
+#include <directfb.h>
+#include <directfb_util.h>
+
+#include <core/core.h>
+
+#include <core/gfxcard.h>
+#include <core/surface.h>
+#include <core/surface_buffer.h>
+
+#include <direct/debug.h>
+#include <direct/messages.h>
+#include <direct/util.h>
+
+#include <gfx/convert.h>
+
+#include "surfacemanager.h"
+
+D_DEBUG_DOMAIN( SurfMan, "SurfaceManager", "DirectFB Surface Manager" );
+
+DFBResult
+dfb_surfacemanager_create( CoreDFB       *core,
+                           unsigned int   length,
+                           void         **ret_manager )
+{
+     D_DEBUG_AT( SurfMan, "%s( %p, %d )\n", __FUNCTION__, core, length );
+
+     D_ASSERT( core != NULL );
+
+     return DFB_NOSHAREDMEMORY;
+}
+
+void
+dfb_surfacemanager_destroy( void *manager )
+{
+     D_DEBUG_AT( SurfMan, "%s( %p )\n", __FUNCTION__, manager );
+}
+
+/** public functions NOT locking the surfacemanger theirself,
+    to be called between lock/unlock of surfacemanager **/
+
+DFBResult dfb_surfacemanager_allocate( CoreDFB               *core,
+                                       void                  *manager,
+                                       CoreSurfaceBuffer     *buffer,
+                                       CoreSurfaceAllocation *allocation,
+                                       void                  **ret_chunk )
+{
+     D_DEBUG_AT( SurfMan, "%s( %p, %p, %p, %p, %p )\n", __FUNCTION__,
+                 core, manager, buffer, allocation, ret_chunk );
+
+     return DFB_NOVIDEOMEMORY; /* Sorry Bro... */
+}
+
+DFBResult dfb_surfacemanager_displace( CoreDFB           *core,
+                                       void              *manager,
+                                       CoreSurfaceBuffer *buffer )
+{
+     D_DEBUG_AT( SurfMan, "%s( %p, %p, %p )\n", __FUNCTION__,
+                 core, manager, buffer );
+
+     return DFB_NOVIDEOMEMORY;
+}
+
+DFBResult dfb_surfacemanager_deallocate( void *manager,
+                                         void *chunk )
+{
+     D_DEBUG_AT( SurfMan, "%s( %p, %p )\n", __FUNCTION__,
+                 manager, chunk );
+
+     return DFB_UNSUPPORTED;
+}
diff --git a/systems/null/surfacemanager.h b/systems/null/surfacemanager.h
new file mode 100644
index 0000000..5a38743
--- /dev/null
+++ b/systems/null/surfacemanager.h
@@ -0,0 +1,52 @@
+/*
+   (c) Copyright 2009  The world wide DirectFB Open Source Community 
(directfb.org)
+
+   All rights reserved.
+
+   Written by Lionel Landwerlin <llandwer...@gmail.com>.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the
+   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+*/
+
+#ifndef __SURFACEMANAGER_H__
+#define __SURFACEMANAGER_H__
+
+#include <directfb.h>
+
+#include <core/coretypes.h>
+
+
+DFBResult dfb_surfacemanager_create ( CoreDFB       *core,
+                                      unsigned int   length,
+                                      void         **ret_manager );
+
+void      dfb_surfacemanager_destroy( void *manager );
+
+DFBResult dfb_surfacemanager_allocate( CoreDFB               *core,
+                                       void                  *manager,
+                                       CoreSurfaceBuffer     *buffer,
+                                       CoreSurfaceAllocation *allocation,
+                                       void                  **ret_chunk );
+
+DFBResult dfb_surfacemanager_displace( CoreDFB           *core,
+                                       void              *manager,
+                                       CoreSurfaceBuffer *buffer );
+
+DFBResult dfb_surfacemanager_deallocate( void *manager,
+                                         void *chunk );
+
+#endif
+
--
1.6.5.7



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

Reply via email to