1 /* 2 (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org) 3 (c) Copyright 2000-2004 Convergence (integrated media) GmbH 4 5 All rights reserved. 6 7 Written by Denis Oliver Kropp <dok@directfb.org>, 8 Andreas Hundt <andi@fischlustig.de>, 9 Sven Neumann <neo@directfb.org>, 10 Ville Syrjälä <syrjala@sci.fi> and 11 Claudio Ciccani <klan@users.sf.net>. 12 13 This library is free software; you can redistribute it and/or 14 modify it under the terms of the GNU Lesser General Public 15 License as published by the Free Software Foundation; either 16 version 2 of the License, or (at your option) any later version. 17 18 This library is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 Lesser General Public License for more details. 22 23 You should have received a copy of the GNU Lesser General Public 24 License along with this library; if not, write to the 25 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 26 Boston, MA 02111-1307, USA. 27 */ 28 29 #ifndef __SURFACEMANAGER_H__ 30 #define __SURFACEMANAGER_H__ 31 32 #include <directfb.h> 33 34 #include <core/coretypes.h> 35 36 typedef struct _SurfaceManager SurfaceManager; 37 typedef struct _Chunk Chunk; 38 39 /* 40 * initially there is one big free chunk, 41 * chunks are splitted into a free and an occupied chunk if memory is allocated, 42 * two chunks are merged to one free chunk if memory is deallocated 43 */ 44 struct _Chunk { 45 int magic; 46 47 int offset; /* offset in memory, 48 is greater or equal to the heap offset */ 49 int length; /* length of this chunk in bytes */ 50 51 int pitch; 52 53 CoreSurfaceBuffer *buffer; /* pointer to surface buffer occupying 54 this chunk, or NULL if chunk is free */ 55 CoreSurfaceAllocation *allocation; 56 57 int tolerations; /* number of times this chunk was scanned 58 occupied, resetted in assure_video */ 59 60 Chunk *prev; 61 Chunk *next; 62 }; 63 64 struct _SurfaceManager { 65 int magic; 66 67 FusionSHMPoolShared *shmpool; 68 69 Chunk *chunks; 70 71 int offset; 72 int length; /* length of the heap in bytes */ 73 int avail; /* amount of available memory in bytes */ 74 75 int min_toleration; 76 77 bool suspended; 78 }; 79 80 81 DFBResult dfb_surfacemanager_create ( CoreDFB *core, 82 unsigned int length, 83 SurfaceManager **ret_manager ); 84 85 void dfb_surfacemanager_destroy( SurfaceManager *manager ); 86 87 /* 88 * finds and allocates one for the surface or fails, 89 * after success the video health is CSH_RESTORE. 90 * NOTE: this does not notify the listeners 91 */ 92 DFBResult dfb_surfacemanager_allocate( CoreDFB *core, 93 SurfaceManager *manager, 94 CoreSurfaceBuffer *buffer, 95 CoreSurfaceAllocation *allocation, 96 Chunk **ret_chunk ); 97 98 DFBResult dfb_surfacemanager_displace( CoreDFB *core, 99 SurfaceManager *manager, 100 CoreSurfaceBuffer *buffer ); 101 102 /* 103 * sets the video health to CSH_INVALID frees the chunk and 104 * notifies the listeners 105 */ 106 DFBResult dfb_surfacemanager_deallocate( SurfaceManager *manager, 107 Chunk *chunk ); 108 109 #endif 110 111