Jonathan Gordon | db658d9 | 2010-06-17 08:36:28 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id: skin_buffer.c 25962 2010-05-12 09:31:40Z jdgordon $ |
| 9 | * |
| 10 | * Copyright (C) 2002 by Linus Nielsen Feltzing |
| 11 | * Copyright (C) 2009 Jonathan Gordon |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License |
| 15 | * as published by the Free Software Foundation; either version 2 |
| 16 | * of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 | * KIND, either express or implied. |
| 20 | * |
| 21 | ****************************************************************************/ |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <string.h> |
| 25 | #include <stdlib.h> |
| 26 | |
| 27 | #ifdef ROCKBOX |
| 28 | #define SKIN_BUFFER_SIZE (400*1024) /* Excessivly large for now */ |
| 29 | static unsigned char buffer[SKIN_BUFFER_SIZE]; |
| 30 | static unsigned char *buffer_front = NULL; /* start of the free space, |
| 31 | increases with allocation*/ |
Jonathan Gordon | db658d9 | 2010-06-17 08:36:28 +0000 | [diff] [blame] | 32 | #endif |
| 33 | |
Björn Stenberg | f1a144a | 2010-06-17 11:04:32 +0000 | [diff] [blame] | 34 | void skin_buffer_init(void) |
Jonathan Gordon | db658d9 | 2010-06-17 08:36:28 +0000 | [diff] [blame] | 35 | { |
Björn Stenberg | f1a144a | 2010-06-17 11:04:32 +0000 | [diff] [blame] | 36 | #if defined(ROCKBOX) |
Jonathan Gordon | db658d9 | 2010-06-17 08:36:28 +0000 | [diff] [blame] | 37 | { |
| 38 | /* reset the buffer.... */ |
| 39 | buffer_front = buffer; |
| 40 | //TODO: buf_size = size; |
| 41 | } |
| 42 | #endif |
| 43 | } |
| 44 | |
| 45 | /* Allocate size bytes from the buffer */ |
| 46 | void* skin_buffer_alloc(size_t size) |
| 47 | { |
| 48 | void *retval = NULL; |
| 49 | #ifdef ROCKBOX |
| 50 | retval = buffer_front; |
| 51 | buffer_front += size; |
| 52 | /* 32-bit aligned */ |
| 53 | buffer_front = (void *)(((unsigned long)buffer_front + 3) & ~3); |
| 54 | #else |
| 55 | retval = malloc(size); |
| 56 | #endif |
| 57 | return retval; |
| 58 | } |
Jonathan Gordon | 95b0cef | 2010-06-17 13:54:09 +0000 | [diff] [blame] | 59 | |
| 60 | |
| 61 | #ifdef ROCKBOX |
| 62 | /* get the number of bytes currently being used */ |
| 63 | size_t skin_buffer_usage(void) |
| 64 | { |
| 65 | return buffer_front - buffer; |
| 66 | } |
| 67 | size_t skin_buffer_freespace(void) |
| 68 | { |
| 69 | return SKIN_BUFFER_SIZE - skin_buffer_usage(); |
| 70 | } |
| 71 | #endif |